├── docs
├── _static
│ ├── img
│ │ ├── favicon.ico
│ │ ├── favicon.png
│ │ ├── moon.svg
│ │ ├── hamburger-dark.svg
│ │ ├── hamburger-light.svg
│ │ ├── solid-share-arrow.svg
│ │ ├── logo.svg
│ │ ├── logo-dark.svg
│ │ └── sun.svg
│ ├── css
│ │ ├── fonts.css
│ │ ├── toggle.css
│ │ └── pygments.css
│ └── js
│ │ ├── constants.js
│ │ └── toggle.js
├── _templates
│ ├── footer.html
│ ├── layout.html
│ └── versions.html
├── solidity-by-example.rst
├── grammar.rst
├── robots.txt.template
├── logo.svg
├── README.md
├── diff.py
├── types.rst
├── requirements.txt
├── internals
│ ├── layout_in_calldata.rst
│ ├── layout_in_memory.rst
│ ├── variable_cleanup.rst
│ └── source_mappings.rst
├── credits-and-attribution.rst
├── contracts.rst
├── solidity_logo.svg
├── docs.sh
├── brand-guide.rst
├── ext
│ ├── html_extra_template_renderer.py
│ └── remix_code_links.py
├── language-influences.rst
├── examples
│ ├── modular.rst
│ ├── safe-remote.rst
│ └── voting.rst
├── contracts
│ ├── interfaces.rst
│ ├── abstract-contracts.rst
│ ├── custom-storage-layout.rst
│ ├── creating-contracts.rst
│ ├── function-modifiers.rst
│ ├── errors.rst
│ ├── constant-state-variables.rst
│ └── events.rst
├── progress-checklist.md
├── structure-of-a-contract.rst
├── types
│ ├── operator-precedence-table.rst
│ └── operators.rst
├── index.rst
├── text_linter.py
├── bugs.rst
├── Makefile
├── make.bat
├── analysing-compilation-output.rst
├── cheatsheet.rst
├── layout-of-source-files.rst
└── 070-breaking-changes.rst
├── translation-bot.json
├── .gitignore
├── .readthedocs.yml
├── .github
├── scripts
│ ├── check-remote-branch.sh
│ ├── set-assignees.sh
│ ├── create-sync-branch-for-release.sh
│ ├── load-translation-bot-config.sh
│ ├── pull-and-resolve-english-changes.sh
│ └── generate-pr-body.sh
└── workflows
│ ├── build.yml
│ └── create-weekly-docs-sync-pr.yaml
├── README.md
└── CMakeLists.txt
/docs/_static/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidity-docs/ja-japanese/HEAD/docs/_static/img/favicon.ico
--------------------------------------------------------------------------------
/docs/_static/img/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidity-docs/ja-japanese/HEAD/docs/_static/img/favicon.png
--------------------------------------------------------------------------------
/docs/_static/css/fonts.css:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.cdnfonts.com/css/overpass");
2 | @import url("https://fonts.cdnfonts.com/css/overpass-mono");
--------------------------------------------------------------------------------
/translation-bot.json:
--------------------------------------------------------------------------------
1 | {
2 | "disabled": true,
3 | "custom_sync_disabled": false,
4 | "randomly_assign_maintainers": false,
5 | "pr_labels": [
6 | "sync-pr"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/docs/_templates/footer.html:
--------------------------------------------------------------------------------
1 | {% extends "!footer.html" %}
2 |
3 | {% block extrafooter %}
4 |
5 | Credits and attribution.
6 |
7 | {% endblock %}
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built docs
2 | /docs/_build
3 |
4 | # Automatically generated robots.txt
5 | /docs/_static/robots.txt
6 |
7 | # Python bytecode
8 | *.pyc
9 | __pycache__
10 |
11 | .vscode
12 |
13 | .DS_Store
14 |
15 | venv
16 |
17 | AGENTS.md
--------------------------------------------------------------------------------
/docs/_templates/layout.html:
--------------------------------------------------------------------------------
1 | {% extends "!layout.html" %}
2 |
3 | {% block menu %}
4 | {{ super() }}
5 |
10 | {% endblock %}
11 |
--------------------------------------------------------------------------------
/.readthedocs.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | build:
4 | os: ubuntu-22.04
5 | tools:
6 | python: "3.11"
7 |
8 | sphinx:
9 | builder: html
10 | configuration: docs/conf.py
11 |
12 | formats:
13 | - pdf
14 | - epub
15 |
16 | python:
17 | install:
18 | - requirements: docs/requirements.txt
19 |
--------------------------------------------------------------------------------
/docs/solidity-by-example.rst:
--------------------------------------------------------------------------------
1 | ###################
2 | Solidity by Example
3 | ###################
4 |
5 | .. include:: examples/voting.rst
6 |
7 | .. include:: examples/blind-auction.rst
8 |
9 | .. include:: examples/safe-remote.rst
10 |
11 | .. include:: examples/micropayment.rst
12 |
13 | .. include:: examples/modular.rst
--------------------------------------------------------------------------------
/docs/grammar.rst:
--------------------------------------------------------------------------------
1 | **********
2 | 言語の文法
3 | **********
4 |
5 | .. a4:autogrammar:: SolidityParser
6 | :only-reachable-from: SolidityParser.sourceUnit
7 | :undocumented:
8 | :cc-to-dash:
9 |
10 | .. a4:autogrammar:: SolidityLexer
11 | :only-reachable-from: SolidityParser.sourceUnit
12 | :fragments:
13 | :cc-to-dash:
14 |
15 |
--------------------------------------------------------------------------------
/docs/_static/img/moon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/_static/img/hamburger-dark.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/_static/img/hamburger-light.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/robots.txt.template:
--------------------------------------------------------------------------------
1 | User-Agent: *
2 | Sitemap: http://docs.soliditylang.org/sitemap.xml
3 | Host: docs.soliditylang.org
4 |
5 | Allow: /en/latest/
6 | Allow: /en/v0.7.6/
7 | Allow: /en/v{{ LATEST_VERSION }}/
8 | Allow: /_/downloads/en/latest/
9 | Allow: /_/downloads/en/0.7.6/
10 | Allow: /_/downloads/en/{{ LATEST_VERSION }}/
11 |
12 | # Prevent documentation for the development branches and older Solidity
13 | # versions from showing up in search results.
14 | Disallow: /en/*
15 | Disallow: /_/downloads/en/*
16 |
--------------------------------------------------------------------------------
/docs/_static/img/solid-share-arrow.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.github/scripts/check-remote-branch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | function fail { >&2 echo -e "ERROR: $1"; exit 1; }
5 |
6 | (( $# == 1 )) || fail "Wrong number of arguments\nUsage: $0 > "$GITHUB_OUTPUT"
20 |
--------------------------------------------------------------------------------
/docs/logo.svg:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/docs/_static/img/logo.svg:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/docs/_static/img/logo-dark.svg:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # Solidity Language Docs
2 |
3 | ## Local environment setup
4 |
5 | 1. Install python https://www.python.org/downloads/
6 | 1. Install sphinx (the tool used to generate the docs) https://www.sphinx-doc.org/en/master/usage/installation.html
7 |
8 | Go to `/docs` and run `./docs.sh` to install dependencies and build the project:
9 |
10 | ```sh
11 | cd docs
12 | ./docs.sh
13 | ```
14 |
15 | That will output the generated htmls under _build/
16 |
17 | ## Serve environment
18 |
19 | ```py
20 | python3 -m http.server -d _build/html --cgi 8080
21 | ```
22 |
23 | Visit dev server at http://localhost:8080
24 |
--------------------------------------------------------------------------------
/docs/_static/img/sun.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches: [ "develop" ]
6 | pull_request:
7 | branches: [ "develop" ]
8 |
9 | workflow_dispatch:
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | if: github.event.pull_request.draft == false
15 |
16 | steps:
17 | - uses: actions/checkout@v3
18 |
19 | - uses: actions/setup-python@v4
20 | with:
21 | python-version: '3.10'
22 | # cache: 'pip' # ERROR
23 | - run: pip install -r docs/requirements.txt
24 |
25 | - name: Build
26 | working-directory: ./docs
27 | run: make html
28 |
29 |
--------------------------------------------------------------------------------
/docs/diff.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | """
4 | ただ改行するだけの変更かどうかを判別
5 | """
6 |
7 | a = """
8 | """
9 |
10 | b = """
11 | """
12 |
13 | a = a.split("\n")
14 | for i in range(len(a)):
15 | if a[i].startswith("-"):
16 | a[i] = a[i][1:]
17 |
18 | b = b.split("\n")
19 | for i in range(len(b)):
20 | if b[i].startswith("+"):
21 | b[i] = b[i][1:]
22 |
23 | a = " ".join(a).replace(".", ".\n").split("\n")
24 | b = " ".join(b).replace(".", ".\n").split("\n")
25 |
26 | for x, y in zip(a, b):
27 | x , y = x.strip(), y.strip()
28 | x = re.sub(r"\s+", " ", x)
29 | y = re.sub(r"\s+", " ", y)
30 | if x != y:
31 | print(x)
32 | print(y)
33 | print()
--------------------------------------------------------------------------------
/docs/types.rst:
--------------------------------------------------------------------------------
1 | .. index:: type
2 |
3 | .. _types:
4 |
5 | **
6 | 型
7 | **
8 |
9 | Solidityは静的型付け言語です。
10 | つまり、各変数(ステートとローカル)の型を指定する必要があります。
11 | Solidityにはいくつかの基本的な型があり、それらを組み合わせて複雑な型を作ることができます。
12 |
13 | また、演算子を含む式では、型同士が相互に作用できます。
14 | 様々な演算子のクイックリファレンスについては、 :ref:`order` を参照してください。
15 |
16 | Solidityには "undefined"や"null"の値の概念はありませんが、新しく宣言された変数は常にその型に依存した :ref:`デフォルト値` を持ちます。
17 | 予期せぬ値を処理するには、 :ref:`リバート` を使ってトランザクション全体をリバートするか、成功を示す ``bool`` 値を2番目に持つタプルを返す必要があります。
18 |
19 | .. include:: types/value-types.rst
20 |
21 | .. include:: types/reference-types.rst
22 |
23 | .. include:: types/mapping-types.rst
24 |
25 | .. include:: types/operators.rst
26 |
27 | .. include:: types/conversion.rst
28 |
29 |
--------------------------------------------------------------------------------
/docs/requirements.txt:
--------------------------------------------------------------------------------
1 | # Older versions of sphinx-rtd-theme do not work with never docutils but have a bug in the dependency
2 | # which could result in it being installed anyway and the style (especially bullet points) being broken.
3 | # See https://github.com/readthedocs/sphinx_rtd_theme/issues/1115
4 | # theme >=3.0.0 removes the display_version option in favor of version_selector and language_selector
5 | sphinx_rtd_theme>=0.5.2, <3.0.0
6 |
7 | pygments-lexer-solidity>=0.7.0
8 | sphinx-a4doc>=1.6.0; python_version < '3.13'
9 | # todo remove this once there is a version > 1.6.0
10 | sphinx-a4doc @ git+https://github.com/taminomara/sphinx-a4doc@f63d3b2; python_version >= '3.13'
11 |
12 | # Sphinx 2.1.0 is the oldest version that accepts a lexer class in add_lexer()
13 | sphinx>=2.1.0, <9.0
14 |
--------------------------------------------------------------------------------
/.github/scripts/set-assignees.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 | LANGUAGE=$1
4 |
5 | # extracts de from de-german
6 | lang_code=${LANGUAGE:0:2}
7 | number_of_maintainers=$(jq '.maintainers | length' ".github-workflow/langs/$lang_code.json")
8 |
9 |
10 | assignee=$((($RANDOM%$number_of_maintainers)))
11 | reviewer=$((($RANDOM%$number_of_maintainers)))
12 |
13 | while [[ $assignee == "$reviewer" && number_of_maintainers -gt 1 ]]
14 | do
15 | reviewer=$((($RANDOM%$number_of_maintainers)))
16 | done
17 |
18 | echo "reviewer=$(
19 | jq --raw-output ".maintainers[$reviewer]" ".github-workflow/langs/$lang_code.json"
20 | )" >> $GITHUB_ENV
21 |
22 | echo "assignee=$(
23 | jq --raw-output ".maintainers[$assignee]" ".github-workflow/langs/$lang_code.json"
24 | )" >> $GITHUB_ENV
25 |
26 |
--------------------------------------------------------------------------------
/docs/internals/layout_in_calldata.rst:
--------------------------------------------------------------------------------
1 |
2 | .. index: calldata layout
3 |
4 | ************************
5 | コールデータのレイアウト
6 | ************************
7 |
8 | .. The input data for a function call is assumed to be in the format defined by the :ref:`ABI
9 | .. specification `. Among others, the ABI specification requires arguments to be padded to multiples of 32
10 | .. bytes. The internal function calls use a different convention.
11 |
12 | 関数呼び出しの入力データは、 :ref:`ABIの仕様` で定義されたフォーマットであることが前提となっています。
13 | とりわけ、ABI仕様では、引数を32バイトの倍数にパディングすることが求められています。
14 | 内部の関数呼び出しでは、これとは異なる規則が用いられています。
15 |
16 | .. Arguments for the constructor of a contract are directly appended at the end of the
17 | .. contract's code, also in ABI encoding. The constructor will access them through a hard-coded offset, and
18 | .. not by using the ``codesize`` opcode, since this of course changes when appending
19 | .. data to the code.
20 |
21 | コントラクトのコンストラクタの引数は、コントラクトのコードの最後にABIエンコーディングで直接追加されます。
22 | コンストラクタはハードコードされたオフセットを使ってアクセスしますが、コードにデータを追加するときに変更されるため、 ``codesize`` オペコードは使用しません。
23 |
24 |
--------------------------------------------------------------------------------
/.github/scripts/create-sync-branch-for-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | # This script creates sync branches matching tagged releases in the main Solidity repository.
5 | # The result is a sync commit and a branch. The script does NOT push the branch or create a PR.
6 |
7 | # ASSUMPTIONS:
8 | # - The current directory already contains a clone of the translation repository.
9 | # - If a remote called 'english' exists, it points to the main Solidity repository.
10 |
11 | script_dir="$(dirname "$0")"
12 |
13 | function fail { >&2 echo -e "ERROR: $1"; exit 1; }
14 |
15 | (( $# == 1 )) || fail "Wrong number of arguments\nUsage: $0 "
16 | TAG="$1"
17 | if ! git config remote.english.url; then
18 | git remote add english "https://github.com/ethereum/solidity.git"
19 | fi
20 |
21 | git fetch english tag "$TAG" --no-tags
22 | git fetch english develop
23 |
24 | git checkout origin/develop
25 | git checkout -b "sync-${TAG}"
26 |
27 | today=$(date -u +%Y-%m-%d)
28 | "${script_dir}/pull-and-resolve-english-changes.sh" "$TAG" "Sync with ethereum/solidity@${TAG} (${today})"
29 |
--------------------------------------------------------------------------------
/docs/credits-and-attribution.rst:
--------------------------------------------------------------------------------
1 | .. This page is meant to be linked to from the footer.
2 |
3 | :orphan:
4 |
5 | .. Credits and Attribution
6 |
7 | ##############################
8 | クレジットとアトリビューション
9 | ##############################
10 |
11 | Webサイトのアイコン
12 | ===================
13 |
14 | .. |icon-share-solid| image:: _static/img/solid-share-arrow.svg
15 | .. _share icon: https://fontawesome.com/v5.15/icons/share?style=solid
16 | .. _Font Awesome Free License: https://fontawesome.com/license/free
17 |
18 | +-------------------------+-----------------------------------------------------------------------+
19 | | アイコン | アトリビューション |
20 | +=========================+=======================================================================+
21 | | |icon-share-solid| | - ソース: `share icon`_ from Font Awesome 5.15.0 |
22 | | | - ライセンス: `Font Awesome Free License`_ (CC BY 4.0) |
23 | +-------------------------+-----------------------------------------------------------------------+
24 |
25 |
--------------------------------------------------------------------------------
/docs/_templates/versions.html:
--------------------------------------------------------------------------------
1 | {# Add rst-badge after rst-versions for small badge style. #}
2 |
3 |
4 | RTD
5 |
6 |
7 |
8 |
9 |
10 |
11 | v: {{ current_version }}
12 |
13 |
14 |
15 |
16 | - {{ _('Downloads') }}
{% for type, url in downloads %}
17 | - {{ type }}
18 | {% endfor %}
19 |
20 |
21 | - {{ _('Versions') }}
{% for slug, url in versions %}
22 | - {{ slug }}
23 | {% endfor %}
24 |
25 |
26 | {# Translators: The phrase "Read the Docs" is not translated #}
27 | - {{ _('On Read the Docs') }}
28 | -
29 | {{ _('Project Home') }}
30 |
31 | -
32 | {{ _('Builds') }}
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/docs/contracts.rst:
--------------------------------------------------------------------------------
1 | .. index:: ! contract
2 |
3 | .. _contracts:
4 |
5 | ############
6 | コントラクト
7 | ############
8 |
9 | .. Contracts in Solidity are similar to classes in object-oriented languages. They
10 | .. contain persistent data in state variables, and functions that can modify these
11 | .. variables. Calling a function on a different contract (instance) will perform
12 | .. an EVM function call and thus switch the context such that state variables
13 | .. in the calling contract are
14 | .. inaccessible. A contract and its functions need to be called for anything to happen.
15 | .. There is no "cron" concept in Ethereum to call a function at a particular event automatically.
16 |
17 | Solidityのコントラクトは、オブジェクト指向言語のクラスに似ています。
18 | コントラクトには、状態変数に格納された永続的なデータと、これらの変数を変更できる関数が含まれています。
19 | 別のコントラクト(インスタンス)の関数を呼び出すと、EVM関数呼び出しが実行され、呼び出したコントラクトの状態変数にアクセスできないようにコンテキストが切り替わります。
20 | コントラクトとその関数は、何かが起こるために呼び出される必要があります。
21 | Ethereumには、特定のイベントで自動的に関数を呼び出す「cron」の概念はありません。
22 |
23 | .. include:: contracts/creating-contracts.rst
24 |
25 | .. include:: contracts/visibility-and-getters.rst
26 |
27 | .. include:: contracts/function-modifiers.rst
28 |
29 | .. include:: contracts/transient-storage.rst
30 |
31 | .. include:: contracts/constant-state-variables.rst
32 | .. include:: contracts/custom-storage-layout.rst
33 | .. include:: contracts/functions.rst
34 |
35 | .. include:: contracts/events.rst
36 | .. include:: contracts/errors.rst
37 |
38 | .. include:: contracts/inheritance.rst
39 |
40 | .. include:: contracts/abstract-contracts.rst
41 | .. include:: contracts/interfaces.rst
42 |
43 | .. include:: contracts/libraries.rst
44 |
45 | .. include:: contracts/using-for.rst
46 |
--------------------------------------------------------------------------------
/docs/solidity_logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
28 |
--------------------------------------------------------------------------------
/docs/_static/js/constants.js:
--------------------------------------------------------------------------------
1 | // Site URL
2 | const SITE_URL = "https://docs.soliditylang.org"
3 | const { origin, pathname } = location;
4 | const pathSplit = pathname.split("/");
5 | const rootPath = origin.includes(SITE_URL) && pathSplit.length > 3 ? pathSplit.splice(1, 2).join("/") : ''
6 | const ROOT_URL = `${origin}/${rootPath}`;
7 |
8 | // Color mode constants
9 | const [DARK, LIGHT] = ["dark", "light"];
10 | const LIGHT_LOGO_PATH = `${ROOT_URL}/_static/img/logo.svg`;
11 | const DARK_LOGO_PATH = `${ROOT_URL}/_static/img/logo-dark.svg`;
12 | const SUN_ICON_PATH = `${ROOT_URL}/_static/img/sun.svg`;
13 | const MOON_ICON_PATH = `${ROOT_URL}/_static/img/moon.svg`;
14 | const LIGHT_HAMBURGER_PATH = `${ROOT_URL}/_static/img/hamburger-light.svg`;
15 | const DARK_HAMBURGER_PATH = `${ROOT_URL}/_static/img/hamburger-dark.svg`;
16 | const COLOR_TOGGLE_ICON_CLASS = "color-toggle-icon";
17 | const SOLIDITY_LOGO_CLASS = "solidity-logo";
18 | const LS_COLOR_SCHEME = "color-scheme";
19 |
20 | // Solidity navigation constants
21 | const SOLIDITY_HOME_URL = "https://soliditylang.org";
22 | const BLOG_URL = `${SOLIDITY_HOME_URL}/blog`;
23 | const DOCS_URL = "/";
24 | const USE_CASES_PATH = `${SOLIDITY_HOME_URL}/use-cases`;
25 | const CONTRIBUTE_PATH = `/en/latest/contributing.html`;
26 | const ABOUT_PATH = `${SOLIDITY_HOME_URL}/about`;
27 | const FORUM_URL = "https://forum.soliditylang.org/";
28 | const NAV_LINKS = [
29 | { name: "Blog", href: BLOG_URL },
30 | { name: "Documentation", href: DOCS_URL },
31 | { name: "Use cases", href: USE_CASES_PATH },
32 | { name: "Contribute", href: CONTRIBUTE_PATH },
33 | { name: "About", href: ABOUT_PATH },
34 | { name: "Forum", href: FORUM_URL },
35 | ];
36 |
37 | const MOBILE_MENU_TOGGLE_CLASS = "shift";
38 | const WRAPPER_CLASS = "unified-wrapper";
39 |
--------------------------------------------------------------------------------
/docs/docs.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | #------------------------------------------------------------------------------
4 | # Bash script to build the Solidity Sphinx documentation locally.
5 | #
6 | # The documentation for solidity is hosted at:
7 | #
8 | # https://docs.soliditylang.org
9 | #
10 | # ------------------------------------------------------------------------------
11 | # This file is part of solidity.
12 | #
13 | # solidity is free software: you can redistribute it and/or modify
14 | # it under the terms of the GNU General Public License as published by
15 | # the Free Software Foundation, either version 3 of the License, or
16 | # (at your option) any later version.
17 | #
18 | # solidity is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | # GNU General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU General Public License
24 | # along with solidity. If not, see
25 | #
26 | # (c) 2016 solidity contributors.
27 | #------------------------------------------------------------------------------
28 |
29 | set -euo pipefail
30 |
31 | script_dir="$(dirname "$0")"
32 |
33 | cd "${script_dir}"
34 | # TODO `--ignore-installed` now fixes an issue where pip tries to uninstall a Debian installed package, but is unable to
35 | # TODO since Debian has decided to not use the RECORD file, which then breaks pip.
36 | # TODO https://github.com/pypa/pip/issues/11631 and https://bugs.launchpad.net/ubuntu/+source/wheel/+bug/2063151
37 | pip3 install -r requirements.txt --ignore-installed --upgrade --upgrade-strategy eager
38 | sphinx-build -nW -b html -d _build/doctrees . _build/html
39 |
--------------------------------------------------------------------------------
/docs/_static/js/toggle.js:
--------------------------------------------------------------------------------
1 | function toggleColorMode() {
2 | // Check localStorage for previous color scheme preference, assign the opposite
3 | var newMode = localStorage.getItem(LS_COLOR_SCHEME) == DARK ? LIGHT : DARK;
4 |
5 | // Update localStorage with new color scheme preference
6 | localStorage.setItem(LS_COLOR_SCHEME, newMode);
7 |
8 | // Update the root element with the new color scheme preference
9 | document
10 | .querySelector(":root")
11 | .setAttribute("style", `--color-scheme: ${newMode}`);
12 |
13 | // Update logo
14 | document
15 | .querySelector(`img.${SOLIDITY_LOGO_CLASS}`)
16 | .setAttribute("src", newMode === LIGHT ? LIGHT_LOGO_PATH : DARK_LOGO_PATH);
17 |
18 | // Update color mode toggle icon
19 | document
20 | .querySelector(`img.${COLOR_TOGGLE_ICON_CLASS}`)
21 | .setAttribute("src", newMode === LIGHT ? MOON_ICON_PATH : SUN_ICON_PATH);
22 |
23 | // Update hamburger menu icon color
24 | document
25 | .querySelector("button.mobile-menu-button img")
26 | .setAttribute(
27 | "src",
28 | newMode === LIGHT ? LIGHT_HAMBURGER_PATH : DARK_HAMBURGER_PATH
29 | );
30 | }
31 |
32 | function toggleMenu(options = {}) {
33 | const handleClassToggle = ({ classList }, className) => {
34 | if (typeof options.force !== "undefined") {
35 | classList.toggle(className, options.force);
36 | } else {
37 | classList.toggle(className);
38 | }
39 | };
40 | document
41 | .querySelectorAll('[data-toggle="rst-versions"]')
42 | .forEach((e) => handleClassToggle(e, MOBILE_MENU_TOGGLE_CLASS));
43 | document
44 | .querySelectorAll('[data-toggle="wy-nav-shift"]')
45 | .forEach((e) => handleClassToggle(e, MOBILE_MENU_TOGGLE_CLASS));
46 | handleClassToggle(document.querySelector(`.${WRAPPER_CLASS}`), "menu-open");
47 | }
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Japanese Translation of the Solidity Documentation
2 |
3 | Solidityドキュメントの日本語翻訳プロジェクトです。
4 | 進捗状況は https://github.com/solidity-docs/ja-japanese/issues/1 で確認できます。
5 | このリポジトリは https://docs.soliditylang.org/ja/latest/ と連携しています。
6 |
7 | Solidityドキュメントの翻訳者のチャットは https://forum.soliditylang.org/t/new-communication-channel-about-solidity-docs-community-translations/918 に記載されています。
8 |
9 | なお以前は、 https://solidity-ja.readthedocs.io/ で日本語翻訳を閲覧可能でした(ビルド元はこのリポジトリと同期している https://github.com/minaminao/ja-japanese です)。
10 | 現在は https://docs.soliditylang.org/ja/ にリダイレクトされます。
11 |
12 | ## 翻訳に際して
13 |
14 | ### 同期PRの対処の仕方
15 |
16 | [ethereum/solidity](https://github.com/ethereum/solidity) と同期するPRが定期的に作成される。
17 |
18 | 基本的にGitHubのGUIだけでは翻訳するのは難しく、gitコマンドを使ったCUI操作が必要。
19 |
20 | まず、同期PRの「Files changed」から変更されたドキュメントのファイル一覧を見る。
21 |
22 | 次に、前回の同期PRの最終コミットハッシュから、今回の同期PRの最新コミットハッシュ間の差分を、オリジナルの ethereum/solidity リポジトリで、 `git diff ..` を実行して表示する。
23 | 具体的なコミットハッシュは前回の同期PRの最後のコミットハッシュ(botによるコミットの直前)と、今回の同期PRの最後のコミットハッシュ(botによるコミットの直前)を使えば良い。
24 |
25 | そして、変更された各ファイルごとに、 `git diff` の結果画面で `/` コマンドで変更点を調べる。
26 | `gh pr checkout ` 等を用いて該当PRのブランチに切り替え、コンフリクトの対処や翻訳を行う。
27 |
28 | ### 環境構築の一例
29 |
30 | ```
31 | pyenv shell 3.12.7
32 | python -m venv venv
33 | source venv/bin/activate.fish
34 | pip install -r docs/requirements.txt
35 | ```
36 |
37 | ### ビルド
38 |
39 | HTML:
40 | ```
41 | source venv/bin/activate.fish
42 | cd docs
43 | make html
44 | ```
45 |
46 | PDF:
47 | ```
48 | source venv/bin/activate.fish
49 | cd docs
50 | make latexpdf
51 | ```
52 |
53 |
58 |
59 | ### 特定のバージョンの同期PRの作り方
60 |
61 | https://github.com/solidity-docs/.github/blob/main/scripts/create-sync-branch-for-release.sh をこのリポジトリのルートで実行するとブランチが生成される。
62 | それをpushしてPRを作成する。
63 |
--------------------------------------------------------------------------------
/docs/brand-guide.rst:
--------------------------------------------------------------------------------
1 | ######################
2 | Solidityブランドガイド
3 | ######################
4 |
5 | このブランドガイドでは、Solidityのブランドポリシーやロゴ使用のガイドラインなどを紹介します。
6 |
7 | Solidityのブランド
8 | ==================
9 |
10 | Solidity プログラミング言語は、コアチームが運営するオープンソースのコミュニティプロジェクトです。
11 | コアチームのスポンサーは `Ethereum Foundation `_ です。
12 |
13 | このドキュメントは、Solidityのブランド名とロゴの最適な使用方法についての情報を提供することを目的としています。
14 |
15 | ブランド名やロゴを使用する前に、この文書をよくお読みになってください。
16 | 皆様のご協力に深く感謝いたします!
17 |
18 | Solidityのブランド名
19 | ====================
20 |
21 | 『Solidity』は、Solidity プログラミング言語のみを指す言葉です。
22 |
23 | 以下の場合に『Solidity』は使用しないでください:
24 |
25 | - 他のプログラミング言語を指し示す行為。
26 | - 誤解を招くような方法や、無関係なモジュール、ツール、ドキュメント、その他のリソースとSolidityの関連性を示唆するような方法での使用。
27 | - Solidity プログラミング言語がオープンソースであり無料で使用できるかどうかについて、コミュニティを混乱させるような方法。
28 |
29 | Solidityロゴのライセンス
30 | ========================
31 |
32 | .. image:: https://i.creativecommons.org/l/by/4.0/88x31.png
33 | :width: 88
34 | :alt: Creative Commons License
35 |
36 | Solidityのロゴは、 `Creative Commons Attribution 4.0 International License `_ の下で配布され、ライセンスされています。
37 |
38 | これは、最も寛容なクリエイティブ・コモンズ・ライセンスであり、いかなる目的のためにも再利用や修正を認めています。
39 |
40 | あなたは後で示す条件のもとで次のことを自由に行えます:
41 |
42 | - **Share** — 媒体や形式を問わず、コピーして再配布すること。
43 | - **Adapt** — 営利目的含むいかなる目的であっても、素材をリミックス、変換、構築すること。
44 |
45 | 条件は以下です:
46 |
47 | - **Attribution** — 適切なクレジットを表示し、ライセンスへのリンクを提供し、変更が加えられた場合にはその旨を明示しなければなりません。これらは社会通念上適切と認められる範囲で行うことができますが、Solidity コアチームがあなたやあなたの利用を支持していると示唆するような方法で行ってはなりません。
48 |
49 | また、Solidityロゴを使用する際は、Solidityロゴのガイドラインを尊重してください。
50 |
51 | Solidityロゴのガイドライン
52 | ==========================
53 |
54 | .. image:: solidity_logo.svg
55 | :width: 256
56 |
57 | *(ロゴの上で右クリックするとダウンロードできます。)*
58 |
59 | 次のことをしないでください:
60 |
61 | - ロゴの比率を変更すること(伸ばしたり切ったりしない)。
62 | - ロゴの色を変更すること。どうしても必要な場合を除く。
63 |
64 | クレジット
65 | ==========
66 |
67 | このドキュメントは、 `Python Software Foundation Trademark Usage Policy `_ と `Rust Media Guide `_ から派生した部分があります。
68 |
--------------------------------------------------------------------------------
/docs/ext/html_extra_template_renderer.py:
--------------------------------------------------------------------------------
1 | import os.path
2 |
3 |
4 | def render_html_extra_templates(app):
5 | if app.builder.format != 'html':
6 | # Non-HTML builders do not provide .templates.render_string(). Note that a HTML
7 | # builder is still used also when building some other formats like json or epub.
8 | return
9 |
10 | for input_path, template_config in app.config.html_extra_templates.items():
11 | # Requiring absolute paths simplifies the implementation.
12 | if not os.path.isabs(input_path):
13 | raise RuntimeError(f"Template input path is not absolute: {input_path}")
14 | if not os.path.isabs(template_config['target']):
15 | raise RuntimeError(f"Template target path is not absolute: {template_config['target']}")
16 |
17 | with open(input_path, 'r', encoding='utf8') as input_file:
18 | # This runs Jinja2, which supports rendering {{ }} tags among other things.
19 | rendered_template = app.builder.templates.render_string(
20 | input_file.read(),
21 | template_config['context'],
22 | )
23 |
24 | with open(template_config['target'], 'w', encoding='utf8') as target_file:
25 | target_file.write(rendered_template)
26 |
27 | app.config.html_extra_path.append(template_config['target'])
28 |
29 |
30 | def setup(app):
31 | app.add_config_value('html_extra_templates', default={}, rebuild='', types=dict)
32 |
33 | # Register a handler for the env-before-read-docs event. Any event that's fired before static
34 | # files get copied would do.
35 | app.connect(
36 | 'env-before-read-docs',
37 | lambda app, env, docnames: render_html_extra_templates(app)
38 | )
39 |
40 | return {
41 | # NOTE: Need to access _raw_config here because setup() runs before app.config is ready.
42 | 'version': app.config._raw_config['version'], # pylint: disable=protected-access
43 | 'parallel_read_safe': True,
44 | 'parallel_write_safe': True,
45 | }
46 |
--------------------------------------------------------------------------------
/.github/scripts/load-translation-bot-config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | CONFIG_FILE="$1"
5 |
6 | function load_option {
7 | local option="$1"
8 | local default="$2"
9 |
10 | if [[ ! -e $CONFIG_FILE ]]; then
11 | echo "$default"
12 | return 0
13 | fi
14 |
15 | # We want single-line output to be able to easily pass it to $GITHUB_OUTPUT
16 | local value
17 | value=$(jq --compact-output ".${option}" "$CONFIG_FILE")
18 |
19 | if [[ $value == null ]]; then
20 | echo "$default"
21 | else
22 | echo "$value"
23 | fi
24 | }
25 |
26 | function validate_boolean {
27 | local option="$1"
28 | local value="$2"
29 |
30 | if [[ $value != true && $value != false ]]; then
31 | >&2 echo "${CONFIG_FILE}: Invalid option value for '${option}'. Expected 'true' or 'false', got '${value}'."
32 | return 1
33 | fi
34 | }
35 |
36 | function validate_list {
37 | local option="$1"
38 | local value="$2"
39 |
40 | if ! echo "$value" | jq > /dev/null 2>&1; then
41 | >&2 echo "${CONFIG_FILE}: Invalid option value for '${option}'. Expected a JSON list, got '${value}'."
42 | return 1
43 | fi
44 | }
45 |
46 | function print_option {
47 | local option="$1"
48 | local value="$2"
49 |
50 | # The second echo is there so that we can actually see the value in the log for debug purposes
51 | echo "${option}=${value}" >> "$GITHUB_OUTPUT"
52 | echo "${option}: ${value}"
53 | }
54 |
55 | # NOTE: If you change defaults here, remember to update the README
56 | bot_disabled=$(load_option custom_sync_disabled true)
57 | randomly_assign_maintainers=$(load_option randomly_assign_maintainers false)
58 | pr_labels=$(load_option pr_labels '["sync-pr"]')
59 |
60 | validate_boolean disabled "$bot_disabled"
61 | validate_boolean randomly_assign_maintainers "$randomly_assign_maintainers"
62 | validate_list pr_labels "$pr_labels"
63 |
64 | print_option bot_disabled "$bot_disabled"
65 | print_option randomly_assign_maintainers "$randomly_assign_maintainers"
66 | print_option pr_labels "$pr_labels"
67 |
--------------------------------------------------------------------------------
/docs/_static/css/toggle.css:
--------------------------------------------------------------------------------
1 | input[type=checkbox] {
2 | visibility: hidden;
3 | height: 0;
4 | width: 0;
5 | margin: 0;
6 | }
7 |
8 | .rst-versions .rst-current-version {
9 | padding: 10px;
10 | display: flex;
11 | justify-content: space-between;
12 | background-color: var(--color-f);
13 | border-top: 1px solid var(--color-c);
14 | }
15 |
16 | .fa-caret-down,
17 | .fa-book {
18 | color: var(--color-a) !important;
19 | }
20 |
21 | .rst-versions .rst-current-version .fa-book,
22 | .rst-versions .rst-current-version .fa-v,
23 | .rst-versions .rst-current-version .fa-caret-down {
24 | height: 24px;
25 | line-height: 24px;
26 | vertical-align: middle;
27 | }
28 |
29 | .rst-versions .rst-current-version .fa-element {
30 | width: 80px;
31 | text-align: center;
32 | }
33 |
34 | .rst-versions .rst-current-version .fa-book {
35 | text-align: left;
36 | }
37 |
38 | .rst-versions .rst-current-version .fa-v {
39 | color: #27AE60;
40 | text-align: right;
41 | }
42 |
43 | label {
44 | margin: 0 auto;
45 | display: inline-block;
46 | justify-content: center;
47 | align-items: right;
48 | border-radius: 100px;
49 | position: relative;
50 | cursor: pointer;
51 | text-indent: -9999px;
52 | width: 50px;
53 | height: 21px;
54 | background: #000;
55 | }
56 |
57 | label:after {
58 | border-radius: 50%;
59 | position: absolute;
60 | content: '';
61 | background: #fff;
62 | width: 15px;
63 | height: 15px;
64 | top: 3px;
65 | left: 3px;
66 | transition: ease-in-out 200ms;
67 | }
68 |
69 | input:checked+label {
70 | background: #3a7ca8;
71 | }
72 |
73 | input:checked+label:after {
74 | left: calc(100% - 5px);
75 | transform: translateX(-100%);
76 | }
77 |
78 | html.transition,
79 | html.transition *,
80 | html.transition *:before,
81 | html.transition *:after {
82 | transition: ease-in-out 200ms !important;
83 | transition-delay: 0 !important;
84 | }
85 |
86 | .wy-menu-vertical a:hover {
87 | background-color: #0002;
88 | }
89 |
90 | body {
91 | font-weight: 300;
92 | letter-spacing: 0.5px;
93 | }
--------------------------------------------------------------------------------
/docs/language-influences.rst:
--------------------------------------------------------------------------------
1 | .. Language Influences
2 |
3 | ##########
4 | 言語の影響
5 | ##########
6 |
7 | Solidityは、いくつかの有名なプログラミング言語に影響やインスピレーションを受けた `カーリーブラケット言語 `_ です。
8 |
9 | .. Solidity is most profoundly influenced by C++, but also borrowed concepts from languages like Python, JavaScript, and others.
10 |
11 | Solidityは、C++から最も大きな影響を受けていますが、PythonやJavaScriptなどの言語からもコンセプトを借りています。
12 |
13 | .. The influence from C++ can be seen in the syntax for variable declarations, for loops, the concept of overloading functions, implicit and explicit type conversions and many other details.
14 |
15 | C++からの影響は、変数宣言やforループの構文、関数のオーバーロードの概念、暗黙的な型変換と明示的な型変換、その他多くの細部に見られます。
16 |
17 | .. In the early days of the language, Solidity used to be partly influenced by JavaScript.
18 | .. This was due to function-level scoping of variables and the use of the keyword ``var``.
19 | .. The JavaScript influence was reduced starting from version 0.4.0.
20 | .. Now, the main remaining similarity to JavaScript is that functions are defined using the keyword ``function``.
21 | .. Solidity also supports import syntax and semantics that are similar to those available in JavaScript.
22 | .. Besides those points, Solidity looks like most other curly-bracket languages and has no major JavaScript influence anymore.
23 |
24 | 言語開発の初期において、SolidityはJavaScriptの影響を部分的に受けていました。
25 | これは、関数レベルでの変数のスコープや、キーワード ``var`` の使用によるものでした。
26 | JavaScriptの影響はバージョン0.4.0から少なくなりました。
27 | 現在、JavaScriptとの主な類似点は、関数がキーワード ``function`` を使って定義されていることです。
28 | また、Solidityは、JavaScriptと同様のインポート構文とセマンティクスをサポートしています。
29 | これらの点を除けば、Solidityは他の多くのカーリーブラケット言語と同じように見えますし、もはやJavaScriptの影響は大きくありません。
30 |
31 | .. Another influence to Solidity was Python.
32 | .. Solidity's modifiers were added trying to model Python's decorators with a much more restricted functionality.
33 | .. Furthermore, multiple inheritance, C3 linearization, and the ``super`` keyword are taken from Python as well as the general assignment and copy semantics of value and reference types.
34 |
35 | もう一つSolidityに影響を与えたのがPythonです。
36 | Solidityのモディファイアは、Pythonのデコレータをモデルにして追加されたもので、機能はより制限されています。
37 | さらに、多重継承、C3線形化、 ``super`` キーワードは、値や参照型の一般的な代入とコピーのセマンティクスと同様に、Pythonから採用されています。
38 |
--------------------------------------------------------------------------------
/docs/examples/modular.rst:
--------------------------------------------------------------------------------
1 | .. index:: contract;modular, modular contract
2 |
3 | **********************
4 | モジュラーコントラクト
5 | **********************
6 |
7 | モジュラーアプローチでコントラクトを構築すると、複雑さを軽減し、読みやすさを向上させることができ、開発やコードレビューの際にバグや脆弱性を特定するのに役立ちます。
8 | 各モジュールの動作を個別に指定して制御する場合、考慮しなければならない相互作用はモジュールの仕様間のものだけで、コントラクトの他のすべての可動部分ではありません。
9 | 以下の例では、コントラクトは ``Balances`` :ref:`ライブラリ ` の ``move`` メソッドを使用して、アドレス間で送信された残高が期待したものと一致するかどうかをチェックしています。
10 | このように、 ``Balances`` ライブラリはアカウントの残高を適切に追跡する独立したコンポーネントを提供しています。
11 | ``Balances`` ライブラリが負の残高やオーバーフローを決して生成せず、すべての残高の合計がコントラクトのライフタイムにわたって不変であることを簡単に確認できます。
12 |
13 | .. code-block:: solidity
14 |
15 | // SPDX-License-Identifier: GPL-3.0
16 | pragma solidity >=0.5.0 <0.9.0;
17 |
18 | library Balances {
19 | function move(mapping(address => uint256) storage balances, address from, address to, uint amount) internal {
20 | require(balances[from] >= amount);
21 | require(balances[to] + amount >= balances[to]);
22 | balances[from] -= amount;
23 | balances[to] += amount;
24 | }
25 | }
26 |
27 | contract Token {
28 | mapping(address => uint256) balances;
29 | using Balances for *;
30 | mapping(address => mapping(address => uint256)) allowed;
31 |
32 | event Transfer(address from, address to, uint amount);
33 | event Approval(address owner, address spender, uint amount);
34 |
35 | function transfer(address to, uint amount) external returns (bool success) {
36 | balances.move(msg.sender, to, amount);
37 | emit Transfer(msg.sender, to, amount);
38 | return true;
39 |
40 | }
41 |
42 | function transferFrom(address from, address to, uint amount) external returns (bool success) {
43 | require(allowed[from][msg.sender] >= amount);
44 | allowed[from][msg.sender] -= amount;
45 | balances.move(from, to, amount);
46 | emit Transfer(from, to, amount);
47 | return true;
48 | }
49 |
50 | function approve(address spender, uint tokens) external returns (bool success) {
51 | require(allowed[msg.sender][spender] == 0, "");
52 | allowed[msg.sender][spender] = tokens;
53 | emit Approval(msg.sender, spender, tokens);
54 | return true;
55 | }
56 |
57 | function balanceOf(address tokenOwner) external view returns (uint balance) {
58 | return balances[tokenOwner];
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/.github/scripts/pull-and-resolve-english-changes.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | function fail { >&2 echo -e "ERROR: $1"; exit 1; }
5 |
6 | (( $# == 2 )) || fail "Wrong number of arguments\nUsage: $0 "
7 | git config remote.english.url || fail "Remote 'english' is not defined"
8 | SOLIDITY_REF="$1"
9 | COMMIT_MESSAGE="$2"
10 |
11 | # ASSUMPTIONS:
12 | # - We're in the root directory of a working copy of the translation repository.
13 | # - Remote 'english' exists and points at the main Solidity repository.
14 | # - Working copy is clean, with no modified or untracked files.
15 |
16 | # Try to merge changes from the main repository. Anything changed at the same time in the translation
17 | # and in the main repo will result in a conflict and will make the command fail. This is fine.
18 | # We want to include the conflict markers as a part of the merge commit so that they're easy to spot in the PR.
19 | # The command will also fail if in the main repo there were modifications to files outside
20 | # of docs/ (these files are deleted in translation repos). These are the conflicts we want to ignore.
21 | if ! git merge "${SOLIDITY_REF}" -m "$COMMIT_MESSAGE"; then
22 | # Unstage everything without aborting the merge.
23 | # This also "resolves" conflicts by keeping conflicted files as is including the conflict markers.
24 | git reset .
25 |
26 | # The only changes from the main repo that we're interested in are those in docs/ and
27 | # CMakeLists.txt, which is parsed by our Sphinx config to determine version. Stage them.
28 | git add docs/ CMakeLists.txt .readthedocs.yml
29 |
30 | # Reset any files seen by git as modified/deleted to the state from before the merge.
31 | # We need this for files outside of docs/ that happen to match the path of some file that exists
32 | # in the main repo, for example README.md or .gitignore. We do not copy these when setting up a
33 | # translation repo but to git they look like files from the main repo that need to be synced.
34 | files_to_reset=$(git ls-files --modified --deleted)
35 | if [[ $files_to_reset != "" ]]; then
36 | # NOTE: If the file list passed to `git checkout` is empty, git aborts the merge. We don't want that.
37 | git ls-files --modified --deleted | xargs git checkout --
38 | fi
39 |
40 | # All the other files from the original merge commit are now untracked. We don't want them in the PR.
41 | git clean -d --force
42 |
43 | # Finalize the merge. Should create a commit with the message we specified in the original command.
44 | git commit --no-edit
45 | fi
46 |
--------------------------------------------------------------------------------
/docs/contracts/interfaces.rst:
--------------------------------------------------------------------------------
1 | .. index:: ! contract;interface, ! interface contract
2 |
3 | .. _interfaces:
4 |
5 | ****************
6 | インターフェース
7 | ****************
8 |
9 | インターフェースは、抽象コントラクトと似ていますが、いかなる関数も実装できません。
10 | さらに以下の制限があります。
11 |
12 | - 他のコントラクトを継承できませんが、他のインターフェースを継承できます。
13 | - 宣言された関数は、コントラクトでpublicであっても、インターフェースではexternalでなければなりません。
14 | - コンストラクタを宣言できません。
15 | - 状態変数を宣言できません。
16 | - モディファイアを宣言できません。
17 |
18 | これらの制限の一部は、将来解除される可能性があります。
19 |
20 | インターフェースは基本的にコントラクトABIが表現できる内容に限定されており、ABIとインターフェースの間の変換は情報を失うことなく可能でなければなりません。
21 |
22 | インターフェースは、次のように定義されます。
23 |
24 | .. code-block:: solidity
25 |
26 | // SPDX-License-Identifier: GPL-3.0
27 | pragma solidity >=0.6.2 <0.9.0;
28 |
29 | interface Token {
30 | enum TokenType { Fungible, NonFungible }
31 | struct Coin { string obverse; string reverse; }
32 | function transfer(address recipient, uint amount) external;
33 | }
34 |
35 | コントラクトは、他のコントラクトを継承するように、インターフェースを継承できます。
36 |
37 | .. All functions declared in interfaces are implicitly ``virtual`` and any
38 | .. functions that override them do not need the ``override`` keyword.
39 | .. This does not automatically mean that an overriding function can be overridden again -
40 | .. this is only possible if the overriding function is marked ``virtual``.
41 |
42 | インターフェースで宣言されたすべての関数は暗黙のうちに ``virtual`` となり、それをオーバーライドする関数には ``override`` キーワードは必要ありません。
43 | これは、オーバーライドされた関数が再びオーバーライドできることを自動的に意味するものではありません。
44 | オーバーライドされた関数が ``virtual`` とマークされている場合にのみ、それは可能です。
45 |
46 | インターフェースは、他のインターフェースを継承できます。
47 | これには通常の継承と同じルールがあります。
48 |
49 | .. code-block:: solidity
50 |
51 | // SPDX-License-Identifier: GPL-3.0
52 | pragma solidity >=0.6.2 <0.9.0;
53 |
54 | interface ParentA {
55 | function test() external returns (uint256);
56 | }
57 |
58 | interface ParentB {
59 | function test() external returns (uint256);
60 | }
61 |
62 | interface SubInterface is ParentA, ParentB {
63 | // Parentと互換性があることを主張するために、testを再定義する必要があります。
64 | function test() external override(ParentA, ParentB) returns (uint256);
65 | }
66 |
67 | .. Types defined inside interfaces and other contract-like structures
68 | .. can be accessed from other contracts: ``Token.TokenType`` or ``Token.Coin``.
69 |
70 | インターフェースや他のコントラクトに似た構造の中で定義された型は、他のコントラクトからアクセスできます。
71 | ``Token.TokenType`` または ``Token.Coin`` 。
72 |
73 | .. warning::
74 |
75 | .. Interfaces have supported ``enum`` types since :doc:`Solidity version 0.5.0 <050-breaking-changes>`, make sure the pragma version specifies this version as a minimum.
76 |
77 | インターフェースは :doc:`Solidity version 0.5.0 <050-breaking-changes>` 以降 ``enum`` 型をサポートしています。
78 | プラグマバージョンが最低限このバージョンを指定していることを確認してください。
79 |
--------------------------------------------------------------------------------
/docs/progress-checklist.md:
--------------------------------------------------------------------------------
1 | ## Translation Progress Checklist
2 |
3 | This document helps to track the state of your translation. Please copy it as an issue into your translation repo to track your progress.
4 |
5 | ### Maintainer List
6 |
7 | [List the maintainers here.]
8 |
9 | ### Information for New Translators
10 |
11 | To translate a page:
12 |
13 | Check that no one else has claimed your page in the checklist and comments below.
14 | Comment below with the name of the page you would like to translate. Please take only one page at a time.
15 | Clone this repo, translate your page, and submit a pull request!
16 |
17 | Before contributing, read the glossary and style guide (link them here if they exist) to understand how to translate various technical or Solidity/Ethereum-specific terms.
18 |
19 | Please be prompt with your translations! If you find that you can't commit anymore, let the maintainers know so they can assign the page to someone else.
20 |
21 | ### For Maintainers
22 |
23 | When someone likes to contribute, edit this issue with the username of the contributor, and with the PR.
24 |
25 | E.g.
26 | - [ ] index (@franzihei) #1
27 |
28 | When PRs are merged, make sure to mark that page as completed.
29 |
30 | ### Core Pages
31 |
32 | These pages need to be translated before the translation will be added as a new language to the Solidity docs flyout menu. Please translate these pages first.
33 |
34 | #### Basics
35 | - [ ] index
36 | - [ ] intro-to-smart-contracts
37 | - [ ] installing-solidity
38 | - [ ] solidity-by-example
39 |
40 | #### Language Description
41 | - [ ] layout-of-source-files
42 | - [ ] structure-of-a-contract
43 | - [ ] types
44 | - [ ] units-and-global-variables
45 | - [ ] control-structures
46 | - [ ] contracts
47 | - [ ] assembly
48 | - [ ] cheatsheet
49 | - [ ] grammar
50 |
51 | #### Internals
52 | - [ ] layout_in_storage
53 | - [ ] layout_in_memory
54 | - [ ] layout_in_calldata
55 | - [ ] variable_cleanup
56 | - [ ] source_mappings
57 | - [ ] optimiser
58 | - [ ] metadata
59 | - [ ] abi-spec
60 |
61 | #### Additional Material
62 | - [ ] yul
63 | - [ ] natspec-format
64 | - [ ] security-considerations
65 | - [ ] common-patterns
66 |
67 | ### Next Steps
68 |
69 | These are the next most important translations, ordered by importance:
70 |
71 | #### Additional Material
72 |
73 | - [ ] using-the-compiler
74 | - [ ] contributing
75 | - [ ] 080-breaking-changes
76 | - [ ] 070-breaking-changes
77 | - [ ] 060-breaking-changes
78 | - [ ] 050-breaking-changes
79 | - [ ] resources
80 | - [ ] bugs
81 |
82 | ### Additional Translations
83 |
84 | These are not the primary translation targets but still a nice to have!
85 |
86 | - [ ] style-guide
87 | - [ ] brand-guide
88 |
89 |
90 | _Credits: This doc is derived from the [Progress Template](https://github.com/reactjs/reactjs.org-translation/blob/master/PROGRESS.template.md) of the ReactJS Localization Team._
--------------------------------------------------------------------------------
/docs/contracts/abstract-contracts.rst:
--------------------------------------------------------------------------------
1 | .. index:: ! contract;abstract, ! abstract contract
2 |
3 | .. _abstract-contract:
4 |
5 | ****************
6 | 抽象コントラクト
7 | ****************
8 |
9 | コントラクトは、その関数の少なくとも1つが実装されていない場合、またはすべてのベースコントラクトコンストラクタに引数を提供しない場合、abstractとマークする必要があります。
10 | そうでない場合でも、コントラクトを直接作成するつもりがない場合などには、コントラクトをabstractとマークすることがあります。
11 | 抽象コントラクトは :ref:`interfaces` と似ていますが、インターフェースは宣言できる内容がより限定されています。
12 |
13 | 抽象コントラクトは、次の例に示すように ``abstract`` キーワードを使用して宣言します。
14 | 関数 ``utterance()`` が宣言されているが、実装が提供されていない(実装本体 `{ }` が与えられていない)ため、このコントラクトは抽象として定義する必要があることに注意してください。
15 |
16 | .. code-block:: solidity
17 |
18 | // SPDX-License-Identifier: GPL-3.0
19 | pragma solidity >=0.6.0 <0.9.0;
20 |
21 | abstract contract Feline {
22 | function utterance() public virtual returns (bytes32);
23 | }
24 |
25 | .. Such abstract contracts can not be instantiated directly.
26 | .. This is also true, if an abstract contract itself does implement all defined functions. The usage of an abstract contract as a base class is shown in the following example:
27 |
28 | このような抽象コントラクトは、直接インスタンス化できません。
29 | これは、抽象コントラクト自体がすべての定義された関数を実装している場合にも当てはまります。
30 | ベースクラスとしての抽象コントラクトの使い方を以下の例で示します。
31 |
32 | .. code-block:: solidity
33 |
34 | // SPDX-License-Identifier: GPL-3.0
35 | pragma solidity >=0.6.0 <0.9.0;
36 |
37 | abstract contract Feline {
38 | function utterance() public pure virtual returns (bytes32);
39 | }
40 |
41 | contract Cat is Feline {
42 | function utterance() public pure override returns (bytes32) { return "miaow"; }
43 | }
44 |
45 | コントラクトが抽象コントラクトを継承し、オーバーライドによって未実装関数を全て実装していない場合は、抽象としてマークする必要があります。
46 |
47 | .. Note that a function without implementation is different from
48 | .. a :ref:`Function Type ` even though their syntax looks very similar.
49 |
50 | なお、実装のない関数は、構文がよく似ていても、 :ref:`関数型 ` とは異なるものです。
51 |
52 | 実装のない関数(関数宣言)の例:
53 |
54 | .. code-block:: solidity
55 |
56 | function foo(address) external returns (address);
57 |
58 | 型が関数型である変数の宣言の例:
59 |
60 | .. code-block:: solidity
61 |
62 | function(address) external returns (address) foo;
63 |
64 | .. Abstract contracts decouple the definition of a contract from its
65 | .. implementation providing better extensibility and self-documentation and
66 | .. facilitating patterns like the `Template method `_ and removing code duplication.
67 | .. Abstract contracts are useful in the same way that defining methods
68 | .. in an interface is useful. It is a way for the designer of the
69 | .. abstract contract to say "any child of mine must implement this method".
70 |
71 | 抽象コントラクトは、コントラクトの定義とその実装を切り離し、より良い拡張性と自己文書化を提供し、 `テンプレートメソッド `_ のようなパターンを促進し、コードの重複を取り除きます。
72 | 抽象コントラクトは、インターフェースでメソッドを定義することが有用であるのと同じ方法で有用です。
73 | 抽象コントラクトの設計者が「私の子供はこのメソッドを実装しなければならない」と言える方法です。
74 |
75 | .. note::
76 |
77 | 抽象コントラクトは、実装済みの仮想関数を未実装の仮想関数で上書きできません。
78 |
--------------------------------------------------------------------------------
/docs/ext/remix_code_links.py:
--------------------------------------------------------------------------------
1 | import base64
2 | import docutils # pragma pylint: disable=import-error
3 |
4 | from sphinx.util import logging # pragma pylint: disable=import-error
5 |
6 | # NOTE: 2000 should generally be safe for all browsers, while 8000 for most of them.
7 | MAX_SAFE_URL_LENGTH = 10000
8 |
9 | logger = logging.getLogger(__name__)
10 |
11 |
12 | def insert_node_before(child, new_sibling):
13 | assert child in child.parent.children
14 |
15 | for position, node in enumerate(child.parent.children):
16 | if node == child:
17 | child.parent.insert(position, new_sibling)
18 | break
19 |
20 |
21 | def remix_code_url(source_code, language, solidity_version):
22 | # NOTE: base64 encoded data may contain +, = and / characters. Remix seems to handle them just
23 | # fine without any escaping.
24 | base64_encoded_source = base64.b64encode(source_code.encode('utf-8')).decode('ascii')
25 | return f"https://remix.ethereum.org/?#language={language}&version={solidity_version}&code={base64_encoded_source}"
26 |
27 |
28 | def build_remix_link_node(url):
29 | reference_node = docutils.nodes.reference('', 'open in Remix', internal=False, refuri=url, target='_blank')
30 | reference_node['classes'].append('remix-link')
31 |
32 | paragraph_node = docutils.nodes.paragraph()
33 | paragraph_node['classes'].append('remix-link-container')
34 | paragraph_node.append(reference_node)
35 | return paragraph_node
36 |
37 |
38 | def insert_remix_link(app, doctree, solidity_version):
39 | if app.builder.format != 'html' or app.builder.name == 'epub':
40 | return
41 |
42 | for literal_block_node in doctree.traverse(docutils.nodes.literal_block):
43 | assert 'language' in literal_block_node.attributes
44 | language = literal_block_node.attributes['language'].lower()
45 | if language not in ['solidity', 'yul']:
46 | continue
47 |
48 | text_nodes = list(literal_block_node.traverse(docutils.nodes.Text))
49 | assert len(text_nodes) == 1
50 |
51 | remix_url = remix_code_url(text_nodes[0], language, solidity_version)
52 | url_length = len(remix_url.encode('utf-8'))
53 | if url_length > MAX_SAFE_URL_LENGTH:
54 | logger.warning(
55 | "Remix URL generated from the code snippet exceeds the maximum safe URL length "
56 | " (%d > %d bytes).",
57 | url_length,
58 | MAX_SAFE_URL_LENGTH,
59 | location=(literal_block_node.source, literal_block_node.line),
60 | )
61 |
62 | insert_node_before(literal_block_node, build_remix_link_node(remix_url))
63 |
64 |
65 | def setup(app):
66 | # NOTE: Need to access _raw_config here because setup() runs before app.config is ready.
67 | solidity_version = app.config._raw_config['version'] # pylint: disable=protected-access
68 |
69 | app.connect(
70 | 'doctree-resolved',
71 | lambda app, doctree, docname: insert_remix_link(app, doctree, solidity_version)
72 | )
73 |
74 | return {
75 | 'version': solidity_version,
76 | 'parallel_read_safe': True,
77 | 'parallel_write_safe': True,
78 | }
79 |
--------------------------------------------------------------------------------
/docs/internals/layout_in_memory.rst:
--------------------------------------------------------------------------------
1 |
2 | .. index: memory layout
3 |
4 | ********************
5 | メモリ内のレイアウト
6 | ********************
7 |
8 | .. Solidity reserves four 32-byte slots, with specific byte ranges (inclusive of endpoints) being used as follows:
9 | .. - ``0x00`` - ``0x3f`` (64 bytes): scratch space for hashing methods
10 | .. - ``0x40`` - ``0x5f`` (32 bytes): currently allocated memory size (aka. free memory pointer)
11 | .. - ``0x60`` - ``0x7f`` (32 bytes): zero slot
12 |
13 | Solidityは4つの32バイトスロットを確保しており、特定のバイト範囲(エンドポイントを含む)は以下のように使用されます。
14 |
15 | - ``0x00`` - ``0x3f`` (64バイト): ハッシュ化のためのスクラッチ領域
16 |
17 | - ``0x40`` - ``0x5f`` (32バイト): 現在割り当てられているメモリサイズ(別名: フリーメモリポインタ)
18 |
19 | - ``0x60`` - ``0x7f`` (32バイト): ゼロスロット
20 |
21 | .. Scratch space can be used between statements (i.e. within inline assembly).
22 | .. The zero slot is used as initial value for dynamic memory arrays and should never be written to (the free memory pointer points to ``0x80`` initially).
23 |
24 | スクラッチ領域は、文の間(インラインアセンブリ内)で使用できます。
25 | ゼロスロットは、動的メモリ配列の初期値として使用され、決して書き込まれてはいけません(フリーメモリポインタは初期値として ``0x80`` を指します)。
26 |
27 | .. Solidity always places new objects at the free memory pointer and
28 | .. memory is never freed (this might change in the future).
29 |
30 | Solidityは常に新しいオブジェクトをフリーメモリポインタに配置し、メモリは解放されません(これは将来変更されるかもしれません)。
31 |
32 | .. Elements in memory arrays in Solidity always occupy multiples of 32 bytes (this
33 | .. is even true for ``bytes1[]``, but not for ``bytes`` and ``string``).
34 | .. Multi-dimensional memory arrays are pointers to memory arrays. The length of a
35 | .. dynamic array is stored at the first slot of the array and followed by the array
36 | .. elements.
37 |
38 | Solidityのメモリ配列の要素は、常に32バイトの倍数を占めています(これは ``bytes1[]`` でも当てはまりますが、 ``bytes`` と ``string`` では当てはまりません)。
39 | 多次元のメモリ配列は、メモリ配列へのポインタです。
40 | 動的配列の長さは、配列の最初のスロットに格納され、その後に配列要素が続きます。
41 |
42 | .. .. warning::
43 |
44 | .. There are some operations in Solidity that need a temporary memory area
45 | .. larger than 64 bytes and therefore will not fit into the scratch space.
46 | .. They will be placed where the free memory points to, but given their
47 | .. short lifetime, the pointer is not updated. The memory may or may not
48 | .. be zeroed out. Because of this, one should not expect the free memory
49 | .. to point to zeroed out memory.
50 |
51 | .. While it may seem like a good idea to use ``msize`` to arrive at a
52 | .. definitely zeroed out memory area, using such a pointer non-temporarily
53 | .. without updating the free memory pointer can have unexpected results.
54 |
55 | .. warning::
56 |
57 | Solidityには、64バイト以上の一時的なメモリ領域を必要とする操作があり、そのためスクラッチ領域には収まりません。
58 | これらはフリーメモリが指す場所に配置されますが、その寿命が短いため、ポインタは更新されません。
59 | メモリはゼロになってもならなくても構いません。
60 | このため、フリーメモリがゼロアウトされたメモリを指していると思ってはいけません。
61 |
62 | 確実にゼロになったメモリ領域に到達するために ``msize`` を使用するのは良いアイデアに思えるかもしれませんが、空きメモリポインタを更新せずにそのようなポインタを非一時的に使用すると、予期しない結果になることがあります。
63 |
64 | ストレージ内のレイアウトとの違い
65 | ================================
66 |
67 | 以上のように、メモリ上のレイアウトと :ref:`ストレージ` 上のレイアウトは異なります。
68 | 以下、いくつかの例を紹介します。
69 |
70 | 配列における違いの例
71 | --------------------
72 |
73 | 次の配列は、ストレージでは32バイト(1スロット)ですが、メモリでは128バイト(32バイトずつの4つのアイテム)を占有します。
74 |
75 | .. code-block:: solidity
76 |
77 | uint8[4] a;
78 |
79 | 構造体レイアウトにおける違いの例
80 | --------------------------------
81 |
82 | 次の構造体は、ストレージでは96バイト(32バイトのスロットが3つ)ですが、メモリでは128バイト(32バイトずつのアイテムが4つ)を占有します。
83 |
84 | .. code-block:: solidity
85 |
86 | struct S {
87 | uint a;
88 | uint b;
89 | uint8 c;
90 | uint8 d;
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/docs/contracts/custom-storage-layout.rst:
--------------------------------------------------------------------------------
1 | .. index:: ! custom storage layout, ! storage layout specifier, ! layout at, ! base slot
2 |
3 | .. _custom-storage-layout:
4 |
5 | ****************************
6 | カスタムストレージレイアウト
7 | ****************************
8 |
9 | .. A contract can define an arbitrary location for its storage using the ``layout`` specifier.
10 | .. The contract's state variables, including those inherited from base contracts, start from the specified base slot instead of the default slot zero.
11 |
12 | コントラクトは ``layout`` 指定子を使って、ストレージの開始位置を任意に定義できます。
13 | この場合、基底コントラクトから継承された変数を含む状態変数は、デフォルトのスロット 0 ではなく、指定されたベーススロットから配置されます。
14 |
15 | .. code-block:: solidity
16 |
17 | // SPDX-License-Identifier: GPL-3.0
18 | pragma solidity ^0.8.29;
19 |
20 | contract C layout at 0xAAAA + 0x11 {
21 | uint[3] x; // Occupies slots 0xAABB..0xAABD
22 | }
23 |
24 | .. As the above example shows, the specifier uses the ``layout at `` syntax and is located in the header of a contract definition.
25 |
26 | 上の例に示されているように、この指定子は ``layout at `` という構文を使用し、
27 | コントラクト定義のヘッダー部分に記述されます。
28 |
29 | .. The layout specifier can be placed either before or after the inheritance specifier, and can appear at most once.
30 | .. The ``base-slot-expression`` must be an :ref:`integer literal` expression that can be evaluated at compilation time and yields a value in the range of ``uint256``.
31 |
32 | layout 指定子は、継承指定子の前でも後でも記述可能で、1つのコントラクトにつき1回までしか使用できません。
33 | ``base-slot-expression`` は、コンパイル時に評価可能な :ref:`整数リテラル` 式である必要があり、
34 | その値は ``uint256`` の範囲内でなければなりません。
35 |
36 | .. A custom layout cannot make contract's storage "wrap around".
37 | .. If the selected base slot would push the static variables past the end of storage, the compiler will issue an error.
38 | .. Note that the data areas of dynamic arrays and mappings are not affected by this check because their layout is not linear.
39 | .. Regardless of the base slot used, their locations are calculated in a way that always puts them within the range of ``uint256`` and their sizes are not known at compilation time.
40 |
41 | カスタムレイアウトを使用しても、コントラクトのストレージが「ラップアラウンド(末尾から先頭へ巻き戻る)」することはできません。
42 | もし指定されたベーススロットによって、静的変数がストレージの末尾を超えることになる場合、コンパイラはエラーを出力します。
43 | なお、動的配列やマッピングのデータ領域は線形なレイアウトを持たないため、このチェックの対象外となります。
44 | 使用するベーススロットに関係なく、それらの位置は ``uint256`` の範囲内に収まるように計算され、
45 | またそのサイズはコンパイル時には不明です。
46 |
47 | .. While there are no other limits placed on the base slot, it is recommended to avoid locations that are too close to the end of the address space.
48 | .. Leaving too little space may complicate contract upgrades or cause problems for contracts that store additional values past their allocated space using inline assembly.
49 |
50 | ベーススロットに対して他の制限はありませんが、アドレス空間の末尾に近すぎる位置は避けることが推奨されます。
51 | 残されたスペースが少なすぎると、コントラクトのアップグレードが難しくなったり、
52 | インラインアセンブリで割り当て領域を超えて値を保存するようなコントラクトで問題が発生する可能性があります。
53 |
54 | .. The storage layout can only be specified for the topmost contract of an inheritance tree, and affects locations of all the storage variables in all the contracts in that tree.
55 | .. Variables are laid out according to the order of their definitions and the positions of their contracts in the :ref:`linearized inheritance hierarchy` and a custom base slot preserves their relative positions, shifting them all by the same amount.
56 |
57 | ストレージレイアウトは、継承ツリーの最上位のコントラクトに対してのみ指定でき、
58 | そのツリー内にあるすべてのコントラクトのストレージ変数の位置に影響を与えます。
59 | 変数は、定義された順番とコントラクトの :ref:`線形化された継承階層` に従って配置され、
60 | カスタムベーススロットを指定した場合でも、それらの相対位置は保たれ、すべて同じ量だけシフトされます。
61 |
62 | .. The storage layout cannot be specified for abstract contracts, interfaces and libraries.
63 | .. Also, it is important to note that it does *not* affect transient state variables.
64 |
65 | ストレージレイアウトは、抽象コントラクト、インターフェース、およびライブラリには指定できません。
66 | また、この指定はトランジェント状態変数には *影響を与えない* ことにも注意が必要です。
67 |
68 | .. For details about storage layout and the effect of the layout specifier on it see
69 | .. :ref:`layout of storage variables`.
70 |
71 | ストレージレイアウトの詳細や、layout 指定子がそれに与える影響については
72 | :ref:`ストレージ変数のレイアウト` を参照してください。
73 |
74 | .. warning::
75 | .. The identifiers ``layout`` and ``at`` are not yet reserved as keywords in the language.
76 | .. It is strongly recommended to avoid using them since they will become reserved in a future
77 | .. breaking release.
78 |
79 | 識別子 ``layout`` および ``at`` は、現時点ではまだ言語の予約語ではありません。
80 | しかし、将来の後方互換性を破るリリースにおいて予約語となる予定のため、これらを使用しないことが強く推奨されます。
81 |
--------------------------------------------------------------------------------
/docs/contracts/creating-contracts.rst:
--------------------------------------------------------------------------------
1 | .. index:: ! contract;creation, constructor
2 |
3 | ******************
4 | コントラクトの作成
5 | ******************
6 |
7 | コントラクトは、Ethereumのトランザクションを介して「外部から」作成することも、Solidityのコントラクトから作成することもできます。
8 |
9 | `Remix `_ に代表されるIDEは、UIによって作成プロセスをシームレスにします。
10 |
11 | Ethereumでプログラマティックにコントラクトを作成する方法の一つとして、JavaScript APIの `web3.js `_ があります。
12 | これにはコントラクトの作成を容易にする `web3.eth.Contract `_ という関数があります。
13 |
14 | コントラクトが作成されると、その :ref:`コンストラクタ ` ( ``constructor`` キーワードで宣言された関数)が一度だけ実行されます。
15 |
16 | コンストラクタはオプションです。
17 | ココンストラクタは1つしか許可されていないので、オーバーロードはサポートされていません。
18 |
19 | .. After the constructor has executed, the final code of the contract is stored on the
20 | .. blockchain. This code includes all public and external functions and all functions
21 | .. that are reachable from there through function calls. The deployed code does not
22 | .. include the constructor code or internal functions only called from the constructor.
23 |
24 | コンストラクタが実行された後、コントラクトの最終コードがブロックチェーンに保存されます。
25 | このコードには、すべてのパブリック関数と外部関数、および関数呼び出しによってそこから到達可能なすべての関数が含まれます。
26 | デプロイされたコードには、コンストラクタのコードや、コンストラクタからのみ呼び出される内部関数は含まれません。
27 |
28 | .. index:: constructor;arguments
29 |
30 | .. Internally, constructor arguments are passed :ref:`ABI encoded ` after the code of
31 | .. the contract itself, but you do not have to care about this if you use ``web3.js``.
32 |
33 | 内部的にはコンストラクタの引数はコントラクト自体のコードの後に :ref:`ABIエンコード ` を渡していますが、 ``web3.js`` を使用する場合はこれを気にする必要はありません。
34 |
35 | あるコントラクトが別のコントラクトを作成したい場合、作成するコントラクトのソースコード(およびバイナリ)を作成者が知っていなければなりません。
36 | これは周期的な作成の依存関係は不可能であることを意味します。
37 |
38 | .. code-block:: solidity
39 |
40 | // SPDX-License-Identifier: GPL-3.0
41 | pragma solidity >=0.4.22 <0.9.0;
42 |
43 | contract OwnedToken {
44 | // `TokenCreator` は、以下で定義されるコントラクトの型です。
45 | // 新しいコントラクトを作成するために使用しない限り、これを参照することは問題ありません。
46 | TokenCreator creator;
47 | address owner;
48 | bytes32 name;
49 |
50 | // 作成者と割り当てられた名前を登録するコンストラクタです。
51 | constructor(bytes32 name_) {
52 | // 状態変数には、その名前を通してアクセスします(`this.owner` などではない)。
53 | // 関数には、直接アクセスすることも、 `this.f` を介してアクセスすることもできますが、後者は関数への外部からのアクセスを提供します。
54 | // 特にコンストラクタでは、まだ関数が存在しないので、外部から関数にアクセスするべきではありません。
55 | // 詳しくは次のセクションを参照してください。
56 | owner = msg.sender;
57 |
58 | // `address` から `TokenCreator` への明示的な型変換を行い、
59 | // 呼び出したコントラクトの型が `TokenCreator` であることを仮定していますが、
60 | // 実際にそれを確認する方法はありません。
61 | // これは新しいコントラクトを作成するわけではありません。
62 | creator = TokenCreator(msg.sender);
63 | name = name_;
64 | }
65 |
66 | function changeName(bytes32 newName) public {
67 | // 作成者のみが名称を変更できます。
68 | // コントラクトの比較は、アドレスに明示的に変換することで取得できるアドレスをもとに行う。
69 | if (msg.sender == address(creator))
70 | name = newName;
71 | }
72 |
73 | function transfer(address newOwner) public {
74 | // トークンを送信できるのは、現在の所有者のみです。
75 | if (msg.sender != owner) return;
76 |
77 | // 以下に定義する `TokenCreator` コントラクトの関数を用いて、送金を進めるべきかどうかを作成者コントラクトに問い合わせます。
78 | // 呼び出しに失敗した場合(ガス欠など)、ここでの実行も失敗します。
79 | if (creator.isTokenTransferOK(owner, newOwner))
80 | owner = newOwner;
81 | }
82 | }
83 |
84 | contract TokenCreator {
85 | function createToken(bytes32 name)
86 | public
87 | returns (OwnedToken tokenAddress)
88 | {
89 | // 新しい `Token` コントラクトを作成し、そのアドレスを返す。
90 | // JavaScript側から見ると、この関数の戻り値の型は `address` です。
91 | // これはABIで利用可能な最も近い型だからです。
92 | return new OwnedToken(name);
93 | }
94 |
95 | function changeName(OwnedToken tokenAddress, bytes32 name) public {
96 | // ここでも、`tokenAddress` の外部型は単純に `address` です。
97 | tokenAddress.changeName(name);
98 | }
99 |
100 | // `OwnedToken`コントラクトにトークンを送信するかどうかのチェックを行う。
101 | function isTokenTransferOK(address currentOwner, address newOwner)
102 | public
103 | pure
104 | returns (bool ok)
105 | {
106 | // 送金を進めるかどうか、任意の条件をチェックします。
107 | return keccak256(abi.encodePacked(currentOwner, newOwner))[0] == 0x7f;
108 | }
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/docs/examples/safe-remote.rst:
--------------------------------------------------------------------------------
1 | .. index:: purchase, remote purchase, escrow
2 |
3 | ******************
4 | 安全なリモート購入
5 | ******************
6 |
7 | 現在、遠隔地で商品を購入するには、複数の当事者がお互いに信頼し合う必要があります。
8 | 最もシンプルなのは、売り手と買い手の関係です。
9 | 買い手は売り手から商品を受け取り、売り手はその見返りとして対価(例えばEther)を得たいと考えます。
10 | 問題となるのは、ここでの発送です。
11 | 商品が買い手に届いたかどうかを確実に判断する方法がありません。
12 |
13 | この問題を解決するには複数の方法がありますが、いずれも1つまたは他の方法で不足しています。
14 | 次の例では、両当事者がアイテムの2倍の価値をエスクローとして コントラクトに入れなければなりません。
15 | これが起こるとすぐに、買い手がアイテムを受け取ったことを確認するまで、Etherはコントラクトの中にロックされたままになります。
16 | その後、買い手にはvalue(デポジットの半分)が返却され、売り手にはvalueの3倍(デポジット + value)が支払われます。
17 | これは、双方が事態を解決しようとするインセンティブを持ち、そうしないとEtherが永遠にロックされてしまうという考えに基づいています。
18 |
19 | このコントラクトはもちろん問題を解決するものではありませんが、コントラクトの中でステートマシンのような構造をどのように使用できるかの概要を示しています。
20 |
21 | .. code-block:: solidity
22 |
23 | // SPDX-License-Identifier: GPL-3.0
24 | pragma solidity ^0.8.4;
25 | contract Purchase {
26 | uint public value;
27 | address payable public seller;
28 | address payable public buyer;
29 |
30 | enum State { Created, Locked, Release, Inactive }
31 | // state変数のデフォルト値は、最初のメンバーである`State.created`です。
32 | State public state;
33 |
34 | modifier condition(bool condition_) {
35 | require(condition_);
36 | _;
37 | }
38 |
39 | /// 買い手だけがこの機能を呼び出すことができます。
40 | error OnlyBuyer();
41 | /// 売り手だけがこの機能を呼び出すことができます。
42 | error OnlySeller();
43 | /// 現在の状態では、この関数を呼び出すことはできません。
44 | error InvalidState();
45 | /// 提供される値は偶数でなければなりません。
46 | error ValueNotEven();
47 |
48 | modifier onlyBuyer() {
49 | if (msg.sender != buyer)
50 | revert OnlyBuyer();
51 | _;
52 | }
53 |
54 | modifier onlySeller() {
55 | if (msg.sender != seller)
56 | revert OnlySeller();
57 | _;
58 | }
59 |
60 | modifier inState(State state_) {
61 | if (state != state_)
62 | revert InvalidState();
63 | _;
64 | }
65 |
66 | event Aborted();
67 | event PurchaseConfirmed();
68 | event ItemReceived();
69 | event SellerRefunded();
70 |
71 | // `msg.value` が偶数であることを確認します。
72 | // 割り算は奇数だと切り捨てられます。
73 | // 奇数でなかったことを乗算で確認します。
74 | constructor() payable {
75 | seller = payable(msg.sender);
76 | value = msg.value / 2;
77 | if ((2 * value) != msg.value)
78 | revert ValueNotEven();
79 | }
80 |
81 | /// 購入を中止し、Etherを再クレームします。
82 | /// コントラクトがロックされる前に売り手によってのみ呼び出すことができます。
83 | function abort()
84 | external
85 | onlySeller
86 | inState(State.Created)
87 | {
88 | emit Aborted();
89 | state = State.Inactive;
90 | // ここではtransferを直接使っています。
91 | // この関数の最後のコールであり、すでに状態を変更しているため、reentrancy-safeになっています。
92 | seller.transfer(address(this).balance);
93 | }
94 |
95 | /// 買い手として購入を確認します。
96 | /// 取引には `2 * value` のEtherが含まれていなければなりません。
97 | /// EtherはconfirmReceivedが呼ばれるまでロックされます。
98 | function confirmPurchase()
99 | external
100 | inState(State.Created)
101 | condition(msg.value == (2 * value))
102 | payable
103 | {
104 | emit PurchaseConfirmed();
105 | buyer = payable(msg.sender);
106 | state = State.Locked;
107 | }
108 |
109 | /// あなた(買い手)が商品を受け取ったことを確認します。
110 | /// これにより、ロックされていたEtherが解除されます。
111 | function confirmReceived()
112 | external
113 | onlyBuyer
114 | inState(State.Locked)
115 | {
116 | emit ItemReceived();
117 | // 最初に状態を変更することが重要です。
118 | // そうしないと、以下の `send` を使用して呼び出されたコントラクトが、ここで再び呼び出される可能性があるからです。
119 | state = State.Release;
120 |
121 | buyer.transfer(value);
122 | }
123 |
124 | /// この機能は、売り手に返金する、つまり売り手のロックされた資金を払い戻すものです。
125 | function refundSeller()
126 | external
127 | onlySeller
128 | inState(State.Release)
129 | {
130 | emit SellerRefunded();
131 | // otherwise, the contracts called using `send` below
132 | // can call in again here.
133 | // 最初に状態を変更することが重要です。
134 | // そうしないと、以下の `send` を使用して呼び出されたコントラクトが、ここで再び呼び出される可能性があるからです。
135 | state = State.Inactive;
136 |
137 | seller.transfer(3 * value);
138 | }
139 | }
140 |
141 |
--------------------------------------------------------------------------------
/docs/internals/variable_cleanup.rst:
--------------------------------------------------------------------------------
1 | .. index: variable cleanup
2 |
3 | ********************
4 | 変数のクリーンアップ
5 | ********************
6 |
7 | .. Ultimately, all values in the EVM are stored in 256 bit words.
8 | .. Thus, in some cases, when the type of a value has less than 256 bits, it is necessary to clean the remaining bits.
9 | .. The Solidity compiler is designed to do such cleaning before any operations
10 | .. that might be adversely affected by the potential garbage in the remaining bits.
11 | .. For example, before writing a value to memory, the remaining bits need
12 | .. to be cleared because the memory contents can be used for computing
13 | .. hashes or sent as the data of a message call. Similarly, before
14 | .. storing a value in the storage, the remaining bits need to be cleaned
15 | .. because otherwise the garbled value can be observed.
16 |
17 | 値が256ビットよりも短い場合、場合によっては残りのビットをクリーンアップする必要があります。
18 | 最終的に、EVM内のすべての値は256ビットのワードで保存されます。
19 | したがって、値の型が256ビット未満である場合、残りのビットをクリーニングする必要があるケースがあります。
20 | Solidityのコンパイラは、残りのビットに含まれる潜在的なゴミによって悪影響を受ける可能性のある演算の前に、このようなクリーニングを行うように設計されています。
21 |
22 | 例えば、値をメモリに書き込む前に、残りのビットをクリアする必要があります。
23 | これは、メモリの内容がハッシュの計算に使用されたり、メッセージコールのデータとして送信されたりする可能性があるためです。
24 | 同様に、ストレージに値を格納する前に、残りのビットを消去する必要があります。
25 | そうしないと、文字化けした値が観測される可能性があるからです。
26 |
27 | .. Note that access via inline assembly is not considered such an operation:
28 | .. If you use inline assembly to access Solidity variables
29 | .. shorter than 256 bits, the compiler does not guarantee that
30 | .. the value is properly cleaned up.
31 |
32 | なお、インラインアセンブリによるアクセスはそのような操作とはみなされません。
33 | インラインアセンブリを使用して256ビットより短いSolidity変数にアクセスした場合、コンパイラは値が適切にクリーンアップされることを保証しません。
34 |
35 | .. Moreover, we do not clean the bits if the immediately
36 | .. following operation is not affected. For instance, since any non-zero
37 | .. value is considered ``true`` by ``JUMPI`` instruction, we do not clean
38 | .. the boolean values before they are used as the condition for
39 | .. ``JUMPI``.
40 |
41 | また、直後の演算に影響がない場合は、ビットのクリーニングは行いません。
42 | 例えば、 ``JUMPI`` 命令では0以外の値は ``true`` とみなされるので、 ``JUMPI`` の条件として使われる前のブーリアン値のクリーニングは行いません。
43 |
44 | .. In addition to the design principle above, the Solidity compiler
45 | .. cleans input data when it is loaded onto the stack.
46 |
47 | 上記の設計原理に加えて、Solidityのコンパイラは、入力データがスタックに読み込まれる際に、入力データをクリーニングします。
48 |
49 | .. The following table describes the cleaning rules applied to different types, where ``higher bits`` refers to the remaining bits in case the type has less than 256 bits.
50 |
51 | 次の表は、異なるタイプに適用されるクリーニングルールを説明するもので、 ``higher bits`` は、タイプが256ビット未満の場合の残りのビットを指します。
52 |
53 | .. csv-table::
54 | :header: "型", "有効な値", "無効な値のクリーンアップ"
55 | :widths: 10, 10, 30
56 |
57 | "n個のメンバーのenum", "0 から n-1", "例外を投げる"
58 | "bool", "0 あるいは 1", "1になる"
59 | "符号付き整数", "higher bits set to the sign bit", "currently silently signextends to a valid value, i.e. all higher bits are set to the sign bit; may throw an exception in the future"
60 | "符号なし整数", "上位ビットがゼロ", "currently silently masks to a valid value, i.e. all higher bits are set to zero; may throw an exception in the future"
61 |
62 | .. Note that valid and invalid values are dependent on their type size.
63 | .. Consider ``uint8``, the unsigned 8-bit type, which has the following valid values:
64 |
65 | 有効な値と無効な値は、その型サイズに依存することに注意してください。
66 | 符号なし8ビット型である ``uint8`` を考えてみると、次のような有効な値があります:
67 |
68 | .. code-block:: none
69 |
70 | 0000...0000 0000 0000
71 | 0000...0000 0000 0001
72 | 0000...0000 0000 0010
73 | ....
74 | 0000...0000 1111 1111
75 |
76 | .. Any invalid value will have the higher bits set to zero:
77 |
78 | 無効な値は、上位ビットが0に設定されます:
79 |
80 | .. code-block:: none
81 |
82 | 0101...1101 0010 1010 invalid value
83 | 0000...0000 0010 1010 cleaned value
84 |
85 | .. For ``int8``, the signed 8-bit type, the valid values are:
86 |
87 | 符号付き8ビット型である ``int8`` の場合、有効な値は次のとおりです:
88 |
89 | Negative
90 |
91 | .. code-block:: none
92 |
93 | 1111...1111 1111 1111
94 | 1111...1111 1111 1110
95 | ....
96 | 1111...1111 1000 0000
97 |
98 | Positive
99 |
100 | .. code-block:: none
101 |
102 | 0000...0000 0000 0000
103 | 0000...0000 0000 0001
104 | 0000...0000 0000 0010
105 | ....
106 | 0000...0000 1111 1111
107 |
108 | .. The compiler will ``signextend`` the sign bit, which is 1 for negative and 0 for positive values, overwriting the higher bits:
109 |
110 | コンパイラは符号ビットを ``signextend`` します。
111 | 符号ビットは負の値を1、正の値を0とし、上位ビットを上書きします:
112 |
113 | Negative
114 |
115 | .. code-block:: none
116 |
117 | 0010...1010 1111 1111 invalid value
118 | 1111...1111 1111 1111 cleaned value
119 |
120 | Positive
121 |
122 | .. code-block:: none
123 |
124 | 1101...0101 0000 0100 invalid value
125 | 0000...0000 0000 0100 cleaned value
126 |
--------------------------------------------------------------------------------
/.github/workflows/create-weekly-docs-sync-pr.yaml:
--------------------------------------------------------------------------------
1 | name: weekly docs sync PR
2 |
3 | on:
4 | schedule:
5 | # Runs "at minute 44 past midnight on Mondays"
6 | - cron: "44 0 * * 1"
7 | workflow_dispatch:
8 |
9 | env:
10 | BOT_USERNAME: soldocsbot
11 | BOT_EMAIL: solidity-docs-translations@ethereum.org
12 | GITHUB_REPOSITORY_OWNER: solidity-docs
13 |
14 | jobs:
15 | createPullRequest:
16 | runs-on: ubuntu-latest
17 | permissions:
18 | contents: write
19 | pull-requests: write
20 | steps:
21 | - name: Fetch translation repository
22 | uses: actions/checkout@v2
23 | with:
24 | token: ${{ secrets.GITHUB_TOKEN }}
25 | repository: ${{ env.GITHUB_REPOSITORY_OWNER }}/ja-japanese
26 | # By default, checkout is fetching only the last commit. This will
27 | # cause "unrelated histories" error. "0" means unlimited fetch-depth.
28 | fetch-depth: 0
29 | # This is the working copy we'll prepare the sync PR in.
30 | path: translation/
31 |
32 | - name: Configure translation repository
33 | run: |
34 | cd translation/
35 | git config user.name "$BOT_USERNAME"
36 | git config user.email "$BOT_EMAIL"
37 | git remote add english "https://github.com/ethereum/solidity.git"
38 | git fetch english develop
39 |
40 | - name: Fetch main Solidity repository
41 | uses: actions/checkout@v2
42 | with:
43 | repository: ethereum/solidity
44 | fetch-depth: 0
45 | # This is the checkout where we can safely fetch the tags from the main Soldity repo and use git describe.
46 | # Translation repositories have their own version tags that conflict with the ones in the main repo.
47 | path: solidity/
48 |
49 | - name: Fetch bot's repository
50 | uses: actions/checkout@v2
51 | with:
52 | token: ${{ secrets.GITHUB_TOKEN }}
53 | repository: ${{ github.repository }}
54 | path: bot/
55 |
56 | - name: Load bot configuration from translation-bot.json in the translation repository
57 | id: bot-config
58 | run: |
59 | bot/.github/scripts/load-translation-bot-config.sh translation/translation-bot.json
60 |
61 | - name: Prepare pull request title and description
62 | if: ${{ steps.bot-config.outputs.bot_disabled == 'false' }}
63 | run: |
64 | # Use the main repository checkout with tags to get them in `git describe` output.
65 | cd solidity/
66 | ../bot/.github/scripts/generate-pr-body.sh
67 |
68 | - name: Check if sync branch already exists
69 | id: check-sync-branch
70 | if: ${{ steps.bot-config.outputs.bot_disabled == 'false' }}
71 | run: |
72 | pushd solidity/
73 | sync_branch="sync-$(git describe --tags --always develop)"
74 | echo "branch_name=$sync_branch" >> "$GITHUB_OUTPUT"
75 | popd
76 |
77 | cd translation/
78 | ../bot/.github/scripts/check-remote-branch.sh "$sync_branch"
79 |
80 | - name: Prepare pull request content
81 | if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }}
82 | run: |
83 | cd translation/
84 |
85 | # NOTE: The script will end up not creating a merge commit if there are no new upstream changes.
86 | # In that case we expect that the PR action will simply not create a PR.
87 | ../bot/.github/scripts/pull-and-resolve-english-changes.sh english/develop "$pr_title"
88 |
89 | if [[ ${{ steps.bot-config.outputs.randomly_assign_maintainers }} == 'true' ]]; then
90 | ../bot/.github/scripts/set-assignees.sh "ja-japanese"
91 | fi
92 |
93 | - name: Remove this repository
94 | if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }}
95 | run: |
96 | rm -rf bot/
97 |
98 | - name: Create Pull Request
99 | if: ${{ steps.bot-config.outputs.bot_disabled == 'false' && steps.check-sync-branch.outputs.branch_exists == 'false' }}
100 | uses: peter-evans/create-pull-request@v3
101 | with:
102 | path: translation/
103 | token: "${{ secrets.GITHUB_TOKEN }}"
104 | commit-message: "${{ env.pr_title }}"
105 | committer: "${{ env.BOT_USERNAME }} <${{ env.BOT_EMAIL }}>"
106 | author: "${{ env.BOT_USERNAME }} <${{ env.BOT_EMAIL }}>"
107 | branch: "${{ steps.check-sync-branch.outputs.branch_name }}"
108 | title: "${{ env.pr_title }}"
109 | body: "${{ env.pr_body }}"
110 | labels: "${{ join(fromJSON(steps.bot-config.outputs.pr_labels)) }}"
111 | assignees: ${{ env.assignee }}
112 | reviewers: ${{ env.reviewer }}
113 |
--------------------------------------------------------------------------------
/.github/scripts/generate-pr-body.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | function modified_file_list {
5 | commit_hash=$(git rev-parse --verify develop)
6 | git status --short |
7 | grep "docs" |
8 | awk '{print "- [ ] ["$2"](https://github.com/ethereum/solidity/tree/'"${commit_hash}"'/"$2")"}'
9 | }
10 |
11 | function today_utc {
12 | date --utc +%Y-%m-%d
13 | }
14 |
15 | function sync_commit_human_readable_id {
16 | git describe --tags --always develop
17 | }
18 |
19 | function sync_commit_link {
20 | local commit_hash truncated_commit_hash
21 | commit_hash=$(git rev-parse --verify develop)
22 | truncated_commit_hash=$(echo "$commit_hash" | head -c 8)
23 |
24 | echo "[${truncated_commit_hash}](https://github.com/ethereum/solidity/tree/${commit_hash})"
25 | }
26 |
27 | function title {
28 | echo "English documentation updates up to $(sync_commit_human_readable_id) ($(today_utc))"
29 | }
30 |
31 | # shellcheck disable=SC2016 # Any Backticks here are markdown syntax not Bash expressions
32 | function pr_body {
33 | echo "This is an automatically-generated sync PR to bring this translation repository up to date with the state of the English documentation as of $(today_utc) (commit $(sync_commit_link))."
34 | echo
35 | echo "### How to work on a sync PR"
36 | echo "#### Resolve conflicts and translate newly added text"
37 | echo "- The PR includes all documentation changes from the main repository since the last time a sync PR was merged. " \
38 | "If this translation repository is fully caught up with the English version, translate any newly added English text you see here by pushing more commits to the PR. " \
39 | "However, if the translation is incomplete, you may prefer to leave the text added in this PR and add it to your translation checklist to handle at a later time."
40 | echo "- Scan the PR for merge conflict markers. " \
41 | "If there were changes in the English text that has already been translated, the PR will contain merge conflicts that need to be resolved:"
42 | echo ' ```diff'
43 | echo ' <<<<<<< HEAD'
44 | echo ' El valor más grande representable por el tipo ``T``.'
45 | echo ' ======='
46 | echo ' The smallest value representable by type ``T``.'
47 | echo ' >>>>>>> 800088e38b5835ebdc71e9ba5299a70a5accd7c2'
48 | echo ' ```'
49 | echo " The top part of the conflict is the current translation (corresponding to the old English text), the bottom shows the new English text. " \
50 | "To solve the conflict simply translate the new text, possibly reusing parts of the current translation. " \
51 | "**After doing so, do not forget to remove the conflict markers.**"
52 | echo "- You may get conflicts also if there were structual changes that did not affect the meaning of the text and therefore do not require retranslation. " \
53 | "For example when text is moved from one page to another, you will find matching conflicts in two places and the solution is to move the translation to the new spot. " \
54 | "If only whitespace changed, it may even seem like there was no change at all but if there is a conflict, there is always a reason, however trivial it may be." \
55 | "Be careful, though, because there is a possibility that the text was both moved **and** modified. "
56 | echo
57 | echo "#### Work on one sync PR at a time"
58 | echo "- Sync PRs are produced by the translation bot in regular intervals as long as there are changes in the English documentation. " \
59 | "You will not lose any updates by closing this PR. " \
60 | "The next sync PR will also include them. " \
61 | "The latest sync PR will always include all changes that need to be done. " \
62 | "If you haven't worked on any sync PR yet and there are several open sync PRs in your repo, choose the latest (newest) one to get started."
63 | echo "- It is recommended to work only on one sync PR at a time. " \
64 | "Close this PR if you are already working on a different one."
65 | echo "- Once you merge this PR, the conflict resolutions and new commits you pushed to it are likely to cause conflicts with other open sync PRs. " \
66 | "It is possible solve these conflicts if you are proficient with git and fully understand what changed in which PR, " \
67 | "but for simplicity it is recommended to close all pending sync PRs and wait for a fresh one, which will no longer include the merged changes."
68 | echo
69 | echo "#### Do not squash merge or rebase this PR"
70 | echo "Rebasing or squashing a sync PR erases the information about the commits that the changes originally came from, which will result in extra conflicts in the next sync PR."
71 | echo "If you do it by accident, don't worry - simply make sure to handle the next sync PR properly, which will restore the missing commits."
72 | echo
73 | echo "### Review checklist"
74 | echo "The following files were modified in this pull request. " \
75 | "Please review them before merging the PR:"
76 | modified_file_list
77 | }
78 |
79 | printf "pr_title=%s\n" "$(title)" >> "$GITHUB_ENV"
80 | printf "pr_body<> "$GITHUB_ENV"
81 |
--------------------------------------------------------------------------------
/docs/structure-of-a-contract.rst:
--------------------------------------------------------------------------------
1 | .. index:: contract, state variable, function, event, struct, enum, function;modifier
2 |
3 | .. _contract_structure:
4 |
5 | ******************
6 | コントラクトの構造
7 | ******************
8 |
9 | Solidityのコントラクトは、オブジェクト指向言語のクラスに似ています。
10 | 各コントラクトは、 :ref:`structure-state-variables` 、 :ref:`structure-functions` 、 :ref:`structure-function-modifiers` 、 :ref:`structure-events` 、 :ref:`structure-errors` 、 :ref:`structure-struct-types` 、 :ref:`structure-enum-types` の宣言を含むことができます。
11 | さらに、コントラクトは他のコントラクトを継承できます。
12 |
13 | また、 :ref:`ライブラリ` や :ref:`インターフェース` と呼ばれる特別な種類のコントラクトもあります。
14 |
15 | :ref:`コントラクト` のセクションには、このセクションよりも詳細な情報が記載されており、概要を説明するための役割を担っています。
16 |
17 | .. _structure-state-variables:
18 |
19 | 状態変数
20 | ========
21 |
22 | 状態変数とは、その値がコントラクトのストレージに永続的に保存されるか、
23 | あるいは一時的にトランジェントストレージに保存され、トランザクションの終了時にクリアされる変数です。
24 | 詳細については :ref:`データロケーション ` を参照してください。
25 |
26 | .. code-block:: solidity
27 |
28 | // SPDX-License-Identifier: GPL-3.0
29 | pragma solidity >=0.4.0 <0.9.0;
30 |
31 | contract SimpleStorage {
32 | uint storedData; // 状態変数
33 | // ...
34 | }
35 |
36 | 有効な状態変数の型については :ref:`types` セクションを、ビジビリティについての可能な選択肢については :ref:`visibility-and-getters` を参照してください。
37 |
38 | .. _structure-functions:
39 |
40 | 関数
41 | ====
42 |
43 | 関数は、実行可能なコードの単位です。
44 | 関数は通常、コントラクトの中で定義されますが、コントラクトの外で定義することもできます。
45 |
46 | .. code-block:: solidity
47 |
48 | // SPDX-License-Identifier: GPL-3.0
49 | pragma solidity >=0.7.1 <0.9.0;
50 |
51 | contract SimpleAuction {
52 | function bid() public payable { // 関数
53 | // ...
54 | }
55 | }
56 |
57 | // コントラクトの外で定義されたヘルパー関数
58 | function helper(uint x) pure returns (uint) {
59 | return x * 2;
60 | }
61 |
62 | :ref:`function-calls` は内部または外部で起こり、他のコントラクトに対して異なるレベルの :ref:`ビジビリティ` を持つことができます。
63 | :ref:`関数` は、それらの間でパラメータと値を渡すために :ref:`パラメータと返り値` を受け入れます。
64 |
65 | .. _structure-function-modifiers:
66 |
67 | 関数モディファイア
68 | ==================
69 |
70 | 関数モディファイアを使うと、宣言的に関数のセマンティクスを変更できます(コントラクトセクションの :ref:`modifiers` を参照)。
71 |
72 | オーバーロード、つまり、同じモディファイア名で異なるパラメータを持つことはできません。
73 |
74 | 関数と同様、モディファイアも :ref:`オーバーライド ` できます。
75 |
76 | .. code-block:: solidity
77 |
78 | // SPDX-License-Identifier: GPL-3.0
79 | pragma solidity >=0.4.22 <0.9.0;
80 |
81 | contract Purchase {
82 | address public seller;
83 |
84 | modifier onlySeller() { // モディファイア
85 | require(
86 | msg.sender == seller,
87 | "Only seller can call this."
88 | );
89 | _;
90 | }
91 |
92 | function abort() public view onlySeller { // モディファイアの使用
93 | // ...
94 | }
95 | }
96 |
97 | .. _structure-events:
98 |
99 | イベント
100 | ========
101 |
102 | イベントは、EVMのログ機能を使った便利なインターフェースです。
103 |
104 | .. code-block:: solidity
105 |
106 | // SPDX-License-Identifier: GPL-3.0
107 | pragma solidity ^0.8.22;
108 |
109 | event HighestBidIncreased(address bidder, uint amount); // イベント
110 |
111 | contract SimpleAuction {
112 | function bid() public payable {
113 | // ...
114 | emit HighestBidIncreased(msg.sender, msg.value); // イベントのトリガー
115 | }
116 | }
117 |
118 | イベントがどのように宣言され、dapp内でどのように使用されるかについては、コントラクトセクションの :ref:`events` を参照してください。
119 |
120 | .. _structure-errors:
121 |
122 | エラー
123 | ======
124 |
125 | エラーは障害が発生したときの記述的な名前とデータを定義できます。
126 | エラーは :ref:`リバート文` で使用できます。
127 | 文字列による説明に比べて、エラーははるかに安価で、追加データをエンコードできます。
128 | NatSpecを使って、ユーザーにエラーを説明できます。
129 |
130 | .. code-block:: solidity
131 |
132 | // SPDX-License-Identifier: GPL-3.0
133 | pragma solidity ^0.8.4;
134 |
135 | // 送金資金の不足。要求したのは`requested`だが、利用可能なのは`available`だけ。
136 | error NotEnoughFunds(uint requested, uint available);
137 |
138 | contract Token {
139 | mapping(address => uint) balances;
140 | function transfer(address to, uint amount) public {
141 | uint balance = balances[msg.sender];
142 | if (balance < amount)
143 | revert NotEnoughFunds(amount, balance);
144 | balances[msg.sender] -= amount;
145 | balances[to] += amount;
146 | // ...
147 | }
148 | }
149 |
150 | 詳しくは、コントラクト編の :ref:`errors` を参照してください。
151 |
152 | .. _structure-struct-types:
153 |
154 | 構造体型
155 | ========
156 |
157 | 構造体(struct)は、複数の変数をグループ化できるカスタム定義の型です(型の項の :ref:`structs` を参照)。
158 |
159 | .. code-block:: solidity
160 |
161 | // SPDX-License-Identifier: GPL-3.0
162 | pragma solidity >=0.4.0 <0.9.0;
163 |
164 | contract Ballot {
165 | struct Voter { // 構造体
166 | uint weight;
167 | bool voted;
168 | address delegate;
169 | uint vote;
170 | }
171 | }
172 |
173 | .. _structure-enum-types:
174 |
175 | 列挙型
176 | ======
177 |
178 | 列挙(enum)は、有限の「定数値」を持つカスタム型を作成するために使用できます(型の項の :ref:`enums` を参照)。
179 |
180 | .. code-block:: solidity
181 |
182 | // SPDX-License-Identifier: GPL-3.0
183 | pragma solidity >=0.4.0 <0.9.0;
184 |
185 | contract Purchase {
186 | enum State { Created, Locked, Inactive } // 列挙
187 | }
188 |
189 |
--------------------------------------------------------------------------------
/docs/types/operator-precedence-table.rst:
--------------------------------------------------------------------------------
1 | 演算子の優先順位を評価順に並べると以下のようになります。
2 |
3 | +------------+-------------------------------------+--------------------------------------------+
4 | | 優先順位 | 説明 | 演算子 |
5 | +============+=====================================+============================================+
6 | | *1* | 後置インクリメントとデクリメント | ``++``, ``--`` |
7 | + +-------------------------------------+--------------------------------------------+
8 | | | New式 | ``new `` |
9 | + +-------------------------------------+--------------------------------------------+
10 | | | 配列添字アクセス | ``[]`` |
11 | + +-------------------------------------+--------------------------------------------+
12 | | | メンバアクセス | ``