Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文
solc:solidity的编译器
, E9 c# X5 m# t& F6 P2 k& g& `$ `7 D: ^7 Y! K+ }. w1 @- l
    solidity编写的以太坊智能合约可通过命令行编译工具solc来进行编译,成为以太坊虚拟机中的代码。solc编译后最终部署到链上形成我们所见到的各种智能合约。
; g  \8 q" C9 r# ]
4 U, p8 q$ A6 `# G" ]    作为一个solidity命令行编译工具,我们来看看官网都怎么说solc。  _! m, h  F  Z

! P( B* k$ M& L( E5 f* W    solc的安装很简单:8 E/ v  c! G- ?1 R9 }; s
3 o/ p2 A  i) }# H# O
    npminstall-gsolc
7 Q) c; ^' b" x" y2 p1 H2 ~7 T8 L1 n
    //或者
9 L( @( w$ X9 \- f2 \
4 s' q+ v3 R. I' z0 X# C    npminstall-gsolc-cli$ @) H2 m+ ?4 a0 i! \
* r% `. L" i" W! Y! I
    //或者
" @4 P) U* |" N9 m) S. S% j* n' F
/ F& i# z+ v' L/ \# G" h    sudoapt-getinstallsolc: J' h& v% o; J& y" f- M* }0 Q9 u

$ X6 D% \. ]+ r    安装完成后我们来看,solc--help,solc--help命令显示所有的solc命令选项。编译器可以生成各种输出,比如最终的二进制合约文件、语法树的汇编或者需要预计的要花费的gas等。solc--binsourceFile.sol,可以编译后输出一个名为sourceFile.sol的智能合约文件。如果你想从solc获得更丰富的一些输出变量,你可以使用solc-ooutputDirectory--bin--ast--asmsourceFile.sol。
) J% s& ^/ {3 F5 w" ~- h6 Y0 T! f* w
    你在部署以太坊智能合约之前可以用solc--optimize--binsourceFile.sol优化一下。默认情况下solc编译器会帮你优化200次。你也可以设置--runs=1,这样就按照最小化的方式进行编译,如果你希望多次交易不太在乎成本,那你可以设置成你想要的次数:)。
: m' F. `' D# {( l. x4 R5 U8 l3 ^! J7 M& F( D" q
    命令行编译器会自动读取需要导入的文件,也可以通过使用prefix=path来指定路径,例如:
