-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddresses.go
117 lines (94 loc) · 2.78 KB
/
addresses.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
package walletapi
// Addresses - gets all the addresses in the wallet container
func (wAPI WalletAPI) Addresses() ([]string, error) {
var addresses []string
resp, _, err := wAPI.sendRequest(
"GET",
wAPI.Host+":"+wAPI.Port+"/addresses",
"",
)
if err == nil {
for _, v := range (*resp)["addresses"].([]interface{}) {
addresses = append(addresses, v.(string))
}
}
return addresses, err
}
// DeleteAddress - deletes a subwallet in the wallet container
func (wAPI WalletAPI) DeleteAddress(address string) error {
_, _, err := wAPI.sendRequest(
"DELETE",
wAPI.Host+":"+wAPI.Port+"/addresses/"+address,
"",
)
return err
}
// PrimaryAddress - gets the primary address in the wallet container
func (wAPI WalletAPI) PrimaryAddress() (string, error) {
resp, _, err := wAPI.sendRequest(
"GET",
wAPI.Host+":"+wAPI.Port+"/addresses/primary",
"",
)
return (*resp)["address"].(string), err
}
// CreateAddress - creates a new random address in the wallet container
func (wAPI WalletAPI) CreateAddress() (map[string]string, error) {
address := make(map[string]string, 3)
resp, _, err := wAPI.sendRequest(
"POST",
wAPI.Host+":"+wAPI.Port+"/addresses/create",
"",
)
if err == nil {
address["address"] = (*resp)["address"].(string)
address["privateSpendKey"] = (*resp)["privateSpendKey"].(string)
address["publicSpendKey"] = (*resp)["publicSpendKey"].(string)
}
return address, err
}
// ImportAddress - import a subwallet with the given private spend key
func (wAPI WalletAPI) ImportAddress(spendKey string, scanHeight uint64) (string, error) {
var address string
resp, _, err := wAPI.sendRequest(
"POST",
wAPI.Host+":"+wAPI.Port+"/addresses/import",
makeJSONString(map[string]interface{}{
"scanHeight": scanHeight,
"privateSpendKey": spendKey,
}),
)
if err == nil {
address = (*resp)["address"].(string)
}
return address, err
}
// ImportViewAddress - import a view only subwallet with the given public spend key
func (wAPI WalletAPI) ImportViewAddress(spendKey string, scanHeight uint64) (string, error) {
var address string
resp, _, err := wAPI.sendRequest(
"POST",
wAPI.Host+":"+wAPI.Port+"/addresses/import/view",
makeJSONString(map[string]interface{}{
"scanHeight": scanHeight,
"publicSpendKey": spendKey,
}),
)
if err == nil {
address = (*resp)["address"].(string)
}
return address, err
}
// CreateIntegratedAddress - creates an integrated address from and address and paymentID
func (wAPI WalletAPI) CreateIntegratedAddress(address, paymentID string) (string, error) {
var integratedAddress string
resp, _, err := wAPI.sendRequest(
"GET",
wAPI.Host+":"+wAPI.Port+"/addresses/"+address+"/"+paymentID,
"",
)
if err == nil {
integratedAddress = (*resp)["integratedAddress"].(string)
}
return integratedAddress, err
}