@@ -46,10 +46,10 @@ type Backend interface {
46
46
}
47
47
48
48
// Deploy deploys an instance of the underlying contract and returns its `Contract` abstraction
49
- func Deploy (auth * bind.TransactOpts , backend bind.ContractBackend , owner common.Address , harddepositTimeout time.Duration ) (common. Address , Contract , * types.Transaction , error ) {
49
+ func Deploy (auth * bind.TransactOpts , backend bind.ContractBackend , owner common.Address , harddepositTimeout time.Duration ) (Contract , * types.Transaction , error ) {
50
50
addr , tx , s , err := contract .DeploySimpleSwap (auth , backend , owner , big .NewInt (int64 (harddepositTimeout )))
51
51
c := simpleContract {instance : s , address : addr }
52
- return addr , c , tx , err
52
+ return c , tx , err
53
53
}
54
54
55
55
// InstanceAt creates a new instance of a contract at a specific address.
@@ -86,64 +86,16 @@ type CashChequeResult struct {
86
86
87
87
// Params encapsulates some contract parameters (currently mostly informational)
88
88
type Params struct {
89
- ContractCode , ContractAbi string
90
- }
91
-
92
- // ValidateCode checks that the on-chain code at address matches the expected swap
93
- // contract code.
94
- func ValidateCode (ctx context.Context , b bind.ContractBackend , address common.Address ) error {
95
- codeReadFromAddress , err := b .CodeAt (ctx , address , nil )
96
- if err != nil {
97
- return err
98
- }
99
- referenceCode := common .FromHex (contract .SimpleSwapDeployedCode )
100
- if ! bytes .Equal (codeReadFromAddress , referenceCode ) {
101
- return ErrNotASwapContract
102
- }
103
- return nil
104
- }
105
-
106
- // WaitFunc is the default function to wait for transactions
107
- // We can overwrite this in tests so that we don't need to wait for mining
108
- var WaitFunc = waitForTx
109
-
110
- // waitForTx waits for transaction to be mined and returns the receipt
111
- func waitForTx (auth * bind.TransactOpts , backend Backend , tx * types.Transaction ) (* types.Receipt , error ) {
112
- // it blocks here until tx is mined
113
- receipt , err := bind .WaitMined (auth .Context , backend , tx )
114
- if err != nil {
115
- return nil , err
116
- }
117
- // indicate whether the transaction did not revert
118
- if receipt .Status != types .ReceiptStatusSuccessful {
119
- return nil , ErrTransactionReverted
120
- }
121
- return receipt , nil
89
+ ContractCode string
90
+ ContractAbi string
91
+ ContractAddress common.Address
122
92
}
123
93
124
94
type simpleContract struct {
125
95
instance * contract.SimpleSwap
126
96
address common.Address
127
97
}
128
98
129
- // ContractParams returns contract information
130
- func (s simpleContract ) ContractParams () * Params {
131
- return & Params {
132
- ContractCode : contract .SimpleSwapBin ,
133
- ContractAbi : contract .SimpleSwapABI ,
134
- }
135
- }
136
-
137
- // PaidOut returns the total paid out amount for the given address
138
- func (s simpleContract ) PaidOut (opts * bind.CallOpts , addr common.Address ) (* big.Int , error ) {
139
- return s .instance .PaidOut (opts , addr )
140
- }
141
-
142
- // Issuer returns the contract owner from the blockchain
143
- func (s simpleContract ) Issuer (opts * bind.CallOpts ) (common.Address , error ) {
144
- return s .instance .Issuer (opts )
145
- }
146
-
147
99
// CashChequeBeneficiary cashes the cheque on the blockchain and blocks until the transaction is mined.
148
100
func (s simpleContract ) CashChequeBeneficiary (auth * bind.TransactOpts , backend Backend , beneficiary common.Address , cumulativePayout * big.Int , ownerSig []byte ) (* CashChequeResult , * types.Receipt , error ) {
149
101
tx , err := s .instance .CashChequeBeneficiary (auth , beneficiary , cumulativePayout , ownerSig )
@@ -177,3 +129,54 @@ func (s simpleContract) CashChequeBeneficiary(auth *bind.TransactOpts, backend B
177
129
178
130
return result , receipt , nil
179
131
}
132
+
133
+ // ContractParams returns contract information
134
+ func (s simpleContract ) ContractParams () * Params {
135
+ return & Params {
136
+ ContractCode : contract .SimpleSwapBin ,
137
+ ContractAbi : contract .SimpleSwapABI ,
138
+ ContractAddress : s .address ,
139
+ }
140
+ }
141
+
142
+ // Issuer returns the contract owner from the blockchain
143
+ func (s simpleContract ) Issuer (opts * bind.CallOpts ) (common.Address , error ) {
144
+ return s .instance .Issuer (opts )
145
+ }
146
+
147
+ // PaidOut returns the total paid out amount for the given address
148
+ func (s simpleContract ) PaidOut (opts * bind.CallOpts , addr common.Address ) (* big.Int , error ) {
149
+ return s .instance .PaidOut (opts , addr )
150
+ }
151
+
152
+ // ValidateCode checks that the on-chain code at address matches the expected swap
153
+ // contract code.
154
+ func ValidateCode (ctx context.Context , b bind.ContractBackend , address common.Address ) error {
155
+ codeReadFromAddress , err := b .CodeAt (ctx , address , nil )
156
+ if err != nil {
157
+ return err
158
+ }
159
+ referenceCode := common .FromHex (contract .SimpleSwapDeployedCode )
160
+ if ! bytes .Equal (codeReadFromAddress , referenceCode ) {
161
+ return ErrNotASwapContract
162
+ }
163
+ return nil
164
+ }
165
+
166
+ // WaitFunc is the default function to wait for transactions
167
+ // We can overwrite this in tests so that we don't need to wait for mining
168
+ var WaitFunc = waitForTx
169
+
170
+ // waitForTx waits for transaction to be mined and returns the receipt
171
+ func waitForTx (auth * bind.TransactOpts , backend Backend , tx * types.Transaction ) (* types.Receipt , error ) {
172
+ // it blocks here until tx is mined
173
+ receipt , err := bind .WaitMined (auth .Context , backend , tx )
174
+ if err != nil {
175
+ return nil , err
176
+ }
177
+ // indicate whether the transaction did not revert
178
+ if receipt .Status != types .ReceiptStatusSuccessful {
179
+ return nil , ErrTransactionReverted
180
+ }
181
+ return receipt , nil
182
+ }
0 commit comments