mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13916 from NicoAcosta/mapping-style
Fix mapping style in docs
This commit is contained in:
commit
78608e8d17
@ -34,7 +34,7 @@ you receive the funds of the person who is now the richest.
|
|||||||
address public richest;
|
address public richest;
|
||||||
uint public mostSent;
|
uint public mostSent;
|
||||||
|
|
||||||
mapping (address => uint) pendingWithdrawals;
|
mapping(address => uint) pendingWithdrawals;
|
||||||
|
|
||||||
/// The amount of Ether sent was not higher than
|
/// The amount of Ether sent was not higher than
|
||||||
/// the currently highest amount.
|
/// the currently highest amount.
|
||||||
|
@ -61,7 +61,7 @@ if they are marked ``virtual``. For details, please see
|
|||||||
}
|
}
|
||||||
|
|
||||||
contract Register is priced, destructible {
|
contract Register is priced, destructible {
|
||||||
mapping (address => bool) registeredAddresses;
|
mapping(address => bool) registeredAddresses;
|
||||||
uint price;
|
uint price;
|
||||||
|
|
||||||
constructor(uint initialPrice) { price = initialPrice; }
|
constructor(uint initialPrice) { price = initialPrice; }
|
||||||
|
@ -200,12 +200,12 @@ The next example is more complex:
|
|||||||
struct Data {
|
struct Data {
|
||||||
uint a;
|
uint a;
|
||||||
bytes3 b;
|
bytes3 b;
|
||||||
mapping (uint => uint) map;
|
mapping(uint => uint) map;
|
||||||
uint[3] c;
|
uint[3] c;
|
||||||
uint[] d;
|
uint[] d;
|
||||||
bytes e;
|
bytes e;
|
||||||
}
|
}
|
||||||
mapping (uint => mapping(bool => Data[])) public data;
|
mapping(uint => mapping(bool => Data[])) public data;
|
||||||
}
|
}
|
||||||
|
|
||||||
It generates a function of the following form. The mapping and arrays (with the
|
It generates a function of the following form. The mapping and arrays (with the
|
||||||
|
@ -34,7 +34,7 @@ and the sum of all balances is an invariant across the lifetime of the contract.
|
|||||||
contract Token {
|
contract Token {
|
||||||
mapping(address => uint256) balances;
|
mapping(address => uint256) balances;
|
||||||
using Balances for *;
|
using Balances for *;
|
||||||
mapping(address => mapping (address => uint256)) allowed;
|
mapping(address => mapping(address => uint256)) allowed;
|
||||||
|
|
||||||
event Transfer(address from, address to, uint amount);
|
event Transfer(address from, address to, uint amount);
|
||||||
event Approval(address owner, address spender, uint amount);
|
event Approval(address owner, address spender, uint amount);
|
||||||
|
@ -232,7 +232,7 @@ value and reference types, types that are encoded packed, and nested types.
|
|||||||
uint y;
|
uint y;
|
||||||
S s;
|
S s;
|
||||||
address addr;
|
address addr;
|
||||||
mapping (uint => mapping (address => bool)) map;
|
mapping(uint => mapping(address => bool)) map;
|
||||||
uint[] array;
|
uint[] array;
|
||||||
string s1;
|
string s1;
|
||||||
bytes b1;
|
bytes b1;
|
||||||
|
@ -91,7 +91,7 @@ registering with a username and password, all you need is an Ethereum keypair.
|
|||||||
// The keyword "public" makes variables
|
// The keyword "public" makes variables
|
||||||
// accessible from other contracts
|
// accessible from other contracts
|
||||||
address public minter;
|
address public minter;
|
||||||
mapping (address => uint) public balances;
|
mapping(address => uint) public balances;
|
||||||
|
|
||||||
// Events allow clients to react to specific
|
// Events allow clients to react to specific
|
||||||
// contract changes you declare
|
// contract changes you declare
|
||||||
@ -151,7 +151,7 @@ You do not need to do this, the compiler figures it out for you.
|
|||||||
|
|
||||||
.. index:: mapping
|
.. index:: mapping
|
||||||
|
|
||||||
The next line, ``mapping (address => uint) public balances;`` also
|
The next line, ``mapping(address => uint) public balances;`` also
|
||||||
creates a public state variable, but it is a more complex datatype.
|
creates a public state variable, but it is a more complex datatype.
|
||||||
The :ref:`mapping <mapping-types>` type maps addresses to :ref:`unsigned integers <integers>`.
|
The :ref:`mapping <mapping-types>` type maps addresses to :ref:`unsigned integers <integers>`.
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ field of a ``struct`` that is the base type of a dynamic storage array. The
|
|||||||
pragma solidity >=0.6.0 <0.9.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract Map {
|
contract Map {
|
||||||
mapping (uint => uint)[] array;
|
mapping(uint => uint)[] array;
|
||||||
|
|
||||||
function allocate(uint newMaps) public {
|
function allocate(uint newMaps) public {
|
||||||
for (uint i = 0; i < newMaps; i++)
|
for (uint i = 0; i < newMaps; i++)
|
||||||
|
@ -95,8 +95,8 @@ The example below uses ``_allowances`` to record the amount someone else is allo
|
|||||||
|
|
||||||
contract MappingExample {
|
contract MappingExample {
|
||||||
|
|
||||||
mapping (address => uint256) private _balances;
|
mapping(address => uint256) private _balances;
|
||||||
mapping (address => mapping (address => uint256)) private _allowances;
|
mapping(address => mapping(address => uint256)) private _allowances;
|
||||||
|
|
||||||
event Transfer(address indexed from, address indexed to, uint256 value);
|
event Transfer(address indexed from, address indexed to, uint256 value);
|
||||||
event Approval(address indexed owner, address indexed spender, uint256 value);
|
event Approval(address indexed owner, address indexed spender, uint256 value);
|
||||||
|
@ -686,11 +686,11 @@ shown in the following example:
|
|||||||
uint fundingGoal;
|
uint fundingGoal;
|
||||||
uint numFunders;
|
uint numFunders;
|
||||||
uint amount;
|
uint amount;
|
||||||
mapping (uint => Funder) funders;
|
mapping(uint => Funder) funders;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint numCampaigns;
|
uint numCampaigns;
|
||||||
mapping (uint => Campaign) campaigns;
|
mapping(uint => Campaign) campaigns;
|
||||||
|
|
||||||
function newCampaign(address payable beneficiary, uint goal) public returns (uint campaignID) {
|
function newCampaign(address payable beneficiary, uint goal) public returns (uint campaignID) {
|
||||||
campaignID = numCampaigns++; // campaignID is return variable
|
campaignID = numCampaigns++; // campaignID is return variable
|
||||||
|
Loading…
Reference in New Issue
Block a user