Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文
solc:solidity的编译器
% v- \- T& o, p+ x) n- h' z. Y$ D( ~% b, M8 N) N! i4 C3 d
    solidity编写的以太坊智能合约可通过命令行编译工具solc来进行编译,成为以太坊虚拟机中的代码。solc编译后最终部署到链上形成我们所见到的各种智能合约。
8 i8 k; f3 q6 w: {7 y
2 @! R2 l3 c% }/ @7 ?1 w9 h    作为一个solidity命令行编译工具,我们来看看官网都怎么说solc。1 z9 k3 s: o7 U, o; t7 \  H
7 T  ]+ s- _" s" {9 T
    solc的安装很简单:' V" M& p1 r; V3 o$ l6 }; x

! s" R2 H* D! s) q* `4 m    npminstall-gsolc* A, J" v3 I5 b4 h3 w
( H, H$ e- B/ j
    //或者
8 h" v& n( f+ z& m- {9 C2 k% y; i  Y& n
    npminstall-gsolc-cli
. V" Z* U& W5 K* M) Z
! L4 b. m8 P% H    //或者$ o+ q  y. R2 x- G$ Y8 m3 m7 G' m

- R: D# R" s" k2 r* j0 {2 c    sudoapt-getinstallsolc! K/ [% q; ]5 z; i1 O7 A4 y
) f/ A/ t4 K9 p. ]. w1 \
    安装完成后我们来看,solc--help,solc--help命令显示所有的solc命令选项。编译器可以生成各种输出,比如最终的二进制合约文件、语法树的汇编或者需要预计的要花费的gas等。solc--binsourceFile.sol,可以编译后输出一个名为sourceFile.sol的智能合约文件。如果你想从solc获得更丰富的一些输出变量,你可以使用solc-ooutputDirectory--bin--ast--asmsourceFile.sol。
