Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文
solc:solidity的编译器8 p8 E; \) ~; O  a
% j# t- m/ M/ v" q8 O
    solidity编写的以太坊智能合约可通过命令行编译工具solc来进行编译,成为以太坊虚拟机中的代码。solc编译后最终部署到链上形成我们所见到的各种智能合约。" n$ b% n% S" c
6 _* D+ ~) U: Z* A6 |% l3 }) b' r* y+ h
    作为一个solidity命令行编译工具,我们来看看官网都怎么说solc。
/ e1 }% R; o, K! t8 N) {& i; ?, o9 n  l
    solc的安装很简单:
1 s: @0 [" h+ S$ _
7 Q$ n$ J7 S( {* ?, e! o    npminstall-gsolc" O7 \0 V# U4 F! h3 n

9 F8 Q, w% L$ H1 X    //或者
( O' b  ^& G& x) o  p0 j! b. H& c9 t- L  j0 X
    npminstall-gsolc-cli) J! _7 n& Q+ d. P' [$ S

! C1 z7 Z! v( d  |( z: J$ p    //或者5 |6 [0 \4 \2 z/ t6 H( [
% ~" O( `# p5 Y# a
    sudoapt-getinstallsolc
; j6 b- \- p2 n( v4 Y- s. h' R& k+ J0 U% ^$ n( H
    安装完成后我们来看,solc--help,solc--help命令显示所有的solc命令选项。编译器可以生成各种输出,比如最终的二进制合约文件、语法树的汇编或者需要预计的要花费的gas等。solc--binsourceFile.sol,可以编译后输出一个名为sourceFile.sol的智能合约文件。如果你想从solc获得更丰富的一些输出变量,你可以使用solc-ooutputDirectory--bin--ast--asmsourceFile.sol。
6 J  b, s! |2 e) e$ ^3 |8 h4 D) @  c4 ~! a
    你在部署以太坊智能合约之前可以用solc--optimize--binsourceFile.sol优化一下。默认情况下solc编译器会帮你优化200次。你也可以设置--runs=1,这样就按照最小化的方式进行编译,如果你希望多次交易不太在乎成本,那你可以设置成你想要的次数:)。( Q& T5 N1 \4 \0 o0 _# E. w/ v6 Z. R$ X

% b0 D. ~/ T- m( y/ M- W/ R    命令行编译器会自动读取需要导入的文件,也可以通过使用prefix=path来指定路径,例如:7 R, Q% B( g9 U" K5 L, T
* |2 y6 R+ p$ P" |$ R% {
    solcgithub.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/=/usr/local/lib/fallbackfile.sol2 s( d; w) u1 s. d. }' Y

$ Q- C, }8 W2 o3 W; N! [    这样编译器就会从指定目录github.com/ethereum/dapp-bin/下的/usr/local/lib/dapp-bin/目录开始搜索,如果没有找到文件,它将查看/usr/local/lib/fallback。solc将只读取你指定的这两个路径的,因此像import"/etc/passwd";必须要通过/=重新映射才起作用。如果有多个匹配,则选择具有最长公共前缀的进行匹配。
2 I/ V  V/ Y- O5 N% J+ ^
- l) f/ ~# n; ]8 w' D    出于安全上的考虑,编译器限制了它可以访问的一些目录。在命令行中指定的源文件的路径(及其子目录)和命令行指定的路径外其他所有内容都会被拒绝。--allow-paths/sample/path,/another/sample/path来切换。
% R, k! G& t5 b$ p+ R$ d* k7 k- H5 G! T
0 V) z. [; F+ X" @- t3 p    如果智能合约使用了libraries,你会注意到字节码包含了__LibraryName______的子字符串。您可以使用solc作为链接器,这意味着它将在这些点为您插入库地址。; m( b& }& E8 T# M) t8 i- m  s

8 C0 m# s% L1 C5 ~# A7 @    可以通过添加库--libraries"Math:0x12345678901234567890Heap:0xabcdef0123456"到您的命令,以提供每个库的地址,或者使用文件中的说明字符串(每行一个库),并使用--librariesfileName运行solc。
) S, ~5 E) S" S+ K" l$ q$ l+ q: B6 v" H( S
    如果用选项--link调用Solc,则所有输入文件都被解释为未链接的二进制文件(HEX编码),在上面给出的__LibraryName____格式中,将其链接到适当地址(如果从stdin读取输入,则将其写入stdout)。在这种情况下,除了库外,所有选项都被忽略(包括-o)。9 A0 @" E, \! j% N

$ v) l2 K- J- `1 V7 |; B8 c    如果用--standard-json调用SOLC,它就将标准的JSON输入(如下所述),并返回JSON输出。8 H% s  s$ }) Z0 O2 ^( }, G

3 C# g- P/ s! [  t9 |- C    #solc编译器输入输出JSON描述9 F0 K" ^. m; a/ `3 w. W
. N2 Q! ^: K5 S% O% R8 E
    这些JSON格式通过编译器API使用,可以通过SOLC获得。内容都是可以修改的,一些对象是可选的(如前所述),其目的是向后兼容。
9 A8 r9 B$ `; W: D: c+ @. F/ V& v3 `
    编译器的API需要一个JSON格式的输入,然后以JSON格式输出编译结果。
/ j% Y) C/ Z4 n- A: K7 c* @' D1 R0 y) |( c8 p$ j
    注意不允许注释。下面示例中的注释,是官网为了学习者更好的理解标注的。% ~/ M+ v0 B1 v; p5 U

# O& O  [1 u- D- V% g6 b: Z* S    输入格式说明:
  P5 C7 O7 \: @, ]% Z/ h, [
0 E# L' @* l; ^    {
! f! s! h1 ?- ?! i  E$ u4 U& k2 Z% r: f* V
    //Required:Sourcecodelanguage,suchas"Solidity","serpent","lll","assembly",etc.) L4 h/ G* Y, p* e0 G
' l# v) u" M3 O% K9 w
    language:"Solidity",
6 E( h9 y, I- U+ V: Q4 K3 t) |* d2 z2 G! D0 Y
    //Required# O$ ?  ?9 t. l2 p" i

+ o; W: t# p8 b! @3 ?( ~, S    sources:
# ^$ |" w* _' s# E! k& n; C1 e
5 \# r8 k$ S/ N1 Z/ w4 C    {# b# H/ R  D& X
. G. x) O  O% }% i; q
    //Thekeysherearethe"global"namesofthesourcefiles,2 y  T; @7 ]1 e* H1 g/ Z

