Skip to content

Commit 55a5320

Browse files
authored
accounts/abi: check presence of payable fallback or receive before proceeding with transfer (#32374)
remove todo
1 parent e03d97a commit 55a5320

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

accounts/abi/abigen/bind_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,13 @@ var bindTests = []struct {
485485
contract Defaulter {
486486
address public caller;
487487
488-
function() {
488+
fallback() external payable {
489489
caller = msg.sender;
490490
}
491491
}
492492
`,
493-
[]string{`6060604052606a8060106000396000f360606040523615601d5760e060020a6000350463fc9c8d3981146040575b605e6000805473ffffffffffffffffffffffffffffffffffffffff191633179055565b606060005473ffffffffffffffffffffffffffffffffffffffff1681565b005b6060908152602090f3`},
494-
[]string{`[{"constant":true,"inputs":[],"name":"caller","outputs":[{"name":"","type":"address"}],"type":"function"}]`},
493+
[]string{`608060405234801561000f575f80fd5b5061013d8061001d5f395ff3fe608060405260043610610021575f3560e01c8063fc9c8d391461006257610022565b5b335f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055005b34801561006d575f80fd5b5061007661008c565b60405161008391906100ee565b60405180910390f35b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100d8826100af565b9050919050565b6100e8816100ce565b82525050565b5f6020820190506101015f8301846100df565b9291505056fea26469706673582212201e9273ecfb1f534644c77f09a25c21baaba81cf1c444ebc071e12a225a23c72964736f6c63430008140033`},
494+
[]string{`[{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"caller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]`},
495495
`
496496
"math/big"
497497

accounts/abi/bind/v2/base.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ func (c *BoundContract) RawCreationTransact(opts *TransactOpts, calldata []byte)
277277
// Transfer initiates a plain transaction to move funds to the contract, calling
278278
// its default method if one is available.
279279
func (c *BoundContract) Transfer(opts *TransactOpts) (*types.Transaction, error) {
280-
// todo(rjl493456442) check the payable fallback or receive is defined
281-
// or not, reject invalid transaction at the first place
280+
// Check if payable fallback or receive is defined
281+
if !c.abi.HasReceive() && !(c.abi.HasFallback() && c.abi.Fallback.IsPayable()) {
282+
return nil, fmt.Errorf("contract does not have a payable fallback or receive function")
283+
}
282284
return c.transact(opts, &c.address, nil)
283285
}
284286

0 commit comments

Comments
 (0)