-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrefunds.go
More file actions
117 lines (93 loc) · 2.86 KB
/
refunds.go
File metadata and controls
117 lines (93 loc) · 2.86 KB
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
package substrate
import (
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/pkg/errors"
)
type RefundTransaction struct {
Block types.U32 `json:"block"`
Amount types.U64 `json:"amount"`
Target string `json:"target"`
TxHash string `json:"tx_hash"`
Signatures []StellarSignature `json:"signatures"`
SequenceNumber types.U64 `json:"sequence_number"`
}
func (s *Substrate) CreateRefundTransactionOrAddSig(identity Identity, tx_hash string, target string, amount int64, signature string, stellarAddress string, sequence_number uint64) error {
cl, meta, err := s.GetClient()
if err != nil {
return err
}
c, err := types.NewCall(meta, "TFTBridgeModule.create_refund_transaction_or_add_sig",
tx_hash, target, types.U64(amount), signature, stellarAddress, sequence_number,
)
if err != nil {
return errors.Wrap(err, "failed to create call")
}
_, err = s.Call(cl, meta, identity, c)
if err != nil {
return errors.Wrap(err, "failed to create refund transaction")
}
return nil
}
func (s *Substrate) SetRefundTransactionExecuted(identity Identity, txHash string) error {
cl, meta, err := s.GetClient()
if err != nil {
return err
}
c, err := types.NewCall(meta, "TFTBridgeModule.set_refund_transaction_executed", txHash)
if err != nil {
return errors.Wrap(err, "failed to create call")
}
_, err = s.Call(cl, meta, identity, c)
if err != nil {
return errors.Wrap(err, "failed to create refund transaction")
}
return nil
}
func (s *Substrate) IsRefundedAlready(txHash string) (exists bool, err error) {
cl, meta, err := s.GetClient()
if err != nil {
return false, err
}
bytes, err := Encode(txHash)
if err != nil {
return false, errors.Wrap(err, "substrate: encoding error building query arguments")
}
var refundTx RefundTransaction
key, err := types.CreateStorageKey(meta, "TFTBridgeModule", "ExecutedRefundTransactions", bytes, nil)
if err != nil {
err = errors.Wrap(err, "failed to create storage key")
return
}
ok, err := cl.RPC.State.GetStorageLatest(key, &refundTx)
if err != nil {
return false, err
}
if !ok {
return false, nil
}
return true, nil
}
func (s *Substrate) GetRefundTransaction(txHash string) (*RefundTransaction, error) {
cl, meta, err := s.GetClient()
if err != nil {
return nil, err
}
bytes, err := Encode(txHash)
if err != nil {
return nil, errors.Wrap(err, "substrate: encoding error building query arguments")
}
var refundTx RefundTransaction
key, err := types.CreateStorageKey(meta, "TFTBridgeModule", "RefundTransactions", bytes, nil)
if err != nil {
err = errors.Wrap(err, "failed to create storage key")
return nil, err
}
ok, err := cl.RPC.State.GetStorageLatest(key, &refundTx)
if err != nil {
return nil, err
}
if !ok {
return nil, ErrBurnTransactionNotFound
}
return &refundTx, nil
}