2 L! H9 T6 P7 z6 H( `5 P    //importscanuseotherfilesviaremappings(seebelow).
. b3 D5 B  X2 p2 D# c/ D, W2 B& @3 \8 y$ R
    "myFile.sol":: o" U% q  [. e) v, V

, S& [: U+ K) {9 O5 \    {
- x$ P# m' h8 k# d8 e& s/ F) l* ^( E% o- U# i' ~- Q  I. f
    //Optional:keccak256hashofthesourcefile9 l* V  ]6 |$ r6 E: R4 K

+ \3 V+ L6 x! K0 ]4 c9 `! K    //ItisusedtoverifytheretrievedcontentifimportedviaURLs.
* |6 D/ P' U+ J2 k- C" l
- y/ G2 v) W7 n" ]. A, s    "keccak256":"0x123...",
) A9 o4 v( P  @; e4 U& E2 s  C9 ?' X8 q, s# T* U4 J( _- Q
    //Required(unless"content"isused,seebelow):URL(s)tothesourcefile.
: Z8 g8 W9 P$ m2 k% j0 U1 A0 S) }. d/ B1 L& o* ^1 N
    //URL(s)shouldbeimportedinthisorderandtheresultcheckedagainstthe* k" v4 \  G0 l# s/ j

2 K, _) R' g& L5 m    //keccak256hash(ifavailable).Ifthehashdoesn'tmatchornoneofthe
0 X; s+ x$ E  ^9 p+ }0 u
# `- Y8 `+ D8 t# O    //URL(s)resultinsuccess,anerrorshouldberaised.
9 C& F9 o6 w9 a$ R5 V- x+ C- F! n# N7 @' E% U( }
    "urls":
8 h1 X! r9 T: A
/ C) `. @) G# U) E    [
, T3 A9 O" l8 @- L* R" i' a0 i3 R2 A: L9 G
    "bzzr://56ab...",6 @8 F/ c# B" y  `$ B  H# n
; i, Y8 Z6 A; O( w7 t, D) @1 x  g
    "ipfs://Qma...",
+ N' G& x; ]8 i1 X" g5 e; _4 [$ Q5 z0 y3 t. C! z% c/ C
    "file:///tmp/path/to/file.sol"2 F" X$ |8 ~+ H, |5 h5 ^5 \

- W! n3 X7 z: Q- ~3 k, R    ]
1 V. N- H0 W2 i" r. d: u" O9 |0 m7 y( W: h: O
    },- |6 P  ?. z, }% o
3 r) D1 u' m9 O5 F2 ?1 `! w
    "mortal":
1 z  T; f, R. E4 M
( X$ P4 P, r1 }, N    {: S4 z; p4 y: w; b; O1 v* p

% ^. l: R1 Y) ?4 E    //Optional:keccak256hashofthesourcefile
; R* |& o7 P6 J: e" q6 A' M- ^
0 m3 X) z& S5 M' R    "keccak256":"0x234...",+ n5 W; T5 t0 Y8 d1 _. g
) X$ B  G1 G6 m# L& }* U
    //Required(unless"urls"isused):literalcontentsofthesourcefile! L5 k: F: Q3 W+ l' a

8 b: r' c! ~+ w; X0 }2 ^    "content":"contractmortalisowned{functionkill(){if(msg.sender==owner)selfdestruct(owner);}}"
, o% d% o6 V$ u: w5 ?1 p
/ C1 y* c6 T- p    }7 V3 H) f- Z5 p# |- v
4 U1 c+ K+ W& ~$ ~1 ~
    },