" \* }0 F' c/ }) d
7 t8 u/ N, z2 f* {# f    solcgithub.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/=/usr/local/lib/fallbackfile.sol
7 W) Z) U2 `) z- M" z6 h4 m( }6 O9 o* v9 b& Y
    这样编译器就会从指定目录github.com/ethereum/dapp-bin/下的/usr/local/lib/dapp-bin/目录开始搜索,如果没有找到文件,它将查看/usr/local/lib/fallback。solc将只读取你指定的这两个路径的,因此像import"/etc/passwd";必须要通过/=重新映射才起作用。如果有多个匹配,则选择具有最长公共前缀的进行匹配。
6 I2 ~+ C8 i. l' Z# r" v6 B: D7 j6 d. |9 T& r
    出于安全上的考虑,编译器限制了它可以访问的一些目录。在命令行中指定的源文件的路径(及其子目录)和命令行指定的路径外其他所有内容都会被拒绝。--allow-paths/sample/path,/another/sample/path来切换。
2 i2 b& R+ L/ i" T; L9 |! S6 @5 x+ h5 C% f3 Q
    如果智能合约使用了libraries,你会注意到字节码包含了__LibraryName______的子字符串。您可以使用solc作为链接器,这意味着它将在这些点为您插入库地址。$ v& g3 P7 \( X3 G

8 u; z6 c4 S9 U& K7 I4 m    可以通过添加库--libraries"Math:0x12345678901234567890Heap:0xabcdef0123456"到您的命令,以提供每个库的地址,或者使用文件中的说明字符串(每行一个库),并使用--librariesfileName运行solc。. m- v, n  i1 m" K) r6 E6 g. b

1 a" B; g8 y3 r9 e% w    如果用选项--link调用Solc,则所有输入文件都被解释为未链接的二进制文件(HEX编码),在上面给出的__LibraryName____格式中,将其链接到适当地址(如果从stdin读取输入,则将其写入stdout)。在这种情况下,除了库外,所有选项都被忽略(包括-o)。( d3 D5 o" q# l# g3 Q0 o" S
1 e  t& w) H. U) u. B1 u$ Q3 q5 s3 I
    如果用--standard-json调用SOLC,它就将标准的JSON输入(如下所述),并返回JSON输出。
1 u9 H( s9 f$ n$ h( R8 K2 }& \
0 q& C- L% m6 I6 A" i    #solc编译器输入输出JSON描述' K; c& S. W/ A
- H3 w" ]  _) U+ I1 s7 o
    这些JSON格式通过编译器API使用,可以通过SOLC获得。内容都是可以修改的,一些对象是可选的(如前所述),其目的是向后兼容。
! G$ d' e: I4 G* @* N5 y  ]
. d* O' @# o3 C5 ^' w    编译器的API需要一个JSON格式的输入,然后以JSON格式输出编译结果。2 m; N! l4 z) f$ \' @

. W4 I* ]! u2 f* H3 D/ W    注意不允许注释。下面示例中的注释,是官网为了学习者更好的理解标注的。
' Y9 h3 y7 ~& Q0 |* z! ?
5 V7 q" u. r4 Z    输入格式说明:: M% D' v# [8 g! `. `: R
" C: T, D! q7 Q0 R0 s' a; F) V
    {
# W, \5 m6 r2 B$ L1 K' t# Z9 L: w8 O; u( X: S1 ]
    //Required:Sourcecodelanguage,suchas"Solidity","serpent","lll","assembly",etc.- C5 M4 N9 }1 [+ M

7 D# p6 U* q$ r; K/ f( O# v. Z1 v    language:"Solidity",! @: Q: x8 z* E; P9 z
3 o7 {/ y6 B9 m+ L! t) C% A3 V) z( z
    //Required
  E& d) S" F* [0 b( H
) \$ q% h$ [) \* J3 e2 ^    sources:
' `# Q, \$ g- F- e* H$ ]' N# F/ u7 d) N( ?  x+ A. ?
    {
  [% O7 v0 w' ]7 v1 I  i& Q6 C/ X; _/ C
    //Thekeysherearethe"global"namesofthesourcefiles,
9 P3 z# R" G, R, L; g, T( [9 `% P- u  z
    //importscanuseotherfilesviaremappings(seebelow)." k4 c1 }- M- _4 j- u3 J
$ B- j& K  ~# H; F4 O5 C
    "myFile.sol":, m- v- Q$ m/ O6 d# p1 d$ v/ O2 ~& P

* u% J) n- Z& n' e6 A3 a0 _' w' D    {; f! S4 i% L7 S
& L8 g# I) l- ]' `7 v
    //Optional:keccak256hashofthesourcefile
4 H8 V5 {$ }& n( f7 A
8 K- B3 n7 I, a" S" k/ ~    //ItisusedtoverifytheretrievedcontentifimportedviaURLs.
" F7 w! f1 d: T. h* d( ?  w$ N5 D  |( O8 A0 j9 r$ ~
    "keccak256":"0x123...",% S( q7 |' G/ u5 n0 C1 r& |

8 F& ~( Y9 J  C0 `" y  }( D$ i) }. Q    //Required(unless"content"isused,seebelow):URL(s)tothesourcefile.$ w. r  q2 I! h# Y7 t2 z  k
" r: V3 k8 x: U. p" b
    //URL(s)shouldbeimportedinthisorderandtheresultcheckedagainstthe' E! a# [1 J& d$ ^; f9 z5 A, ^$ M& v

$ n9 D( {6 a' }' m% A8 o$ F    //keccak256hash(ifavailable).Ifthehashdoesn'tmatchornoneofthe7 `! b" y# P; Q0 F1 y. d0 B! g+ A

/ b( q6 {# U% t' G! m    //URL(s)resultinsuccess,anerrorshouldberaised.
1 M8 Z* y) ]: F
) d) {/ c! f5 g9 M/ h* {    "urls":
4 R" J% b! X6 e: @: p3 {8 p" N# N1 W  p0 ~1 g/ H4 [
    [
2 L! ?' e  n5 j2 v
% F5 h. w0 E1 a6 {) W9 k    "bzzr://56ab...",
6 R5 `$ x2 d6 e/ i# k. X% Y) F' {( E7 \/ A2 M0 Y4 |
    "ipfs://Qma...",' L) P  h# O6 Q3 C2 \* J
  p, y8 k* L: l2 X
    "file:///tmp/path/to/file.sol"4 f) ~% x$ V! q( i4 `7 J8 [9 C5 f

8 a" U+ C8 Z; R& u    ]; l0 W5 d) P& M( V5 _

1 n3 e  P; e0 G    },+ H! V8 {- U0 [7 W: e

# o% P7 L, }! j- N4 o+ i2 H    "mortal":# n( Y, g0 l) n! m

- }8 i* P+ x, U# {0 T    {$ ^- Z- h7 A' E: u

. U- w6 B& y# W- P5 v0 Y    //Optional:keccak256hashofthesourcefile  ]! Y* I9 _$ s3 ~4 C) Y- V( e; W

3 }) H0 o2 n, z2 U3 Y% U* W% ]    "keccak256":"0x234...",/ K  T& O7 i) O  {

/ @5 y( y5 G8 o% n/ P+ E    //Required(unless"urls"isused):literalcontentsofthesourcefile
, @4 x1 {( }" N, w7 ]; `% `+ F
- P5 o  r" K" V) ?    "content":"contractmortalisowned{functionkill(){if(msg.sender==owner)selfdestruct(owner);}}"* {  W. j! I3 d& W& @
$ [6 g4 A% z6 b
    }
. `* G9 j0 K! a3 y2 G
9 a7 m# j' b9 j    },
. ]9 W, E' ]; ~- q3 c& `" J! E% w6 R8 y8 ^  I
    //Optional# Z+ V* [! d1 }; |
0 r' }, N( l- c, ~* h
    settings:3 K( X8 h* \# w( z) w- t/ x6 N

4 j  {/ z6 d! w- |0 S    {$ d# i, j* Z4 @4 E( \$ ]! i; P
3 B. b' I. ^8 ^+ r8 p
    //Optional:Sortedlistofremappings
5 p( p/ \8 _4 U- L' F6 o' v6 s) Q
4 c8 F3 _% S: \- ~; ^: p) k& d    remappings:[":g/dir"],, e  P# e$ X+ m* n
; E$ y1 }# V& \5 E
    //Optional:Optimizersettings
9 R7 w7 j2 s: `* Q( \0 u, @5 R1 t! [3 {; y* _3 T8 }* m1 N
    optimizer:{8 T6 f# B; G& t
5 q, I% s' z5 y. t
    //disabledbydefault
' N9 r' B- R" V; A8 h8 x. H, G- |
    enabled:true,2 p* O8 f( b3 w6 ^+ S9 Y

" {2 C- _) k7 M6 i    //Optimizeforhowmanytimesyouintendtorunthecode.! n" o& W/ J+ p4 z! s  ]/ M
: s# D& w1 ?- X9 Y
    //Lowervalueswilloptimizemoreforinitialdeploymentcost,highervalueswilloptimizemoreforhigh-frequencyusage.
! ^. ]' F2 k% _6 z# _
7 F" d+ |3 W) @+ ?( ~    runs:200
& k8 t. O0 ]0 a% I. m' \( p: y6 R4 S$ E& L, D& ~
    },3 C; u$ l2 A9 `5 p
% h9 L' t7 x" k6 s0 m( D* R
    evmVersion:"byzantium",//VersionoftheEVMtocompilefor.Affectstypecheckingandcodegeneration.Canbehomestead,tangerineWhistle,spuriousDragon,byzantiumorconstantinople4 z' y. J' F# i

- ?% l$ b- u0 F$ G* @, g    //Metadatasettings(optional)- M% Q5 Z  z. X& k0 F% t8 y
% l5 m2 ~8 T' ?0 X) [  b
    metadata:{
. P2 @/ m" G. j: U% J
( d" w0 O* G# }) y! w2 _! T8 T    //UseonlyliteralcontentandnotURLs(falsebydefault)& y6 l1 d5 b# A' @% C: j' g4 B
% i& A5 Y/ ]* N' e" X+ g
    useLiteralContent:true0 Y8 R/ b) Q" Q& ]

7 D" L5 O( e( a    },, d9 s6 N9 E! E2 R
% b7 _8 u: ?( J6 \5 A. \1 |: s  n
    //Addressesofthelibraries.Ifnotalllibrariesaregivenhere,itcanresultinunlinkedobjectswhoseoutputdataisdifferent.
" h- z) n' P9 Q+ q6 i- K0 D* }" \1 @: N
    libraries:{) [! R+ H6 a" v5 ~7 l8 L

1 y2 f$ T  Q6 O& K# `9 e    //Thetoplevelkeyisthethenameofthesourcefilewherethelibraryisused.# A  [- y- ]3 h' S' B

6 a) m! c9 h/ v9 w. q! ]    //Ifremappingsareused,thissourcefileshouldmatchtheglobalpathafterremappingswereapplied.
" I9 Z% s# N' j5 A1 y: `) P2 p) \! U/ U# K5 y- M0 W) ^& G, R
    //Ifthiskeyisanemptystring,thatreferstoagloballevel.! b+ m* [* u, u
' ~$ M1 W) C0 h( \' k/ r) ]$ t
    "myFile.sol":{
" E4 B; P5 P8 Q$ \+ E
- ?8 o  J5 k$ Q4 R; z4 L    "MyLib":"0x123123..."
& t! Z6 c2 F: X6 ~% }( {' @6 @+ E' w* ]- K6 L" p
    }1 b) c1 N( W6 I$ |

4 P+ Y4 [/ e" a& V: }$ f    }6 l- ]. J' O0 ^, |
) ~1 }$ Y6 N; {( M
    //Thefollowingcanbeusedtoselectdesiredoutputs.
* P4 l  _# }: C+ t6 Y* d6 |( y. J# I
    //Ifthisfieldisomitted,thenthecompilerloadsanddoestypechecking,butwillnotgenerateanyoutputsapartfromerrors.
) f, v% w' y" f1 L- h. s9 _! F+ w  k3 c# N8 V# \. N
    //Thefirstlevelkeyisthefilenameandthesecondisthecontractname,whereemptycontractnamereferstothefileitself,
) M8 l$ `7 @1 E7 Y: J" z- I
4 _$ D# R* q6 g' m& Z* H2 r    //whilethestarreferstoallofthecontracts.. |6 x  `. m4 }: e* F4 y, P! L

) b* o6 u. ]" C    //
% u$ j  [2 d: v, J# j2 c/ E% Z
0 T; S3 g0 \0 F4 A2 l    //Theavailableoutputtypesareasfollows:
1 m1 ?: @+ w3 ~4 }' F+ `$ y- u4 q6 b. h+ J, J+ p+ S& e
    //abi-ABI/ G7 a5 `5 T# J* Z" {

) A. r. e! \1 c* K, v" Y, f" l$ e    //ast-ASTofallsourcefiles! l- B' E& k+ L2 R- X% i, [9 Y
9 R. P0 [5 ~  @
    //legacyAST-legacyASTofallsourcefiles: m  I2 f7 y: R; y' [( V7 H

' T) Y1 w1 g; ?- c3 P    //devdoc-Developerdocumentation(natspec)5 F) o1 V! k* q9 C% c
: ]8 l/ N) Q8 D. z8 \
    //userdoc-Userdocumentation(natspec)0 X# d# y9 \2 i. x% J

