Skip to content

Commit 3f82dfc

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

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,11 @@ 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+
if !c.abi.HasReceive() && !(c.abi.HasFallback() && c.abi.Fallback.IsPayable()) {
277+
return nil, fmt.Errorf("contract does not have a payable fallback or receive function")
278+
}
279+
277280
return c.transact(opts, &c.address, nil)
278281
}
279282

0 commit comments

Comments
 (0)