# n# r6 D$ A9 o, Y4 q) J+ ?" |; f9 _
    //Optional
( s: @0 p3 _8 j6 |- l2 y
4 b& d3 u6 }. T% R$ x8 y! u    settings:
6 V: w) [( y. m4 O1 K# r8 r8 |& j9 S, v) ?
    {* [: |/ Z" n; u0 A* f5 F
' o" ^; |: D# E( F' Q
    //Optional:Sortedlistofremappings
6 [. Y+ w7 q* s, F* n; b* b5 `4 X
    remappings:[":g/dir"],& C) U3 i( A4 M; i: y+ N# Y: x

8 j) @& e4 Q0 i, e, g1 P    //Optional:Optimizersettings
1 ?( Q# s' c& q2 {, Y3 B
' }/ I: ^! ^6 T1 F9 D    optimizer:{+ X7 j, ?$ q, ]: @* V# M+ K
. m$ @0 ~4 A* x; ^) g) _2 k* b4 d- A) F
    //disabledbydefault/ {$ l2 f& d( n2 i9 ]3 n8 ~
1 M/ V( v) }. n- |( N( B3 Q1 B
    enabled:true,
7 m# ~1 Z1 i0 G! n& c9 H! b
6 d" Z, c' G* Z) i1 H9 P; G+ L! J% V: D3 f    //Optimizeforhowmanytimesyouintendtorunthecode.6 _, w9 r1 i8 q2 x3 L) i6 n7 _" R. V' {5 ]

6 Q) x. a8 P. s( [    //Lowervalueswilloptimizemoreforinitialdeploymentcost,highervalueswilloptimizemoreforhigh-frequencyusage.7 b6 Q, M- r+ J. `1 A" O

4 q( @  n, `4 v# E    runs:200! _# U! h3 Z  Z$ u- p2 h  H
: e$ K! H: ~8 c; C0 J$ m' b
    },9 q- |7 k7 D4 n6 ?

# S# m2 b; E" Y. K    evmVersion:"byzantium",//VersionoftheEVMtocompilefor.Affectstypecheckingandcodegeneration.Canbehomestead,tangerineWhistle,spuriousDragon,byzantiumorconstantinople" O: Q; }7 {6 z8 R0 o' d: N! v6 y+ m. @9 l
, |( |' n/ P3 T: B
    //Metadatasettings(optional)
2 S! ~' C( T- M8 H/ R( f. i* ^, V9 I, O) Q
    metadata:{
6 c, u4 }" w) E& e4 Q. G, V) p7 i1 f+ `6 T, J& P- ?# b3 S. A- o
    //UseonlyliteralcontentandnotURLs(falsebydefault)
: p8 ~" N: s. m+ j) x% |7 J
& f, _* j; R+ s- k& s    useLiteralContent:true
% t# F; P% e3 Q6 \' X$ F9 A0 f
# H1 B! {" Y* m) T5 _5 c    },
( ~  J/ ]6 i3 Q( j
" P" _$ K4 l, p% E3 [% G- Y    //Addressesofthelibraries.Ifnotalllibrariesaregivenhere,itcanresultinunlinkedobjectswhoseoutputdataisdifferent.. d- Y9 _9 d9 I" X# V. H$ i
" b' Y5 e- E" m1 Y
    libraries:{
5 x" _- I: m  Y8 v; \& W8 v6 F+ V& i) e% [1 n
    //Thetoplevelkeyisthethenameofthesourcefilewherethelibraryisused.
% U1 ^: m# `- c
2 _1 u, u, w7 ]6 T; d    //Ifremappingsareused,thissourcefileshouldmatchtheglobalpathafterremappingswereapplied.8 `: H0 P+ [% t* o5 d1 P
0 q; v/ B; F% _5 M% _3 n2 ~
    //Ifthiskeyisanemptystring,thatreferstoagloballevel.* [5 J9 m( j1 R5 V- ^6 T

  k5 P  {' y. v. [4 N, a    "myFile.sol":{
( u& G; y$ r; @( B- Z- l# y+ C
' `1 ]" V2 T" x' \* l2 b) }    "MyLib":"0x123123..."* x; i/ F$ s, ]. F  x- ]$ A' _

9 m6 t3 J7 G: k6 k" w& d    }
3 ]& M0 h0 J* I' ~8 a
* L2 x; n' T( \    }0 v0 g% a# y/ l: _+ |7 Q' `
3 w' r; P# V% F7 X, L' j/ [
    //Thefollowingcanbeusedtoselectdesiredoutputs.
# I0 J- A; t; o) U, }, x0 S3 T8 E8 o- a6 W
    //Ifthisfieldisomitted,thenthecompilerloadsanddoestypechecking,butwillnotgenerateanyoutputsapartfromerrors.8 ^  ?! G; \4 G
% u- l# s: j: L  E6 B1 x, z
    //Thefirstlevelkeyisthefilenameandthesecondisthecontractname,whereemptycontractnamereferstothefileitself,
3 a" c  E9 M& v6 T# @- h1 ]) t* f: U. B7 H
    //whilethestarreferstoallofthecontracts.
/ x& \4 q7 |# d/ {( i' X8 b9 E. V# g0 i& P, @
    //- O* z9 |; d5 @) Q# L7 k) K6 ?7 o
4 Q9 R/ y6 q% g
    //Theavailableoutputtypesareasfollows:
3 M/ |2 P  i4 n. A! v
) m  l6 ^2 F1 q' M; ]5 F    //abi-ABI
6 L0 G5 P. c$ _. m/ ]3 L9 e# u3 q3 c5 ^0 {& p
    //ast-ASTofallsourcefiles0 V: f% g: Q$ v$ n, O  N# ~
. O4 c2 M4 ]# u2 X
    //legacyAST-legacyASTofallsourcefiles
; o6 o- O5 c) T% _2 z; h5 Y( g( t* c) b. s% W3 X+ V
    //devdoc-Developerdocumentation(natspec)
  _. M+ X4 G' |' G3 [8 R: s5 g/ a- L! d/ n) P, t+ K# t
    //userdoc-Userdocumentation(natspec)+ |+ f+ x( H, S" T2 m& Y9 k) ~0 U

1 s! u3 P, v& X9 \- n    //metadata-Metadata# x- l" }0 `0 H8 U8 A
  a  ~/ I7 K1 i' V
    //ir-Newassemblyformatbeforedesugaring
+ Q6 e: M  N$ B; x) E4 m3 f% b  j5 g; R+ V* A- F
    //evm.assembly-Newassemblyformatafterdesugaring* \; c% l6 ~/ R; f" [% Q4 S3 R
& p9 u& |0 T" @) e, i
    //evm.legacyAssembly-Old-styleassemblyformatinJSON) h: B/ k: k% l6 P4 y

4 _2 F2 V6 [! Q0 g/ s    //evm.bytecode.object-Bytecodeobject
6 o0 d7 y1 w, Q- s0 O; y7 K8 J* E# g5 D  j
    //evm.bytecode.opcodes-Opcodeslist; C5 C' j' q7 ~+ X
, [8 R+ F' T+ M
    //evm.bytecode.sourceMap-Sourcemapping(usefulfordebugging)
1 Q1 K. `% F. n/ t
; r2 r7 x# B1 Q) J: P    //evm.bytecode.linkReferences-Linkreferences(ifunlinkedobject)) m  g) l1 \) ^* O4 h
8 x- n7 y! e3 {4 G. a, I
    //evm.deployedBytecode*-Deployedbytecode(hasthesameoptionsasevm.bytecode)' @) t/ Q8 A7 i+ ^: s

- ~, [3 R4 h7 R3 H* ]    //evm.methodIdentifiers-Thelistoffunctionhashes
! Q) a+ t, F6 s! X
6 f' K. u* x$ f! c2 P6 S8 j' }0 C9 k  }6 F    //evm.gasEstimates-Functiongasestimates. p2 D3 Y% n& E% ~+ G

  F9 R! @  a2 e$ b( {. {    //ewasm.wast-eWASMS-expressionsformat(notsupportedatm)
' h3 @& q5 q% i6 S4 s
' K, W, e0 ]2 z% a$ f, ~; X9 F    //ewasm.wasm-eWASMbinaryformat(notsupportedatm)
) S7 t& k: |6 z
  l$ y4 g3 A. I9 v% C) ^. Z' \$ P" |    //
/ t" q- u/ z2 v3 M
5 O, n$ A6 ]$ u4 Z' X    //Notethatusingausing`evm`,`evm.bytecode`,`ewasm`,etc.willselectevery
+ a6 s8 Q0 w$ f! {  ^% w( q; ?0 @* ^) M; x$ ?
    //targetpartofthatoutput.Additionally,`*`canbeusedasawildcardtorequesteverything.
' e, I7 g  v( l, m6 L6 I' [7 j4 \. v5 ]
    //
# }* z+ J$ o. }+ ^8 f) u2 [
* Q! n# J/ @' y" b9 e2 y. C    outputSelection:{0 l# N# V7 o( R$ W
& T; T: }8 F: e0 T! a. v2 h/ c
    //Enablethemetadataandbytecodeoutputsofeverysinglecontract.
( X6 z3 D2 H; K" A3 m( [7 x5 X+ b9 p+ M
- E+ Y& K1 e6 D6 @. X: b/ L9 d- m/ Z    "*":{& n8 L$ d8 S( _1 A
9 l0 S! ]( n9 ?
    "*":["metadata","evm.bytecode"]; A: i- e/ c) w
4 z. a9 p. w0 j& p) w4 \  c8 g8 u
    },6 S! c( z2 g& F9 J% y2 _
* z7 o3 _+ @" d
    //EnabletheabiandopcodesoutputofMyContractdefinedinfiledef.- `4 R( u: j  A1 K. h1 P
, ?3 L1 \6 T. n) L3 z- d/ g
    "def":{
( w' m- y- O' L4 x! P( c/ e' m5 c  `" `  A) [; a! D
    "MyContract":["abi","evm.bytecode.opcodes"]) ]5 R0 ^5 p9 a) s: R" ]. @  h$ B

! Y. K7 U  ]9 F$ [7 k    },
. i% B9 J8 A0 V! y& X/ W1 I
" {" x9 c5 m: m9 m/ v8 [& t1 o$ ]    //Enablethesourcemapoutputofeverysinglecontract.
) f; ^: z' @( Z/ k6 ]$ j. y0 g
9 |6 V6 w, B1 m$ c0 U    "*":{
- P* g8 {9 ?; D0 H0 s' s' e2 |; V0 h
    "*":["evm.bytecode.sourceMap"]% \- h) R: o# h$ L: e

; d5 j' d/ v9 K$ e& i" F" e+ c  r    },0 h6 k6 d7 q9 _, i) U2 T/ T

7 }$ i4 b/ c# J    //EnablethelegacyASToutputofeverysinglefile.
2 Q0 E+ n* `' D4 ]' M
5 X6 k0 d, j+ \* t' K* h; A    "*":{0 D) h5 ?+ V' U3 T$ v
+ Y/ l' A2 l/ C6 i5 U/ X: j# Q) p
    "":["legacyAST"]; [1 Y) u/ o* s# z7 A
+ @7 y& b" }; s: r9 D
    }
$ \6 o& W2 H0 f+ C% C) u3 X2 d2 d, z; t7 r/ B. {- ^- u  o+ x
    }
* W2 b1 i0 P8 s3 `" x- L
  B- }9 U5 k: q2 H4 g5 k: B    }
! Z* x; G: o, U" M5 j7 k
+ N* I6 |! U, b' A. C    }2 A  J5 S- P4 G- d/ b' p3 {3 \
$ P7 q7 Q4 z3 N3 b/ s$ t: O* ~
    输出格式说明# H8 q! d$ B9 P9 i
5 B- c" n5 j( J$ I
    {. }" I8 R' w: A" J
1 b: \- W0 `. P9 a" s  T
    //Optional:notpresentifnoerrors/warningswereencountered8 u# @1 E/ d# t3 w
" z3 y. G) i: C' B1 @3 V0 a9 y
    errors:[7 a7 a  u0 v" V$ O* d

7 N8 R0 n' J4 a9 ^9 S- _( t$ x    {1 V( W: p) k5 d
0 ]4 c+ F/ ^' w% R, U7 W+ T+ x
    //Optional:Locationwithinthesourcefile.6 Z! S8 K6 Q6 s2 ]: N6 m3 I, E' f
# [+ k# a% Z, ^, j: Z# O
    sourceLocation:{: t' c3 A8 l* T% M( t

2 ]1 h9 g4 K+ f' Y. @    file:"sourceFile.sol",
) W9 M2 M0 a& `: s2 O4 ]) \- }3 S& V+ }& O
    start:0,
