From 5febe81d56a59b03029e93db35ceaa00f578aded Mon Sep 17 00:00:00 2001 From: 0xAA Date: Sat, 28 Sep 2024 13:36:50 +0800 Subject: [PATCH] Update Call.sol ja version --- Languages/ja/22_Call_ja/Call.sol | 55 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/Languages/ja/22_Call_ja/Call.sol b/Languages/ja/22_Call_ja/Call.sol index af1c98eb6..45167a67c 100644 --- a/Languages/ja/22_Call_ja/Call.sol +++ b/Languages/ja/22_Call_ja/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); // イベントを放出 } }