Adding ListAddresses function
This commit is contained in:
parent
f5690fc43d
commit
e9b8ab3b66
9
api.go
9
api.go
|
@ -11,6 +11,7 @@ type Method string
|
||||||
const (
|
const (
|
||||||
GetTransaction Method = "gettransaction"
|
GetTransaction Method = "gettransaction"
|
||||||
|
|
||||||
|
ZListAddresses = "z_listaddresses"
|
||||||
ZListReceivedByAddress = "z_listreceivedbyaddress"
|
ZListReceivedByAddress = "z_listreceivedbyaddress"
|
||||||
ZSendMany = "z_sendmany"
|
ZSendMany = "z_sendmany"
|
||||||
ZValidateAddress = "z_validateaddress"
|
ZValidateAddress = "z_validateaddress"
|
||||||
|
@ -46,6 +47,14 @@ func NewZValidateAddress(address string) []byte {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewZListAddresses constructs a properly formatted z_listaddresses request
|
||||||
|
func NewZListAddresses() []byte {
|
||||||
|
request := setupZcashRequest()
|
||||||
|
request.Method = ZListAddresses
|
||||||
|
data, _ := json.Marshal(request)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
// NewZListReceivedByAddress constructs a properly formatted z_listreceivedbyaddress request
|
// NewZListReceivedByAddress constructs a properly formatted z_listreceivedbyaddress request
|
||||||
func NewZListReceivedByAddress(fromAddress string) []byte {
|
func NewZListReceivedByAddress(fromAddress string) []byte {
|
||||||
request := setupZcashRequest()
|
request := setupZcashRequest()
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package zcash2cwtch
|
package zcash2cwtch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/zcash2cwtch"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
|
"git.openprivacy.ca/openprivacy/zcashrpc"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,20 @@ type ZcashConfig struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListAddresses(t *testing.T) {
|
||||||
|
log.SetLevel(log.LevelDebug)
|
||||||
|
configFile, _ := ioutil.ReadFile("config.json")
|
||||||
|
config := ZcashConfig{}
|
||||||
|
_ = json.Unmarshal(configFile, &config)
|
||||||
|
|
||||||
|
zc := zcashrpc.NewLocalClient(config.Username, config.Password)
|
||||||
|
result, err := zc.ListAddresses()
|
||||||
|
t.Logf("Result: %v %v", result, err)
|
||||||
|
if len(result) == 0 {
|
||||||
|
t.Errorf("Failed to list zaddresses")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewZValidateAddress(t *testing.T) {
|
func TestNewZValidateAddress(t *testing.T) {
|
||||||
log.SetLevel(log.LevelDebug)
|
log.SetLevel(log.LevelDebug)
|
||||||
configFile, _ := ioutil.ReadFile("config.json")
|
configFile, _ := ioutil.ReadFile("config.json")
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
|
|
||||||
// ZcashClient defines an interface for any zcash client to present.
|
// ZcashClient defines an interface for any zcash client to present.
|
||||||
type ZcashClient interface {
|
type ZcashClient interface {
|
||||||
ListReceivedTransactionsByAddress(string) ([]ZcashTransaction, error)
|
|
||||||
GetTransaction(string) (Transaction, error)
|
GetTransaction(string) (Transaction, error)
|
||||||
|
ListAddresses() ([]string, error)
|
||||||
|
ListReceivedTransactionsByAddress(string) ([]ZcashTransaction, error)
|
||||||
SendOne(string, string, string, float64) ([]byte, error)
|
SendOne(string, string, string, float64) ([]byte, error)
|
||||||
ValidateAddress(address string) (ZValidateAddressResponse, error)
|
ValidateAddress(address string) (ZValidateAddressResponse, error)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +69,17 @@ func (zc *zcashClient) GetTransaction(id string) (Transaction, error) {
|
||||||
return transaction, err
|
return transaction, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a list of all the zaddrs in this node’s wallet for which you have a spending key.
|
||||||
|
func (zc *zcashClient) ListAddresses() ([]string, error) {
|
||||||
|
body, err := zc.sendRequest(NewZListAddresses())
|
||||||
|
var addresses []string
|
||||||
|
if err == nil {
|
||||||
|
result := &ZcashResult{Result: &addresses}
|
||||||
|
err = json.Unmarshal(body, &result)
|
||||||
|
}
|
||||||
|
return addresses, err
|
||||||
|
}
|
||||||
|
|
||||||
// ListReceivedTransactionsByAddress returns all the transactions received by a given zcash address
|
// ListReceivedTransactionsByAddress returns all the transactions received by a given zcash address
|
||||||
func (zc *zcashClient) ListReceivedTransactionsByAddress(address string) ([]ZcashTransaction, error) {
|
func (zc *zcashClient) ListReceivedTransactionsByAddress(address string) ([]ZcashTransaction, error) {
|
||||||
body, err := zc.sendRequest(NewZListReceivedByAddress(address))
|
body, err := zc.sendRequest(NewZListReceivedByAddress(address))
|
||||||
|
|
Loading…
Reference in New Issue