1 @/ k- H: b$ t/ V- M" v3 \
: R0 H% s* l0 j* \- J    end:1002 m8 H" z5 ^" F; I- d8 k  n# C
2 q' b# y, t. m  A) g; ~
    ],
; u/ l, ?0 r; o7 b% B/ g& z
, G; f: K  [2 D/ \+ ~" B    //Mandatory:Errortype,suchas"TypeError","InternalCompilerError","Exception",etc.0 O" J% B6 t0 \7 r) S- f3 X

$ s( m7 b) V  I8 \5 N3 U0 b& k    //Seebelowforcompletelistoftypes.
# W% B1 k) M9 d- X' X) E7 [+ Y6 f3 b9 ]$ o# ^. b8 p6 y
    type:"TypeError",3 `# B  F9 Z' R# ^4 ^

" Q+ O+ n8 _! [$ T, q' p. y    //Mandatory:Componentwheretheerrororiginated,suchas"general","ewasm",etc.2 C" t7 R0 k+ _8 Z
" N' [/ w% L, X/ j6 G; m
    component:"general",
6 K3 s7 u& `2 w$ v% ~- z$ O" {4 u1 D3 j" y0 P) b+ f: j
    //Mandatory("error"or"warning")& Q8 x: g8 k6 ~8 Q4 v1 o. T: S5 \

