-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmethods.go
143 lines (124 loc) · 4.29 KB
/
methods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package electrumrpc
// Version returns the version of Electrum.
func (c *Client) Version() (res string, err error) {
err = c.Call("version", nil, &res)
return
}
// GetAddressBalance returns balance for given address
func (c *Client) GetAddressBalance(address string) (res Balance, err error) {
err = c.Call("getaddressbalance", address, &res)
return
}
// GetBalance return the balance of your wallet.
func (c *Client) GetBalance() (res Balance, err error) {
err = c.Call("getbalance", nil, &res)
return
}
// ValidateAddress check that an address is valid
func (c *Client) ValidateAddress(address string) (res bool, err error) {
err = c.Call("validateaddress", address, &res)
return
}
// GetServers returns the list of available servers
func (c *Client) GetServers() (res map[string]Server, err error) {
err = c.Call("getservers", nil, &res)
return
}
// CreateNewAddress creates a new receiving address, beyond the gap limit of the wallet
func (c *Client) CreateNewAddress() (res string, err error) {
err = c.Call("createnewaddress", nil, &res)
return
}
// GetUnusedAddress returns the first unused address of the wallet, or None if all addresses are used
// An address is considered as used if it has received a transaction, or if it is used in a payment request.
func (c *Client) GetUnusedAddress() (res string, err error) {
err = c.Call("getunusedaddress", nil, &res)
return
}
// IsMine checks if address is in wallet.
// Return true if and only address is in wallet
func (c *Client) IsMine(address string) (res bool, err error) {
err = c.Call("ismine", address, &res)
return
}
// GetTransaction retrieve a transaction by id
func (c *Client) GetTransaction(txid string) (res Transaction, err error) {
err = c.Call("gettransaction", txid, &res)
return
}
// GetSeed returns the generation seed of your wallet
func (c *Client) GetSeed(password string) (res string, err error) {
var pass *string
if len(password) > 0 {
pass = &password
}
// cannot pass empty string, we need to pass nil for none password wallet
err = c.Call("getseed", pass, &res)
return
}
// ListAdddresses returns the list of all addresses in your wallet
// @TODO, support optional arguments to filter the results
func (c *Client) ListAdddresses() (res []string, err error) {
err = c.Call("listaddresses", nil, &res)
return
}
// AddRequest creates a payment request, using the first unused address of the wallet
func (c *Client) AddRequest(amount float64, memo string, expiration uint64) (res PaymentRequest, err error) {
err = c.Call("addrequest", []interface{}{amount, memo, expiration}, &res)
return
}
// ListRequest lists the payment requests you made
func (c *Client) ListRequest(pending, expired, paid bool) (res []PaymentRequest, err error) {
err = c.Call("listrequests", []bool{pending, expired, paid}, &res)
return
}
// RemoveRequest removes a payment request
// Returns true if removal was successful
func (c *Client) RemoveRequest(btcAddress string) (res bool, err error) {
err = c.Call("rmrequest", btcAddress, &res)
return
}
// GetRequest returns a payment request
func (c *Client) GetRequest(btcAddress string) (res PaymentRequest, err error) {
err = c.Call("getrequest", btcAddress, &res)
return
}
// ClearRequests removes all payment requests
func (c *Client) ClearRequests() (err error) {
err = c.Call("clearrequests", nil, nil)
// invalid JSON RPC response
// check if result is null which is valid response
if err != nil && err.Error() == "result is null" {
err = nil
}
return
}
// GetFeeRate returns current suggested fee rate (in sat/kvByte), according to config
// settings or supplied parameters
func (c *Client) GetFeeRate(feeMethod FeeMethod) (res uint64, err error) {
if feeMethod == "" {
err = c.Call("getfeerate", nil, &res)
return
}
err = c.Call("getfeerate", feeMethod, &res)
return
}
// SignMessage signs a message with a key
func (c *Client) SignMessage(btcAddress, message string) (res string, err error) {
req := &SignMessageRequest{
Address: btcAddress,
Message: message,
}
err = c.Call("signmessage", req, &res)
return
}
// VerifyMessage verifies a signature
func (c *Client) VerifyMessage(btcAddress, signature, message string) (res bool, err error) {
req := &VerifyMessageRequest{
Address: btcAddress,
Signature: signature,
Message: message,
}
err = c.Call("verifymessage", req, &res)
return
}