, u$ G) y/ f6 u, w7 [. x; D% l' U* B" J+ y
    你在部署以太坊智能合约之前可以用solc--optimize--binsourceFile.sol优化一下。默认情况下solc编译器会帮你优化200次。你也可以设置--runs=1,这样就按照最小化的方式进行编译,如果你希望多次交易不太在乎成本,那你可以设置成你想要的次数:)。/ w( l2 @" @% }% B
5 Q6 j4 E: D3 f8 s  [
    命令行编译器会自动读取需要导入的文件,也可以通过使用prefix=path来指定路径,例如:
/ E" n1 R0 }: V! I1 b) E
( P  v6 c* u  j. _    solcgithub.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/=/usr/local/lib/fallbackfile.sol
# e, l# T+ q& V/ b4 p  d5 c5 g$ g
  G& F, @. p" }$ u* y3 J    这样编译器就会从指定目录github.com/ethereum/dapp-bin/下的/usr/local/lib/dapp-bin/目录开始搜索,如果没有找到文件,它将查看/usr/local/lib/fallback。solc将只读取你指定的这两个路径的,因此像import"/etc/passwd";必须要通过/=重新映射才起作用。如果有多个匹配,则选择具有最长公共前缀的进行匹配。
' O* Q8 }, P8 l1 k- j3 n# n
  T+ \/ G4 O6 \# C6 V- h0 g    出于安全上的考虑,编译器限制了它可以访问的一些目录。在命令行中指定的源文件的路径(及其子目录)和命令行指定的路径外其他所有内容都会被拒绝。--allow-paths/sample/path,/another/sample/path来切换。2 E% N: X8 Z% q) Z  }- D/ I( d
% `; i1 Y( B) R; X
    如果智能合约使用了libraries,你会注意到字节码包含了__LibraryName______的子字符串。您可以使用solc作为链接器,这意味着它将在这些点为您插入库地址。
/ T4 j+ f3 {# P! T7 f  F( h4 x- P5 q, A
    可以通过添加库--libraries"Math:0x12345678901234567890Heap:0xabcdef0123456"到您的命令,以提供每个库的地址,或者使用文件中的说明字符串(每行一个库),并使用--librariesfileName运行solc。1 `. l3 e5 E5 C2 E( |' ]- }3 E1 U6 d
- e% o9 B# d. v9 A/ c
    如果用选项--link调用Solc,则所有输入文件都被解释为未链接的二进制文件(HEX编码),在上面给出的__LibraryName____格式中,将其链接到适当地址(如果从stdin读取输入,则将其写入stdout)。在这种情况下,除了库外,所有选项都被忽略(包括-o)。( l4 b2 q* i3 c/ U1 k0 T

: ]5 G4 w# K  u8 Z1 ?    如果用--standard-json调用SOLC,它就将标准的JSON输入(如下所述),并返回JSON输出。0 E$ B7 l; m5 @$ G5 |

7 e* t) i" t( M, Z4 y6 l    #solc编译器输入输出JSON描述# {2 u1 r+ \% C& u3 Z

& U! ]$ U* [( u5 D4 u    这些JSON格式通过编译器API使用,可以通过SOLC获得。内容都是可以修改的,一些对象是可选的(如前所述),其目的是向后兼容。
6 U' \0 V; s# z( O# p6 i
5 m$ j, A. @$ _* ^2 y  x& l    编译器的API需要一个JSON格式的输入,然后以JSON格式输出编译结果。9 d/ J% }, U( I- B, r( `

, ^8 A6 t, a( j$ d* T. F+ ^' V% }5 F    注意不允许注释。下面示例中的注释,是官网为了学习者更好的理解标注的。& F* y7 w7 A& n6 J- @& n: x4 v

0 D. g: ^) [: w" C3 K    输入格式说明:) c6 q% I" ]6 _8 a& T

, N# I% o2 b. G. H    {
, Z; s; i- L* c' Z  v8 V" Z
, m6 d- \7 d4 K2 R3 o4 [6 z    //Required:Sourcecodelanguage,suchas"Solidity","serpent","lll","assembly",etc.
0 p3 M8 X! D& o& U: I
6 V- B5 D7 z- V$ u    language:"Solidity",
: r* \9 J9 w! v% Z1 \8 f( b7 A  x  o, W( M/ K. A+ R
    //Required
8 r+ j/ M5 ]3 J1 L& _  c6 \# C' l: ?2 K! h) S
    sources:
9 T' A( q$ _- O# i. E! L0 n& k9 \$ K! J' q" I, g0 Y
    {- E- }$ Z  k/ _+ c
* s5 X0 ~4 A$ ~, @4 |# ~
    //Thekeysherearethe"global"namesofthesourcefiles,
! k! h4 m- x: P% e; Q0 y5 E/ C* T. P, A- `, m* c- N5 x, x, T' L$ R, F
    //importscanuseotherfilesviaremappings(seebelow).
; o* F0 m; `, N% J* J
: I) S( K8 W" a' l8 y    "myFile.sol":
, V4 ^, U9 [1 S! ]1 u$ R1 {3 q' [( J. |; Q$ F
    {
5 V4 ]2 F4 D* K/ \- P5 D' Q0 _: T0 a+ x9 H
    //Optional:keccak256hashofthesourcefile& u6 f( R% T& o+ ~. M7 s# x
  z- D# i) B; j) R& U
    //ItisusedtoverifytheretrievedcontentifimportedviaURLs.! E4 \0 n& Q& f6 e8 N

# |; p- Z% @+ S& m    "keccak256":"0x123...",4 [" X7 z* r1 B; q

7 U4 ?2 Y; X. A: `    //Required(unless"content"isused,seebelow):URL(s)tothesourcefile.1 L+ c7 c# }& u9 t7 u( _) C) ?
; y- ^2 s6 ~- M+ \
    //URL(s)shouldbeimportedinthisorderandtheresultcheckedagainstthe1 _9 R- @* h7 g, V
4 s( y. L3 j+ i- A
    //keccak256hash(ifavailable).Ifthehashdoesn'tmatchornoneofthe5 h. o6 d$ b8 g% _

6 a; Q. z4 k& S$ K: N. [/ C" }    //URL(s)resultinsuccess,anerrorshouldberaised.6 |" X5 `$ i: J7 M: |% m8 {

) {/ e3 x3 Q* b: {/ x    "urls":7 p' W$ M$ D. f4 A
: s6 Q; t% R, c* k
    [& |  [; ]& R0 R  v4 ~
( O3 f" R# D. n! X: ?1 \- P: w
    "bzzr://56ab...",
. z4 z- ^( K9 G( y
& H  Q, c/ D0 z8 x# K/ }7 X    "ipfs://Qma...",
) G% z6 j) D  Y  i# r/ |
& t- `1 }, f6 m8 \; D    "file:///tmp/path/to/file.sol"+ o( [% V. i$ I1 z5 Y& M+ d- h

3 q1 X/ \  l8 A0 |    ]1 _6 V3 `* ~& e
" ?: v) R' h' G* k) `! ^
    },2 G: f: M1 X, M
: B: N9 C8 ~3 I: K: B
    "mortal":
$ a7 P3 W4 J* I: B$ Y3 O% X. A! K! m/ j, d5 P; H  z& }0 y% J
    {
0 U& q/ q0 j* _+ |- v+ Z; D( B3 M: x: u' d0 t1 h
    //Optional:keccak256hashofthesourcefile7 J# a' h" q! p  w' }) K: B
' X7 y% K/ T/ Y" F1 u
    "keccak256":"0x234...",
, T/ I, R2 T( |4 t/ k
$ K5 v5 r9 R5 k6 k& [6 K- v; M. h    //Required(unless"urls"isused):literalcontentsofthesourcefile
7 c% @, V7 o! V0 X$ k( [$ }; @
! L5 f" A' m3 Y    "content":"contractmortalisowned{functionkill(){if(msg.sender==owner)selfdestruct(owner);}}"; G. r' `9 _+ n/ r& V& `( h3 L, A6 [

5 A, {8 r+ L3 p' O; o0 p5 ?* m+ r    }% M5 W6 u) _- u
. l7 H6 h$ X  j, n
    },$ Y. A) K7 I* |+ y* h& d
$ F- c" J/ O7 i& l
    //Optional3 j& l9 ^1 l" ]: M5 F& d: ?
) u: l' Q/ u  e! [! b
    settings:
0 p1 N! r1 U% U$ G
2 \0 c( f) M9 z$ D4 a# S    {: r0 `1 W* ?8 a" z3 X

% {; a6 [- f2 k4 b  O% c+ ]    //Optional:Sortedlistofremappings
% w. O- _1 q  t. @" l9 h$ K; C, j+ \9 A
    remappings:[":g/dir"],  t5 m: A/ Z1 p. P/ e4 E1 I
$ y: C) i% g5 |/ k- B1 |- a/ h8 l
    //Optional:Optimizersettings
- p+ |& K4 b  ?6 c6 ]& Q  J2 M, N- L5 i. Z1 Q
    optimizer:{
) b1 Z1 r+ T- g1 x- G+ E' k1 Q. v  w
    //disabledbydefault
- l  D! l' u" j% U# W' i; [/ M# ~' d  K7 w% B$ `2 s: N" u' t
    enabled:true,
1 P/ D  F7 \% V" n4 Z* H
/ i  C7 l4 ~5 N4 g. _" I  {    //Optimizeforhowmanytimesyouintendtorunthecode.
1 F1 W# h# a; N! ~
7 \/ T) @' ]' s4 N% k    //Lowervalueswilloptimizemoreforinitialdeploymentcost,highervalueswilloptimizemoreforhigh-frequencyusage.+ i: ]  ~: L% c: A3 |# j2 z
, v- I6 C7 u1 R- i" {% T3 F5 h
    runs:200
8 C8 b- O7 |" y: J5 d' M/ u0 Y7 b+ _, _4 D! N8 @
    },
# t( n6 N4 q9 T" u* `5 S  j  C9 ]$ G! N; R' t- ~5 r
    evmVersion:"byzantium",//VersionoftheEVMtocompilefor.Affectstypecheckingandcodegeneration.Canbehomestead,tangerineWhistle,spuriousDragon,byzantiumorconstantinople  w6 a0 ^+ Q. }1 O- D" R

, @4 d! g& c& k4 X" o, c1 Q3 ]7 r    //Metadatasettings(optional)
- ]- q$ ]5 f! f
3 H: k1 c  e4 M$ {$ m    metadata:{
/ q, Z' j1 _5 e6 Y# v7 u7 D
5 x& J! x1 U6 D: `- |    //UseonlyliteralcontentandnotURLs(falsebydefault)# b& h3 e9 ]4 d

5 c) B$ _0 w( P0 u    useLiteralContent:true0 F* ~' S5 C0 K+ ]  k& N* v$ c

( Q! s1 x/ G9 Q* c: j4 g8 U7 S  z/ |' \    },
) I- J2 _  [4 x" D, [8 D+ R4 O& h2 A6 ^0 L: f1 P
    //Addressesofthelibraries.Ifnotalllibrariesaregivenhere,itcanresultinunlinkedobjectswhoseoutputdataisdifferent.
! M- B2 [7 v+ [0 v+ X
' @+ J# W) C; P4 Y    libraries:{9 b" g% R' ?  l( R1 w) r; }

- {' {3 d/ r$ K' a    //Thetoplevelkeyisthethenameofthesourcefilewherethelibraryisused.) e# `& d- t! p: Z  r* g# I
( S* X0 k6 F8 e9 F; t
    //Ifremappingsareused,thissourcefileshouldmatchtheglobalpathafterremappingswereapplied.* m& `& z% @' B# G( N( k. @4 s4 l

! t3 g1 P5 r$ D: K    //Ifthiskeyisanemptystring,thatreferstoagloballevel.. B* i0 D/ F5 j: m- M# s7 J+ H

+ ?5 t* m1 y5 A) ^2 {, X7 h    "myFile.sol":{" _9 H$ L+ Q0 V6 ^2 T

2 s3 W1 X" [# l- U9 A. P' c6 t! N    "MyLib":"0x123123..."& d0 c, K  H' L0 P4 ]; c; `
4 [# \) B0 j- X: N
    }
' ?; [, ]7 Y' R  m% ^$ T6 s7 o* o+ g5 q( T" k. u' T' ^" J
    }6 R9 G1 n; \; i* Z

3 I; {  W* u) ~    //Thefollowingcanbeusedtoselectdesiredoutputs.
0 I3 t) ^% C/ s- E. Z" B' l& Y, [% U2 v+ Z
    //Ifthisfieldisomitted,thenthecompilerloadsanddoestypechecking,butwillnotgenerateanyoutputsapartfromerrors.+ @% {4 b8 W  J0 h  q0 c$ [, T

) P' _" G9 f1 F1 g) o* t0 v0 D    //Thefirstlevelkeyisthefilenameandthesecondisthecontractname,whereemptycontractnamereferstothefileitself,
: J# h- }1 G3 f4 t. r) ^
- v+ H" ]$ E$ ?( Y6 u" \    //whilethestarreferstoallofthecontracts.
9 t: A# x( B2 o; i5 S) E- b
; Z. L# `6 r5 s9 `    //
) S; R% v- Q6 I- V. }) y
1 L* [2 o* F- D6 b    //Theavailableoutputtypesareasfollows:
1 y8 t; f: I, D. f, {: l
8 G8 D  o1 g0 f. K" M, {5 Z- i, \    //abi-ABI5 C  n0 I  Z+ s, ]; h* A- t: a7 }! C. h
- l% Q7 a" e6 w
    //ast-ASTofallsourcefiles
( O6 m9 P7 `1 f( g! P* g/ V) G* U* p9 n+ k6 O; q: R# A
    //legacyAST-legacyASTofallsourcefiles1 M% q' v+ c; |
/ i9 Y6 _" G& h
    //devdoc-Developerdocumentation(natspec)
/ O, L8 d; h' J. H2 [- T" ~) ~
9 o- j2 w0 v; M  N" r/ _    //userdoc-Userdocumentation(natspec)
! f# [' t5 [4 g3 y! l2 `4 Z- t0 g! w  M0 g* F, N
    //metadata-Metadata
. I% p# x* M9 q7 F( C& l, q/ S
1 L' _' J1 |, j+ M3 ?* e    //ir-Newassemblyformatbeforedesugaring
  V) q0 M  w5 W2 P/ |7 ~0 H- |5 o8 e
    //evm.assembly-Newassemblyformatafterdesugaring* l! c8 q2 |3 {  _4 H7 g3 J

$ [7 B4 s/ `) Y; Y1 p. ?6 N    //evm.legacyAssembly-Old-styleassemblyformatinJSON
- `. N( W: @' l" z. e- ]' c: e0 R/ E- B& H2 B
    //evm.bytecode.object-Bytecodeobject
/ u! e# }9 K% F
/ {. D, w1 }7 z& y. q4 M! f    //evm.bytecode.opcodes-Opcodeslist
! i# u" I/ N  V" Q( y
, |0 q+ n. V' Z0 ?/ R    //evm.bytecode.sourceMap-Sourcemapping(usefulfordebugging)! Y0 q6 h3 h+ J2 J! T4 V+ I3 H2 s
! u/ A7 Z5 S! k- {0 [. |
    //evm.bytecode.linkReferences-Linkreferences(ifunlinkedobject)
) o. w- k  U/ T1 k( O1 j( D) R. l- j* b5 Q
    //evm.deployedBytecode*-Deployedbytecode(hasthesameoptionsasevm.bytecode)  b! G! _; a" @% v) W9 W$ z. {

. X% J- U! I2 ?) L) w    //evm.methodIdentifiers-Thelistoffunctionhashes8 b6 N' B  b5 G% ^9 C
) g1 n8 Z; h' B) t* @  y& G
    //evm.gasEstimates-Functiongasestimates
8 M5 ]8 Q- B3 d, D  U/ B) E+ ?( d2 Q$ T9 q0 j0 B; Q
    //ewasm.wast-eWASMS-expressionsformat(notsupportedatm)' z; F) d8 \8 Q% }
! m2 t+ U5 a7 M' F4 Q3 e
    //ewasm.wasm-eWASMbinaryformat(notsupportedatm)
  _, ?2 X7 m/ j0 ?# s" C7 C
4 `1 e; T7 e8 g% `7 t" \    //3 `/ W" P, K$ O# G. J: {
, p. h7 Q5 `: D3 v. T: W
    //Notethatusingausing`evm`,`evm.bytecode`,`ewasm`,etc.willselectevery
3 f. H, {  S# H- T" Y( q2 b
, ^2 @, G) n7 e. s    //targetpartofthatoutput.Additionally,`*`canbeusedasawildcardtorequesteverything.
+ H/ _- j: v/ ^- f" S6 x4 u( j* W; F! c" @  R
    //
& t7 g1 \/ `4 w
/ F, W% i7 `  a9 N1 e  `% G2 k1 h! m    outputSelection:{
  W7 }  F/ C' O( K; z) f6 j" T4 _4 O3 d
    //Enablethemetadataandbytecodeoutputsofeverysinglecontract.
6 |! P' _+ Z5 t# @; o% }- W( _/ {0 L; A  {( k
    "*":{0 F. S! w8 t" W% @5 U3 K$ d1 g

3 l; D6 l! A: Q; Z    "*":["metadata","evm.bytecode"]0 K! J, p) |: \' M# {6 V1 B

! o, l& y5 [& ~5 G+ j& P7 v" R' F3 W' e    },
8 d: T% m; g2 ^
* p  _$ b  h+ \& O: J' a    //EnabletheabiandopcodesoutputofMyContractdefinedinfiledef.
6 A4 P* E3 Y* m+ \, _) |7 t# E, h& k! l6 d- k5 b
    "def":{9 Y9 T8 l- B2 _6 Y
$ W- p4 W# E5 i1 X
    "MyContract":["abi","evm.bytecode.opcodes"]2 g3 o, k/ _1 y2 h

9 i: R$ |% ~+ D  U" h    },
1 K  i  i5 j1 S8 r& e+ }
# Y" J' x7 S( h! |3 Z4 T    //Enablethesourcemapoutputofeverysinglecontract.
' C' H5 a, v: S5 i
6 f! @0 |: }! n" E# i- N    "*":{& V6 t8 M" @. J
4 [) Y$ g& Q1 O5 g# x
    "*":["evm.bytecode.sourceMap"]
  t5 E( F$ Y. g: S6 d! _
4 f! e( S3 a0 s0 J' H2 o! `/ S    },5 n' Q8 ^) {. @

! Q3 {  O) }& ^/ @: y7 a4 r7 [6 Z5 a    //EnablethelegacyASToutputofeverysinglefile.) J, G% ~, V. K) g$ U
1 T4 R# d' G* N# L4 Y" b
    "*":{, K* e5 o$ @( ^9 i* N3 K

1 c( e' E7 T5 D! X- ~  M# W& \) @  p    "":["legacyAST"]: Z  J$ ?( O# \" H$ z

& d: q6 w# ^" I+ s  R& R    }' ~  K1 x& t7 G

) s$ e) K0 Y5 v4 o, M( q* _  @. B    }
' w4 E$ Q2 G9 s
) @* C' ?1 |7 O. Y    }  S( e* J* }0 n! s8 }; X" a
7 b, @2 x. r- Y7 w2 S& [
    }
" U8 C: z2 s, y( z; j0 N' G& D: z' o  |, N) O8 E1 t" p9 B
    输出格式说明/ m. k' M# M" W0 [

' D- J' E( G/ ]4 V; @8 {! D    {
8 f5 k: c9 I' H6 g8 s. Z
; L/ O, v# [8 S6 G7 ^/ l4 O    //Optional:notpresentifnoerrors/warningswereencountered
$ H$ o. X- l, G' w0 P. K8 C4 k8 \# Z1 }; @
    errors:[( S% f! ^- u) |
8 R3 M1 j) Z( |
    {# @% n& `  _3 Z- H  r' N# m

% q( z2 M  G$ }    //Optional:Locationwithinthesourcefile.
0 Z  r3 Y: c, V0 W! f" P, x
/ A+ @* u2 ]; m* b" H% M    sourceLocation:{# _: F4 \  e; ~3 C

. K" S1 B! P2 x6 F- _* l    file:"sourceFile.sol",
8 d; @9 |9 K! @/ @1 P% D
1 Q0 ]3 U( k4 n" Y1 q    start:0,! o" T# I/ C6 O2 u0 j. y8 q( J+ d

* R! X7 F0 [; F% y    end:100
1 z! ?. v- n; X5 u8 m% n3 W; c9 K- t1 `8 ]% o
    ],
1 t/ |$ F/ D  E7 b7 v4 `& Z' m- m5 c  `' E; o4 u
    //Mandatory:Errortype,suchas"TypeError","InternalCompilerError","Exception",etc.
! n& U1 W1 p) D! Q/ c! g$ ]2 L# K2 O5 R. B! m* e
    //Seebelowforcompletelistoftypes.
/ y: K# ~* f2 h  s) R6 {3 D, b
    type:"TypeError",
2 o( U- }6 v8 A, n. [) K
9 s: O8 F: h+ }, O1 K; q0 E" K    //Mandatory:Componentwheretheerrororiginated,suchas"general","ewasm",etc.
1 x2 E& h6 _& d, l# x! }: ^# ^! B( \6 P* h
    component:"general",2 {( M# s1 C  G2 B
0 A$ |. i4 q5 W) o4 m2 q
    //Mandatory("error"or"warning")9 G$ N" H! `9 I  ]; Z: X
5 u# A. U# P8 g: g# G
    severity:"error",& ^+ a/ p: P4 f2 Z' x' q7 m

  g6 p6 E& {; j% M* o% ]% C    //Mandatory
: i5 b4 a8 l3 M: i
; l8 O9 _: }3 B    message:"Invalidkeyword"
* E9 y# U+ C! o8 r+ @- \0 I! h* ^1 A& q
    //Optional:themessageformattedwithsourcelocation
* E: Q6 v9 Y! Q2 E7 x) @4 X0 t" w; U. s3 c  H$ S3 V$ R' }. E/ ]3 Z
    formattedMessage:"sourceFile.sol:100:Invalidkeyword"
' |4 [6 U3 \5 O6 ?
/ g# h# b3 b/ U+ }    }2 Z# q1 g* _* o! p; \
2 S. @& X6 g# z# N# C
    ],( u7 s$ |, H2 H' j; v! b0 r: \/ B
4 }* n$ z( v( D! k6 a" F
    //Thiscontainsthefile-leveloutputs.Incanbelimited/filteredbytheoutputSelectionsettings.! T* _6 c3 ?9 c5 [. D
& n6 j5 ~9 ]/ }
    sources:{$ z) @3 ^5 a: `0 m  D) [8 F1 p

& Y0 |, V( x, o2 z7 C  S4 K3 n    "sourceFile.sol":{
  `; l6 x) g5 F! s0 i5 L# b  Y; N* N
; j) u, c0 H1 \) w2 ]0 Q    //Identifier(usedinsourcemaps)
* Q; o! ~! X  k& w5 R& W  L; B3 r4 W! C
    id:1,
  U( B4 X0 G7 Z% K+ P- L+ |9 c  A/ r# J
    //TheASTobject/ B1 Q6 P. G& q8 {8 _
* X) v8 ?. f0 _1 |$ M
    ast:{},
! Q) X* [! K2 {6 s  v2 a! ?
& ?# l- W- _1 W  X* U* }    //ThelegacyASTobject
5 ^. I9 ^! Z5 z% }# a9 A8 J  a( v4 ^6 B! v
    legacyAST:{}  d8 D9 A$ e' ?7 r4 ?
0 t+ J5 N# _5 V: {& f1 A
    }