# V/ x8 n8 p# j4 t4 }    severity:"error",
2 D8 K: c; G. J; C9 f% j) N% a: v8 h4 ~0 W
    //Mandatory
+ E3 I: M/ [8 y6 L9 e- A! M* r
5 M3 B2 h. A9 e/ H& d    message:"Invalidkeyword"
1 D, n: B+ d. w* j7 V1 g( }
) B+ F; X: _7 a% K    //Optional:themessageformattedwithsourcelocation
7 O+ H+ ~; S. s
; E# Y- b; c3 d    formattedMessage:"sourceFile.sol:100:Invalidkeyword"6 B# Z; w2 T& U0 h# W! X! |" D
0 X/ T/ f! c9 c% Z9 ?& J: |/ [4 k
    }1 M9 O7 V% u8 l# p# m1 V

: o* e- K- m; t- G) W    ],8 A" Z4 T+ K# V$ W1 e

6 [) B. L  c$ U0 s2 V/ _    //Thiscontainsthefile-leveloutputs.Incanbelimited/filteredbytheoutputSelectionsettings.7 B: I+ ~! i* a# \7 c* ^3 N
8 r1 V) w% M, l. Q2 Q% @, e$ I
    sources:{  }9 e4 f- p; ]( x
# V5 Z$ y: N: l' j+ _6 ?6 H9 q
    "sourceFile.sol":{/ K( E$ n$ B# |+ z0 g+ |% a

, `7 e: F8 s8 Y* E2 ]: L    //Identifier(usedinsourcemaps)
* \, f1 i- Q# j. G0 j3 j8 f$ s
    id:1,* U+ O9 v5 e$ z$ P( Z9 G

1 W2 ]( \6 K' J3 m1 f% m) K    //TheASTobject& a# [4 {6 X; n. M- R3 J$ A
1 _8 j0 p- p) M0 B: I# @) K* {6 p
    ast:{},% m. T2 S6 `+ c2 N& n( ?

/ a, E4 K0 ^8 P- B! l+ T% X    //ThelegacyASTobject
" t, W* D9 F$ k& G5 }' H6 B. h4 M
  p* V$ r# d9 M5 w1 ~( \    legacyAST:{}
( B# m3 J( H7 }" `: K! m) F+ S+ ~  i' |# X" E
    }) X  q8 F/ T8 U+ x/ A2 n! {3 V9 ^
1 `7 F% J! C) k/ j
    },& `( @4 P) |6 @6 Y& ]! q# S
% n. C+ z4 ^. Z9 L) P) M
    //Thiscontainsthecontract-leveloutputs.Itcanbelimited/filteredbytheoutputSelectionsettings.
. c9 k1 ^' e/ b
) b. y. N, O' x7 P1 _% ~    contracts:{
, X. X# `# v% a4 ~' Q% ]" w9 N. D7 p1 v  ~8 ?1 X
    "sourceFile.sol":{
1 P4 f. |! ]; C0 l% I3 {) z9 L' x+ |7 K' R- I7 {
    //Ifthelanguageusedhasnocontractnames,thisfieldshouldequaltoanemptystring.
8 n* e6 Q) U5 O1 }
. F. A! D% I# }; O3 Z    "ContractName":{
# u0 R% R! X+ X# w- ~# w, b% t0 Z0 _" M; H
    //TheEthereumContractABI.Ifempty,itisrepresentedasanemptyarray.
, G( b: b& r/ b: ]" X; c2 K8 C: S" J) W3 @
    //Seehttps://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
" q$ C- v( N& `" d( r
, ?$ M( v  k1 O5 o    abi:[],
5 @8 }$ H. x1 p$ {, F  Q3 N0 ^9 R4 A' L4 t. L
    //SeetheMetadataOutputdocumentation(serialisedJSONstring)
, ?# [! G% U' \, L+ j1 q- l/ |# j' ]& \1 I5 K6 w
    metadata:"{...}",$ a  @3 V7 p& m9 h; J' O

+ [* q+ i  C8 H9 w& g7 ^' h1 \( E    //Userdocumentation(natspec)
% _- Y2 m3 N+ H  _7 c# j) g2 |0 P) u3 d. m$ |
    userdoc:{},/ h' N- [9 d" R$ R
0 z. u8 O1 x) T! Z+ J
    //Developerdocumentation(natspec)
& K7 K7 b: `0 R, G7 \. I. u  e: J* w9 u# |; X' c* |- A
    devdoc:{},
5 X+ h) ^# b  {2 v2 d. F2 \5 t4 n8 u# ]. I
    //Intermediaterepresentation(string)
0 \% N- S. u: H3 K$ V/ G
0 r; u- M" ]5 F    ir:"",
( r/ o% [3 n6 [; H2 [) S. L, W2 c% X
    //EVM-relatedoutputs
; f  J* B: p7 X/ |* |1 e- H: @8 x/ d$ B- Z0 W( e. e8 l+ \) A
    evm:{
* A* n! I# y, Y3 p: e
/ |& O6 V, q% V" n2 [% T    //Assembly(string)
* r+ w4 E  C9 Z6 K# Y
. G' c5 p' s8 S+ ]: J. w    assembly:"",8 A' h8 r2 X0 I) u

2 p7 C/ {2 e0 H- D4 c$ G    //Old-styleassembly(object)
0 S! `2 Y$ Q1 h3 Y$ W7 l
. Q7 H0 @1 b( n- b. J0 Z    legacyAssembly:{},7 F* K7 a9 f4 o0 ]! U9 f' v

8 |5 k+ i9 p+ Z9 U- c; X    //Bytecodeandrelateddetails./ P) P4 V  w' m, E' e. O
: s! g' k6 }1 \2 @" y0 P
    bytecode:{
* I5 u; X, m' m& G8 u. }4 i" z+ D  {
    //Thebytecodeasahexstring.3 Z! u: F+ V! N; F  a4 t+ O

; B' S' N! I0 a! _6 y    object:"00fe",
( w5 X8 S6 j! Q5 h; U" n' Z
& O; J- t/ T/ f' P6 N4 j( l    //Opcodeslist(string)7 e4 @: v( @6 D. w; A0 x$ K- N* J5 S( t

+ p  f6 a- p2 L' K% }1 C, U    opcodes:"",
. O- c6 D: g# {* P# z" I9 D. S% {& K* Y7 f( G
    //Thesourcemappingasastring.Seethesourcemappingdefinition.8 D' i: h) p- _5 Y' h

% y/ S3 V9 p/ b3 ~    sourceMap:"",& D; t/ V% A, U. z. b

. ?  ^0 Y' W5 H: l- M% X    //Ifgiven,thisisanunlinkedobject.. [  ~0 e% K6 L# \! ^' `+ z
1 v( w% ^  H5 p# J3 h
    linkReferences:{% p+ D3 W+ Z) e

' `" T; v+ z' ^! \3 i    "libraryFile.sol":{
# o  I! _% _. G1 t) C. R, k& L1 R
    //Byteoffsetsintothebytecode.Linkingreplacesthe20byteslocatedthere.
& Y+ ~: o4 t0 X8 d. X
$ [& ]3 D( o" b+ Y* \0 [' [    "Library1":[
! Q" l" F' F" P& p" z; z: Q2 U( Q) U
    {start:0,length:20},
6 o$ _% s2 N; Y: Q% T8 S
7 ~: \/ B* Q8 v1 Q# d/ m0 A' C# e    {start:200,length:20}
  T* d) j) @) G+ ^! u) n0 L" G( b% ?5 w9 ]/ G2 L
    ]
