-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
71 lines (59 loc) · 1.68 KB
/
models.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
package main
import "fmt"
type Destination struct {
Amount int `json:"amount"`
Address string `json:"address"`
}
type Tx struct {
TXID string `json:"txid"`
Destinations []Destination `json:"destinations"`
Height int `json:"height"`
Timestamp int `json:"timestamp"`
UnlockTime int `json:"unlock_time"`
Confirmations int `json:"confirmations"`
}
// RpcTxToTx converts the Monero Transaction representation
// returned by the RPC, into the representation that we intend to
// push through NATS
func RpcTxToTx(rpcTxs []RpcTx) (*Tx, error) {
tx := Tx{}
for _, rpcTx := range rpcTxs {
if !rpcTx.IsIncoming() {
continue
}
tx.TXID = rpcTx.TXID
tx.Height = rpcTx.Height
tx.Timestamp = rpcTx.Timestamp
tx.UnlockTime = rpcTx.UnlockTime
tx.Confirmations = rpcTx.Confirmations
dest := Destination{
Amount: rpcTx.Amount,
Address: rpcTx.Address,
}
tx.Destinations = append(tx.Destinations, dest)
}
if tx.TXID == "" || len(tx.Destinations) == 0 {
return nil, fmt.Errorf("Unable to turn RPC result into TX: %+v", rpcTxs)
}
return &tx, nil
}
type Block struct {
Hash string `json:"hash"`
Height int `json:"height"`
Timestamp int `json:"timestamp"`
PrevHashes []string `json:"prev_hashes"`
TxHashes []string `json:"tx_hashes"`
}
func RpcBlockToBlock(b RpcBlock) Block {
prevHashes := []string{}
if b.BlockHeader.PrevHash != "" {
prevHashes = append(prevHashes, b.BlockHeader.PrevHash)
}
return Block{
Hash: b.BlockHeader.Hash,
Height: b.BlockHeader.Height,
Timestamp: b.BlockHeader.Timestamp,
PrevHashes: prevHashes,
TxHashes: b.TxHashes,
}
}