From 924aca9b38529fccab5a20a841c2bb805e5b7530 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 18 Aug 2024 01:03:20 +0000 Subject: [PATCH] Update tutorials --- changes.txt | 16 ++++++ docs/solidity-101/09_Constant/readme.md | 5 +- docs/solidity-102/22_Call/Call.sol | 55 +++++++++---------- docs/solidity-102/26_DeleteContract/readme.md | 2 +- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/changes.txt b/changes.txt index 36948858..70d7c60b 100644 --- a/changes.txt +++ b/changes.txt @@ -23,3 +23,19 @@ docs/ethers-101/01_HelloVitalik/HelloVitalik.js docs/ethers-101/02_Provider/Prov Changes in docs/solidity-104: docs/ethers-101/01_HelloVitalik/HelloVitalik.js docs/ethers-101/02_Provider/Provider.js docs/ethers-101/03_ReadContract/ReadContract.js docs/ethers-101/04_SendETH/SendETH.js docs/ethers-101/05_WriteContract/WriteContract.js docs/ethers-101/06_DeployContract/DeployContract.js docs/ethers-101/07_Event/Event.js docs/ethers-101/08_ContractListener/ContractListener.js docs/ethers-101/09_EventFilter/EventFilter.js docs/ethers-101/10_Units/Units.js docs/ethers-102/11_StaticCall/readme.md docs/ethers-102/11_StaticCall/staticCall.js docs/ethers-102/12_ERC721Check/ERC721Check.js docs/ethers-102/12_ERC721Check/readme.md docs/ethers-102/13_EncodeCalldata/EncodeCalldata.js docs/ethers-102/14_HDwallet/HDwallet.js docs/ethers-102/14_HDwallet/readme.md docs/ethers-102/15_MultiTransfer/MultiTransfer.js docs/ethers-102/15_MultiTransfer/readme.md docs/ethers-102/16_MultiCollect/MultiCollect.js docs/ethers-102/16_MultiCollect/readme.md docs/ethers-102/17_MerkleTree/MerkleTree.js docs/ethers-102/18_Signature/Signature.js docs/ethers-102/18_Signature/readme.md docs/ethers-102/19_Mempool/Mempool.js docs/ethers-102/19_Mempool/readme.md docs/ethers-102/20_DecodeTx/DecodeTx.js docs/ethers-102/20_DecodeTx/img/20-3.png docs/ethers-102/20_DecodeTx/img/20-4.png docs/ethers-102/20_DecodeTx/readme.md docs/ethers-102/21_VanityAddress/readme.md docs/ethers-102/23_Frontrun/Frontrun.sol docs/ethers-102/23_Frontrun/frontrun.js docs/ethers-102/23_Frontrun/img/23-2.png docs/ethers-102/23_Frontrun/img/23-3.png docs/ethers-102/23_Frontrun/readme.md docs/ethers-102/24_ERC20Check/readme.md docs/ethers-102/25_Flashbots/Flashbots.js docs/ethers-102/25_Flashbots/img/25-4.png docs/ethers-102/25_Flashbots/img/25-5.png docs/ethers-102/25_Flashbots/readme.md docs/solidity-101/01_HelloWeb3/HelloWeb3.sol docs/solidity-101/01_HelloWeb3/img/1-2.png docs/solidity-101/01_HelloWeb3/readme.md docs/solidity-101/02_ValueTypes/ValueTypes.sol docs/solidity-101/02_ValueTypes/readme.md docs/solidity-101/03_Function/Function.sol docs/solidity-101/03_Function/readme.md docs/solidity-101/04_Return/Return.sol docs/solidity-101/04_Return/readme.md docs/solidity-101/05_DataStorage/DataStorage.sol docs/solidity-101/05_DataStorage/readme.md docs/solidity-101/06_ArrayAndStruct/ArrayAndStruct.sol docs/solidity-101/06_ArrayAndStruct/readme.md docs/solidity-101/07_Mapping/Mapping.sol docs/solidity-101/07_Mapping/readme.md docs/solidity-101/08_InitialValue/InitialValue.sol docs/solidity-101/08_InitialValue/readme.md docs/solidity-101/09_Constant/Constant.sol docs/solidity-101/09_Constant/readme.md docs/solidity-101/10_InsertionSort/InsertionSort.sol docs/solidity-101/10_InsertionSort/readme.md docs/solidity-101/11_Modifier/Owner.sol docs/solidity-101/11_Modifier/img/11-1.jpg docs/solidity-101/11_Modifier/img/11-2.jpg docs/solidity-101/11_Modifier/img/11-3.jpg docs/solidity-101/11_Modifier/readme.md docs/solidity-101/12_Event/Event.sol docs/solidity-101/12_Event/readme.md docs/solidity-101/13_Inheritance/Inheritance.sol docs/solidity-101/13_Inheritance/ModifierInheritance.sol docs/solidity-101/13_Inheritance/readme.md docs/solidity-101/14_Interface/Interface.sol docs/solidity-101/14_Interface/img/14-2.png docs/solidity-101/14_Interface/readme.md docs/solidity-101/15_Errors/Error.sol docs/solidity-101/15_Errors/readme.md docs/solidity-102/16_Overloading/Overloading.sol docs/solidity-102/16_Overloading/readme.md docs/solidity-102/17_Library/Library.sol docs/solidity-102/17_Library/readme.md docs/solidity-102/18_Import/Yeye.sol docs/solidity-102/18_Import/readme.md docs/solidity-102/19_Fallback/Fallback.sol docs/solidity-102/19_Fallback/readme.md docs/solidity-102/20_SendETH/SendETH.sol docs/solidity-102/20_SendETH/readme.md docs/solidity-102/21_CallContract/CallContract.sol docs/solidity-102/21_CallContract/readme.md docs/solidity-102/22_Call/Call.sol docs/solidity-102/22_Call/readme.md docs/solidity-102/23_Delegatecall/Delegatecall.sol docs/solidity-102/23_Delegatecall/readme.md docs/solidity-102/24_Create/Create.sol docs/solidity-102/24_Create/readme.md docs/solidity-102/25_Create2/create2test.js docs/solidity-102/25_Create2/readme.md docs/solidity-102/26_DeleteContract/DeleteContract.sol docs/solidity-102/26_DeleteContract/img/26-1.png docs/solidity-102/26_DeleteContract/img/26-2.png docs/solidity-102/26_DeleteContract/readme.md docs/solidity-102/27_ABIEncode/ABIEncode.sol docs/solidity-102/27_ABIEncode/readme.md docs/solidity-102/28_Hash/Hash.sol docs/solidity-102/28_Hash/readme.md docs/solidity-102/29_Selector/Selector.sol docs/solidity-102/29_Selector/img/29-2.png docs/solidity-102/29_Selector/img/29-3.png docs/solidity-102/29_Selector/readme.md docs/solidity-102/30_TryCatch/TryCatch.sol docs/solidity-102/30_TryCatch/readme.md docs/solidity-103/31_ERC20/ERC20.sol docs/solidity-103/31_ERC20/IERC20.sol docs/solidity-103/31_ERC20/readme.md docs/solidity-103/32_Faucet/Faucet.sol docs/solidity-103/32_Faucet/IERC20.sol docs/solidity-103/32_Faucet/readme.md docs/solidity-103/33_Airdrop/Airdrop.sol docs/solidity-103/33_Airdrop/IERC20.sol docs/solidity-103/33_Airdrop/readme.md docs/solidity-103/34_ERC721/ERC721.sol docs/solidity-103/34_ERC721/String.sol docs/solidity-103/34_ERC721/WTFApe.sol docs/solidity-103/34_ERC721/readme.md docs/solidity-103/35_DutchAuction/DutchAuction.sol docs/solidity-103/35_DutchAuction/readme.md docs/solidity-103/36_MerkleTree/MerkleTree.sol docs/solidity-103/36_MerkleTree/readme.md docs/solidity-103/37_Signature/Signature.sol docs/solidity-103/37_Signature/readme.md docs/solidity-103/38_NFTSwap/NFTSwap.sol docs/solidity-103/38_NFTSwap/readme.md docs/solidity-103/39_Random/Random.sol docs/solidity-103/39_Random/RandomNumberConsumer.sol docs/solidity-103/39_Random/img/39-2.png docs/solidity-103/39_Random/img/39-3.png docs/solidity-103/39_Random/img/39-4.png docs/solidity-103/39_Random/img/39-5.png docs/solidity-103/39_Random/img/39-6.png docs/solidity-103/39_Random/img/39-7.png docs/solidity-103/39_Random/readme.md docs/solidity-103/40_ERC1155/BAYC1155.sol docs/solidity-103/40_ERC1155/readme.md docs/solidity-103/41_WETH/readme.md docs/solidity-103/42_PaymentSplit/PaymentSplit.sol docs/solidity-103/42_PaymentSplit/readme.md docs/solidity-103/43_TokenVesting/readme.md docs/solidity-103/44_TokenLocker/readme.md docs/solidity-103/45_Timelock/Timelock.sol docs/solidity-103/45_Timelock/readme.md docs/solidity-103/46_ProxyContract/ProxyContract.sol docs/solidity-103/46_ProxyContract/readme.md docs/solidity-103/47_Upgrade/Upgrade.sol docs/solidity-103/47_Upgrade/readme.md docs/solidity-103/48_TransparentProxy/TransparentProxy.sol docs/solidity-103/48_TransparentProxy/readme.md docs/solidity-103/49_UUPS/UUPS.sol docs/solidity-103/49_UUPS/readme.md docs/solidity-103/50_MultisigWallet/MultisigWallet.sol docs/solidity-103/50_MultisigWallet/readme.md docs/solidity-104/S01_ReentrancyAttack/ReentrancyAttack.sol docs/solidity-104/S01_ReentrancyAttack/readme.md docs/solidity-104/S02_SelectorClash/SelectorClash.sol docs/solidity-104/S02_SelectorClash/readme.md docs/solidity-104/S03_Centralization/Centralization.sol docs/solidity-104/S03_Centralization/readme.md docs/solidity-104/S04_AccessControlExploit/AccessControlExploit.sol docs/solidity-104/S04_AccessControlExploit/readme.md docs/solidity-104/S05_Overflow/Overflow.sol docs/solidity-104/S05_Overflow/readme.md docs/solidity-104/S06_SignatureReplay/SingatureReplay.sol docs/solidity-104/S06_SignatureReplay/readme.md docs/solidity-104/S07_BadRandomness/BadRandomness.sol docs/solidity-104/S07_BadRandomness/readme.md docs/solidity-104/S08_ContractCheck/ContractCheck.sol docs/solidity-104/S08_ContractCheck/readme.md docs/solidity-104/S09_DoS/DoS.sol docs/solidity-104/S09_DoS/readme.md docs/solidity-104/S10_Honeypot/Honeypot.sol docs/solidity-104/S10_Honeypot/readme.md docs/solidity-104/S11_Frontrun/Frontrun.sol docs/solidity-104/S11_Frontrun/frontrun.js docs/solidity-104/S11_Frontrun/readme.md docs/solidity-104/S12_TxOrigin/readme.md docs/solidity-104/S13_UncheckedCall/UncheckedCall.sol docs/solidity-104/S13_UncheckedCall/readme.md docs/solidity-104/S14_TimeManipulation/readme.md docs/solidity-104/S14_TimeManipulation/src/TimeManipulation.sol docs/solidity-104/S14_TimeManipulation/test/TimeManipulation.t.sol docs/solidity-104/S15_OracleManipulation/readme.md docs/solidity-104/S15_OracleManipulation/src/Oracle.sol docs/solidity-104/S15_OracleManipulation/test/Oracle.t.sol docs/solidity-104/S16_NFTReentrancy/NFTReentrancy.sol docs/solidity-104/S16_NFTReentrancy/readme.md docs/ethers-102/21_VanityAddress/BulkVanityAddress.js docs/solidity-101/05_DataStorage/img/5-5.png docs/solidity-101/05_DataStorage/img/5-6.png docs/solidity-101/06_ArrayAndStruct/img/6-4.png docs/solidity-101/06_ArrayAndStruct/img/6-5.png docs/solidity-101/11_Modifier/img/11-4.jpg docs/solidity-101/12_Event/img/12-4.png docs/solidity-101/13_Inheritance/DiamondInheritance.sol docs/solidity-101/14_Interface/AbstractDemo.sol docs/solidity-101/14_Interface/InterfaceDemo.sol docs/solidity-102/18_Import/Import.sol docs/solidity-102/25_Create2/Create2.sol docs/solidity-102/26_DeleteContract/DeployContract.sol docs/solidity-102/26_DeleteContract/img/26-3.png docs/solidity-102/26_DeleteContract/img/26-4.png docs/solidity-102/26_DeleteContract/img/26-5.png docs/solidity-102/26_DeleteContract/img/26-6.png docs/solidity-103/39_Random/img/39-10.png docs/solidity-103/39_Random/img/39-6-1.png docs/solidity-103/39_Random/img/39-8.png docs/solidity-103/39_Random/img/39-9.png docs/solidity-103/51_ERC4626/ docs/solidity-103/52_EIP712/ docs/solidity-103/53_ERC20Permit/ docs/solidity-103/54_CrossChainBridge/ docs/solidity-103/55_MultiCall/ docs/solidity-103/56_DEX/ docs/solidity-103/57_Flashloan/ docs/solidity-104/S17_CrossReentrancy/ +-------------------------------- +Sync started at Sun Aug 18 01:02:57 UTC 2024 + + +Changes in docs/solidity-101: +docs/solidity-101/09_Constant/readme.md + +Changes in docs/solidity-102: +docs/solidity-101/09_Constant/readme.md docs/solidity-102/22_Call/Call.sol docs/solidity-102/26_DeleteContract/readme.md + +Changes in docs/solidity-103: +docs/solidity-101/09_Constant/readme.md docs/solidity-102/22_Call/Call.sol docs/solidity-102/26_DeleteContract/readme.md + +Changes in docs/solidity-104: +docs/solidity-101/09_Constant/readme.md docs/solidity-102/22_Call/Call.sol docs/solidity-102/26_DeleteContract/readme.md + diff --git a/docs/solidity-101/09_Constant/readme.md b/docs/solidity-101/09_Constant/readme.md index ed179d2e..cbc30860 100755 --- a/docs/solidity-101/09_Constant/readme.md +++ b/docs/solidity-101/09_Constant/readme.md @@ -40,13 +40,14 @@ address constant CONSTANT_ADDRESS = 0x0000000000000000000000000000000000000000; ### immutable -`immutable`变量可以在声明时或构造函数中初始化,因此更加灵活。在`Solidity v8.0.21`以后,`immutable`变量不需要显式初始化。反之,则需要显式初始化。 +`immutable`变量可以在声明时或构造函数中初始化,因此更加灵活。在`Solidity v8.0.21`以后,`immutable`变量不需要显式初始化,未显式初始化的`immutable`变量将使用数值类型的初始值(见 [8. 变量初始值](https://github.com/AmazingAng/WTF-Solidity/blob/main/08_InitialValue/readme.md#%E5%8F%98%E9%87%8F%E5%88%9D%E5%A7%8B%E5%80%BC))。反之,则需要显式初始化。 若`immutable`变量既在声明时初始化,又在constructor中初始化,会使用constructor初始化的值。 ``` solidity // immutable变量可以在constructor里初始化,之后不能改变 uint256 public immutable IMMUTABLE_NUM = 9999999999; -address public immutable IMMUTABLE_ADDRESS; +// 在`Solidity v8.0.21`以后,下列变量数值暂为初始值 +address public immutable IMMUTABLE_ADDRESS; uint256 public immutable IMMUTABLE_BLOCK; uint256 public immutable IMMUTABLE_TEST; ``` diff --git a/docs/solidity-102/22_Call/Call.sol b/docs/solidity-102/22_Call/Call.sol index af1c98eb..45167a67 100755 --- a/docs/solidity-102/22_Call/Call.sol +++ b/docs/solidity-102/22_Call/Call.sol @@ -2,61 +2,56 @@ pragma solidity ^0.8.21; contract OtherContract { - uint256 private _x = 0; // 状态变量x - // 收到eth事件,记录amount和gas - event Log(uint amount, uint gas); + uint256 private _x = 0; // 状態変数_x + // ethを受け取るイベント、amountとgasを記録 - fallback() external payable{} + event Log(uint256 amount, uint256 gas); - // 返回合约ETH余额 - function getBalance() view public returns(uint) { + fallback() external payable {} + + // コントラクトのETH残高を返す関数 + function getBalance() public view returns (uint256) { return address(this).balance; } - // 可以调整状态变量_x的函数,并且可以往合约转ETH (payable) - function setX(uint256 x) external payable{ + // _xの値を設定できる関数。同時にコントラクトへETHを送信することもできる(payable) + function setX(uint256 x) external payable { _x = x; - // 如果转入ETH,则释放Log事件 - if(msg.value > 0){ + // もしETHの送信がある場合のみLogイベントを放出 + if (msg.value > 0) { emit Log(msg.value, gasleft()); } } - // 读取x - function getX() external view returns(uint x){ + // xの値を取得する関数 + function getX() external view returns (uint256 x) { x = _x; } } -contract Call{ - // 定义Response事件,输出call返回的结果success和data +contract Call { + // Response イベントは`call`の結果`success`と`data`を出力します event Response(bool success, bytes data); function callSetX(address payable _addr, uint256 x) public payable { - // call setX(),同时可以发送ETH - (bool success, bytes memory data) = _addr.call{value: msg.value}( - abi.encodeWithSignature("setX(uint256)", x) - ); + // setX()をcallし、ETHを送信 + (bool success, bytes memory data) = _addr.call{value: msg.value}(abi.encodeWithSignature("setX(uint256)", x)); - emit Response(success, data); //释放事件 + emit Response(success, data); // イベントを放出 } - function callGetX(address _addr) external returns(uint256){ + function callGetX(address _addr) external returns (uint256) { // call getX() - (bool success, bytes memory data) = _addr.call( - abi.encodeWithSignature("getX()") - ); + (bool success, bytes memory data) = _addr.call(abi.encodeWithSignature("getX()")); - emit Response(success, data); //释放事件 + emit Response(success, data); // イベントを放出 return abi.decode(data, (uint256)); } - function callNonExist(address _addr) external{ - // call 不存在的函数 - (bool success, bytes memory data) = _addr.call( - abi.encodeWithSignature("foo(uint256)") - ); + function callNonExist(address _addr) external { + // 存在しない関数を呼び出す + (bool success, bytes memory data) = _addr.call(abi.encodeWithSignature("foo(uint256)")); - emit Response(success, data); //释放事件 + emit Response(success, data); // イベントを放出 } } diff --git a/docs/solidity-102/26_DeleteContract/readme.md b/docs/solidity-102/26_DeleteContract/readme.md index 2d4fe7f5..1a6f46d0 100755 --- a/docs/solidity-102/26_DeleteContract/readme.md +++ b/docs/solidity-102/26_DeleteContract/readme.md @@ -149,4 +149,4 @@ contract DeployContract { `selfdestruct`是智能合约的紧急按钮,销毁合约并将剩余`ETH`转移到指定账户。当著名的`The DAO`攻击发生时,以太坊的创始人们一定后悔过没有在合约里加入`selfdestruct`来停止黑客的攻击吧。在坎昆升级后,`selfdestruct`的作用也逐渐发生了改变,什么都不是一成不变的,还是要保持学习。 - + \ No newline at end of file