This commit is contained in:
Ting-Jun Wang 2023-04-07 14:14:08 +08:00
parent 2f70767578
commit 07197296bd
Signed by: snsd0805
GPG Key ID: 8DB0D22BC1217D33
10 changed files with 15405 additions and 2316 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,12 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [],
"name": "Destroy",
"type": "event"
},
{
"inputs": [],
"name": "owner",
@ -31,9 +37,9 @@
"type": "function"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"destroy\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"project:/contracts/BaseContract.sol\":\"BaseContract\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"project:/contracts/BaseContract.sol\":{\"keccak256\":\"0xe4a7a376123fde9f62e656195c2b5208f8fe81b22346263c4f52fd2408eb3ef1\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://921d16d096d80ce97a7596e3706588d1bbf0e3f55df790bfedac171cd9bd2dc5\",\"dweb:/ipfs/QmQmXW1HZoNrhhEtgSxapUg8hghEtVWJ1DLvbDZNbikr5j\"]}},\"version\":1}",
"bytecode": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102cb806100606000396000f3fe60806040526004361061002d5760003560e01c806383197ef0146100395780638da5cb5b1461005057610034565b3661003457005b600080fd5b34801561004557600080fd5b5061004e61007b565b005b34801561005c57600080fd5b50610065610172565b60405161007291906101d7565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610109576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010090610275565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f1935050505015801561016f573d6000803e3d6000fd5b50565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101c182610196565b9050919050565b6101d1816101b6565b82525050565b60006020820190506101ec60008301846101c8565b92915050565b600082825260208201905092915050565b7f546869732066756e6374696f6e206f6e6c7920746865206f776e65722063616e60008201527f2061636365737300000000000000000000000000000000000000000000000000602082015250565b600061025f6027836101f2565b915061026a82610203565b604082019050919050565b6000602082019050818103600083015261028e81610252565b905091905056fea26469706673582212200fa5d463616292cb14aa33ab6eb50cc7c3a0cdc8699d1a8831a5c7f5caf14f2264736f6c63430008130033",
"deployedBytecode": "0x60806040526004361061002d5760003560e01c806383197ef0146100395780638da5cb5b1461005057610034565b3661003457005b600080fd5b34801561004557600080fd5b5061004e61007b565b005b34801561005c57600080fd5b50610065610172565b60405161007291906101d7565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610109576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010090610275565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f1935050505015801561016f573d6000803e3d6000fd5b50565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101c182610196565b9050919050565b6101d1816101b6565b82525050565b60006020820190506101ec60008301846101c8565b92915050565b600082825260208201905092915050565b7f546869732066756e6374696f6e206f6e6c7920746865206f776e65722063616e60008201527f2061636365737300000000000000000000000000000000000000000000000000602082015250565b600061025f6027836101f2565b915061026a82610203565b604082019050919050565b6000602082019050818103600083015261028e81610252565b905091905056fea26469706673582212200fa5d463616292cb14aa33ab6eb50cc7c3a0cdc8699d1a8831a5c7f5caf14f2264736f6c63430008130033",
"metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"Destroy\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"destroy\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"project:/contracts/BaseContract.sol\":\"BaseContract\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"project:/contracts/BaseContract.sol\":{\"keccak256\":\"0x224dc0bd4bed0626cd3c6472ddbd14b3f81e594690ef64800f94db034a180417\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://8c18e9e30dc4ce07c3c55b64ca66aba0dd42a268e324c5413bd9dff599d0802e\",\"dweb:/ipfs/QmPkFdsgvrei43P1ockcmKr5XNwz7ZPVNe69jTMCcL6mve\"]}},\"version\":1}",
"bytecode": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102cb806100606000396000f3fe60806040526004361061002d5760003560e01c806383197ef0146100395780638da5cb5b1461005057610034565b3661003457005b600080fd5b34801561004557600080fd5b5061004e61007b565b005b34801561005c57600080fd5b50610065610172565b60405161007291906101d7565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610109576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010090610275565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f1935050505015801561016f573d6000803e3d6000fd5b50565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101c182610196565b9050919050565b6101d1816101b6565b82525050565b60006020820190506101ec60008301846101c8565b92915050565b600082825260208201905092915050565b7f546869732066756e6374696f6e206f6e6c7920746865206f776e65722063616e60008201527f2061636365737300000000000000000000000000000000000000000000000000602082015250565b600061025f6027836101f2565b915061026a82610203565b604082019050919050565b6000602082019050818103600083015261028e81610252565b905091905056fea2646970667358221220580ef1aec442559597ff7e58999a3ef38eb23778dd144e069c1b6e87394d2d9f64736f6c63430008130033",
"deployedBytecode": "0x60806040526004361061002d5760003560e01c806383197ef0146100395780638da5cb5b1461005057610034565b3661003457005b600080fd5b34801561004557600080fd5b5061004e61007b565b005b34801561005c57600080fd5b50610065610172565b60405161007291906101d7565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610109576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010090610275565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f1935050505015801561016f573d6000803e3d6000fd5b50565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101c182610196565b9050919050565b6101d1816101b6565b82525050565b60006020820190506101ec60008301846101c8565b92915050565b600082825260208201905092915050565b7f546869732066756e6374696f6e206f6e6c7920746865206f776e65722063616e60008201527f2061636365737300000000000000000000000000000000000000000000000000602082015250565b600061025f6027836101f2565b915061026a82610203565b604082019050919050565b6000602082019050818103600083015261028e81610252565b905091905056fea2646970667358221220580ef1aec442559597ff7e58999a3ef38eb23778dd144e069c1b6e87394d2d9f64736f6c63430008130033",
"immutableReferences": {},
"generatedSources": [],
"deployedGeneratedSources": [
@ -801,23 +807,23 @@
"name": "#utility.yul"
}
],
"sourceMap": "66:324:2:-:0;;;115:40;;;;;;;;;;141:10;133:5;;:18;;;;;;;;;;;;;;;;;;66:324;;;;;;",
"deployedSourceMap": "66:324:2:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;267:89;;;;;;;;;;;;;:::i;:::-;;91:20;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;267:89;206:5;;;;;;;;;;192:19;;:10;:19;;;184:71;;;;;;;;;;;;:::i;:::-;;;;;;;;;314:5:::1;::::0;::::1;;;;;;;;306:23;;:46;330:21;306:46;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;267:89::o:0;91:20::-;;;;;;;;;;;;:::o;7:126:3:-;44:7;84:42;77:5;73:54;62:65;;7:126;;;:::o;139:96::-;176:7;205:24;223:5;205:24;:::i;:::-;194:35;;139:96;;;:::o;241:118::-;328:24;346:5;328:24;:::i;:::-;323:3;316:37;241:118;;:::o;365:222::-;458:4;496:2;485:9;481:18;473:26;;509:71;577:1;566:9;562:17;553:6;509:71;:::i;:::-;365:222;;;;:::o;593:169::-;677:11;711:6;706:3;699:19;751:4;746:3;742:14;727:29;;593:169;;;;:::o;768:226::-;908:34;904:1;896:6;892:14;885:58;977:9;972:2;964:6;960:15;953:34;768:226;:::o;1000:366::-;1142:3;1163:67;1227:2;1222:3;1163:67;:::i;:::-;1156:74;;1239:93;1328:3;1239:93;:::i;:::-;1357:2;1352:3;1348:12;1341:19;;1000:366;;;:::o;1372:419::-;1538:4;1576:2;1565:9;1561:18;1553:26;;1625:9;1619:4;1615:20;1611:1;1600:9;1596:17;1589:47;1653:131;1779:4;1653:131;:::i;:::-;1645:139;;1372:419;;;:::o",
"source": "// SPDX-License-Identifier: MIT\npragma solidity >=0.4.22 <0.9.0;\n\ncontract BaseContract {\n\taddress public owner;\n\n\tconstructor() {\n\t\towner = msg.sender;\n\t}\n\t\n\tmodifier onlyOwner() {\n\t\trequire(msg.sender == owner, \"This function only the owner can access\");\n\t\t_;\n\t}\n\n\tfunction destroy() public onlyOwner{\n\t\tpayable(owner).transfer(address(this).balance);\n\t}\n\n\treceive() external payable {}\n}\n",
"sourcePath": "/home/snsd0805/code/1112_blockchain/HW2_Advanced_Faucet/contracts/BaseContract.sol",
"sourceMap": "66:342:2:-:0;;;133:40;;;;;;;;;;159:10;151:5;;:18;;;;;;;;;;;;;;;;;;66:342;;;;;;",
"deployedSourceMap": "66:342:2:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;285:89;;;;;;;;;;;;;:::i;:::-;;91:20;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;285:89;224:5;;;;;;;;;;210:19;;:10;:19;;;202:71;;;;;;;;;;;;:::i;:::-;;;;;;;;;332:5:::1;::::0;::::1;;;;;;;;324:23;;:46;348:21;324:46;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;285:89::o:0;91:20::-;;;;;;;;;;;;:::o;7:126:3:-;44:7;84:42;77:5;73:54;62:65;;7:126;;;:::o;139:96::-;176:7;205:24;223:5;205:24;:::i;:::-;194:35;;139:96;;;:::o;241:118::-;328:24;346:5;328:24;:::i;:::-;323:3;316:37;241:118;;:::o;365:222::-;458:4;496:2;485:9;481:18;473:26;;509:71;577:1;566:9;562:17;553:6;509:71;:::i;:::-;365:222;;;;:::o;593:169::-;677:11;711:6;706:3;699:19;751:4;746:3;742:14;727:29;;593:169;;;;:::o;768:226::-;908:34;904:1;896:6;892:14;885:58;977:9;972:2;964:6;960:15;953:34;768:226;:::o;1000:366::-;1142:3;1163:67;1227:2;1222:3;1163:67;:::i;:::-;1156:74;;1239:93;1328:3;1239:93;:::i;:::-;1357:2;1352:3;1348:12;1341:19;;1000:366;;;:::o;1372:419::-;1538:4;1576:2;1565:9;1561:18;1553:26;;1625:9;1619:4;1615:20;1611:1;1600:9;1596:17;1589:47;1653:131;1779:4;1653:131;:::i;:::-;1645:139;;1372:419;;;:::o",
"source": "// SPDX-License-Identifier: MIT\npragma solidity >=0.4.22 <0.9.0;\n\ncontract BaseContract {\n\taddress public owner;\n\tevent Destroy();\n\n\tconstructor() {\n\t\towner = msg.sender;\n\t}\n\t\n\tmodifier onlyOwner() {\n\t\trequire(msg.sender == owner, \"This function only the owner can access\");\n\t\t_;\n\t}\n\n\tfunction destroy() public onlyOwner{\n\t\tpayable(owner).transfer(address(this).balance);\n\t}\n\n\treceive() external payable {}\n}\n",
"sourcePath": "/srv/http/code/1112_blockchain/advance_faucet/contracts/BaseContract.sol",
"ast": {
"absolutePath": "project:/contracts/BaseContract.sol",
"exportedSymbols": {
"BaseContract": [
212
272
]
},
"id": 213,
"id": 273,
"license": "MIT",
"nodeType": "SourceUnit",
"nodes": [
{
"id": 166,
"id": 224,
"literals": [
"solidity",
">=",
@ -837,9 +843,9 @@
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 212,
"id": 272,
"linearizedBaseContracts": [
212
272
],
"name": "BaseContract",
"nameLocation": "75:12:2",
@ -848,12 +854,12 @@
{
"constant": false,
"functionSelector": "8da5cb5b",
"id": 168,
"id": 226,
"mutability": "mutable",
"name": "owner",
"nameLocation": "106:5:2",
"nodeType": "VariableDeclaration",
"scope": 212,
"scope": 272,
"src": "91:20:2",
"stateVariable": true,
"storageLocation": "default",
@ -862,7 +868,7 @@
"typeString": "address"
},
"typeName": {
"id": 167,
"id": 225,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "91:7:2",
@ -874,26 +880,41 @@
},
"visibility": "public"
},
{
"anonymous": false,
"eventSelector": "f58fef8e187ef8dfd7bef096c1ef3e4f3c54f98d95b8ad5659349b07e61204df",
"id": 228,
"name": "Destroy",
"nameLocation": "120:7:2",
"nodeType": "EventDefinition",
"parameters": {
"id": 227,
"nodeType": "ParameterList",
"parameters": [],
"src": "127:2:2"
},
"src": "114:16:2"
},
{
"body": {
"id": 176,
"id": 236,
"nodeType": "Block",
"src": "129:26:2",
"src": "147:26:2",
"statements": [
{
"expression": {
"id": 174,
"id": 234,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"id": 171,
"id": 231,
"name": "owner",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 168,
"src": "133:5:2",
"referencedDeclaration": 226,
"src": "151:5:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
@ -903,44 +924,44 @@
"operator": "=",
"rightHandSide": {
"expression": {
"id": 172,
"id": 232,
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4294967281,
"src": "141:3:2",
"src": "159:3:2",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
"typeString": "msg"
}
},
"id": 173,
"id": 233,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberLocation": "145:6:2",
"memberLocation": "163:6:2",
"memberName": "sender",
"nodeType": "MemberAccess",
"src": "141:10:2",
"src": "159:10:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"src": "133:18:2",
"src": "151:18:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"id": 175,
"id": 235,
"nodeType": "ExpressionStatement",
"src": "133:18:2"
"src": "151:18:2"
}
]
},
"id": 177,
"id": 237,
"implemented": true,
"kind": "constructor",
"modifiers": [],
@ -948,28 +969,28 @@
"nameLocation": "-1:-1:-1",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 169,
"id": 229,
"nodeType": "ParameterList",
"parameters": [],
"src": "126:2:2"
"src": "144:2:2"
},
"returnParameters": {
"id": 170,
"id": 230,
"nodeType": "ParameterList",
"parameters": [],
"src": "129:0:2"
"src": "147:0:2"
},
"scope": 212,
"src": "115:40:2",
"scope": 272,
"src": "133:40:2",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
},
{
"body": {
"id": 188,
"id": 248,
"nodeType": "Block",
"src": "180:84:2",
"src": "198:84:2",
"statements": [
{
"expression": {
@ -979,33 +1000,33 @@
"typeIdentifier": "t_address",
"typeString": "address"
},
"id": 183,
"id": 243,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression": {
"expression": {
"id": 180,
"id": 240,
"name": "msg",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4294967281,
"src": "192:3:2",
"src": "210:3:2",
"typeDescriptions": {
"typeIdentifier": "t_magic_message",
"typeString": "msg"
}
},
"id": 181,
"id": 241,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberLocation": "196:6:2",
"memberLocation": "214:6:2",
"memberName": "sender",
"nodeType": "MemberAccess",
"src": "192:10:2",
"src": "210:10:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
@ -1014,18 +1035,18 @@
"nodeType": "BinaryOperation",
"operator": "==",
"rightExpression": {
"id": 182,
"id": 242,
"name": "owner",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 168,
"src": "206:5:2",
"referencedDeclaration": 226,
"src": "224:5:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"src": "192:19:2",
"src": "210:19:2",
"typeDescriptions": {
"typeIdentifier": "t_bool",
"typeString": "bool"
@ -1033,14 +1054,14 @@
},
{
"hexValue": "546869732066756e6374696f6e206f6e6c7920746865206f776e65722063616e20616363657373",
"id": 184,
"id": 244,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "string",
"lValueRequested": false,
"nodeType": "Literal",
"src": "213:41:2",
"src": "231:41:2",
"typeDescriptions": {
"typeIdentifier": "t_stringliteral_f481286fd7e35fb08a942fbbdf386ddc72236b2a397440207a7e669288de8002",
"typeString": "literal_string \"This function only the owner can access\""
@ -1059,7 +1080,7 @@
"typeString": "literal_string \"This function only the owner can access\""
}
],
"id": 179,
"id": 239,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
@ -1067,13 +1088,13 @@
4294967278
],
"referencedDeclaration": 4294967278,
"src": "184:7:2",
"src": "202:7:2",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$",
"typeString": "function (bool,string memory) pure"
}
},
"id": 185,
"id": 245,
"isConstant": false,
"isLValue": false,
"isPure": false,
@ -1082,43 +1103,43 @@
"nameLocations": [],
"names": [],
"nodeType": "FunctionCall",
"src": "184:71:2",
"src": "202:71:2",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
},
"id": 186,
"id": 246,
"nodeType": "ExpressionStatement",
"src": "184:71:2"
"src": "202:71:2"
},
{
"id": 187,
"id": 247,
"nodeType": "PlaceholderStatement",
"src": "259:1:2"
"src": "277:1:2"
}
]
},
"id": 189,
"id": 249,
"name": "onlyOwner",
"nameLocation": "168:9:2",
"nameLocation": "186:9:2",
"nodeType": "ModifierDefinition",
"parameters": {
"id": 178,
"id": 238,
"nodeType": "ParameterList",
"parameters": [],
"src": "177:2:2"
"src": "195:2:2"
},
"src": "159:105:2",
"src": "177:105:2",
"virtual": false,
"visibility": "internal"
},
{
"body": {
"id": 206,
"id": 266,
"nodeType": "Block",
"src": "302:54:2",
"src": "320:54:2",
"statements": [
{
"expression": {
@ -1127,14 +1148,14 @@
"expression": {
"arguments": [
{
"id": 201,
"id": 261,
"name": "this",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4294967268,
"src": "338:4:2",
"src": "356:4:2",
"typeDescriptions": {
"typeIdentifier": "t_contract$_BaseContract_$212",
"typeIdentifier": "t_contract$_BaseContract_$272",
"typeString": "contract BaseContract"
}
}
@ -1142,30 +1163,30 @@
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_contract$_BaseContract_$212",
"typeIdentifier": "t_contract$_BaseContract_$272",
"typeString": "contract BaseContract"
}
],
"id": 200,
"id": 260,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "330:7:2",
"src": "348:7:2",
"typeDescriptions": {
"typeIdentifier": "t_type$_t_address_$",
"typeString": "type(address)"
},
"typeName": {
"id": 199,
"id": 259,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "330:7:2",
"src": "348:7:2",
"typeDescriptions": {}
}
},
"id": 202,
"id": 262,
"isConstant": false,
"isLValue": false,
"isPure": false,
@ -1174,22 +1195,22 @@
"nameLocations": [],
"names": [],
"nodeType": "FunctionCall",
"src": "330:13:2",
"src": "348:13:2",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"id": 203,
"id": 263,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberLocation": "344:7:2",
"memberLocation": "362:7:2",
"memberName": "balance",
"nodeType": "MemberAccess",
"src": "330:21:2",
"src": "348:21:2",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
@ -1206,12 +1227,12 @@
"expression": {
"arguments": [
{
"id": 196,
"id": 256,
"name": "owner",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 168,
"src": "314:5:2",
"referencedDeclaration": 226,
"src": "332:5:2",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
@ -1225,27 +1246,27 @@
"typeString": "address"
}
],
"id": 195,
"id": 255,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "306:8:2",
"src": "324:8:2",
"typeDescriptions": {
"typeIdentifier": "t_type$_t_address_payable_$",
"typeString": "type(address payable)"
},
"typeName": {
"id": 194,
"id": 254,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "306:8:2",
"src": "324:8:2",
"stateMutability": "payable",
"typeDescriptions": {}
}
},
"id": 197,
"id": 257,
"isConstant": false,
"isLValue": false,
"isPure": false,
@ -1254,28 +1275,28 @@
"nameLocations": [],
"names": [],
"nodeType": "FunctionCall",
"src": "306:14:2",
"src": "324:14:2",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_address_payable",
"typeString": "address payable"
}
},
"id": 198,
"id": 258,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"memberLocation": "321:8:2",
"memberLocation": "339:8:2",
"memberName": "transfer",
"nodeType": "MemberAccess",
"src": "306:23:2",
"src": "324:23:2",
"typeDescriptions": {
"typeIdentifier": "t_function_transfer_nonpayable$_t_uint256_$returns$__$",
"typeString": "function (uint256)"
}
},
"id": 204,
"id": 264,
"isConstant": false,
"isLValue": false,
"isPure": false,
@ -1284,70 +1305,70 @@
"nameLocations": [],
"names": [],
"nodeType": "FunctionCall",
"src": "306:46:2",
"src": "324:46:2",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
},
"id": 205,
"id": 265,
"nodeType": "ExpressionStatement",
"src": "306:46:2"
"src": "324:46:2"
}
]
},
"functionSelector": "83197ef0",
"id": 207,
"id": 267,
"implemented": true,
"kind": "function",
"modifiers": [
{
"id": 192,
"id": 252,
"kind": "modifierInvocation",
"modifierName": {
"id": 191,
"id": 251,
"name": "onlyOwner",
"nameLocations": [
"293:9:2"
"311:9:2"
],
"nodeType": "IdentifierPath",
"referencedDeclaration": 189,
"src": "293:9:2"
"referencedDeclaration": 249,
"src": "311:9:2"
},
"nodeType": "ModifierInvocation",
"src": "293:9:2"
"src": "311:9:2"
}
],
"name": "destroy",
"nameLocation": "276:7:2",
"nameLocation": "294:7:2",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 190,
"id": 250,
"nodeType": "ParameterList",
"parameters": [],
"src": "283:2:2"
"src": "301:2:2"
},
"returnParameters": {
"id": 193,
"id": 253,
"nodeType": "ParameterList",
"parameters": [],
"src": "302:0:2"
"src": "320:0:2"
},
"scope": 212,
"src": "267:89:2",
"scope": 272,
"src": "285:89:2",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
},
{
"body": {
"id": 210,
"id": 270,
"nodeType": "Block",
"src": "386:2:2",
"src": "404:2:2",
"statements": []
},
"id": 211,
"id": 271,
"implemented": true,
"kind": "receive",
"modifiers": [],
@ -1355,30 +1376,30 @@
"nameLocation": "-1:-1:-1",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 208,
"id": 268,
"nodeType": "ParameterList",
"parameters": [],
"src": "366:2:2"
"src": "384:2:2"
},
"returnParameters": {
"id": 209,
"id": 269,
"nodeType": "ParameterList",
"parameters": [],
"src": "386:0:2"
"src": "404:0:2"
},
"scope": 212,
"src": "359:29:2",
"scope": 272,
"src": "377:29:2",
"stateMutability": "payable",
"virtual": false,
"visibility": "external"
}
],
"scope": 213,
"src": "66:324:2",
"scope": 273,
"src": "66:342:2",
"usedErrors": []
}
],
"src": "32:359:2"
"src": "32:377:2"
},
"compiler": {
"name": "solc",
@ -1386,7 +1407,7 @@
},
"networks": {},
"schemaVersion": "3.4.13",
"updatedAt": "2023-03-29T08:06:21.136Z",
"updatedAt": "2023-04-06T14:26:33.017Z",
"devdoc": {
"kind": "dev",
"methods": {},

View File

@ -5,7 +5,7 @@ import "./BaseContract.sol";
import "./Bank.sol";
contract ATM is BaseContract{
Bank bank;
Bank public bank;
event Withdraw(address from, uint amount, uint balance );
constructor(address bank_addr) {
bank = Bank(payable(bank_addr));
@ -18,5 +18,8 @@ contract ATM is BaseContract{
}
payable(msg.sender).transfer(amount);
emit Withdraw(msg.sender, amount, address(this).balance);
if(address(this).balance <= 0.1 ether) {
bank.withdraw(0.5 ether);
}
}
}

View File

@ -22,13 +22,17 @@ contract Bank is BaseContract{
_;
}
function getATMs() public view returns (address[] memory){
return atms;
}
function addATM(address atm) public onlyOwner {
atms.push(atm);
emit AddATM(atm);
}
function withdraw(uint amount) public onlyATM {
if(amount<=address(this).balance){
if(amount>address(this).balance){
emit NoMoney(msg.sender, amount, address(this).balance);
revert("Bank doesn't have enough money to withdraw");
}

View File

@ -3,6 +3,7 @@ pragma solidity >=0.4.22 <0.9.0;
contract BaseContract {
address public owner;
event Destroy();
constructor() {
owner = msg.sender;

View File

@ -6,15 +6,19 @@ module.exports = function(_deployer) {
_deployer.deploy(Bank).then((bank) => {
return bank.sendTransaction({value: "2000000000000000000"}).then(() => {
_deployer.deploy(ATM, bank.address).then((atm1) => {
return _deployer.deploy(ATM, bank.address).then((atm1) => {
return Bank.deployed().then((instance) => {
return instance.addATM(atm1.address);
}).then(() => {
return atm1.sendTransaction({value: "100000000000000000"});
})
})
}).then(() => {
return _deployer.deploy(ATM, bank.address).then((atm2) => {
return Bank.deployed().then((instance) => {
return instance.addATM(atm2.address);
}).then(() => {
return atm2.sendTransaction({value: "100000000000000000"});
})
})
})

10361
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"@truffle/hdwallet-provider": "^2.1.9",
"dotenv": "^16.0.3"
}
}