-
Notifications
You must be signed in to change notification settings - Fork 8
/
transaction.go
96 lines (78 loc) · 3.2 KB
/
transaction.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
package types
import (
"encoding/json"
"fmt"
)
// TransactionRecord Single Transaction
type TransactionRecord struct {
ConfirmedAtHeight uint32 `json:"confirmed_at_height"`
CreatedAtTime uint64 `json:"created_at_time"` // @TODO time.Time?
ToPuzzleHash *PuzzleHash `json:"to_puzzle_hash"`
Amount uint64 `json:"amount"`
FeeAmount uint64 `json:"fee_amount"`
Confirmed bool `json:"confirmed"`
Sent uint32 `json:"sent"`
SpendBundle *SpendBundle `json:"spend_bundle"`
Additions []*Coin `json:"additions"`
Removals []*Coin `json:"removals"`
WalletID uint32 `json:"wallet_id"`
SentTo []*SentTo `json:"sent_to"`
TradeID string `json:"trade_id"`
Type *TransactionType `json:"type"`
Name string `json:"name"` // @TODO bytes32 / hex
// ToAddress is not on the official type, but some endpoints return it anyways
ToAddress *Address `json:"to_address"`
}
// Address Own type for future methods to encode/decode
type Address string
// SentTo Represents the list of peers that we sent the transaction to, whether each one
// included it in the mempool, and what the error message (if any) was
// sent_to: List[Tuple[str, uint8, Optional[str]]]
type SentTo struct {
Peer string
MempoolInclusionStatus *MempoolInclusionStatus
Error *string
}
// UnmarshalJSON unmarshals the SentTo tuple into the struct
func (s *SentTo) UnmarshalJSON(buf []byte) error {
tmp := []interface{}{&s.Peer, &s.MempoolInclusionStatus, &s.Error}
wantLen := len(tmp)
if err := json.Unmarshal(buf, &tmp); err != nil {
return err
}
if g, e := len(tmp), wantLen; g != e {
return fmt.Errorf("wrong number of fields in SentTo: %d != %d", g, e)
}
return nil
}
// MempoolInclusionStatus status of being included in the mempool
type MempoolInclusionStatus uint8
const (
// MempoolInclusionStatusSuccess Successfully added to mempool
MempoolInclusionStatusSuccess MempoolInclusionStatus = 1
// MempoolInclusionStatusPending Pending being added to the mempool
MempoolInclusionStatusPending MempoolInclusionStatus = 2
// MempoolInclusionStatusFailed Failed being added to the mempool
MempoolInclusionStatusFailed MempoolInclusionStatus = 3
)
// TransactionType type of transaction
type TransactionType uint32
const (
// TransactionTypeIncomingTX incoming transaction
TransactionTypeIncomingTX TransactionType = 0
// TransactionTypeOutgoingTX outgoing transaction
TransactionTypeOutgoingTX TransactionType = 1
// TransactionTypeCoinbaseReward coinbase reward
TransactionTypeCoinbaseReward TransactionType = 2
// TransactionTypeFeeReward fee reward
TransactionTypeFeeReward TransactionType = 3
// TransactionTypeIncomingTrade incoming trade
TransactionTypeIncomingTrade TransactionType = 4
// TransactionTypeOutgoingTrade outgoing trade
TransactionTypeOutgoingTrade TransactionType = 5
)
// SpendBundle Spend Bundle...
type SpendBundle struct {
AggregatedSignature string `json:"aggregated_signature"`
CoinSolutions []*CoinSolution `json:"coin_solutions"`
}