4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "net/url"
7
8
"time"
8
9
)
9
10
@@ -25,6 +26,11 @@ type Address struct {
25
26
UpdatedAt string `json:"updated_at"`
26
27
}
27
28
29
+ type SimpleAddress struct {
30
+ Destination string `json:"destination"`
31
+ Tag string `json:"tag"`
32
+ }
33
+
28
34
func CreateAddress (ctx context.Context , in * AddressInput , user * SafeUser ) (* Address , error ) {
29
35
tipBody := TipBodyForAddressAdd (in .AssetId , in .Destination , in .Tag , in .Label )
30
36
var err error
@@ -159,3 +165,29 @@ func GetAddressesByAssetId(ctx context.Context, assetId string, user *SafeUser)
159
165
}
160
166
return resp .Data , nil
161
167
}
168
+
169
+ func CheckAddress (ctx context.Context , asset , destination , tag string ) (* SimpleAddress , error ) {
170
+ v := url.Values {}
171
+ v .Set ("asset" , asset )
172
+ v .Set ("destination" , destination )
173
+ if tag != "" {
174
+ v .Set ("tag" , tag )
175
+ }
176
+ path := fmt .Sprintf ("/external/addresses/check?" + v .Encode ())
177
+ body , err := Request (ctx , "GET" , path , nil , "" )
178
+ if err != nil {
179
+ return nil , ServerError (ctx , err )
180
+ }
181
+ var resp struct {
182
+ Data * SimpleAddress `json:"data"`
183
+ Error Error `json:"error"`
184
+ }
185
+ err = json .Unmarshal (body , & resp )
186
+ if err != nil {
187
+ return nil , BadDataError (ctx )
188
+ }
189
+ if resp .Error .Code > 0 {
190
+ return nil , resp .Error
191
+ }
192
+ return resp .Data , nil
193
+ }
0 commit comments