# ?1 {* j) O' L; A6 v  P4 N  h, C) I+ _) @: [
    },
; E- Q( y$ d  ]5 |* @
: q9 W8 O2 ^6 n    //Thiscontainsthecontract-leveloutputs.Itcanbelimited/filteredbytheoutputSelectionsettings.& a' _) l* e0 L1 v
) ^; V; F6 `  @0 \6 n4 t4 r
    contracts:{! [4 ~9 A4 g+ w- h4 ?
: e0 d- n8 `; {! {0 r5 B. ^6 w
    "sourceFile.sol":{
; G/ T8 a6 U, z- k# H; J  n# t4 Z/ N1 _% B6 v/ |1 ]: j7 V* m
    //Ifthelanguageusedhasnocontractnames,thisfieldshouldequaltoanemptystring.
* z* _/ q$ }+ ~0 a9 Q
2 b! J& J* \8 T% P0 b9 w6 J0 T0 G% W    "ContractName":{" ]1 K. z  e/ g8 E3 S) L9 G: ~
/ p3 |, P  t  k, N6 b
    //TheEthereumContractABI.Ifempty,itisrepresentedasanemptyarray.
7 R* M+ R& p" a7 V! o+ _7 T% @* ]: h+ f' e  A
    //Seehttps://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI* e& T6 u1 ^( Q0 c' N

' [& W+ Y. i# n9 e8 I+ J$ Z" z0 J' A    abi:[],: P$ h+ T6 H9 l* f7 _
! f1 B* g0 R  y, t( W
    //SeetheMetadataOutputdocumentation(serialisedJSONstring): j7 s# D0 Z2 p) N* F, ?
) J. ~9 N5 z3 z" Q$ w- e
    metadata:"{...}",$ B( z/ {2 A, c+ w

  s+ G& N& ~' C5 `; q* s7 n8 |7 J    //Userdocumentation(natspec); m1 U" Z' l6 O! Z9 e# D3 K

4 b" `2 R) p; b# J  W! l    userdoc:{},4 x  k% ~1 ~% ~& u0 {2 z2 v
6 a# u" {. c( ~, b; z$ X
    //Developerdocumentation(natspec)4 [, @- O, ~0 ?5 O2 G, p

3 N* M/ e0 M( `; O* V6 ~/ M7 g  p    devdoc:{},
0 n+ E& M0 P# ^& `5 b
* `: @  r+ R9 R    //Intermediaterepresentation(string)+ n! N- f4 |: k2 t1 I

1 _' Q7 A$ z2 C- w( B    ir:"",
/ H* a! ?  h9 `4 I5 u1 ^% i6 I$ y3 w1 g
    //EVM-relatedoutputs3 E8 |) N2 |. z) E# P3 [

8 W5 X8 ^* {/ W    evm:{
1 f3 z2 i* p2 ~; r& c: {, _6 }
: P' \$ y- g% k1 P    //Assembly(string)7 y" v" @, M" V/ _7 D8 g0 B

0 L/ }: D$ I3 N8 G' c. W    assembly:"",
, b. ^+ p+ e, |, n& d1 {3 p3 X  I3 T
    //Old-styleassembly(object)
7 b/ k. y  d2 e# l8 e6 \  ?+ U' {% Q5 f8 U; t) C4 A
    legacyAssembly:{},1 j+ P9 V! g" X
4 T) n' d4 f1 j) h4 D
    //Bytecodeandrelateddetails.3 l2 i- H' R9 A+ Q) d7 C

4 S7 _, Z" h: g% v$ u8 ^    bytecode:{
4 C! W: s" R; V$ O" E/ j
9 L2 x. ]- r# w# g+ m% k    //Thebytecodeasahexstring.. n' d# O* e+ {9 l* W; S
  X6 D9 u* j" E  }
    object:"00fe",6 n7 J- _2 ?# g# b5 \
0 K) T, W! S% o0 e$ k
    //Opcodeslist(string)
' Y, a5 `$ M4 U  y. O* b% w% x( Y6 Y, l) @3 C: c' q: x: {2 a5 b: L
    opcodes:"",
! ~8 S1 R/ ]& o$ _# ~9 a( J4 I6 V8 \
    //Thesourcemappingasastring.Seethesourcemappingdefinition.0 ]- y/ U' x( t) U6 C
8 E6 Y' b1 p: [" d  a0 d* S
    sourceMap:"",
9 ~7 p+ B# {8 d8 P
4 Z! n( W3 s  C! c* S# j/ b- P    //Ifgiven,thisisanunlinkedobject.
: ^( O4 w& P# K- i' ^
4 b# j$ A' t( ^8 G4 W$ ]    linkReferences:{, I, B: R7 S; w( K& f) h, @7 h
1 ^. q- H- u3 ~$ A: B& v
    "libraryFile.sol":{
, R8 O1 i4 M6 B8 p3 Q2 q8 s( |
    //Byteoffsetsintothebytecode.Linkingreplacesthe20byteslocatedthere.
* I% b+ J, B( d+ q! |  f8 a) `" a- _& H/ Q, @/ }( B
    "Library1":[. f; r) \) o9 H6 h4 e, ^
& {' Z( z1 p  ~; ^  i* |, c! k
    {start:0,length:20},
& }* c7 q9 L/ O/ i, O8 |! M6 M9 x: n1 E7 j' J8 e
    {start:200,length:20}- j& m# N8 I$ F
" s$ z5 i6 u9 d/ V+ L+ g+ K
    ]
7 n& n8 c0 F  m2 x& h7 b, [+ z9 A0 d  u% s, L& V
    }0 \7 n- d  @" h! L, b5 C
+ d" l8 m# i! g5 X2 ?! q
    }: |) b5 s' v- l* k
, Q8 u' G- T( @# l
    },- o3 S$ ]0 i% @; a
) L+ v2 D( S7 H# ]2 x* C$ ?! I
    //Thesamelayoutasabove.
' _6 x' G: u0 Y, |
5 f0 `$ q* P' q+ w    deployedBytecode:{},
; S; g% }  ^4 O* m( ^8 h
2 ?2 D9 \! S$ w! W    //Thelistoffunctionhashes
, T. S) b$ \4 b2 s' L* E
. p4 t4 q9 H# y1 T) E    methodIdentifiers:{
3 j. N& s6 J- z/ s) f9 ~3 L
% U+ Z/ N# @2 B# V* F    "delegate(address)":"5c19a95c"- ?% j- o4 n8 y

0 `, L& H4 Y; z: A) t2 P8 }& q    },& |! u" C- \# j& ]& n2 s
. c8 G# w: H6 M) r
    //Functiongasestimates3 f, E! E* a& k: O
! Q: f5 |% V) X& P$ z" r& N
    gasEstimates:{1 y' l5 d" K; v  ]0 B
; @7 k) N; c+ \; T( L6 S
    creation:{* `# ~& \6 l' C
# Y: ]; B. P' n- d
    codeDepositCost:"420000",
  U4 M$ s# I/ k4 e2 d7 z3 ?
* c- L" ~+ |7 Z    executionCost:"infinite",5 m# m; X3 X; B$ G" e
" z6 u$ i- F- B5 ~9 q" z
    totalCost:"infinite"
; h. _! r( [( V: B4 _3 a) k" [7 C! |! J  R  r
    },: o/ ~+ _+ j3 s+ n& {

' D) l3 B3 {7 R1 i9 U7 S  [    external:{1 m, F- o. s! S, _

) h2 m2 S! v: K" V0 A    "delegate(address)":"25000"! F' K6 s) X  w; E# P$ q) d! r
/ J. p) V1 R2 a! C0 f  x" N$ s
    },5 Z9 U  _$ ^/ d$ H0 M: h2 Y/ ]; R: T

5 t4 X4 o( J$ d; \7 z    internal:{
# q- L6 u- E8 M7 }. j" @
3 L  D/ |: L& D" W7 V& j    "heavyLifting()":"infinite"
4 t/ Q% m3 [/ z7 n! w  V" s0 g3 f; G: Q) n  w6 [& |
    }
7 C) z( n, O4 X4 n! l' n* q3 x
0 r8 ?5 n4 x$ {" l8 W    }- S( W" L2 H% r8 P0 p: }
7 ]7 ?5 N; ?% m  B1 B4 K
    },
; v% T: l, d5 b) a8 ]# b. N9 z/ n3 j$ W1 R
    //eWASMrelatedoutputs
0 F( ^# Z) u$ k# |* [9 J
5 ]( [  `1 S; t% `    ewasm:{
; {1 l9 ^) H, U, N9 d3 W3 E, u4 f5 O: O2 I
    //S-expressionsformat
* D3 v1 Z( h# e4 z2 g/ z9 E
5 G$ y) C" o. U. T7 S6 N. @    wast:"",
% E5 x& K# U2 t3 E  ?
- Q; U1 F1 ]3 L3 }+ b# F$ B    //Binaryformat(hexstring)
& b* V; i. q4 Z8 U5 l9 o- s# G- J* D+ O+ T9 L  S
    wasm:""5 g# ^& Q* Q3 z+ a) Y9 k, r
, V' R" C+ w, g. o! S: f2 n
    }. w9 O9 G, M9 L* P
9 \; k, p8 e6 b0 i) Q" V
    }
3 ~- k! Q3 z+ v5 V; G% f
1 a! B! A: J7 t3 _. P- t( Y; _    }, z& X" C" w! Z# s* b
5 @' a9 S$ \6 I& Q! a
    }
" D, I2 P+ e4 H# A% g6 U
' P  X- B9 h' z2 y* i- {5 v3 t0 c    }
7 z, _1 z2 Z; v" ]* u# z$ |, p' F% i6 R3 f
    错误类型说明:( m) \! b3 L9 E4 v8 s3 D  X

% m6 S. [+ w. C& z& I! |   
6 C/ a4 g; }! l5 s. i- \8 e" h2 t' F9 w
    JSONError:JSON错误,JSON输入不符合要求的格式,例如输入不是JSON对象,不支持语言,等等。
0 Z0 J) r0 H( Y) S* f8 H
; t' p6 J6 u& [" \! Z    IOError:IO错误,IO和导入处理错误,如提供的源中的不可解析URL或hash不匹配。! m# X' {6 u- M( S) _! m

, e* ~! z% N3 Z) ]    ParserError:语法f分析错误,源代码不符合语言规则。
# b: b" a) \  K7 c/ S0 @4 a& ?+ |+ O; Z% z& \+ F
    DocstringParsingError:文档解析错误,无法解析注释块中的NATSPEC标记。8 f/ G' l* e) Y0 B: p# W

# F+ `* T* S/ L- B) B    SytRealError:语法错误,如continue在for循环之外使用。" c" l" k9 `2 r( t5 x5 d% _3 S! \$ Q
- d' h6 l2 {) F' l
    DeclarationError:声明错误,无效、不可解析或冲突的标识符名称。例如未找到标识符; R9 w% F4 s" s  @

