Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions Address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"net/http"
"strings"
)

type Address struct {
Expand All @@ -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) },
}
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions Blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package blockchain

import (
"fmt"
)

// BitgesellBlockchainSDK represents the Bitgesell Blockchain SDK
type BitgesellBlockchainSDK struct {
Blockchain Blockchain
Expand Down
6 changes: 3 additions & 3 deletions examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -33,4 +33,4 @@ func main() {
return
}
fmt.Println("Mempool Transactions:", mempoolTransactions)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading