-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_record.go
82 lines (70 loc) · 1.75 KB
/
tx_record.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
package types
import (
"crypto"
"errors"
)
const (
// TxStatusFailed is the status code of a transaction if execution failed.
TxStatusFailed TxStatus = 0
// TxStatusSuccessful is the status code of a transaction if execution succeeded.
TxStatusSuccessful TxStatus = 1
)
type (
TxStatus uint64
// TransactionRecord is a transaction order with "server-side" metadata added to it. TransactionRecord is a structure
// that is added to the block.
TransactionRecord struct {
_ struct{} `cbor:",toarray"`
TransactionOrder *TransactionOrder
ServerMetadata *ServerMetadata
}
ServerMetadata struct {
_ struct{} `cbor:",toarray"`
ActualFee uint64
TargetUnits []UnitID
SuccessIndicator TxStatus
ProcessingDetails RawCBOR
}
TxRecordProof struct {
_ struct{} `cbor:",toarray"`
TxRecord *TransactionRecord
TxProof *TxProof
}
)
func (t *TransactionRecord) Hash(algorithm crypto.Hash) []byte {
bytes, err := t.Bytes()
if err != nil {
// TODO
panic(err)
}
hasher := algorithm.New()
hasher.Write(bytes)
return hasher.Sum(nil)
}
func (t *TransactionRecord) Bytes() ([]byte, error) {
return Cbor.Marshal(t)
}
func (t *TransactionRecord) UnmarshalProcessingDetails(v any) error {
if t == nil {
return errors.New("transaction record is nil")
}
return t.ServerMetadata.UnmarshalDetails(v)
}
func (t *TransactionRecord) GetActualFee() uint64 {
if t == nil {
return 0
}
return t.ServerMetadata.GetActualFee()
}
func (sm *ServerMetadata) GetActualFee() uint64 {
if sm == nil {
return 0
}
return sm.ActualFee
}
func (sm *ServerMetadata) UnmarshalDetails(v any) error {
if sm == nil {
return errors.New("server metadata is nil")
}
return Cbor.Unmarshal(sm.ProcessingDetails, v)
}