9 p2 o6 `  p# B    TypeError:类型错误,如无效类型转换、无效赋值等。
. }" E8 N6 C  S/ Y+ E6 e' h- \' j' U1 H! ]% z9 l
    UnimplementedFeatureError:编译器不支持该特性,但希望在将来的版本中得到支持。$ Z; ?* Z! s4 s6 G3 F+ u
% B! K  s% q- g5 x7 E
    InternalCompilerError:编译器中触发内部错误,这应该作为一个问题来反馈。, l1 b9 @: T& n' i1 r' R; H5 r

, y1 {6 E: R" S6 g( H    Exception:例外,编译过程中未知的故障,这应该作为一个问题反馈。
' U& c" E* S# z; D, V; p: t9 B7 j( Q% I
    CompilerError:编译错误,编译器堆栈的使用无效,这应该作为一个问题来反馈。! Q) o4 K( L7 V; M% m

' ]  g" B5 `* i* u    FatalError:致命错误,这应该作为一个问题来反馈。% l/ p2 y3 H" B$ Q* ]

- C  R% u* S/ C    Warning:警告并没有停止编译,但如果可能的话,应该加以处理。; y1 E& U1 z+ a4 T6 {3 O; i. X+ f
1 y* j" U2 s& F* _
    , d3 U6 n  g% s2 `( l! l: I

" @9 Y& Y2 X8 ]4 n9 b0 F    原文请访问:solc; [2 k8 h5 j4 V1 g$ G

% h& F8 k6 v) D    如果你希望马上开始学习以太坊DApp开发,推荐访问一个在线教程:
( G' e: o- s, a2 u, R( V% J
. U  Y1 j# x6 z8 z' N  I    以太坊智能合约,主要介绍智能合约与dapp应用开发,适合入门。4 J4 R/ N2 I3 S- T. {5 y" t; {' W

5 |+ E/ W. n' d+ e" i6 N: H0 s    以太坊开发,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

曲水流觞113 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    4