; n6 z6 b3 e) `3 B# E" q
" S+ B9 b2 J) X) W    }
8 W9 |" c9 q, n! i5 Y0 i/ b2 \$ T  P1 M2 `" U4 G1 H  O
    }1 V2 N1 w/ ^. q

2 `+ \. t9 X, e5 ^; o5 s$ L2 X    },
8 v8 A  i. c8 O4 o* l. N
  T. m6 b% ~& @( h5 Z) |8 \    //Thesamelayoutasabove.$ g% F  N' k9 r/ R) |

* J  W9 H9 l: i, a    deployedBytecode:{},
  W$ o6 H# Z8 w) Y6 [6 }( ^3 r; U4 u: L
    //Thelistoffunctionhashes
/ W2 t2 V9 ~  J- k0 c2 f$ C9 @
0 i1 G  k  o5 z$ c. H    methodIdentifiers:{
# n- v# Z3 K, W5 ~; P% P
0 T# g% k' @/ D1 Q( `    "delegate(address)":"5c19a95c"2 c3 g! g; z- Y* K6 x8 ?
- `+ @2 _8 l4 t& L) G( \
    },8 ]' N2 C, ]4 ~: ]( N2 \7 \
8 b0 m! B+ C1 N) v- L6 }; z1 G$ }9 c
    //Functiongasestimates
% P  s5 Y0 r( o( y  x9 B/ L+ i
5 s% ?* v! w+ X8 v6 `( }9 A6 p    gasEstimates:{
( [) }( l. t3 D. M
  @* F- ~, \1 A* I6 L! o# x    creation:{; G- v. v4 I* |* @" V
" u. q& h& @# A
    codeDepositCost:"420000",& i0 ^( i1 G- b; U6 }4 Z

, z2 F  h! ?* T, o# }    executionCost:"infinite",/ Z- p5 G; e5 Y
" J& C$ X) ]/ P% g$ S+ d5 G) o, q
    totalCost:"infinite"# f3 h- g+ X& A
/ G6 v& {5 B3 g5 H! O# }8 C1 F
    },
% I0 h. }5 c) `
* ~! M6 ]% E2 R, D5 c0 ]+ o    external:{
$ G, \7 r; J7 x- E9 g
, F0 O: A; A9 K    "delegate(address)":"25000"+ ?& q7 P" I3 p- v1 |& Y

' \9 b; U3 l: V) R, {2 H    },% [& A& V& @3 V8 l+ g: j5 W/ z

: [: D7 Y/ P; J1 G    internal:{3 |3 l7 S. A- m$ v/ l: m4 \3 H
1 |7 d$ @, }0 z6 G2 r6 l, J6 q' r
    "heavyLifting()":"infinite"
! ?; h% z- z" z4 K, u! i, a& l# l8 s" I6 W; x; ~2 t) X
    }, M2 S9 g7 B8 A0 g

- g; n- W( H( w0 I% O6 H: _6 V    }
& C5 ?6 ]* J5 X  n, ?/ \5 w% b0 ?; N9 H6 ]% k* P
    },
  W+ G$ G& Y, Q( }5 C$ g) y- A- s
% T0 C  |2 w& J    //eWASMrelatedoutputs$ n2 z( E( P% z8 ]! q: L1 X
1 E0 T* k2 Z3 y8 W& F
    ewasm:{/ _5 c. b2 x$ \$ J

: s7 K6 Y- g- _; R  C    //S-expressionsformat
6 }/ y, R% }" E' b9 t5 o/ ^; [! w) c. g+ ~2 @8 ]9 O  r5 R
    wast:"",* @: }1 M4 [0 Q, s6 A5 M
& @* p8 ?1 R' X* `
    //Binaryformat(hexstring)( ?& R4 Z! l3 u8 H7 k; _4 x  h) h
