Solidity
Solidity
Solidity·Gavin Wood2014·Christian
Reitwiessner
SolidityECMAScript
ECMAScript
JavaCJSSolidity
Solidity
contract Test {
}
contract TEST {
}
Solidityvar
uint8n
string
function add() {
var a = 1;
// a = 1000;
var b = "b";
}
Solidityvar
Solidity
//
/*)*/
@dev
@param
@return
/**
* @dev
*
* @param bytes32Array
* @param intArray
* @param uintArray
*
* @return uint
* @return bytes
* @return uint
*/
function insertEnterpriseEntity(bytes32[] bytes32Array, int[] intArray, uint[]
uintArray) public returns(uint, bytes, uint) {
// 1
uint hyperUserCheck = _hyperUserAddress2HyperUser[msg.sender].hyperUserRol
e;
if (hyperUserCheck != SUPERUSER) {
return (ERROR, "", 0);
}
// 1
hyperUserCheck = _hyperUserAddress2HyperUser[msg.sender].hyperUserState;
if (hyperUserCheck != NORMAL) {
return (ERROR, "", 0);
}
EnterpriseEntity memory newEnterpriseEntity;
uint insertedCount = 0;
uint b = 0;
uint i = 0;
uint u = 0;
while (b < bytes32Array.length || i < intArray.length || u < uintArray.len
gth) {
//
newEnterpriseEntity.enterpriseNo = hyperSubArray(bytes32Array, b, uint
Array[u]);
b += uintArray[u++];
newEnterpriseEntity.enterpriseName = hyperSubArray(bytes32Array, b, ui
ntArray[u]);
b += uintArray[u++];
newEnterpriseEntity.legalPerson = hyperSubArray(bytes32Array, b, uintA
rray[u]);
b += uintArray[u++];
newEnterpriseEntity.enterpriseType = intArray[i];
++i;
newEnterpriseEntity.timestamp = intArray[i];
++i;
//
if (_enterpriseNo2EnterpriseEntity[newEnterpriseEntity.enterpriseNo[0]
][newEnterpriseEntity.enterpriseNo[1]].enterpriseNo.length != 0) {
return (ERROR, "", insertedCount);
}
//
hyperPushSetElement(_enterpriseNoInEnterpriseEntitySet, newEnterpriseE
ntity.enterpriseNo);
//
_enterpriseNo2EnterpriseEntity[newEnterpriseEntity.enterpriseNo[0]][ne
wEnterpriseEntity.enterpriseNo[1]] = newEnterpriseEntity;
//
++insertedCount;
}
return (SUCCESS, "", insertedCount);
}
{}
contract Test {
uint a;
function testA() {
if (a == 0) {
a = 1;
}
}
}
Solidity
contract Test {
//
uint a = b = 1;
}
_$
uint test;
uint $test;
uint $1;
uint _$te$t2;
Solidityvar
var sTest = 1;
sTest2 = sTest + 2;
ECMA-262 ECMAScript keyword ECMAScript
/
Solidity
break
continue
delete ()
do
for
function
if
else
new
return
this
throw
var
while
with
switch
case
default
try
catch
finally
void
typeof
in
instanceof
abstract
after
final
in
inline
let
match
null
of
relocatable
static
type
typeof
Solidity
stack
heappoint
Solidityinterface
-
- -
-
remixSolidity
http://github.com/chriseth/browser-solidity
remixreleasenightlyreleasenightly
https://github.com/ethereum/remix-ide
NPM / node.js
Solidity
SolidityEmscriptenJavaScriptC++JavaScript
NPM
npm install solc
https://github.com/ethereum/solc-js
http://solidity.readthedocs.io/en/latest/installing-solidity.html
pragma solidity ^0.4.0
0.4
^0.5bug0.4.1
bug0.4.2
*
import “filename”;
*
import * as symbolName from “filename”
//
import “filename” as symbolName
import {symbol1 as alias, symbol2} from “filename”
.
SourceUnit = (PragmaDirective | ImportDirective | ContractDefinition)*
// Pragma actually parses anything up to the trailing ';' to be fully forward-comp
atible.
PragmaDirective = 'pragma' Identifier ([^;]+) ';'
ImportDirective = 'import' StringLiteral ('as' Identifier)? ';'
| 'import' ('*' | Identifier) ('as' Identifier)? 'from' StringLiteral ';'
| 'import' '{' Identifier ('as' Identifier)? ( ',' Identifier ('as' Identi
fier)? )* '}' 'from' StringLiteral ';'
ContractDefinition = ( 'contract' | 'library' | 'interface' ) Identifier
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
'{' ContractPart* '}'
ContractPart = StateVariableDeclaration | UsingForDeclaration
| StructDefinition | ModifierDefinition | FunctionDefinition | EventD
efinition | EnumDefinition
InheritanceSpecifier = UserDefinedTypeName ( '(' Expression ( ',' Expression )* ')
' )?
StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' | 'constan
t' )? Identifier ('=' Expression)? ';'
UsingForDeclaration = 'using' Identifier 'for' ('*' | TypeName) ';'
StructDefinition = 'struct' Identifier '{'
( VariableDeclaration ';' (VariableDeclaration ';')* )? '}'
ModifierDefinition = 'modifier' Identifier ParameterList? Block
ModifierInvocation = Identifier ( '(' ExpressionList? ')' )?
FunctionDefinition = 'function' Identifier? ParameterList
( ModifierInvocation | StateMutability | 'external' | 'public
' | 'internal' | 'private' )*
( 'returns' ParameterList )? ( ';' | Block )
EventDefinition = 'event' Identifier IndexedParameterList 'anonymous'? ';'
EnumValue = Identifier
EnumDefinition = 'enum' Identifier '{' EnumValue? (',' EnumValue)* '}'
IndexedParameterList = '(' ( TypeName 'indexed'? Identifier? (',' TypeName 'indexe
d'? Identifier?)* )? ')'
ParameterList = '(' ( TypeName Identifier? (',' TypeName
Identifier?)* )? ')'
TypeNameList = '(' ( TypeName (',' TypeName )* )? ')'
// semantic restriction: mappings and structs (recursively) containing mappings
// are not allowed in argument lists
VariableDeclaration = TypeName StorageLocation? Identifier
TypeName = ElementaryTypeName
| UserDefinedTypeName
| Mapping
| ArrayTypeName
| FunctionTypeName
UserDefinedTypeName = Identifier ( '.' Identifier )*
Mapping = 'mapping' '(' ElementaryTypeName '=>' TypeName ')'
ArrayTypeName = TypeName '[' Expression? ']'
FunctionTypeName = 'function' TypeNameList ( 'internal' | 'external' | StateMutabi
lity )*
( 'returns' TypeNameList )?
StorageLocation = 'memory' | 'storage'
StateMutability = 'pure' | 'constant' | 'view' | 'payable'
Block = '{' Statement* '}'
Statement = IfStatement | WhileStatement | ForStatement | Block | InlineAssemblySt
atement |
( DoWhileStatement | PlaceholderStatement | Continue | Break | Return
|
Throw | SimpleStatement ) ';'