File tree 1 file changed +11
-6
lines changed
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -31,14 +31,19 @@ contract Bank {
31
31
32
32
33
33
// 提取金额
34
- function withdraw () public onlyOwner {
34
+ function withdraw () onlyOwner public returns ( bool ) {
35
35
require (address (this ).balance > 0 );
36
- payable (msg .sender ).transfer (address (this ).balance);
36
+ // payable(msg.sender).transfer(address(this).balance);
37
+ // safe transfer,忽略2300gas限制
38
+ (bool success ,) = msg .sender .call {value : address (this ).balance}("" );
37
39
// 清除所有余额
38
- for (uint256 i = 0 ; i < included.length ; i++ ) {
39
- isIncluded[included[i]] = false ;
40
- balanceOf[included[i]] = 0 ;
40
+ if (success){
41
+ for (uint256 i = 0 ; i < included.length ; i++ ) {
42
+ isIncluded[included[i]] = false ;
43
+ balanceOf[included[i]] = 0 ;
44
+ }
45
+ delete included;
41
46
}
42
- delete included ;
47
+ return success ;
43
48
}
44
49
}
You can’t perform that action at this time.
0 commit comments