-
Notifications
You must be signed in to change notification settings - Fork 13
/
mixinnet_proxy.go
57 lines (45 loc) · 1.19 KB
/
mixinnet_proxy.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
package mixin
import (
"context"
"github.com/go-resty/resty/v2"
)
func (c *Client) callMixinNetRPC(ctx context.Context, method string, params ...interface{}) (*resty.Response, error) {
return c.Request(ctx).
SetBody(map[string]interface{}{
"method": method,
"params": params,
}).Post("/external/proxy")
}
func (c *Client) ReadConsensusInfo(ctx context.Context) (*ConsensusInfo, error) {
r, err := c.callMixinNetRPC(ctx, "getinfo")
if err != nil {
return nil, err
}
var info ConsensusInfo
if err := UnmarshalMixinNetResponse(r, &info); err != nil {
return nil, err
}
return &info, err
}
func (c *Client) SendRawTransaction(ctx context.Context, raw string) (*Hash, error) {
var tx Transaction
r, err := c.callMixinNetRPC(ctx, TxMethodSend, raw)
if err != nil {
return nil, err
}
if err := UnmarshalMixinNetResponse(r, &tx); err != nil {
return nil, err
}
return tx.Hash, nil
}
func (c *Client) GetRawTransaction(ctx context.Context, hash Hash) (*Transaction, error) {
var tx Transaction
r, err := c.callMixinNetRPC(ctx, TxMethodGet, hash)
if err != nil {
return nil, err
}
if err := UnmarshalMixinNetResponse(r, &tx); err != nil {
return nil, err
}
return &tx, nil
}