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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IDE
.idea

# Environment
.env
66 changes: 33 additions & 33 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strconv"
)

//GetAddrBal returns balance information for a given public
//address. Fastest Address API call, but does not
//include transaction details.
// GetAddrBal returns balance information for a given public
// address. Fastest Address API call, but does not
// include transaction details.
func (api *API) GetAddrBal(hash string, params map[string]string) (addr Addr, err error) {
u, err := api.buildURL("/addrs/"+hash+"/balance", params)
if err != nil {
Expand All @@ -17,11 +17,11 @@ func (api *API) GetAddrBal(hash string, params map[string]string) (addr Addr, er
return
}

//GetAddr returns information for a given public
//address, including a slice of confirmed and unconfirmed
//transaction outpus via the TXRef arrays in the Address
//type. Returns more information than GetAddrBal, but
//slightly slower.
// GetAddr returns information for a given public
// address, including a slice of confirmed and unconfirmed
// transaction outpus via the TXRef arrays in the Address
// type. Returns more information than GetAddrBal, but
// slightly slower.
func (api *API) GetAddr(hash string, params map[string]string) (addr Addr, err error) {
u, err := api.buildURL("/addrs/"+hash, params)
if err != nil {
Expand All @@ -31,9 +31,9 @@ func (api *API) GetAddr(hash string, params map[string]string) (addr Addr, err e
return
}

//GetAddrNext returns a given Addr's next page of TXRefs,
//if Addr.HasMore is true. If HasMore is false, will
//return an error. It assumes default API URL parameters.
// GetAddrNext returns a given Addr's next page of TXRefs,
// if Addr.HasMore is true. If HasMore is false, will
// return an error. It assumes default API URL parameters.
func (api *API) GetAddrNext(this Addr) (next Addr, err error) {
if !this.HasMore {
err = errors.New("Func GetAddrNext: this Addr doesn't have more TXRefs according to its HasMore")
Expand All @@ -44,10 +44,10 @@ func (api *API) GetAddrNext(this Addr) (next Addr, err error) {
return
}

//GetAddrFull returns information for a given public
//address, including a slice of TXs associated
//with this address. Returns more data than GetAddr since
//it includes full transactions, but slowest Address query.
// GetAddrFull returns information for a given public
// address, including a slice of TXs associated
// with this address. Returns more data than GetAddr since
// it includes full transactions, but slowest Address query.
func (api *API) GetAddrFull(hash string, params map[string]string) (addr Addr, err error) {
u, err := api.buildURL("/addrs/"+hash+"/full", params)
if err != nil {
Expand All @@ -57,9 +57,9 @@ func (api *API) GetAddrFull(hash string, params map[string]string) (addr Addr, e
return
}

//GetAddrFullNext returns a given Addr's next page of TXs,
//if Addr.HasMore is true. If HasMore is false, will
//return an error. It assumes default API URL parameters, like GetAddrFull.
// GetAddrFullNext returns a given Addr's next page of TXs,
// if Addr.HasMore is true. If HasMore is false, will
// return an error. It assumes default API URL parameters, like GetAddrFull.
func (api *API) GetAddrFullNext(this Addr) (next Addr, err error) {
if !this.HasMore {
err = errors.New("Func GetAddrFullNext: this Addr doesn't have more TXs according to its HasMore")
Expand All @@ -70,24 +70,24 @@ func (api *API) GetAddrFullNext(this Addr) (next Addr, err error) {
return
}

//GenAddrKeychain generates a public/private key pair for use with
//transactions within the specified coin/chain. Please note that
//this call must be made over SSL, and it is not recommended to keep
//large amounts in these addresses, or for very long.
func (api *API) GenAddrKeychain() (pair AddrKeychain, err error) {
u, err := api.buildURL("/addrs", nil)
// GenAddrKeychain generates a public/private key pair for use with
// transactions within the specified coin/chain. Please note that
// this call must be made over SSL, and it is not recommended to keep
// large amounts in these addresses, or for very long.
func (api *API) GenAddrKeychain(params *GenAddrKeychainParams) (pair AddrKeychain, err error) {
u, err := api.buildURL(params.GetURL(), nil)
if err != nil {
return
}
err = postResponse(u, nil, &pair)
return
}

//GenAddrMultisig generates a P2SH multisignature address using an array
//of PubKeys and the ScriptType from a AddrKeychain. Other fields are
//ignored, and the ScriptType must be a "multisig-n-of-m" type. Returns
//an AddrKeychain with the same PubKeys, ScriptType, and the proper
//P2SH address in the AddrKeychain's address field.
// GenAddrMultisig generates a P2SH multisignature address using an array
// of PubKeys and the ScriptType from a AddrKeychain. Other fields are
// ignored, and the ScriptType must be a "multisig-n-of-m" type. Returns
// an AddrKeychain with the same PubKeys, ScriptType, and the proper
// P2SH address in the AddrKeychain's address field.
func (api *API) GenAddrMultisig(multi AddrKeychain) (addr AddrKeychain, err error) {
if len(multi.PubKeys) == 0 || multi.ScriptType == "" {
err = errors.New("GenAddrMultisig: PubKeys or ScriptType are empty.")
Expand All @@ -101,9 +101,9 @@ func (api *API) GenAddrMultisig(multi AddrKeychain) (addr AddrKeychain, err erro
return
}

//Faucet funds the AddrKeychain with an amount. Only works on BlockCypher's
//Testnet and Bitcoin Testnet3. Returns the transaction hash funding
//your AddrKeychain.
// Faucet funds the AddrKeychain with an amount. Only works on BlockCypher's
// Testnet and Bitcoin Testnet3. Returns the transaction hash funding
// your AddrKeychain.
func (api *API) Faucet(a AddrKeychain, amount int) (txhash string, err error) {
if !(api.Coin == "bcy" && api.Chain == "test") && !(api.Coin == "btc" && api.Chain == "test3") {
err = errors.New("Faucet: Cannot use Faucet unless on BlockCypher Testnet or Bitcoin Testnet3.")
Expand All @@ -118,7 +118,7 @@ func (api *API) Faucet(a AddrKeychain, amount int) (txhash string, err error) {
Amount int `json:"amount"`
}
var addr string
//for easy funding/testing of OAPAddresses
// for easy funding/testing of OAPAddresses
if a.OriginalAddress != "" {
addr = a.OriginalAddress
} else {
Expand Down
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/blockcypher/gobcy/v2

go 1.18
go 1.23.0

require github.com/btcsuite/btcd/btcec/v2 v2.3.2

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
15 changes: 8 additions & 7 deletions gobcy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ func TestMain(m *testing.M) {
bcy.Token = "$TOKEN"
//Create/fund the test addresses
var err error
keys1, err = bcy.GenAddrKeychain()
keys1, err = bcy.GenAddrKeychain(NewGenAddrKeychainParams())
if err != nil {
log.Fatal("Error generating test addresses: ", err)
log.Fatal("[Keys1] Error generating test addresses: ", err)
}
keys2, err = bcy.GenAddrKeychain()
keys2, err = bcy.GenAddrKeychain(NewGenAddrKeychainParams().SetBech32())
if err != nil {
log.Fatal("Error generating test addresses: ", err)
log.Fatal("[Keys2] Error generating test addresses: ", err)
}
txhash1, err = bcy.Faucet(keys1, 1e5)
if err != nil {
log.Fatal("Error funding test addresses: ", err)
log.Fatal("[txhash1] Error funding test addresses: ", err)
}
txhash2, err = bcy.Faucet(keys2, 2e5)
if err != nil {
log.Fatal("Error funding test addresses: ", err)
log.Fatal("[txhash2] Error funding test addresses: ", err)
}

os.Exit(m.Run())
}

Expand Down Expand Up @@ -296,7 +297,7 @@ func TestAsset(t *testing.T) {
if err != nil {
t.Error("GenAssetKeychain error encountered: ", err)
}
funder, err := bcy.GenAddrKeychain()
funder, err := bcy.GenAddrKeychain(NewGenAddrKeychainParams())
if err != nil {
t.Error("GenAddrKeychain error encountered: ", err)
}
Expand Down
Loading