Skip to content

Commit

Permalink
Lecture 2, 3, 4, 6, 10 source code comment into Japanese
Browse files Browse the repository at this point in the history
  • Loading branch information
PolymetisOutis committed Jul 27, 2024
1 parent a883b95 commit bff3e42
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
25 changes: 13 additions & 12 deletions Languages/ja/02_ValueTypes_ja/ValueTypes.sol
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
contract ValueTypes{
// Boolean
// Boolean(論理型)
bool public _bool = true;
// Boolean operators
// Boolean operators(論理演算子)
bool public _bool1 = !_bool; // logical NOT
bool public _bool2 = _bool && _bool1; // logical AND
bool public _bool3 = _bool || _bool1; // logical OR
bool public _bool4 = _bool == _bool1; // equality
bool public _bool5 = _bool != _bool1; // inequality


// Integer
// Integer(整数型)
int public _int = -1;
uint public _uint = 1;
uint256 public _number = 20220330;
// Integer operators
// Integer operators(整数型の演算子)
uint256 public _number1 = _number + 1; // +,-,*,/
uint256 public _number2 = 2**2; // exponent
uint256 public _number3 = 7 % 2; // modulo (modulus)
bool public _numberbool = _number2 > _number3; // greater than


// Address data type
// Address data type(アドレス型)
address public _address = 0x7A58c0Be72BE218B41C608b7Fe7C5bB630736C71;
address payable public _address1 = payable(_address); // payable address (allows for token transfer and balance checking)
// Members of addresses
uint256 public balance = _address1.balance; // balance of address
//(ペイアブルなアドレス(トークンの移動や残高の確認が可能))
// Members of addresses(アドレスのメンバ)
uint256 public balance = _address1.balance; // balance of address(アドレスの残高)


// Fixed-size byte arrays
// Fixed-size byte arrays(固定長配列)
bytes32 public _byte32 = "MiniSolidity"; // bytes32: 0x4d696e69536f6c69646974790000000000000000000000000000000000000000
bytes1 public _byte = _byte32[0]; // bytes1: 0x4d


// Enumeration
// Let uint 0, 1, 2 represent Buy, Hold, Sell
// Enumeration(列挙型)
// Let uint 0, 1, 2 represent Buy, Hold, Sell(uint型の0,1,2がBuy,Hold,Sellを表すとする)
enum ActionSet { Buy, Hold, Sell }
// Create an enum variable called action
// Create an enum variable called action(actionという列挙型変数を作成)
ActionSet action = ActionSet.Buy;

// Enum can be converted into uint
// Enum can be converted into uint(列挙型はuint型に変換出来る)
function enumToUint() external view returns(uint){
return uint(action);
}
Expand Down
11 changes: 8 additions & 3 deletions Languages/ja/03_Function_ja/Function.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@ contract FunctionTypes{

constructor() payable {}

// function type
// function type(関数型)
// function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)]
// default function
// default function(デフォルトの関数)
function add() external{
number = number + 1;
}

// pure: not only does the function not save any data to the blockchain, but it also doesn't read any data from the blockchain.
//(pure: 関数がブロックチェーンにどんなデータも保存しないだけでなく、ブロックチェーンからデータを読み込むこともない)
function addPure(uint256 _number) external pure returns(uint256 new_number){
new_number = _number+1;
}

// view: no data will be changed
//(view: 何もデータが変更されない)
function addView() external view returns(uint256 new_number) {
new_number = number + 1;
}

// internal: the function can only be called within the contract itself and any derived contracts
//(internal: 関数は、コントラクトそのものの中か、あらゆる派生したコントラクト内でのみ呼び出されることが出来る)
function minus() internal {
number = number - 1;
}

// external: function can be called by EOA/other contract
//(external: 関数はEOAか他のコントラクトによって呼び出されることが出来る)
function minusCall() external {
minus();
}

//payable: money (ETH) can be sent to the contract via this function
// payable: money (ETH) can be sent to the contract via this function
//(payable: 関数を経由してお金(イーサリアム)をコントラクトに送金することが出来る)
function minusPayable() external payable returns(uint256 balance) {
minus();
balance = address(this).balance;
Expand Down
16 changes: 8 additions & 8 deletions Languages/ja/04_Return_ja/Return.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

// Return multiple variables
// Named returns
// Destructuring assignments
// Return multiple variables(複数の変数を返す)
// Named returns       (名前付き返り値)
// Destructuring assignments(分割代入)

contract Return {
// Return multiple variables
// Return multiple variables(複数の変数を返す)
function returnMultiple() public pure returns(uint256, bool, uint256[3] memory){
return(1, true, [uint256(1),2,5]);
}

// Named returns
// Named returns(名前付き返り値)
function returnNamed() public pure returns(uint256 _number, bool _bool, uint256[3] memory _array){
_number = 2;
_bool = false;
_array = [uint256(3),2,1];
}

// Named returns, still supports return
// Named returns, still supports return(名前付き返り値、通常のreturnステートメントも引き続きサポート)
function returnNamed2() public pure returns(uint256 _number, bool _bool, uint256[3] memory _array){
return(1, true, [uint256(1),2,5]);
}

// Read return values, destructuring assignments
// Read return values, destructuring assignments(返り値の読み込み、分割代入)
function readReturn() public pure{
// Read all return values
uint256 _number;
Expand All @@ -32,7 +32,7 @@ contract Return {
uint256[3] memory _array;
(_number, _bool, _array) = returnNamed();

// Read part of return values, destructuring assignments
// Read part of return values, destructuring assignments(返り値の一部を読み込み、分割代入)
(, _bool2, ) = returnNamed();
}
}
12 changes: 6 additions & 6 deletions Languages/ja/10_InsertionSort_ja/InsertionSort.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ contract InsertionSort {
return(sum);
}

// Ternary/Conditional operator
// Ternary/Conditional operator(三項演算子/条件演算子)
function ternaryTest(uint256 x, uint256 y) public pure returns(uint256){
// return the max of x and y
// return the max of x and y(xとyの最大値を返す)
return x >= y ? x: y;
}


// Insertion Sort(Wrong version)
// Insertion Sort(Wrong version)(挿入ソート(間違いバージョン))
function insertionSortWrong(uint[] memory a) public pure returns(uint[] memory) {
// note that uint can not take negative value
// note that uint can not take negative value(uint型は負の数を取れないことに注意すること)
for (uint i = 1;i < a.length;i++){
uint temp = a[i];
uint j=i-1;
Expand All @@ -63,9 +63,9 @@ contract InsertionSort {
return(a);
}

// Insertion Sort(Correct Version)
// Insertion Sort(Correct Version)(挿入ソート(正確なバージョン))
function insertionSort(uint[] memory a) public pure returns(uint[] memory) {
// note that uint can not take negative value
// note that uint can not take negative value(uint型は負の数を取れないことに注意すること)
for (uint i = 1;i < a.length;i++){
uint temp = a[i];
uint j=i;
Expand Down

0 comments on commit bff3e42

Please sign in to comment.