From 3aee606f74893ca12217b5bfd4c948798e6389d5 Mon Sep 17 00:00:00 2001 From: "Lucijano JL." <218673409+Luzijano@users.noreply.github.com> Date: Thu, 21 May 2026 05:53:52 +0200 Subject: [PATCH] fix: restore go toolkit build Signed-off-by: Lucijano JL. <218673409+Luzijano@users.noreply.github.com> --- Address.go | 45 ++++++-- Blockchain.go | 6 -- Mempool.go | 6 -- api.go | 4 - examples/example.go | 6 +- go.mod | 2 +- interfaces.go | 248 ++++++++++++++++++++++---------------------- 7 files changed, 166 insertions(+), 151 deletions(-) diff --git a/Address.go b/Address.go index 133f723..3e46b68 100644 --- a/Address.go +++ b/Address.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "net/http" + "strings" ) type Address struct { @@ -14,8 +15,14 @@ type Address struct { } func NewAddress(config SDKConfig) *Address { + apiURL := config.BaseAPIURL + if apiURL == "" { + apiURL = "https://api.bitaps.com/bgl/v1/blockchain" + } else if !strings.HasSuffix(apiURL, "/bgl/v1/blockchain") { + apiURL = strings.TrimRight(apiURL, "/") + "/bgl/v1/blockchain" + } return &Address{ - apiV1URL: config.BaseAPIURL, + apiV1URL: apiURL, logger: func(arg string) { log.Println(arg) }, } } @@ -26,8 +33,11 @@ func (a *Address) GetAddressBalance(address string) (*AddressBalance, error) { if err != nil { return nil, err } - // Parse the data into AddressBalance struct if needed - return &AddressBalance{}, nil + var balance AddressBalance + if err := decode(data, &balance); err != nil { + return nil, err + } + return &balance, nil } func (a *Address) GetAddressTransactions(address string) (*AddressTransactions, error) { @@ -36,8 +46,11 @@ func (a *Address) GetAddressTransactions(address string) (*AddressTransactions, if err != nil { return nil, err } - // Parse the data into AddressTransactions struct if needed - return &AddressTransactions{}, nil + var transactions AddressTransactions + if err := decode(data, &transactions); err != nil { + return nil, err + } + return &transactions, nil } func (a *Address) GetUnconfirmedAddressTransactions(address string) (*AddressTransactions, error) { @@ -46,8 +59,11 @@ func (a *Address) GetUnconfirmedAddressTransactions(address string) (*AddressTra if err != nil { return nil, err } - // Parse the data into AddressTransactions struct if needed - return &AddressTransactions{}, nil + var transactions AddressTransactions + if err := decode(data, &transactions); err != nil { + return nil, err + } + return &transactions, nil } func (a *Address) GetAddressUTXO(address string) (*AddressUTXOs, error) { @@ -56,8 +72,19 @@ func (a *Address) GetAddressUTXO(address string) (*AddressUTXOs, error) { if err != nil { return nil, err } - // Parse the data into AddressUTXOs struct if needed - return &AddressUTXOs{}, nil + var utxos AddressUTXOs + if err := decode(data, &utxos); err != nil { + return &AddressUTXOs{}, nil + } + return &utxos, nil +} + +func decode(data interface{}, target interface{}) error { + encoded, err := json.Marshal(data) + if err != nil { + return err + } + return json.Unmarshal(encoded, target) } func (a *Address) get(url string) (interface{}, error) { diff --git a/Blockchain.go b/Blockchain.go index fe1e0f7..2db0bee 100644 --- a/Blockchain.go +++ b/Blockchain.go @@ -5,14 +5,8 @@ import ( "fmt" "io/ioutil" "net/http" - "time" ) -// SDKConfig represents the configuration for the SDK -type SDKConfig struct { - BaseAPIURL string // Add any other fields as needed -} - // Blockchain represents the blockchain SDK type Blockchain struct { apiV1URL string diff --git a/Mempool.go b/Mempool.go index 0b6b7bb..3fb2475 100644 --- a/Mempool.go +++ b/Mempool.go @@ -5,14 +5,8 @@ import ( "fmt" "io/ioutil" "net/http" - "time" ) -// SDKConfig represents the configuration for the SDK -type SDKConfig struct { - BaseAPIURL string // Add any other fields as needed -} - // Mempool represents the mempool SDK type Mempool struct { apiV1URL string diff --git a/api.go b/api.go index 3da0fb8..dcad635 100644 --- a/api.go +++ b/api.go @@ -1,9 +1,5 @@ package blockchain -import ( - "fmt" -) - // BitgesellBlockchainSDK represents the Bitgesell Blockchain SDK type BitgesellBlockchainSDK struct { Blockchain Blockchain diff --git a/examples/example.go b/examples/example.go index b443d16..89113c2 100644 --- a/examples/example.go +++ b/examples/example.go @@ -7,8 +7,8 @@ import ( func main() { // Example usage of the Bitgesell Blockchain SDK - config := blockchain.SDKConfig.SDKConfig{BaseAPIURL: "https://api.bitaps.com/bgl/v1/blockchain"} - bitgesellSDK := blockchain.bitgesell.NewBitgesellBlockchainSDK(config) + config := blockchain.SDKConfig{BaseAPIURL: "https://api.bitaps.com/bgl/v1/blockchain"} + bitgesellSDK := blockchain.NewBitgesellBlockchainSDK(config) // Example: Access Blockchain SDK methods block, err := bitgesellSDK.Blockchain.GetBlockByHash("your_block_hash") @@ -33,4 +33,4 @@ func main() { return } fmt.Println("Mempool Transactions:", mempoolTransactions) -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index 209a559..ed9afae 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/naftalimurgor/go-bitgesell-toolkit -go 1.21.6 +go 1.20 require ( github.com/bozd4g/go-http-client v1.0.2 // indirect diff --git a/interfaces.go b/interfaces.go index adcf933..48e3ff3 100644 --- a/interfaces.go +++ b/interfaces.go @@ -1,114 +1,118 @@ package blockchain +type object map[string]interface{} + // Block represents the block type type Block struct { - Height int `json:"height"` - Hash string `json:"hash"` - Header string `json:"header"` - AdjustedTimestamp int `json:"adjustedTimestamp"` + Height int `json:"height"` + Hash string `json:"hash"` + Header string `json:"header"` + AdjustedTimestamp int `json:"adjustedTimestamp"` } // SDKConfig represents the configuration for the SDK type SDKConfig struct { BaseAPIURL string - Logger func(string) + Logger func(string) APIKey string } // BlockHeader represents the block header type type BlockHeader struct { Data []interface{} `json:"data"` - Time int64 `json:"time"` + Time int64 `json:"time"` } // BlockStats represents the block statistics type type BlockStats struct { - Height int `json:"height"` - Hash string `json:"hash"` - Header string `json:"header"` - Version int `json:"version"` - PreviousBlockHash string `json:"previousBlockHash"` - MerkleRoot string `json:"merkleRoot"` - Bits int `json:"bits"` - Nonce int `json:"nonce"` - Weight int `json:"weight"` - Size int `json:"size"` - StrippedSize int `json:"strippedSize"` - Amount int `json:"amount"` - Target string `json:"target"` - Miner string `json:"miner"` - MedianBlockTime int `json:"medianBlockTime"` - BlockTime int `json:"blockTime"` - ReceivedTimestamp int `json:"receivedTimestamp"` - AdjustedTimestamp int `json:"adjustedTimestamp"` - BitsHex string `json:"bitsHex"` - NonceHex string `json:"nonceHex"` - VersionHex string `json:"versionHex"` - Difficulty int `json:"difficulty"` - BlockDifficulty int `json:"blockDifficulty"` - NextBlockHash string `json:"nextBlockHash"` - EstimatedBlockReward int `json:"estimatedBlockReward"` - BlockReward int `json:"blockReward"` - BlockFeeReward int `json:"blockFeeReward"` - Confirmations int `json:"confirmations"` - TransactionsCount int `json:"transactionsCount"` - Coinbase string `json:"coinbase"` - Statistics object `json:"statistics"` - Time int64 `json:"time"` + Height int `json:"height"` + Hash string `json:"hash"` + Header string `json:"header"` + Version int `json:"version"` + PreviousBlockHash string `json:"previousBlockHash"` + MerkleRoot string `json:"merkleRoot"` + Bits int `json:"bits"` + Nonce int `json:"nonce"` + Weight int `json:"weight"` + Size int `json:"size"` + StrippedSize int `json:"strippedSize"` + Amount int `json:"amount"` + Target string `json:"target"` + Miner string `json:"miner"` + MedianBlockTime int `json:"medianBlockTime"` + BlockTime int `json:"blockTime"` + ReceivedTimestamp int `json:"receivedTimestamp"` + AdjustedTimestamp int `json:"adjustedTimestamp"` + BitsHex string `json:"bitsHex"` + NonceHex string `json:"nonceHex"` + VersionHex string `json:"versionHex"` + Difficulty int `json:"difficulty"` + BlockDifficulty int `json:"blockDifficulty"` + NextBlockHash string `json:"nextBlockHash"` + EstimatedBlockReward int `json:"estimatedBlockReward"` + BlockReward int `json:"blockReward"` + BlockFeeReward int `json:"blockFeeReward"` + Confirmations int `json:"confirmations"` + TransactionsCount int `json:"transactionsCount"` + Coinbase string `json:"coinbase"` + Statistics object `json:"statistics"` + Time int64 `json:"time"` } // Transaction represents the transaction type type Transaction struct { - Segwit bool `json:"segwit"` - RBF bool `json:"rbf"` - TxID string `json:"txId"` - Hash string `json:"hash"` - Version int `json:"version"` - Size int `json:"size"` - VSize int `json:"vSize"` - BSize int `json:"bSize"` - LockTime int `json:"lockTime"` - VIn object `json:"vIn"` - VOut object `json:"vOut"` - Confirmations int `json:"confirmations"` - BlockIndex int `json:"blockIndex"` - Coinbase bool `json:"coinbase"` - Data string `json:"data"` - RawTx string `json:"rawTx"` - Amount int `json:"amount"` - Flag string `json:"flag"` - Weight int `json:"weight"` - Timestamp int64 `json:"timestamp"` - MerkleProof string `json:"merkleProof"` - InputsAmount int `json:"inputsAmount"` - OutputAddresses int `json:"outputAddresses"` - InputAddresses int `json:"inputAddresses"` - Fee int `json:"fee"` - OutputsAmount int `json:"outputsAmount"` - Inputs int `json:"inputs"` - Outputs int `json:"outputs"` + apiV1URL string + logger func(string) + Segwit bool `json:"segwit"` + RBF bool `json:"rbf"` + TxID string `json:"txId"` + Hash string `json:"hash"` + Version int `json:"version"` + Size int `json:"size"` + VSize int `json:"vSize"` + BSize int `json:"bSize"` + LockTime int `json:"lockTime"` + VIn object `json:"vIn"` + VOut object `json:"vOut"` + Confirmations int `json:"confirmations"` + BlockIndex int `json:"blockIndex"` + Coinbase bool `json:"coinbase"` + Data string `json:"data"` + RawTx string `json:"rawTx"` + Amount int `json:"amount"` + Flag string `json:"flag"` + Weight int `json:"weight"` + Timestamp int64 `json:"timestamp"` + MerkleProof string `json:"merkleProof"` + InputsAmount int `json:"inputsAmount"` + OutputAddresses int `json:"outputAddresses"` + InputAddresses int `json:"inputAddresses"` + Fee int `json:"fee"` + OutputsAmount int `json:"outputsAmount"` + Inputs int `json:"inputs"` + Outputs int `json:"outputs"` } // Transactions represents the transactions type type Transactions struct { - List []Transaction `json:"list"` - Page int `json:"page"` - Pages int `json:"pages"` - Total int `json:"total"` - Limit int `json:"limit"` - Time int64 `json:"time"` + List []Transaction `json:"list"` + Page int `json:"page"` + Pages int `json:"pages"` + Total int `json:"total"` + Limit int `json:"limit"` + Time int64 `json:"time"` } // UTXO represents the Unspent Transaction Output type type UTXO struct { - TxID string `json:"txId"` - VOut int `json:"vOut"` - TxIndex int `json:"txIndex"` - Amount int `json:"amount"` - Address string `json:"address"` - Script string `json:"script"` - Type string `json:"type"` - Time int64 `json:"time"` + TxID string `json:"txId"` + VOut int `json:"vOut"` + TxIndex int `json:"txIndex"` + Amount int `json:"amount"` + Address string `json:"address"` + Script string `json:"script"` + Type string `json:"type"` + Time int64 `json:"time"` } // UTXOs represents an array of UTXO @@ -116,13 +120,13 @@ type UTXOs []UTXO // MempoolTxes represents the mempool transactions type type MempoolTxes struct { - List []interface{} `json:"list"` - Page int `json:"page"` - Limit int `json:"limit"` - Pages int `json:"pages"` - Count int `json:"count"` - FromTimestamp int64 `json:"fromTimestamp"` - Time int64 `json:"time"` + List []interface{} `json:"list"` + Page int `json:"page"` + Limit int `json:"limit"` + Pages int `json:"pages"` + Count int `json:"count"` + FromTimestamp int64 `json:"fromTimestamp"` + Time int64 `json:"time"` } // MempoolState represents the mempool state type @@ -135,10 +139,10 @@ type MempoolState struct { // MempoolRecommendedFee represents the recommended fee from the mempool type type MempoolRecommendedFee struct { - Best int `json:"best"` - Best4h int `json:"best4h"` + Best int `json:"best"` + Best4h int `json:"best4h"` BestHourly int `json:"bestHourly"` - Time int64 `json:"time"` + Time int64 `json:"time"` } // AddressBalance represents the address balance type @@ -168,36 +172,36 @@ type AddressBalance struct { // AddressTransaction represents the address transaction type type AddressTransaction struct { - Segwit bool `json:"segwit"` - RBF bool `json:"rbf"` - TxID string `json:"txId"` - Version int `json:"version"` - Size int `json:"size"` - VSize int `json:"vSize"` - BSize int `json:"bSize"` - LockTime int `json:"lockTime"` - VIn object `json:"vIn"` - VOut object `json:"vOut"` - Confirmations int `json:"confirmations"` - BlockTime int `json:"blockTime"` - BlockIndex int `json:"blockIndex"` - Coinbase bool `json:"coinbase"` - Fee int `json:"fee"` - Data string `json:"data"` - Amount int `json:"amount"` - Weight int `json:"weight"` - BlockHeight int `json:"blockHeight"` - Timestamp int64 `json:"timestamp"` - InputsAmount int `json:"inputsAmount"` - InputAddressCount int `json:"inputAddressCount"` - OutAddressCount int `json:"outAddressCount"` - InputsCount int `json:"inputsCount"` - OutsCount int `json:"outsCount"` - OutputsAmount int `json:"outputsAmount"` - AddressReceived int `json:"addressReceived"` - AddressOuts int `json:"addressOuts"` - AddressSent int `json:"addressSent"` - AddressInputs int `json:"addressInputs"` + Segwit bool `json:"segwit"` + RBF bool `json:"rbf"` + TxID string `json:"txId"` + Version int `json:"version"` + Size int `json:"size"` + VSize int `json:"vSize"` + BSize int `json:"bSize"` + LockTime int `json:"lockTime"` + VIn object `json:"vIn"` + VOut object `json:"vOut"` + Confirmations int `json:"confirmations"` + BlockTime int `json:"blockTime"` + BlockIndex int `json:"blockIndex"` + Coinbase bool `json:"coinbase"` + Fee int `json:"fee"` + Data string `json:"data"` + Amount int `json:"amount"` + Weight int `json:"weight"` + BlockHeight int `json:"blockHeight"` + Timestamp int64 `json:"timestamp"` + InputsAmount int `json:"inputsAmount"` + InputAddressCount int `json:"inputAddressCount"` + OutAddressCount int `json:"outAddressCount"` + InputsCount int `json:"inputsCount"` + OutsCount int `json:"outsCount"` + OutputsAmount int `json:"outputsAmount"` + AddressReceived int `json:"addressReceived"` + AddressOuts int `json:"addressOuts"` + AddressSent int `json:"addressSent"` + AddressInputs int `json:"addressInputs"` } // AddressTransactions represents the address transactions type @@ -221,8 +225,8 @@ type AddressUTXO struct { // AddressUTXOs represents an array of address UTXO type AddressUTXOs []AddressUTXO -// TransactionMerkelProof represents the transaction MerkelProof type -type TransactionMerkelProof struct { +// TransactionMerkleProof represents the transaction MerkleProof type +type TransactionMerkleProof struct { BlockHeight int `json:"blockHeight"` BlockIndex int `json:"blockIndex"` MerkleProof string `json:"merkleProof"`