Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrich document with using getter function over state struct instance #15526

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6170061
enrich document with using getter function over state struct instance
haoyang9804 Oct 18, 2024
34c53d6
fix errors in the doc
haoyang9804 Oct 18, 2024
4015242
remove Trailing whitespace
haoyang9804 Oct 18, 2024
40b83b3
Merge branch 'develop' into develop
haoyang9804 Oct 21, 2024
dffaa5d
Refine doc based on suggestions
haoyang9804 Oct 21, 2024
0e9fc9f
refine the doc
haoyang9804 Oct 21, 2024
c23ad79
Merge branch 'develop' into develop
haoyang9804 Oct 21, 2024
79932bf
Merge branch 'develop' into develop
haoyang9804 Oct 21, 2024
a84241c
merge array example and struct example. Remove mapping.
haoyang9804 Oct 21, 2024
046cb36
Merge branch 'develop' into develop
haoyang9804 Oct 22, 2024
daedcd0
Document a special workaround for calldata arrays and struct instances
haoyang9804 Oct 22, 2024
f01f098
reset the incorrect commit
haoyang9804 Oct 22, 2024
7a2d0d9
Merge branch 'develop' into develop
haoyang9804 Oct 23, 2024
4218d58
Merge branch 'develop' into develop
haoyang9804 Oct 24, 2024
b8a072b
refine the doc
haoyang9804 Oct 25, 2024
17c365b
Merge branch 'develop' into develop
haoyang9804 Oct 25, 2024
f3b721f
Fix errors in the code example
haoyang9804 Oct 26, 2024
9052b55
Merge branch 'develop' of github.com:haoyang9804/solidity into develop
haoyang9804 Oct 26, 2024
615c5a8
Merge branch 'develop' into develop
haoyang9804 Oct 30, 2024
c814202
refine the doc
haoyang9804 Oct 30, 2024
901bef0
Merge branch 'develop' of github.com:haoyang9804/solidity into develop
haoyang9804 Oct 30, 2024
7a0e70d
Merge branch 'develop' into develop
haoyang9804 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/contracts/visibility-and-getters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,47 @@ to write a function, for example:
Now you can use ``getArray()`` to retrieve the entire array, instead of
``myArray(i)``, which returns a single element per call.

When you have a public state variable of a struct type, calling the
getter function will return either a tuple containing the struct's members
(if there are multiple members) or just a single member
(if the struct has only one member). For example:
haoyang9804 marked this conversation as resolved.
Show resolved Hide resolved
haoyang9804 marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.0 <0.9.0;

contract structExample {
haoyang9804 marked this conversation as resolved.
Show resolved Hide resolved
// Struct Definition with single member
struct simpleStruct {
bool b;
}

// Struct Definition with multiple members
struct compleStruct {
haoyang9804 marked this conversation as resolved.
Show resolved Hide resolved
uint a;
bool b;
}

// public state variables
simpleStruct public ss;
compleStruct public cs;
haoyang9804 marked this conversation as resolved.
Show resolved Hide resolved

// Getter function generated by the compiler
/*
function ss() public view returns (bool) {
return ss.b;
}
function cs() public view returns (uint, bool) {
return (cs.a, cs.b);
}
*/

}

``this.ss()``'s return type is bool, while ``this.cs()``'s return type is
a tuple of uint and bool.

The next example is more complex:

.. code-block:: solidity
Expand Down