0 Q$ i) \9 H% h+ y4 Y    //metadata-Metadata
) }9 j' z2 R9 X0 R0 \# ~" n1 `1 Q9 P
; }% ^% q4 I& l  a0 X    //ir-Newassemblyformatbeforedesugaring
7 O) }9 e7 t9 Z! {2 s( h$ V. L# I1 f$ K+ D3 F1 w
    //evm.assembly-Newassemblyformatafterdesugaring
2 E# {$ o2 a7 n7 h4 i- k/ w6 w( v# p2 Y9 Y6 Q8 ]' W$ T
    //evm.legacyAssembly-Old-styleassemblyformatinJSON- Y4 n' m3 ~- a$ i8 @
* D3 ]+ B+ S6 _& l% x8 K5 `
    //evm.bytecode.object-Bytecodeobject
0 }# ^* B- {3 X$ ?  m7 L8 P2 [! o; d" M/ Z( N1 v6 @# t4 J3 L& [% w
    //evm.bytecode.opcodes-Opcodeslist
7 E3 h% F& g' k$ Y2 f  g0 Z0 w$ ~! V
1 C9 j* M8 n" I6 p( d$ K( J    //evm.bytecode.sourceMap-Sourcemapping(usefulfordebugging)5 ]7 J8 N2 e$ ~: m' U
' R2 d! Q0 R* ?) V$ }
    //evm.bytecode.linkReferences-Linkreferences(ifunlinkedobject)
7 _& H7 F" a* t4 s9 X0 E, A8 U) _" ]! \- M/ y  v
    //evm.deployedBytecode*-Deployedbytecode(hasthesameoptionsasevm.bytecode)# \1 T, k( ?5 p, ^6 s+ ?

) X+ A# F/ Y" j2 w    //evm.methodIdentifiers-Thelistoffunctionhashes
5 I4 ~/ N% s3 S- l, m. y& }/ [* f% ^
    //evm.gasEstimates-Functiongasestimates
6 G+ M, Y- Z5 d
5 n8 A+ |( D4 ~2 f% c    //ewasm.wast-eWASMS-expressionsformat(notsupportedatm)+ t4 `- K! \( G5 S# x

2 }# C# x. t2 V6 a# G! `    //ewasm.wasm-eWASMbinaryformat(notsupportedatm)4 |% B# T0 Y" h. [0 G0 s" `

8 x6 M3 t2 h2 u5 I7 K) }, M    //' J) r' T, W% D' l
  D4 W9 b8 o4 I8 ?  b5 U
    //Notethatusingausing`evm`,`evm.bytecode`,`ewasm`,etc.willselectevery
