Adding ListAddresses function #4
9
api.go
9
api.go
|
@ -11,6 +11,7 @@ type Method string
|
|||
const (
|
||||
GetTransaction Method = "gettransaction"
|
||||
|
||||
ZListAddresses = "z_listaddresses"
|
||||
ZListReceivedByAddress = "z_listreceivedbyaddress"
|
||||
ZSendMany = "z_sendmany"
|
||||
ZValidateAddress = "z_validateaddress"
|
||||
|
@ -46,6 +47,14 @@ func NewZValidateAddress(address string) []byte {
|
|||
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
|
||||
func NewZListReceivedByAddress(fromAddress string) []byte {
|
||||
request := setupZcashRequest()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package zcash2cwtch
|
||||
|
||||
import (
|
||||
"cwtch.im/zcash2cwtch"
|
||||
"encoding/json"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||
"git.openprivacy.ca/openprivacy/zcashrpc"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
@ -13,6 +13,20 @@ type ZcashConfig struct {
|
|||
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) {
|
||||
log.SetLevel(log.LevelDebug)
|
||||
configFile, _ := ioutil.ReadFile("config.json")
|
||||
|
|
|
@ -13,8 +13,9 @@ import (
|
|||
|
||||
// ZcashClient defines an interface for any zcash client to present.
|
||||
type ZcashClient interface {
|
||||
ListReceivedTransactionsByAddress(string) ([]ZcashTransaction, error)
|
||||
GetTransaction(string) (Transaction, error)
|
||||
ListAddresses() ([]string, error)
|
||||
ListReceivedTransactionsByAddress(string) ([]ZcashTransaction, error)
|
||||
SendOne(string, string, string, float64) ([]byte, error)
|
||||
ValidateAddress(address string) (ZValidateAddressResponse, error)
|
||||
}
|
||||
|
@ -68,6 +69,17 @@ func (zc *zcashClient) GetTransaction(id string) (Transaction, error) {
|
|||
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
|
||||
func (zc *zcashClient) ListReceivedTransactionsByAddress(address string) ([]ZcashTransaction, error) {
|
||||
body, err := zc.sendRequest(NewZListReceivedByAddress(address))
|
||||
|
|
Loading…
Reference in New Issue