-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc_tx.go
49 lines (42 loc) · 1.1 KB
/
rpc_tx.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
package main
import "context"
type RpcTx struct {
TXID string `json:"txid"`
Address string `json:"address"`
Amount int `json:"amount"`
Confirmations int `json:"confirmations"`
Height int `json:"height"`
Timestamp int `json:"timestamp"`
UnlockTime int `json:"unlock_time"`
Type string `json:"type"`
}
func (t *RpcTx) IsIncoming() bool {
validTypes := map[string]int{"in": 1, "pool": 1}
_, ok := validTypes[t.Type]
return ok
}
type RpcResultTransfers struct {
Transfers []RpcTx `json:"transfers"`
}
type GetTransferParams struct {
TXID string `json:"txid"`
}
func NewGetTransferPayload(txid string) RPCRequestPayload {
return RPCRequestPayload{
ID: "0",
JSONRPC: "2.0",
Method: "get_transfer_by_txid",
Params: GetTransferParams{
TXID: txid,
},
}
}
func (c *RPCClient) GetTransferByTxid(ctx context.Context, txid string) ([]RpcTx, error) {
rpcReq := NewGetTransferPayload(txid)
result := RpcResultTransfers{}
err := c.MakeRequest(ctx, rpcReq, &result)
if err != nil {
return nil, err
}
return result.Transfers, nil
}