5 c6 |* S( g5 u1 r0 G5 k: r4 v3 o% l: }3 p1 ^
    //targetpartofthatoutput.Additionally,`*`canbeusedasawildcardtorequesteverything.
' m$ I$ C5 a7 u; F
+ R5 z4 E/ s* Z# f/ G3 e7 X6 T    //
5 P0 S5 V# O- ?3 M+ F/ _2 ~
! }+ M6 r5 P0 H0 h4 C    outputSelection:{  v# G) O6 G+ H& [. w, M
( j1 t! P/ j- I0 b1 A
    //Enablethemetadataandbytecodeoutputsofeverysinglecontract.
3 [* y. u  q% B8 N$ q) T- f# D: u
# x3 @# V0 m! P' o: B; x7 t* ]    "*":{
& I* z" ]' {7 ~& R: `- I/ T! J
    "*":["metadata","evm.bytecode"]6 g; J- a6 h. c2 l3 B* U4 u
6 m, d" b( \; \  A- c7 U
    },
4 e* O" e$ F6 J* ^+ G
1 Q% C0 N, c# t  t4 {7 ~. N  f/ \    //EnabletheabiandopcodesoutputofMyContractdefinedinfiledef.
4 W: K" f) G: ]" M; i, Q/ c2 i) ?7 C
    "def":{3 i- Z$ ]# g6 t/ T+ R6 x4 H

