Skip to content

Commit bebeba4

Browse files
committed
accounts: check fallback and receive before transfer
remove todo
1 parent c3ef6c7 commit bebeba4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

accounts/abi/bind/v2/base.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,24 @@ func (c *BoundContract) RawCreationTransact(opts *TransactOpts, calldata []byte)
272272
// Transfer initiates a plain transaction to move funds to the contract, calling
273273
// its default method if one is available.
274274
func (c *BoundContract) Transfer(opts *TransactOpts) (*types.Transaction, error) {
275-
// todo(rjl493456442) check the payable fallback or receive is defined
276-
// or not, reject invalid transaction at the first place
275+
// Check if payable fallback or receive is defined
276+
hasPayable := false
277+
for _, method := range c.abi.Methods {
278+
// In ABI, receive and fallback are special
279+
if method.Name == "" && method.Type == abi.Fallback && method.Payable {
280+
hasPayable = true
281+
break
282+
}
283+
if method.Type == abi.Receive && method.Payable {
284+
hasPayable = true
285+
break
286+
}
287+
}
288+
289+
if !hasPayable {
290+
return nil, fmt.Errorf("contract does not have a payable fallback or receive function")
291+
}
292+
277293
return c.transact(opts, &c.address, nil)
278294
}
279295

0 commit comments

Comments
 (0)