-
Notifications
You must be signed in to change notification settings - Fork 61
/
transaction_receipt.go
151 lines (128 loc) · 5.57 KB
/
transaction_receipt.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package hedera
import (
"fmt"
"github.com/hashgraph/hedera-sdk-go/proto"
)
// TransactionReceipt is the consensus result for a transaction which is returned from a TransactionReceiptQuery.
type TransactionReceipt struct {
// Status is the consensus status of the receipt's transaction. It might be unknown or have Failed.
Status Status
accountID *AccountID
contractID *ContractID
fileID *FileID
consensusTopicID *ConsensusTopicID
consensusTopicSequenceNumber uint64
consensusTopicRunningHash []byte
}
// GetFileID returns the FileID associated with the receipt's transaction or else panics no FileID exists
func (receipt TransactionReceipt) GetFileID() FileID {
return *receipt.fileID
}
// TryGetFileID returns the FileID associated with the receipt's transaction or else returns an err if no FileID exists.
func (receipt TransactionReceipt) TryGetFileID() (FileID, error) {
if receipt.fileID == nil {
return FileID{}, fmt.Errorf("no file id exists on this receipt")
}
return receipt.GetFileID(), nil
}
// GetAccountID returns the AccountID associated with the receipt's transaction or else panics if no AccountID exists
func (receipt TransactionReceipt) GetAccountID() AccountID {
return *receipt.accountID
}
// TryGetAccountID returns the AccountID associated with the receipt's transaction or else returns an error
// if no AccountID exists
func (receipt TransactionReceipt) TryGetAccountID() (AccountID, error) {
if receipt.accountID == nil {
return AccountID{}, fmt.Errorf("no account id exists on this receipt")
}
return receipt.GetAccountID(), nil
}
// GetContractID returns the ContractID associated with the receipt's transaction or else panics if no ContractID exists
func (receipt TransactionReceipt) GetContractID() ContractID {
return *receipt.contractID
}
// TryGetContractID returns the ContractID associated with the receipt's transaction or else returns an error
// if no ContractID exists
func (receipt TransactionReceipt) TryGetContractID() (ContractID, error) {
if receipt.contractID == nil {
return ContractID{}, fmt.Errorf("no contract id exists on this receipt")
}
return receipt.GetContractID(), nil
}
// GetConsensusTopicID returns the ConsensusTopicID associated with the receipt's transaction or else panics
// if no ConsensusTopicID exists
func (receipt TransactionReceipt) GetConsensusTopicID() ConsensusTopicID {
return *receipt.consensusTopicID
}
// TryGetConsensusTopicID returns the ConsensusTopicID associated with the receipt's transaction or else
// returns an error if no ConsensusTopicID exists
func (receipt TransactionReceipt) TryGetConsensusTopicID() (ConsensusTopicID, error) {
if receipt.consensusTopicID == nil {
return ConsensusTopicID{}, fmt.Errorf("no consensus id exists on this receipt")
}
return receipt.GetConsensusTopicID(), nil
}
// GetConsensusTopicSequenceNumber returns the topic sequence number associated with the
// Consensus Topic. However, if a ConsensusTopicID does not exist on the receipt it will return
// potentially invalid values.
func (receipt TransactionReceipt) GetConsensusTopicSequenceNumber() uint64 {
return receipt.consensusTopicSequenceNumber
}
// TryGetConsensusTopicSequenceNumber checks if the receipt contains a ConsensusTopicID. If
// the ConsensusTopicID exists it will return the ConsensusTopicSequenceNumber. Otherwise an
// error will be returned.
func (receipt TransactionReceipt) TryGetConsensusTopicSequenceNumber() (uint64, error) {
if _, err := receipt.TryGetConsensusTopicID(); err != nil {
return 0, err
}
return receipt.GetConsensusTopicSequenceNumber(), nil
}
// GetConsensusTopicRunningHash returns the running hash associated with the Consensus Topic.
// However, if a ConsensusTopicID does not exist on the receipt it will return potentially
// invalid values (likely an empty slice).
func (receipt TransactionReceipt) GetConsensusTopicRunningHash() []byte {
return receipt.consensusTopicRunningHash
}
// TryGetConsensusTopicRunningHash checks if the receipt contains a ConsensusTopicID. If the
// ConsensusTopicID exists it will return the running hash associated with the consensus Topic.
// Otherwise, an error will be returned.
func (receipt TransactionReceipt) TryGetConsensusTopicRunningHash() ([]byte, error) {
if _, err := receipt.TryGetConsensusTopicID(); err != nil {
return []byte{}, err
}
return receipt.consensusTopicRunningHash, nil
}
func transactionReceiptFromResponse(response *proto.Response) TransactionReceipt {
return transactionReceiptFromProto(response.GetTransactionGetReceipt().Receipt)
}
func transactionReceiptFromProto(pb *proto.TransactionReceipt) TransactionReceipt {
var accountID *AccountID
if pb.AccountID != nil {
accountIDValue := accountIDFromProto(pb.AccountID)
accountID = &accountIDValue
}
var contractID *ContractID
if pb.ContractID != nil {
contractIDValue := contractIDFromProto(pb.ContractID)
contractID = &contractIDValue
}
var fileID *FileID
if pb.FileID != nil {
fileIDValue := fileIDFromProto(pb.FileID)
fileID = &fileIDValue
}
var consensusTopicID *ConsensusTopicID
if pb.TopicID != nil {
consensusTopicIDValue := consensusTopicIDFromProto(pb.TopicID)
consensusTopicID = &consensusTopicIDValue
}
return TransactionReceipt{
Status: Status(pb.Status),
accountID: accountID,
contractID: contractID,
fileID: fileID,
consensusTopicID: consensusTopicID,
consensusTopicSequenceNumber: pb.TopicSequenceNumber,
consensusTopicRunningHash: pb.TopicRunningHash,
}
}