Skip to content

Commit d2c6d7d

Browse files
committed
完成w3 第二部分的作业
1 parent 8a25b88 commit d2c6d7d

20 files changed

+14454
-137
lines changed

w2_2_code/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "w2_1_code",
2+
"name": "w2_2_code",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",

w3_1_code/contracts/contracts/MyERC20.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
55

66
contract MyERC20 is ERC20 {
77

8-
address public owner = msg.sender;
8+
address public owner;
99

1010
constructor(uint256 initialSupply) ERC20("MyERC20", "MERC") {
1111
owner = msg.sender;

w3_1_code/contracts/deployments/localhost/MyERC20.json

+12-12
Large diffs are not rendered by default.

w3_1_code/contracts/deployments/localhost/Vault.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
2+
"address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
33
"abi": [
44
{
55
"inputs": [
@@ -76,26 +76,26 @@
7676
"type": "function"
7777
}
7878
],
79-
"transactionHash": "0x9b9dcb07287688b76f63c5d2b30df6a4b6cbc93e97cf9d6153d6de8f0bae82fd",
79+
"transactionHash": "0xcaa69f9fe280de5ed0a218a5bde09cebae884711c07050649847ffa72beb5a8e",
8080
"receipt": {
8181
"to": null,
8282
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
83-
"contractAddress": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
83+
"contractAddress": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
8484
"transactionIndex": 0,
8585
"gasUsed": "496550",
8686
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
87-
"blockHash": "0x454763998b03f60bd4e63b7edeed31344d4812e8d7fdb2b31afc6ce2a510c2dc",
88-
"transactionHash": "0x9b9dcb07287688b76f63c5d2b30df6a4b6cbc93e97cf9d6153d6de8f0bae82fd",
87+
"blockHash": "0x1d305d3d25e176e6813bfdef7f3b110facbcb68b72c3a2e06ace8f0825c73ac1",
88+
"transactionHash": "0xcaa69f9fe280de5ed0a218a5bde09cebae884711c07050649847ffa72beb5a8e",
8989
"logs": [],
90-
"blockNumber": 20,
90+
"blockNumber": 2,
9191
"cumulativeGasUsed": "496550",
9292
"status": 1,
9393
"byzantium": true
9494
},
9595
"args": [
9696
"0x5FbDB2315678afecb367f032d93F642f64180aa3"
9797
],
98-
"numDeployments": 5,
98+
"numDeployments": 1,
9999
"solcInputHash": "47e7effd00332984b32f277568a78d07",
100100
"metadata": "{\"compiler\":{\"version\":\"0.8.4+commit.c7e474f2\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_token\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"deposit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"deposited\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"token\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/Vault.sol\":\"Vault\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC20 standard as defined in the EIP.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Returns the amount of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the amount of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves `amount` tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n /**\\n * @dev Moves `amount` tokens from `from` to `to` using the\\n * allowance mechanism. `amount` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(\\n address from,\\n address to,\\n uint256 amount\\n ) external returns (bool);\\n\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n}\\n\",\"keccak256\":\"0xbbc8ac883ac3c0078ce5ad3e288fbb3ffcc8a30c3a98c0fda0114d64fc44fca2\",\"license\":\"MIT\"},\"contracts/Vault.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\nimport \\\"@openzeppelin/contracts/token/ERC20/IERC20.sol\\\";\\n//import \\\"@openzeppelin/contracts/token/ERC20/ERC20.sol\\\";\\n\\ncontract Vault {\\n\\n mapping(address => uint) public deposited;\\n address public immutable token;\\n\\n constructor(address _token) {\\n token = _token;\\n }\\n\\n // \\u5b58\\u5165ERC20\\uff0c\\u5e76\\u8bb0\\u5f55\\u91d1\\u989d\\n function deposit(address user, uint amount) public {\\n require(IERC20(token).transferFrom(msg.sender, address(this), amount), \\\"Transfer from error\\\");\\n deposited[user] += amount;\\n }\\n\\n // \\u63d0\\u73b0\\u91d1\\u989d\\n function withdraw(uint amount) public {\\n require(deposited[msg.sender] - amount >= 0, \\\"Balance not enough\\\");\\n IERC20(token).transfer(msg.sender, amount);\\n deposited[msg.sender] -= amount;\\n }\\n}\\n\",\"keccak256\":\"0x3002b39630342545889d4755acbada13f6e5595dd7ca220410bd152f8675a0ff\",\"license\":\"MIT\"}},\"version\":1}",
101101
"bytecode": "0x60a060405234801561001057600080fd5b5060405161091e38038061091e83398181016040528101906100329190610084565b8073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1660601b81525050506100f6565b60008151905061007e816100df565b92915050565b60006020828403121561009657600080fd5b60006100a48482850161006f565b91505092915050565b60006100b8826100bf565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6100e8816100ad565b81146100f357600080fd5b50565b60805160601c6107fc610122600039600081816101660152818161026c01526103cb01526107fc6000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80632e1a7d4d1461005157806347e7ef241461006d578063cb13cddb14610089578063fc0c546a146100b9575b600080fd5b61006b600480360381019061006691906104ba565b6100d7565b005b61008760048036038101906100829190610455565b61026a565b005b6100a3600480360381019061009e919061042c565b6103b1565b6040516100b09190610602565b60405180910390f35b6100c16103c9565b6040516100ce9190610547565b60405180910390f35b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546101239190610684565b1015610164576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015b906105c2565b60405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b81526004016101bf929190610599565b602060405180830381600087803b1580156101d957600080fd5b505af11580156101ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102119190610491565b50806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546102609190610684565b9250508190555050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166323b872dd3330846040518463ffffffff1660e01b81526004016102c793929190610562565b602060405180830381600087803b1580156102e157600080fd5b505af11580156102f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103199190610491565b610358576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034f906105e2565b60405180910390fd5b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546103a6919061062e565b925050819055505050565b60006020528060005260406000206000915090505481565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000813590506103fc81610781565b92915050565b60008151905061041181610798565b92915050565b600081359050610426816107af565b92915050565b60006020828403121561043e57600080fd5b600061044c848285016103ed565b91505092915050565b6000806040838503121561046857600080fd5b6000610476858286016103ed565b925050602061048785828601610417565b9150509250929050565b6000602082840312156104a357600080fd5b60006104b184828501610402565b91505092915050565b6000602082840312156104cc57600080fd5b60006104da84828501610417565b91505092915050565b6104ec816106b8565b82525050565b60006104ff60128361061d565b915061050a8261072f565b602082019050919050565b600061052260138361061d565b915061052d82610758565b602082019050919050565b610541816106f6565b82525050565b600060208201905061055c60008301846104e3565b92915050565b600060608201905061057760008301866104e3565b61058460208301856104e3565b6105916040830184610538565b949350505050565b60006040820190506105ae60008301856104e3565b6105bb6020830184610538565b9392505050565b600060208201905081810360008301526105db816104f2565b9050919050565b600060208201905081810360008301526105fb81610515565b9050919050565b60006020820190506106176000830184610538565b92915050565b600082825260208201905092915050565b6000610639826106f6565b9150610644836106f6565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561067957610678610700565b5b828201905092915050565b600061068f826106f6565b915061069a836106f6565b9250828210156106ad576106ac610700565b5b828203905092915050565b60006106c3826106d6565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f42616c616e6365206e6f7420656e6f7567680000000000000000000000000000600082015250565b7f5472616e736665722066726f6d206572726f7200000000000000000000000000600082015250565b61078a816106b8565b811461079557600080fd5b50565b6107a1816106ca565b81146107ac57600080fd5b50565b6107b8816106f6565b81146107c357600080fd5b5056fea2646970667358221220de3455776e64e219c8799ece36f5b2e1f5fcc12af1b8de32ce8d875a8af6162064736f6c63430008040033",

0 commit comments

Comments
 (0)