4 U9 @" R9 \# H; O    "MyContract":["abi","evm.bytecode.opcodes"]* k+ Q0 H/ @: s# i5 K& D

( o& ~. y" [6 F2 q: d# X    },
# I$ q( Z  s3 u) s- w2 x! T2 O. ^" a3 t) L% m# P' l
    //Enablethesourcemapoutputofeverysinglecontract.1 `  E. q1 b  W; M" F( l, G

& A5 X$ |9 l$ W6 t6 L1 b    "*":{
; a* Q- E1 a3 Y  M4 a! \) [, x& D4 x/ V
    "*":["evm.bytecode.sourceMap"]  J5 p/ Y& O* [& A

) c2 X! P/ R$ I- V2 a$ A" n0 N) z    },4 C6 X+ |8 ~4 L, I' }" [
: L7 e. N7 D, w# @9 S
    //EnablethelegacyASToutputofeverysinglefile.! _) W. m% O( l# f. }
% O; [* Y8 }3 h" u0 Q5 {6 _
    "*":{8 Z( U* T! R! b( F

* O6 [1 ]# M0 _* i    "":["legacyAST"]0 u1 R" e7 p* w
* B' B" K& d& u0 Z! K- \$ M3 ?+ J
    }' K2 H) @9 A& s/ W- s

6 \9 e& E/ l" o/ G* p, X# M    }( o% k2 U' S5 c" M$ l! A) Y
4 [) y2 i1 i9 r' X( T7 [! B  ^- x
    }
' u. }2 H2 A' I! q" G: e/ V% R. h
% z+ d+ C  Y+ {% R* @! ]0 ^* D/ w    }% @- L" `( F9 I5 z9 A

9 ~+ h3 c/ \5 t/ I0 _, K    输出格式说明/ Y  M( `* Q4 O& i
0 Z% z( B# S. c$ V+ e
    {, B6 n9 j. b5 l7 W3 u' ?
; J9 I9 ?7 b4 D" V  s' K
    //Optional:notpresentifnoerrors/warningswereencountered8 R5 z' P$ ]( Z9 E0 m

! B& V! X7 w. l    errors:[2 j; f) E; R3 J+ b6 X, m9 ^

- M" k8 E2 d! x6 a; F0 I7 Z4 y    {
: y; O# c! \" y( i' O
$ A4 e' F) B' B% d8 J- u7 u0 x    //Optional:Locationwithinthesourcefile.
1 S2 j! p/ T/ B$ f8 K8 {: I$ F0 A
! k1 N% p* H3 b# L( l- F9 H    sourceLocation:{, y8 w& h5 ^2 ^5 ]9 e) t

7 o) g1 K8 R6 |7 o* ~    file:"sourceFile.sol",# J# r2 c7 i6 L/ h, n: D

$ V$ T. w, k' Z2 u3 j    start:0,
, J! P1 K8 \# A( }) J+ W
) r2 p0 s6 S7 p8 e* I# \8 S0 L    end:1007 [& s( v4 Z" s# n+ `& U0 h  x& W

8 X- }# N- X% ]; ]+ [) k    ],: P. N, i: M0 }3 i! l) h; t

5 `+ j* t! Z1 S  X( L" b    //Mandatory:Errortype,suchas"TypeError","InternalCompilerError","Exception",etc.
6 X* f8 k7 W* I* S# k1 w( p$ f
    //Seebelowforcompletelistoftypes.% s9 r- j. L' }! Y
4 U% O. O; t: _9 U7 r9 f& K. c# y
    type:"TypeError",* J$ Z! b7 s! r0 G0 w' T
! h) j! Y/ {. e) f
    //Mandatory:Componentwheretheerrororiginated,suchas"general","ewasm",etc.0 z7 ^! _7 D9 k

+ o2 P' [# e$ l7 k. y. U: m0 l) D) ]    component:"general",1 I2 r/ k1 f  A# v6 `

& e4 ~" n1 P$ o  Z& s    //Mandatory("error"or"warning")8 j5 H# s/ s) O% J: h
; u" `9 ], d% g  k% ?
    severity:"error",$ k1 y  x2 |+ k( m# m6 U
8 {# {$ I2 o6 F3 T) K' _+ ?* R( R4 `
    //Mandatory
+ ^7 y3 n+ T0 g2 R) d4 y$ \! M( c! g2 w0 I4 q! f
    message:"Invalidkeyword"0 P# N* e/ ?. L( C1 ~" v

1 l! M9 I; ?3 K: J    //Optional:themessageformattedwithsourcelocation
& Q( o+ l0 S9 C0 [, Q" B( G+ @- s3 ?' T- `& U7 M# e8 [
    formattedMessage:"sourceFile.sol:100:Invalidkeyword", y# o$ l0 D2 |

3 u" P% M* {/ F    }
  |' V& s7 L  q" d& p4 Q% M2 j. K: G4 h/ I  \& W  O1 S
    ],& f- l& T/ m/ T; V, u& E) W  p
: d$ w; ~" i7 t3 d- W; w5 Z% v
    //Thiscontainsthefile-leveloutputs.Incanbelimited/filteredbytheoutputSelectionsettings.
, b: x" _3 r8 o3 ]; v2 x
( ], H* p2 o# o, {% s# R2 c5 U5 _    sources:{
  l6 I; S- c$ z1 B9 m" O
8 j9 i, x7 q' ]    "sourceFile.sol":{" o* R% ^9 g7 v2 }4 l
- g: F' _" S% }6 S
    //Identifier(usedinsourcemaps)$ {0 t- @$ M5 o8 b

8 ?4 ~! {. f# X, {    id:1,/ ^4 l, t) }' e9 J/ e

5 ]# Z; H1 o0 j6 V9 l2 C. a) V$ ]    //TheASTobject# \* e4 F4 t! f( E

7 _4 p1 C. @0 N9 ~; O! \    ast:{},/ W. Z% q; m8 E" B5 D, ?
& P' a1 l& f' I
    //ThelegacyASTobject
% ?: x- N) u/ G/ V* f
8 i- O$ @1 e  i7 j* {% Y- |    legacyAST:{}
$ g% h$ \0 Y2 t0 n- g7 {
3 P9 \- N) W9 T: F; K1 s& ~' w* g    }
# O1 c* \/ i' y+ E" D- }* v9 ?* l' ~- V" o  Q' r5 L3 t2 C. A, M
    },! }" n4 t* h+ Q1 v6 i
+ B% j8 @  ^0 t7 ~" q3 c  Y) u5 c
    //Thiscontainsthecontract-leveloutputs.Itcanbelimited/filteredbytheoutputSelectionsettings.
- K6 N1 I; h! [  z) C
+ ], ]% M7 @9 x; a6 N9 }. r$ z, u    contracts:{
3 x9 n3 c/ ~/ p) ^( ?* h8 |  |7 _$ V% U9 _4 N" U5 J
    "sourceFile.sol":{. T/ W0 ?: ]5 s8 z: g$ S+ E. t* {

2 {1 V/ p. V: J8 e    //Ifthelanguageusedhasnocontractnames,thisfieldshouldequaltoanemptystring.
5 |9 w# N! s$ Q& P" A3 v8 k+ x6 x/ }1 `
    "ContractName":{. C# ?0 u  p' X# w4 T3 D

5 q4 R5 K  s) [0 {" O' S    //TheEthereumContractABI.Ifempty,itisrepresentedasanemptyarray.
$ }9 \* w1 `  U! F1 M- }' [9 {/ K; r/ x- r/ G( J
    //Seehttps://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
/ n% u6 a0 T2 R! Z% [( v0 o) g
9 X9 H% x4 {- X2 S/ W    abi:[],8 f. {5 J3 D0 }# b, `
2 D6 b' e) `; B
    //SeetheMetadataOutputdocumentation(serialisedJSONstring)
$ H2 u3 F! G# ~. i
8 t" v+ ~6 G$ [7 D    metadata:"{...}",
, B- b! {6 a* O! U% Z' |( C9 h5 O& K
    //Userdocumentation(natspec)
& j. s  E) D; @3 X8 o. c6 `. d
. o& u3 n- a  R. T8 t) b9 P    userdoc:{},' y' ]! x. m0 f5 {" i! l! _$ I. L

  @/ Y& O0 o9 b, N5 u% h2 M    //Developerdocumentation(natspec)
: |* c1 ?) G, A% A" E
7 j' `/ y" U# Z7 v$ r    devdoc:{},6 ~0 ^% e+ b( c# U$ B# }

% q  `' N/ o! I  @( V. R# y9 X( Y    //Intermediaterepresentation(string)* q: X' ]: R7 X8 k. @
6 a/ ^9 }# S7 m4 ]3 ^* t: U+ r! d
    ir:"",: p% L" g! J1 K( H+ t
  l3 o% T: M- Q! A
    //EVM-relatedoutputs
$ v; S8 j" S% @8 B; U& O
; ]# N/ n& G# o8 F    evm:{/ `% i0 ~( h  Z7 Q: c3 D
# y/ o: i* I" B/ T1 m, c. B
    //Assembly(string)
6 p, k. M& I% u% H: W" @
+ t0 x' d, O( B/ {0 F( [    assembly:"",. z4 K: R/ G# Z& C: a
. ]- X" H. l* v9 H* ^
    //Old-styleassembly(object)3 ~  H) W" s% ]6 d( U" H% G

% Y! k6 f0 O* o; L    legacyAssembly:{},4 S; c) P# j" f$ [7 k5 F' e1 M
: h: O  i7 G! z8 k, @: r  b, x
    //Bytecodeandrelateddetails.
: x4 H' H: x4 e- s) q
2 r/ L. P* E0 s, T* R9 K, f" ^    bytecode:{
$ Z- f" U5 e! z: B$ p: b# Q& z; u
    //Thebytecodeasahexstring.
  d. K; u6 b  a# M
9 x/ d( u) I: p5 G    object:"00fe",$ X1 Q4 d* f# Z6 M7 X

% @. J: \' H: R2 k4 m+ j6 i9 l    //Opcodeslist(string)- E  a4 @$ Y' Q9 x- d

* T, d; R. g/ i- W    opcodes:"",& v8 W* k5 B2 }2 ~3 k, ?

% a3 B0 K0 s8 t4 q$ d    //Thesourcemappingasastring.Seethesourcemappingdefinition.; C9 N8 M0 D$ k+ B( J$ {; u

) b9 t* e" L6 T- t' C1 z- a8 @    sourceMap:"",
3 |4 O$ `8 D. s8 |" H/ G% z: l& r/ {" C/ h& n# p% ?
    //Ifgiven,thisisanunlinkedobject.' P, n3 N2 |' n4 x2 k

& ^" ]  Z# @  E% u) w# C5 \    linkReferences:{
  P9 t7 g: |3 |3 h+ A! M* ]/ e# p: F$ E" Q
    "libraryFile.sol":{
2 n- y6 F2 r9 f2 X4 R* g& j( {/ _' ?; M
    //Byteoffsetsintothebytecode.Linkingreplacesthe20byteslocatedthere.
- _! A/ Q4 Q& ~5 `( n
' z' J' N( F) c' n4 Z2 w    "Library1":[+ f, w# d6 N% u
, T$ `0 p+ H* Q8 S+ Z  w
    {start:0,length:20},
2 K. Q% V( d/ B8 v3 z# H
, N9 J3 X' o* c3 c* O    {start:200,length:20}, I1 U; I- J  t6 t: K/ m
* w# {# f2 _& J4 [# I
    ]
% h  ?6 x# B5 q% [' ?) d9 [' P6 v2 G; x. w' D" P/ S  i+ U
    }
( k& l4 {/ M! j+ ~$ ~' @( `- d! n, k1 w3 N
    }4 ?9 e* M5 `7 X) C* i6 S* u

+ h7 a0 T* t9 u( ~! j) ?* `    },
( r* Y9 I  D3 e- i0 a8 ]' q/ [' q4 B  z# H( c' X. m! s- L" _
    //Thesamelayoutasabove.
8 ~! i0 B- q* F; r# j8 E: A& Z* ]+ @" H5 y) D0 c% c$ @
    deployedBytecode:{},
5 P6 C' d- n$ W+ ]8 K' \$ r; x6 P. Q+ b
    //Thelistoffunctionhashes
/ Q* v0 [( y& ^( L* _/ m# {+ m# o: I2 ]3 @
    methodIdentifiers:{. a( G" G/ Y6 W/ H* ~9 [

. q% s( n+ G# f, r; V7 _4 N* j    "delegate(address)":"5c19a95c"
! v' g+ t  b5 t" M/ d  T( ]- Y% t' A7 g
    },1 q% _# r  |5 Q* ]' O9 d1 w
% g/ C8 Z( u) L" b2 a5 T
    //Functiongasestimates) m% G# O, t0 A& `( y- J" G
+ ~. j0 [. {% H7 a2 b
    gasEstimates:{
" o) V% N6 v' ]3 e7 Q% N9 G! z% n8 Q4 l3 h- ?& ~1 S
    creation:{* c( A! Z# I1 O3 _; S

8 q  g+ s, @% H/ B  \4 [+ {    codeDepositCost:"420000",
$ t8 ^  ^8 D+ B" o4 j# E3 a0 y1 s0 {6 U5 w
    executionCost:"infinite",
1 t5 d6 ]) `* t4 D. D0 g0 ^, K0 Q1 v% ]# R& s& U
    totalCost:"infinite"
0 z  f; P  \. m6 I
, x8 ^2 a: z% S/ F2 g- Q  v    },
- p& ^/ G7 L! m- z/ s$ U; y( ?
8 j5 I  T4 r  u0 x+ n# ?" z    external:{
0 r- J6 q0 K0 y: T: u3 d" N. z% H  q+ M7 b* k. _
    "delegate(address)":"25000"
% a: C  g( @) P+ D4 I8 m' Q9 o! }' f) D. a
    },
: r. f; H. c# I" G9 b' e
" H9 H' G) t, n# ?    internal:{( [/ A, Q1 D, z3 l& c$ T5 N! @

% L2 S$ }+ t$ S' q5 I: n    "heavyLifting()":"infinite"
7 P1 t: i9 s  Z! u' ^/ ?* o6 E9 W) o& E6 ?5 H% J$ g
    }
7 {8 O+ i  m+ Q8 y0 ^2 Z. }9 T9 Y0 Y6 F
    }
1 W1 l& m8 W; I4 V+ m' q3 [: ~* ^" ^- y/ ]" q
    },
8 |+ W2 A; [5 K: h. I! V$ p! V3 l' h; f" L
    //eWASMrelatedoutputs
4 M: T. r# h6 m: a& E+ m- {) n
    ewasm:{
- F& E9 i+ X1 v5 u' q
% s% n4 v/ H% ]    //S-expressionsformat* L" M7 y2 }4 `$ Y: e7 w- k3 x4 @$ `! C

: W/ A; W8 c$ N3 U# @    wast:"",# S& s' F3 u7 e; u1 G7 d) i6 ~# L2 _
; J" Y6 ]! Z! D- P* K+ D* b
    //Binaryformat(hexstring)
% a8 d6 W, K& u4 f: m! U- m8 T0 f9 u7 c' g0 c. J
    wasm:""
" _# X7 {/ I3 M4 c$ ~  w4 o! C
    }
$ u% P3 A" g6 P% W  A
6 P7 o" \7 i. ?/ g: j- K    }- o0 g$ q6 O( w- b% ]! g. h
0 `3 l% S% ~$ ^" m* {' a5 I
    }' h' G- N1 n5 y3 z

) f; w3 o/ ^+ ^- M+ ~2 M    }
+ W6 _2 |( v2 o; N# i7 t
. v& b' U; p3 z0 l$ s    }
) K, m0 k& c. C7 \* u: P: \2 A6 N# i
' k5 V4 n0 V! a/ J7 S" A    错误类型说明:
0 ?: D/ e9 r& S0 b& Q( I4 x# n. o: t
   
( G7 l' ?0 ^  D1 z9 t# @& P6 _; z. w, q9 _, f
    JSONError:JSON错误,JSON输入不符合要求的格式,例如输入不是JSON对象,不支持语言,等等。  U6 V  e( U, I, u

: i; B$ L1 i+ N& F5 t3 J; r$ H    IOError:IO错误,IO和导入处理错误,如提供的源中的不可解析URL或hash不匹配。% V5 i* z" u: X1 K  B4 y
2 ?6 G: u% c' S
    ParserError:语法f分析错误,源代码不符合语言规则。
; M7 E1 L7 _! Q- _( u5 B& O5 `  h2 O# O% u3 n1 f; [
    DocstringParsingError:文档解析错误,无法解析注释块中的NATSPEC标记。
$ C& f' p+ A" q# g9 C& g4 O
- a- Q4 g. U+ x    SytRealError:语法错误,如continue在for循环之外使用。& p9 b+ H2 e9 a, i, t* ]/ i
% b) G/ i$ B: n
    DeclarationError:声明错误,无效、不可解析或冲突的标识符名称。例如未找到标识符% m, L- {. r  l0 [
4 ]6 C% V& R# v7 s0 i' ?
    TypeError:类型错误,如无效类型转换、无效赋值等。
( e; k; j! Z+ Z/ A
) k; p) I) W! p- W    UnimplementedFeatureError:编译器不支持该特性,但希望在将来的版本中得到支持。+ L# X' ~* ~7 V6 V+ Z6 C" l+ ]) e
1 A9 J6 {' V' b. U! F7 g4 Y
    InternalCompilerError:编译器中触发内部错误,这应该作为一个问题来反馈。
8 l7 |0 H7 w! N! H) O
0 a$ _) s  u5 F' D5 h  b( l% i    Exception:例外,编译过程中未知的故障,这应该作为一个问题反馈。" g1 c3 t* K) E) Z) a

9 I+ l3 s/ p- X. P( C    CompilerError:编译错误,编译器堆栈的使用无效,这应该作为一个问题来反馈。2 s6 Z& C, c4 J5 r; p  Q7 Z% A
0 ~4 t; q+ W+ X' @
    FatalError:致命错误,这应该作为一个问题来反馈。/ ^. m" }* R) r
, z, R9 b! V2 O( q. i- ~2 }& l2 H
    Warning:警告并没有停止编译,但如果可能的话,应该加以处理。' O7 B& D6 Z* ?: O1 C

5 r1 N7 W  |  X% e8 T- J6 t   
* w. O# H" a) C0 o+ ^3 ^2 h/ P. N+ l3 Z9 Y4 P
    原文请访问:solc0 J! S! ]0 d  o* L+ G

. s. Z/ o* z# {! `7 D    如果你希望马上开始学习以太坊DApp开发,推荐访问一个在线教程:
; @' C5 d9 U! K7 D, q, j9 R& ?: w0 }# g# n+ a" N
    以太坊智能合约,主要介绍智能合约与dapp应用开发,适合入门。. j& ?; z: c8 X* Z/ |) u. I

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

本版积分规则

成为第一个吐槽的人

曲水流觞113 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    4