Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文
solc:solidity的编译器
# o' d; g3 Z: z. A( Y! |
* M4 H0 v8 Q: K3 J# \. f- I+ Q    solidity编写的以太坊智能合约可通过命令行编译工具solc来进行编译,成为以太坊虚拟机中的代码。solc编译后最终部署到链上形成我们所见到的各种智能合约。
* U4 v% N6 b+ m- u3 h' |/ E3 W3 h
    作为一个solidity命令行编译工具,我们来看看官网都怎么说solc。
$ ?* y  q; S7 N, V* N! w+ N8 T1 b. ]2 }. X6 ~! C& A8 u: K
    solc的安装很简单:
# d& w/ T/ m! E- [# E# ^
+ C- P# I# Q6 O2 j    npminstall-gsolc- ]/ k% N) |$ D

& y# u1 K* p. a* \4 a# U. b* h    //或者& l3 A( C) W. L) b: V

0 N1 o8 N/ ?1 b3 t) V    npminstall-gsolc-cli
% p- I# a8 L% R% s1 f% X& }7 y9 _# p2 h8 E; C0 c
    //或者
( G  [- p1 k9 p) E  W
5 r- i* F, E# W. k! U( C1 x    sudoapt-getinstallsolc
9 n% P! d" I0 N/ X$ e* U$ O: `' V
    安装完成后我们来看,solc--help,solc--help命令显示所有的solc命令选项。编译器可以生成各种输出,比如最终的二进制合约文件、语法树的汇编或者需要预计的要花费的gas等。solc--binsourceFile.sol,可以编译后输出一个名为sourceFile.sol的智能合约文件。如果你想从solc获得更丰富的一些输出变量,你可以使用solc-ooutputDirectory--bin--ast--asmsourceFile.sol。- j- u& V7 Z, M
: }8 u3 H2 w1 ]  [( P1 {+ v
    你在部署以太坊智能合约之前可以用solc--optimize--binsourceFile.sol优化一下。默认情况下solc编译器会帮你优化200次。你也可以设置--runs=1,这样就按照最小化的方式进行编译,如果你希望多次交易不太在乎成本,那你可以设置成你想要的次数:)。' P8 o7 c2 m% x: ^2 P" y

  G6 x5 m7 X; i# p    命令行编译器会自动读取需要导入的文件,也可以通过使用prefix=path来指定路径,例如:3 \- U! m8 o8 L5 ^" k) U

- L; t* g8 L# E% N. T, F: T    solcgithub.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/=/usr/local/lib/fallbackfile.sol( z. M; b7 \" p
  j+ t- k% W' Z) r) D) f
    这样编译器就会从指定目录github.com/ethereum/dapp-bin/下的/usr/local/lib/dapp-bin/目录开始搜索,如果没有找到文件,它将查看/usr/local/lib/fallback。solc将只读取你指定的这两个路径的,因此像import"/etc/passwd";必须要通过/=重新映射才起作用。如果有多个匹配,则选择具有最长公共前缀的进行匹配。6 b. K8 P0 a$ E; i
/ i1 ]: t+ G' B# \, C
    出于安全上的考虑,编译器限制了它可以访问的一些目录。在命令行中指定的源文件的路径(及其子目录)和命令行指定的路径外其他所有内容都会被拒绝。--allow-paths/sample/path,/another/sample/path来切换。
1 Z6 x& e0 h0 [3 N
3 a# p: Q; Z$ v* ?. z6 w4 H    如果智能合约使用了libraries,你会注意到字节码包含了__LibraryName______的子字符串。您可以使用solc作为链接器,这意味着它将在这些点为您插入库地址。
6 k' C3 F4 k5 d6 ~" p2 o# e9 \9 i9 C6 ?2 l4 y
    可以通过添加库--libraries"Math:0x12345678901234567890Heap:0xabcdef0123456"到您的命令,以提供每个库的地址,或者使用文件中的说明字符串(每行一个库),并使用--librariesfileName运行solc。
$ `$ X, ^8 F- m& m; [2 @$ j- D' U6 R* x( d; {* B
    如果用选项--link调用Solc,则所有输入文件都被解释为未链接的二进制文件(HEX编码),在上面给出的__LibraryName____格式中,将其链接到适当地址(如果从stdin读取输入,则将其写入stdout)。在这种情况下,除了库外,所有选项都被忽略(包括-o)。
' H$ H' j  s4 s' ?& u' U) U4 F8 R$ {, }9 Y
    如果用--standard-json调用SOLC,它就将标准的JSON输入(如下所述),并返回JSON输出。
8 k" c/ @: p- e" ~7 P% x
  U  S8 _9 H+ s    #solc编译器输入输出JSON描述
, s7 [# W2 T2 @% p) s& v( _" s$ p  Q% ~: H: @
    这些JSON格式通过编译器API使用,可以通过SOLC获得。内容都是可以修改的,一些对象是可选的(如前所述),其目的是向后兼容。$ q8 m# f+ D) _

9 s1 w9 j% C2 I    编译器的API需要一个JSON格式的输入,然后以JSON格式输出编译结果。- Z* F' I* @$ u5 j* L

5 }. F4 P: P1 x8 Y    注意不允许注释。下面示例中的注释,是官网为了学习者更好的理解标注的。* ]1 q  B4 Z* ]1 I

* C# m* ^: y/ K3 B) m+ z    输入格式说明:
1 y0 b" z6 {* H; c
' G! E! y0 g& E  O    {
# f$ w* k, q/ P  r2 U3 }8 e5 Y& Z$ }8 q/ Z# y: j  x( R' p
    //Required:Sourcecodelanguage,suchas"Solidity","serpent","lll","assembly",etc.2 c5 [1 E" Z( r( n) C8 u7 u
2 b, u/ a2 P. G9 T7 h. D
    language:"Solidity",* |. C6 ?$ f2 ^* d; n$ m

2 P: C$ n. c! C0 K! w: @; p2 K    //Required: r+ j* h/ t2 w& J/ L* Y' S
  d' q1 ]* L/ v3 i! [1 w+ o) _& f
    sources:
3 ~4 l# m. Q7 z+ F/ s
" s2 w, ?1 q. p# X- m    {
  a) d: S' s' I! X, F2 V% y0 `2 M! `' W0 R% g& d& P
    //Thekeysherearethe"global"namesofthesourcefiles,
6 }4 E" X7 X1 a5 m: T, [0 ?* u- K7 b& n" _# X/ e7 a0 d) M2 i
    //importscanuseotherfilesviaremappings(seebelow).6 ?& F7 ?4 b) X% G3 f

* x/ V! N6 j/ t% b    "myFile.sol":" h1 v: p( C; ]& P. E

1 G& \& P# C7 S2 F6 B    {
* x* x; F9 ^: S4 M) g1 Q8 Z. N8 [
' J) R( a% ^5 d  }    //Optional:keccak256hashofthesourcefile- L& c3 A$ y# r+ t7 \2 h1 {, I: ~

: {7 n( y8 w  U, g# r    //ItisusedtoverifytheretrievedcontentifimportedviaURLs.6 y; j  Z& R5 t
% G3 J4 n6 h; t
    "keccak256":"0x123...",+ A& {2 u4 \4 ]& V

5 W$ k, }; q6 I/ S! y- C    //Required(unless"content"isused,seebelow):URL(s)tothesourcefile.
# z3 U! n' C1 j
! H9 O; R- A- m3 M; E    //URL(s)shouldbeimportedinthisorderandtheresultcheckedagainstthe
$ L( ?' Q8 }! o
. e( O8 B+ I, l1 D    //keccak256hash(ifavailable).Ifthehashdoesn'tmatchornoneofthe
# B; N7 r0 Q0 t1 {
- e0 i4 o- ~0 t% a2 Q( _    //URL(s)resultinsuccess,anerrorshouldberaised.
8 _, C/ u$ {1 P+ S( M4 s
0 }5 P6 W/ V2 J$ N    "urls":
- h) x: A. O) m+ m/ X& s, t2 b% C; A9 E7 L! C
    [1 U- f9 i4 ?' n7 x
1 {  T( T0 X5 m# L2 ~
    "bzzr://56ab...",
6 _. R3 w) j7 _9 X8 I) l# n
" w1 [# L! c7 y* p6 N! ^    "ipfs://Qma...",
4 w  n2 G& ?1 D( S5 Y
+ c5 d$ r( F& x: S    "file:///tmp/path/to/file.sol"- V) q  L8 z; h4 ~% ~
) J# B+ O/ b9 O( H9 d
    ]6 ~' a1 l" A4 ~' @* e" }3 ?

& a: K4 w1 ~$ @0 w9 g    },
+ t; [4 f' R% a
- `8 ~4 o: y+ a4 W! @/ o    "mortal":
2 ~& p5 X3 j$ _! `: X" h* \
/ M- Y/ E2 ], y7 O    {- G' j3 T4 I" n. S7 R- ?
; t4 b% A, s7 t. H
    //Optional:keccak256hashofthesourcefile
0 M9 R+ d; l& y7 N8 M' P4 N+ ~3 s: N
+ b* u( c0 n2 @) W    "keccak256":"0x234...",
% c7 _" S7 E- @' ~8 K$ Y4 q! Q! R! a  J0 W8 f5 N: G  v
    //Required(unless"urls"isused):literalcontentsofthesourcefile/ v& m  u- s+ f

  X' w) I$ w) C, ^2 n7 T4 t    "content":"contractmortalisowned{functionkill(){if(msg.sender==owner)selfdestruct(owner);}}". e7 g2 }8 o) ^  \! u1 N

: E/ P' p5 n6 Z1 [: ], V    }
/ g! `- i) V' b/ ]0 A6 [! m. ]
/ ?7 w9 H* A% P. P4 s1 Y9 k; k    },: Q5 i1 \$ {, H# l5 ?
* R& y9 m; N7 m
    //Optional
  j, ^" d$ ~2 L: V7 E
7 i+ `) U4 g9 _0 A# x1 B7 Q    settings:
/ s6 y1 a6 c" I6 ~: }+ f2 I3 p* G/ L  m6 E
    {
" v; z. N9 e  u* Y- s5 L9 W( ?/ b4 \& t( v- E( C- c# R6 L8 b
    //Optional:Sortedlistofremappings
  Z- ]/ o8 h( _# h5 ^, K: Z$ T7 L* J- @- \( m0 u
    remappings:[":g/dir"],
3 O" g1 x, t, D) D8 }0 `  Q$ f' v5 }0 s- m3 d  W9 |8 D, |
    //Optional:Optimizersettings4 a3 q7 N- F4 Q- L

( r7 w5 ^' T- I- i    optimizer:{1 F2 U9 a1 o% L9 y4 n. z
0 Y7 _& I% c  n% e3 L
    //disabledbydefault
5 p% q. g& I; o! t$ [& [( A  V4 E  {6 U+ L
    enabled:true,- k. ~- y& U; q' h

9 D  t  W$ r( k5 S  Z2 r3 i    //Optimizeforhowmanytimesyouintendtorunthecode.' v& F5 Z" R, j0 ?, x8 _. h1 ]" o0 |
* K% p3 @1 A! H
    //Lowervalueswilloptimizemoreforinitialdeploymentcost,highervalueswilloptimizemoreforhigh-frequencyusage.
" u& A% [, Q+ d& `2 F  I/ T( B# R; r1 I( V& ^# }2 U
    runs:200' ?, a  g, m2 m- z, w, M6 {
  F- s% o* c+ A8 H1 f
    },
+ g+ o3 Q& V5 m2 }# \; t5 r0 y$ D, I( N6 b- O3 F
    evmVersion:"byzantium",//VersionoftheEVMtocompilefor.Affectstypecheckingandcodegeneration.Canbehomestead,tangerineWhistle,spuriousDragon,byzantiumorconstantinople# r5 @1 T* v8 M0 }3 a, }
2 r( K3 q- |7 d/ \. h# N/ I- n
    //Metadatasettings(optional)9 X0 a& U  Z  ^
3 b3 m9 U! I% ]. z( u+ n* J
    metadata:{- E2 A) Q  d+ z, N
( {( p% s3 w0 H; B& E# D# Y% _2 c- p
    //UseonlyliteralcontentandnotURLs(falsebydefault)" b; ?$ n+ L" s1 z: y

3 O6 W7 d" V' D2 ~    useLiteralContent:true0 M* z5 N& O: W3 E- k9 o+ z8 e! e4 Q

' u+ l. m6 Z# {* [1 @    },
) `# ]  C0 G) c' W# R/ F( e5 d$ ^7 R9 J
    //Addressesofthelibraries.Ifnotalllibrariesaregivenhere,itcanresultinunlinkedobjectswhoseoutputdataisdifferent.4 f! I) U9 T5 O. T. v, M4 J; U
6 l( |1 j; a8 L1 u1 P
    libraries:{; o3 B5 Y9 c& I: {. r
! b, V* q: I3 X* U7 k1 A" h
    //Thetoplevelkeyisthethenameofthesourcefilewherethelibraryisused.& J% D8 V( @6 Q: Y, ~" O! A7 z$ C
8 A6 ^6 |2 L# N9 s
    //Ifremappingsareused,thissourcefileshouldmatchtheglobalpathafterremappingswereapplied.* |& B& P9 }, P) n; s! T
; _- D0 o9 S1 K/ H
    //Ifthiskeyisanemptystring,thatreferstoagloballevel.0 m. B, ]6 ~" i, T- y

5 ~8 z! p. p" O$ I    "myFile.sol":{
8 l5 s. x& {7 d7 J" Z* E; @% S
- U9 P( Y# M, @! }  T  G    "MyLib":"0x123123..."( O$ S, }& W; \" X3 p! o/ F5 h; t
3 x: ^1 p+ O7 n! B
    }4 Q/ k7 A" T$ O# e1 g# X+ i
3 i3 B2 a- F5 ^. S
    }1 z' r7 T6 X6 j( g" ]4 V. W
* Y; _' l) t, u+ z
    //Thefollowingcanbeusedtoselectdesiredoutputs.7 S; c: M( d5 Z4 G# K" u8 Y

. j. V) B1 C* T& f, x7 ?    //Ifthisfieldisomitted,thenthecompilerloadsanddoestypechecking,butwillnotgenerateanyoutputsapartfromerrors.
; A/ O. y" r! N) N3 S7 p# `! b* I, {0 a- {3 l+ }
    //Thefirstlevelkeyisthefilenameandthesecondisthecontractname,whereemptycontractnamereferstothefileitself,8 i/ g5 X: @0 m3 N3 n; y, S9 K
% l5 L4 F2 \, ]! m
    //whilethestarreferstoallofthecontracts.
  N4 i! E, N2 R9 [# `/ G
' d) P5 k" \0 P    //
- s3 s: e( m" H; K
" i, d- O, A2 p4 }    //Theavailableoutputtypesareasfollows:% X8 Y, y2 S$ }9 X5 z  X
3 T, Y5 l+ c* }
    //abi-ABI
+ A0 _2 \3 R2 N) @8 ^8 g8 x( p
- H4 a8 x1 b& p( V3 R9 S) h. a1 T* g    //ast-ASTofallsourcefiles
2 k7 ]9 |0 R# @& V
( T9 ?( A- k" O& B    //legacyAST-legacyASTofallsourcefiles
. l2 |9 J' g0 x  u  f  K: b0 b2 y! s# H
    //devdoc-Developerdocumentation(natspec)% i+ b+ o" b" t! \4 \8 ?

+ b1 Q3 `: l' r, E0 W% J, h    //userdoc-Userdocumentation(natspec)
$ N# x( g2 V. n8 W4 L2 L
7 ~9 q6 B) X1 ^5 g5 g    //metadata-Metadata/ M' k2 ~. b, P9 V
, ~* f. E4 i( H! n
    //ir-Newassemblyformatbeforedesugaring7 t2 V% G+ w1 O+ h1 i- z2 ~) m

. t' g0 e+ R3 t( L" h0 K* q3 k8 D/ o, O+ B    //evm.assembly-Newassemblyformatafterdesugaring0 S, @. L; k$ F. ^8 c
4 [% r7 K2 k% m! ?8 }' e: @/ X
    //evm.legacyAssembly-Old-styleassemblyformatinJSON
" ^$ f2 r3 Q! O& _8 l& g3 V/ I% _; j- G6 \5 U9 G- z
    //evm.bytecode.object-Bytecodeobject4 S' L/ B. d' A- @" h

: d# R* b6 w) k* W6 U, L    //evm.bytecode.opcodes-Opcodeslist
( i3 x# e. i- W3 P& S8 j! I# T2 o8 W0 u& X1 N! v
    //evm.bytecode.sourceMap-Sourcemapping(usefulfordebugging)
. K$ u4 q/ C8 H, a
# R) l. D, [$ w9 v& ~9 ^+ ]    //evm.bytecode.linkReferences-Linkreferences(ifunlinkedobject)
1 _% }% k9 I, Q
- [+ L6 V( z/ H    //evm.deployedBytecode*-Deployedbytecode(hasthesameoptionsasevm.bytecode)$ R& L7 C7 @! C) R1 u

- O4 f7 ~8 G! J" z, M    //evm.methodIdentifiers-Thelistoffunctionhashes
9 l( X! `* y: P& H& y
& G7 [1 q- H' k. n    //evm.gasEstimates-Functiongasestimates
" m7 Y$ E) k+ \# `3 e( h* \$ ]
3 O& q/ ~2 N( c* e    //ewasm.wast-eWASMS-expressionsformat(notsupportedatm)$ p2 i( j: p5 W' H( _' L

* v: e* ~  Z9 k2 V, F    //ewasm.wasm-eWASMbinaryformat(notsupportedatm)
1 z* Q; f; n" A( w6 t* q
% ~2 a  c; E& N# v4 {1 @    //9 a' V  e  T; J& p
; y; M% C+ k. E* p! V8 Y7 }
    //Notethatusingausing`evm`,`evm.bytecode`,`ewasm`,etc.willselectevery/ m' g! |) [  F/ d) s
  t. Y" m2 D& [6 O% F9 x$ Y& ]8 c
    //targetpartofthatoutput.Additionally,`*`canbeusedasawildcardtorequesteverything.
4 t8 g) H8 L1 O, B+ _8 m. C: o' c5 }1 {) i
    //' v8 m& e6 i/ ]( L3 C

1 U" m3 V  p: Z+ q    outputSelection:{1 s, A' Z& ]5 P9 s9 {- Q0 N
+ W$ ?# I& Y- t; s' T' a
    //Enablethemetadataandbytecodeoutputsofeverysinglecontract.
* {& W! p" G7 S& U. d; a( \% l0 I+ ?2 {% }& C  W! P( w
    "*":{
6 P2 Y0 J* l; k6 A) t4 w7 @) r
- K: T, s7 [6 x    "*":["metadata","evm.bytecode"]' ^, O! |! R$ e9 D- j# H3 ^( l5 N
- S' g1 {. B7 F/ \- P; E4 g
    },% \( n8 ?' s# X2 Y
4 \. o7 N, U- B3 T7 q8 ]
    //EnabletheabiandopcodesoutputofMyContractdefinedinfiledef.
. P) [4 z. C" _+ c5 d5 R# C1 w
) p% i; }' @0 M    "def":{
/ G5 X; n+ j9 O( z1 t
  Y; Q3 Z: D- w, H! n6 r2 C    "MyContract":["abi","evm.bytecode.opcodes"]
, u& F& ]+ H% c% \6 _3 q! Z6 J6 o% e8 v9 m$ Q" B
    },
, U  P9 {* O6 K; A7 d  B- N- X& R: h9 Z. W5 }; \
    //Enablethesourcemapoutputofeverysinglecontract.
" T- n0 S$ I, `4 G* z7 u+ B3 @: Y4 N' `6 d: N/ h
    "*":{1 T# q4 ?. Z2 s- E! k
2 C% x" u2 U& c) q" G1 [3 J
    "*":["evm.bytecode.sourceMap"]7 s; H( ^/ }( c2 X1 t

0 Y" h7 U3 G2 ]& q9 V% m    },
" D$ t4 N, ~- e
9 {- U3 k% _( s    //EnablethelegacyASToutputofeverysinglefile.
  ]- k$ a0 a. b' H+ v
, d3 `+ Z9 P& u/ k3 E5 l( }    "*":{
( f' r+ g  U. S) }9 |3 i
, g9 l3 L4 Y  l: O  ?    "":["legacyAST"]
' z! e1 D5 R: S/ W2 v8 @; t- f: s4 h  _
    }  C/ h  R3 Z9 _# [; d& C
% }. Z) o5 W, @- w9 g
    }0 D$ N& n4 X! ?7 ~7 ?1 M; N+ _5 t

0 A# X# Q# A" U; t' H    }$ _9 q" ?6 E  J& c; b
& I4 x( t7 B* F/ j0 m  C
    }5 \2 b: u6 V2 L3 ~" m

% W0 Z9 X$ W' v+ t7 i    输出格式说明
) \, d0 X& h$ _, V: U+ V9 Q) @5 T1 \# n- _. ?& T
    {5 V8 a! d4 r- p- R# v- ^! O
% c% p- B' G6 S% d! h
    //Optional:notpresentifnoerrors/warningswereencountered
6 l* T& p, U- H- ?) x/ V: o" K8 C+ h7 {/ I8 j- |# I
    errors:[( A: R" `, g/ {4 T
) r# \1 N8 y' `! s% e
    {% \* L0 q! h9 n$ h4 p, |; f; Y

: q3 w4 m0 y3 j+ w8 Z* C' M    //Optional:Locationwithinthesourcefile.; b* l" ~0 w+ i! Q; F# h9 t% I
8 a& y$ T6 g% _1 C5 ~3 t
    sourceLocation:{" N3 D( Z* V/ {* ~6 c. z* f: |+ ~1 U
  I3 R; q) b6 M
    file:"sourceFile.sol",
' B5 T' u* L9 T9 {# q& f  v8 X- [: T" h6 x' l
    start:0,; p; t, w- R. N% h" G

. b- w0 w2 H; r" h" \; n' j- X1 a3 t    end:100
5 |. g( C( l. @+ a# i" ?% _# @# A3 ?) M2 _* ~: b
    ],# Y0 f  x+ q5 _; [! n

, T; b! R3 r% w! F2 e    //Mandatory:Errortype,suchas"TypeError","InternalCompilerError","Exception",etc.0 x: U8 v6 ~- s: N- F3 S2 U
$ ?' v3 u- x- F$ J0 u
    //Seebelowforcompletelistoftypes.
/ o/ _2 r/ \4 V( ~$ w0 D, A3 a/ T
9 d1 p: i' m' l0 w, O  Y# z    type:"TypeError",9 R$ o/ M- n4 N
* j/ V8 G- l8 c- P0 L8 m
    //Mandatory:Componentwheretheerrororiginated,suchas"general","ewasm",etc.
+ L! J% X" a, n" x0 W9 Q$ q- s* A8 t* R- f! B4 N% {& x
    component:"general",
' E1 j3 J( D% |' C$ |4 n) z. m' g9 [
    //Mandatory("error"or"warning")$ d0 X' k4 a9 n" ]) t2 U

% i3 e6 Z( b3 i+ m/ ~+ ~    severity:"error",+ Q* E: S" D# \8 _% w3 i

* S# @4 D% o0 A, [    //Mandatory$ [% D$ a4 {9 b. |: J$ ]

8 O$ D! ^+ M5 c" c, U8 Y    message:"Invalidkeyword"
2 T- B) q' w4 A1 J, ?7 Q
6 |- f9 w( s: _& A+ I1 r. t    //Optional:themessageformattedwithsourcelocation7 l2 o( U. f" w1 N6 W
* o3 i7 \2 g& Y& J- w
    formattedMessage:"sourceFile.sol:100:Invalidkeyword"
9 Y6 E: @$ N- G- q
+ {0 ]9 Q# t/ X; |1 e    }
7 U3 @5 y2 u, T. ^, X# [! o9 P- \( b. S% r
    ],' L& Z, W5 X. U$ N0 n3 |

' \0 C5 ]) f  @# E+ k    //Thiscontainsthefile-leveloutputs.Incanbelimited/filteredbytheoutputSelectionsettings.
, @7 c0 r' H" Z9 S6 }! y8 M. Q# ^. D- m* s& o+ U
    sources:{
2 A3 W* s9 _  W) `/ C9 |- w
9 k8 h6 x+ J# \3 U1 B- i0 H    "sourceFile.sol":{
  n& k' s& M9 Q& ^
* b2 e; F/ t5 C- S1 g$ I) l0 L    //Identifier(usedinsourcemaps)+ q) F7 k/ m$ n

6 x9 T4 R& G% ]( z7 ~( u9 a4 B4 p    id:1,
/ B' b  K& p. Z7 k8 b/ \9 b
! v  U) J" ^3 \    //TheASTobject
& t5 u  k2 J% n* E; g9 M5 O0 W1 [
; u+ E  B, ^& x0 }4 s# I    ast:{},2 z$ s* b/ c9 ^
1 L5 u% G" X7 T7 A" t: z0 X
    //ThelegacyASTobject& |3 o2 t) H! C9 L7 l1 B2 t2 A3 ~
3 @" T( ]5 E" R3 e3 k
    legacyAST:{}
5 u$ U6 b3 i7 J# H- ?: i: w" l" h" c$ F9 n) T
    }% |5 R  A) [1 r+ A9 k  l
) `. p6 `6 ~/ {1 M; g' J) e& C
    },
: A6 E; A! I+ ]4 s3 S, b4 u! [& M0 e# t$ |% t+ S
    //Thiscontainsthecontract-leveloutputs.Itcanbelimited/filteredbytheoutputSelectionsettings.
$ r/ e9 {2 A0 I6 N$ s8 o9 [
) t, }; a3 d* P$ M* _" Q% |9 Q    contracts:{/ ]  D, w* y0 `! ~2 @; h* O/ K" o
' x6 O9 p, K7 z  L# ]- b, \$ [
    "sourceFile.sol":{
3 Z& p7 H5 T& d1 m( @3 e" V
) i( f" B) k3 a    //Ifthelanguageusedhasnocontractnames,thisfieldshouldequaltoanemptystring.
3 v8 k) s) T- ~$ d! \  ?; Y! h
% R! K) V  `) i. b' P1 N  g    "ContractName":{& t6 w9 I7 k: ~5 n# o

" J; M' A. ?: @    //TheEthereumContractABI.Ifempty,itisrepresentedasanemptyarray.
0 J5 b9 C5 K0 j( k& {; Z: g3 U9 D+ ]
    //Seehttps://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI( X4 y9 I5 ^3 ^; y/ N7 V4 y8 N$ x
& P0 Z, z- p( M; G) l& d
    abi:[],- B. ^0 l9 E% ?8 J! j
( n# _, \7 V  C9 s  e' ~2 F  o
    //SeetheMetadataOutputdocumentation(serialisedJSONstring)
) R, m; |) M. i3 m
0 f7 y. f3 `4 C5 p    metadata:"{...}",' q7 e. S2 F8 ~% E, e! D. o
3 m* i! P# F0 Q( d. Q
    //Userdocumentation(natspec)
) r; U5 {! b/ j7 L1 k1 S9 T7 s
# d$ [9 y5 p- P3 Y- m    userdoc:{},
6 q* E5 b) w/ \4 |# I& I
3 k2 r8 `+ y, B    //Developerdocumentation(natspec)' G" @2 ~! m5 K

4 m$ C: p7 p5 d! p# Q/ g    devdoc:{},
; K6 ~0 S, T% `% R3 H6 z; Q
2 {" T/ b" f! `% Q    //Intermediaterepresentation(string)
# J# B9 j* S5 X# l1 r3 s: a" C
7 Y7 J1 B% I& {) H- ?: Z    ir:"",$ g7 T( y( q" e+ |. i: L

+ e8 T5 P. r+ n    //EVM-relatedoutputs
' P  P3 @4 r( a4 f8 n  g" C& E
. @- x$ E) M" `8 o    evm:{
# m$ ~1 ~. r- p5 V/ H1 Y6 o3 h1 {  I% z1 p# I3 ?. i
    //Assembly(string), @+ @$ g( V+ y$ C* x: f4 W
/ s) S& I& R$ t9 c
    assembly:"",
& s1 ]% M. D/ h. v2 h! L: U& G  f/ G" K, X) ]/ t
    //Old-styleassembly(object)
. I6 z/ f3 s) p
$ A( }, G5 K- O) t% [  E( k+ l; l1 M    legacyAssembly:{},. ~/ B- o6 R6 S: E' Y8 Z) e' T

2 x; z9 {9 t  m: W& M) d+ l    //Bytecodeandrelateddetails.+ E+ P/ A/ ?8 v% l4 N
8 c* ~; ?( j0 n; S; e) j
    bytecode:{
9 F4 w4 Q, u' e# u: F  \$ U1 k
+ b7 K) T. s4 `7 u    //Thebytecodeasahexstring.
8 G# L- O* ~, X# B. I+ `7 c4 n5 [3 ^2 R; J9 y& {
    object:"00fe",3 D* B6 F7 ~3 i2 H

/ y$ F1 o4 h/ j8 {    //Opcodeslist(string)
  E; R  |: A; T$ l: N& R
1 {0 }! L9 b& m    opcodes:"",. W3 N$ e- ~3 I: K# |& v/ e6 W  i8 h- O

: t! s+ O. n( D% F1 W1 A, q/ e    //Thesourcemappingasastring.Seethesourcemappingdefinition.
# I. X. r. `7 K/ J* t4 [* Q8 `" M; S1 d
    sourceMap:"",) \( @$ n1 z7 o' T( W, R0 ]4 a
1 k) e, B8 C: J1 w2 U
    //Ifgiven,thisisanunlinkedobject.# X. ~3 S, L' O: T) g$ u9 y6 A

: O, C( r4 s7 n; f' V! M4 a, ]0 ]    linkReferences:{" {$ P) n; Z7 g! g2 b/ e
: R% o; Y: Z9 Z9 F. s4 l) N
    "libraryFile.sol":{1 B8 O) t% |' B* h

* I: P+ q' d7 k0 j, ]    //Byteoffsetsintothebytecode.Linkingreplacesthe20byteslocatedthere.+ w* L  K4 s: G; O& c; a- Y) s* ?

: e3 t5 j6 |0 j& Y; v9 {1 I    "Library1":[4 Z$ ?2 n5 \( g9 Z
  V, x5 \" {2 C5 o
    {start:0,length:20},
9 C6 D6 ?, n) {1 c8 N) s9 r+ \! T+ ?. w& K
    {start:200,length:20}
! m& X0 j1 P% c; W) l  ~! B- V# Q* O* W# D* H
    ]9 _) Z9 [3 I  O  x; q# v. U1 L
% Q( x/ C8 y7 f  _
    }' g! a( |" \5 d$ v4 v
6 _; ]2 K) G3 [) t: u* B1 B
    }
2 q8 y/ j2 w6 e4 G
7 z# B. Y3 r, D- m    },: t$ Q. j3 x" @2 V

& [9 E4 S6 F- J; I    //Thesamelayoutasabove.
4 t' n$ l  i5 ^7 x1 v- u' Y4 t6 c; O, x6 ?& g
    deployedBytecode:{},2 n6 ^6 S8 w, N

- S) P/ I! {% }$ x0 D4 d8 v% S    //Thelistoffunctionhashes( Z) a- ]( ~9 \4 r
& k3 b4 z+ s1 w& u$ B$ n9 o
    methodIdentifiers:{
$ d- t( P' [8 \! Z; o( o6 _- J' \6 K0 p+ ]
    "delegate(address)":"5c19a95c"7 U4 s) {( c% f2 ^4 v5 D2 K5 V

: f& p8 y/ h9 K( x, `    },/ @1 F4 H$ t$ Y
: K  b! I2 T, S1 C; t1 [2 a! D
    //Functiongasestimates
( j" q: e! f/ j- [. K# c0 S- e7 C: F5 e# w) l$ G6 F
    gasEstimates:{
. {4 j7 L8 Q! Y5 k2 {5 i4 t. f
* j( z% |; y1 J0 ~# Y7 E    creation:{* Y3 z3 e( C, D, Q$ H" x: S9 g3 m

! \1 j% H% i7 [( J- z7 H    codeDepositCost:"420000",- B, {3 F$ S& K

1 H( H5 W4 q& M% G4 R1 d    executionCost:"infinite",$ e" ^  f+ F0 w7 H# L. v' y. t
8 Y' e5 J3 Y/ c2 i% m& j& K0 m1 m
    totalCost:"infinite"/ R. y7 I' A: g9 O; [/ N2 t5 T
- U+ \$ i6 O# c6 S5 d8 Z& b
    },2 U& ~3 k  q3 s7 I" `3 z
8 }! H9 H$ v; E, V. d* O5 x' _
    external:{/ W% W2 s2 L4 W2 a8 ^# g! u, o

' Y! D  P. F7 A  [7 E    "delegate(address)":"25000"
; O/ i/ G4 c: \1 |! c) X0 d* V& S& J" S) j( Q/ r
    },5 ]- v. G% J. s" `5 l
" T- ~0 o* G4 w. Q: w* Q
    internal:{
! `9 G* {. W; P3 ^9 F7 i
: M+ T7 i2 C: S# P. l    "heavyLifting()":"infinite"- `8 F' U- r/ g1 y3 J

2 p2 Z. F( e8 o/ y, s    }
: J- }9 c& p: V* i5 |; s$ ?3 ]
# S, V, e# T& t- a, e( G6 v    }
' {/ q4 @; q$ h, n2 n
+ Y9 Q$ }; m/ l9 j    },
5 ?9 q# Y; ^% ~6 B
1 o5 ?6 x& X# ?    //eWASMrelatedoutputs6 o2 Q! i0 Q1 {' L/ G: g5 o! {
) R( m" p3 A. P8 l' ~+ S4 j+ B
    ewasm:{
9 @+ M3 f4 I9 r
, l( Q( ]% q& h8 [" L5 N    //S-expressionsformat  n& A) N$ s5 b4 M! V1 E$ ~

# H1 i9 ]" ?; D% L* x* Z    wast:"",
: t( J: c1 _7 b, k* r9 N0 y. v- B) ^! O* t! P
    //Binaryformat(hexstring)
# H; t. h, X, E+ ?1 R0 F
0 v: h1 Q9 H/ R+ U    wasm:""
) K, X7 ?, D0 K' |0 H0 Q! x* |( o& W7 F4 \0 T4 q
    }  W6 R4 w0 u3 N* p

# T7 v2 V6 i$ |7 q  W  h    }
; E( S' u3 D' {: V" D" q9 y; g( W4 P/ i* i4 J) g% E
    }) q5 G. c, v3 Y& ]- U9 F, b1 w
9 k7 z5 A, p; T" K# x( n1 k
    }
' U" e; {7 |+ ^+ u: W3 m% \9 v0 i, K* N8 Y, O3 N. ^: f
    }4 s& w% c# X9 c  L  e5 v: Y9 w
  A8 c( d# U: q% S' R9 E
    错误类型说明:2 ~; ~# m( W! O
  m4 B. a5 A" H
   
5 I% U- l: ~, ~7 a* M! f2 l% O
! P3 T% a8 P- x$ J9 ]& C$ ]2 ?    JSONError:JSON错误,JSON输入不符合要求的格式,例如输入不是JSON对象,不支持语言,等等。
  F" u: T& Z# P+ s6 O, @; n/ r
- s0 y/ {) G8 k5 P# \8 l) B8 |    IOError:IO错误,IO和导入处理错误,如提供的源中的不可解析URL或hash不匹配。
+ ?1 R9 Y  R7 K
+ w8 U7 u9 ]3 p& F    ParserError:语法f分析错误,源代码不符合语言规则。
# L! ^% `6 |/ y9 G% c9 S& V) |) L8 c7 k3 }
    DocstringParsingError:文档解析错误,无法解析注释块中的NATSPEC标记。1 A$ S9 ?4 w" C0 C* `
+ Z7 q& x; ~% W' v" g6 ~
    SytRealError:语法错误,如continue在for循环之外使用。% H  \* `% P$ H) X, H

, @0 v0 V7 [7 Y: O' ]" K    DeclarationError:声明错误,无效、不可解析或冲突的标识符名称。例如未找到标识符# t1 I! J0 ~  q6 \" a6 G

) |! v" d- e( @- J9 ], _: s5 ^    TypeError:类型错误,如无效类型转换、无效赋值等。. h7 [" x6 u6 M# s6 k
# }$ a3 R6 I0 P0 \) t
    UnimplementedFeatureError:编译器不支持该特性,但希望在将来的版本中得到支持。
+ T5 g4 e5 N) p* t9 \+ J6 f6 A2 A( I( O, ?6 R$ S- Z
    InternalCompilerError:编译器中触发内部错误,这应该作为一个问题来反馈。
0 A) o/ H3 J  w: P
: o6 K" ]4 S- q. P& d    Exception:例外,编译过程中未知的故障,这应该作为一个问题反馈。
- L2 l; d" d) l1 ?7 q: j4 _& q4 T/ u5 K% D1 Y) G
    CompilerError:编译错误,编译器堆栈的使用无效,这应该作为一个问题来反馈。
' V' l5 y2 H; Z, i+ W( |4 A  g& y; B
: x( h$ ^: U: v1 @$ @    FatalError:致命错误,这应该作为一个问题来反馈。
2 ~  G: n* m, S" ?# i/ m! e  c$ b; W$ H) i0 E
    Warning:警告并没有停止编译,但如果可能的话,应该加以处理。( j3 E6 U8 g3 c: c1 y  [

3 W. r0 P8 _% c1 E7 a   
, \; q" J2 ^, H+ C, X3 i, Z( ^# t  a1 P+ P. O4 a* Q
    原文请访问:solc
- F% t5 k! c5 m& G. I4 S
/ V, ]1 u9 n: f% h9 ^: ?! _    如果你希望马上开始学习以太坊DApp开发,推荐访问一个在线教程:2 [% ~6 `6 Y" n  {) v& F: T% w

! x  q4 K, @1 V    以太坊智能合约,主要介绍智能合约与dapp应用开发,适合入门。* p; I) T' g4 S+ w# r! g

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

本版积分规则

成为第一个吐槽的人

曲水流觞113 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    4