6 o" E  F( t* ]% M2 `; J, k9 T
    wasm:""
6 x. T; r2 j7 V1 O* k$ o
; i- l7 P7 v! A+ |: I$ o9 i. t1 n    }
8 @7 r& S9 P% M8 E, s; t4 T0 Y  Y* d! u
    }
" c: G  S8 V, t
. ~' c1 @! _) x$ i' ?, t  D/ P4 g    }/ I5 ?: o  r, c4 }: G3 |1 ~( t

1 y+ B; U8 j/ ~+ c    }
+ p2 m% x5 ~8 s/ `/ D# t0 e. _8 _2 m; p
    }
; ^' u6 ]( ~1 W. U" S* a! U" x$ r$ @7 D; d
    错误类型说明:" J& n; F# ^, M* }

# ?( M/ N6 `2 n/ {      e: O. C0 Q4 U" L9 D7 {
( g9 E  E5 f& e% t, h9 n$ J
    JSONError:JSON错误,JSON输入不符合要求的格式,例如输入不是JSON对象,不支持语言,等等。
% R2 z& u# S0 x( p8 q$ s& q
7 O6 C" t- Y6 T. W    IOError:IO错误,IO和导入处理错误,如提供的源中的不可解析URL或hash不匹配。
8 W9 R  n& c# V; u8 z% |
' j/ |2 Q- b- N5 ?! L% a: X    ParserError:语法f分析错误,源代码不符合语言规则。/ e2 R0 M3 N( }2 p) K/ \
9 @: s9 w% C# I$ I6 Z% }
    DocstringParsingError:文档解析错误,无法解析注释块中的NATSPEC标记。! D8 h; A; ~: c7 `, ?, s

& ^2 Y# l" M1 T. P, [    SytRealError:语法错误,如continue在for循环之外使用。4 ^& Z, m7 m& y# Y* f, [

2 }* Z: j( n; W: y9 q, J- Q1 F    DeclarationError:声明错误,无效、不可解析或冲突的标识符名称。例如未找到标识符
! T* N5 U2 ]7 ~3 ~4 j* Q# R4 V- ?7 T% Y1 o; a0 |& ~
    TypeError:类型错误,如无效类型转换、无效赋值等。
2 r8 J/ z; u' F6 v3 z, X7 A/ O8 v( m6 \9 l! j1 M8 J: e" Y
    UnimplementedFeatureError:编译器不支持该特性,但希望在将来的版本中得到支持。/ J* k3 K, e1 _

5 [# B8 {8 u( J9 `0 h% D- M/ R6 Q- y    InternalCompilerError:编译器中触发内部错误,这应该作为一个问题来反馈。
' o3 d4 s* c4 L8 F9 f
8 ]7 b/ V' C5 N0 {7 e    Exception:例外,编译过程中未知的故障,这应该作为一个问题反馈。
* _6 D9 t4 @* l( B3 {2 N/ z5 w+ Q: T8 I1 E
    CompilerError:编译错误,编译器堆栈的使用无效,这应该作为一个问题来反馈。" j. {) i! o7 U" y* @1 I
& o3 z; `' h. a" `
    FatalError:致命错误,这应该作为一个问题来反馈。
8 V( E, Y- ]' I% M5 a# W& e9 N+ o
) b% C7 L" x2 M    Warning:警告并没有停止编译,但如果可能的话,应该加以处理。
! }5 e/ w/ u+ J3 D
4 e( `5 Z9 s2 N4 g  j   
- B- `% \& @4 B: f5 }+ w7 K
, v& A0 U( R9 [1 W" n    原文请访问:solc: B+ G; ^" ^' _0 z# R
! x1 n+ R% {  }. @4 i4 ~1 U! q
    如果你希望马上开始学习以太坊DApp开发,推荐访问一个在线教程:
/ M& p. A2 x# C; X/ v' r2 u7 j$ h  o6 j$ h
    以太坊智能合约,主要介绍智能合约与dapp应用开发,适合入门。
* i4 k6 o% Z, a4 {
; M* Q6 c6 J4 M; n. E0 W& {( h    以太坊开发,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

曲水流觞113 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    4