Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文
solc:solidity的编译器& \: q/ U% t3 W5 f. O2 g0 t

1 d; T) G% o7 }+ X5 q    solidity编写的以太坊智能合约可通过命令行编译工具solc来进行编译,成为以太坊虚拟机中的代码。solc编译后最终部署到链上形成我们所见到的各种智能合约。$ a" |4 D4 ~; r0 `% ^- R- h

( g0 e% b: q; X+ d" e9 ~6 H    作为一个solidity命令行编译工具,我们来看看官网都怎么说solc。
  Y  }. y+ z. V6 e' Q+ H) {  [7 Y- @
    solc的安装很简单:6 P4 [7 B0 d" X* x$ p7 @! r: Y( t

( n9 A3 ]$ k# x- T0 {/ a    npminstall-gsolc
# H4 U0 A+ I" E0 C$ H6 f/ g
( z% |! x# Z% i" H    //或者2 i  a# K1 D! _/ g
  ~+ w" M0 [4 |
    npminstall-gsolc-cli5 j6 E" |  D1 H* T& I

8 X* `2 L$ U8 W$ u4 S    //或者
  }3 I; G4 }2 s& q3 \
* s6 ]9 r$ ^/ Z/ @/ O. q6 g+ Q    sudoapt-getinstallsolc0 F: ~$ M& t4 @0 Q& m
) E( v# o5 Z# N2 V+ r& F
    安装完成后我们来看,solc--help,solc--help命令显示所有的solc命令选项。编译器可以生成各种输出,比如最终的二进制合约文件、语法树的汇编或者需要预计的要花费的gas等。solc--binsourceFile.sol,可以编译后输出一个名为sourceFile.sol的智能合约文件。如果你想从solc获得更丰富的一些输出变量,你可以使用solc-ooutputDirectory--bin--ast--asmsourceFile.sol。2 m" N. d2 Y  G- ?
" L% \' j0 ^, W
    你在部署以太坊智能合约之前可以用solc--optimize--binsourceFile.sol优化一下。默认情况下solc编译器会帮你优化200次。你也可以设置--runs=1,这样就按照最小化的方式进行编译,如果你希望多次交易不太在乎成本,那你可以设置成你想要的次数:)。9 A' P( T: Z1 \6 g# L
' O- R# b) p. R5 j" \+ y  {+ U
    命令行编译器会自动读取需要导入的文件,也可以通过使用prefix=path来指定路径,例如:3 H1 O2 S# f# b2 i8 Z$ I/ R
1 r/ q7 {& ?4 F( {5 N
    solcgithub.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/=/usr/local/lib/fallbackfile.sol
8 d" b7 J, G' l# g6 D* G' f1 g$ Y  Y/ @, O9 W% Y# S
    这样编译器就会从指定目录github.com/ethereum/dapp-bin/下的/usr/local/lib/dapp-bin/目录开始搜索,如果没有找到文件,它将查看/usr/local/lib/fallback。solc将只读取你指定的这两个路径的,因此像import"/etc/passwd";必须要通过/=重新映射才起作用。如果有多个匹配,则选择具有最长公共前缀的进行匹配。2 w. Q( Y0 f8 j4 ~! v7 |! a
* M' t& m: B# a9 z: n
    出于安全上的考虑,编译器限制了它可以访问的一些目录。在命令行中指定的源文件的路径(及其子目录)和命令行指定的路径外其他所有内容都会被拒绝。--allow-paths/sample/path,/another/sample/path来切换。
0 G/ Y: I) M; |( S) l6 m& b
, ]* o& [+ ~: R  S/ v    如果智能合约使用了libraries,你会注意到字节码包含了__LibraryName______的子字符串。您可以使用solc作为链接器,这意味着它将在这些点为您插入库地址。" S5 R4 Q  E/ Y$ T
- D/ P- ?2 ^6 q4 ]. r9 j6 ]
    可以通过添加库--libraries"Math:0x12345678901234567890Heap:0xabcdef0123456"到您的命令,以提供每个库的地址,或者使用文件中的说明字符串(每行一个库),并使用--librariesfileName运行solc。
, n: e; {( `: l5 X: n9 f. T
6 K  J2 i9 x. s! ^  _; ~! X" Y    如果用选项--link调用Solc,则所有输入文件都被解释为未链接的二进制文件(HEX编码),在上面给出的__LibraryName____格式中,将其链接到适当地址(如果从stdin读取输入,则将其写入stdout)。在这种情况下,除了库外,所有选项都被忽略(包括-o)。
/ Y' g( h% S0 @/ y. }
, u- K4 ~. G* i9 {    如果用--standard-json调用SOLC,它就将标准的JSON输入(如下所述),并返回JSON输出。8 Q* G& n3 Z# J' P3 `/ u2 \- I
: u; @) e9 y: T- l
    #solc编译器输入输出JSON描述
, j& p! O) J9 d+ V- W) q' N1 S4 [( M0 [" b; X! H" I% Q
    这些JSON格式通过编译器API使用,可以通过SOLC获得。内容都是可以修改的,一些对象是可选的(如前所述),其目的是向后兼容。5 V/ \, A* N& Q/ L6 g1 w

- @& {4 D6 E/ \) N$ J    编译器的API需要一个JSON格式的输入,然后以JSON格式输出编译结果。
; n. R) B. ~. G5 z7 M! p
" b0 Y" X( Z' a# a    注意不允许注释。下面示例中的注释,是官网为了学习者更好的理解标注的。
) H, J5 `( P, t9 }+ M. k% P& v6 `0 u$ x, T( ?+ _$ q" S
    输入格式说明:
3 R/ b7 w8 C" Q3 y
' e9 J4 J& I! I3 t    {
1 k4 P+ U) Y1 `5 l, _+ B2 _6 f% a
3 L- K. s/ }( B5 `8 A% n    //Required:Sourcecodelanguage,suchas"Solidity","serpent","lll","assembly",etc.
- B6 Y) {& E$ s5 N5 g* Q, G: W, v! A( M9 S% e. ~6 F
    language:"Solidity",- k! e* i$ x- h+ f
4 q9 a3 G. U5 Z% d4 b$ Q
    //Required! Q0 o6 `2 `2 C+ B. H, m1 Q  F- Q
+ h) U# Z8 m; j5 P; Y1 B
    sources:2 }5 ^# V! }8 i! R0 m  D5 E' W1 x( B8 Z

6 A; ], E8 E: r" ?/ S( D) x    {
( E# D, w. D" l2 a: a# A3 z7 z
) q" P  ]7 g# K% j0 s8 Q7 c    //Thekeysherearethe"global"namesofthesourcefiles,. v) `8 G+ i) k+ P" d6 v
' s, M1 ]# W$ f- O
    //importscanuseotherfilesviaremappings(seebelow).9 S0 p( C1 }. }5 k8 }3 Y3 C8 s

+ ~; V* k( E2 v( S    "myFile.sol":
. t. `- a$ p; N6 o7 O, K5 |
7 }+ G0 V! v4 m; f( P    {
4 D2 V  W5 c- L8 U' @, y
- L* \% v& ~. |8 [7 v, |    //Optional:keccak256hashofthesourcefile
8 H" d$ D1 l; b# {2 ^6 L" s4 z8 z: n0 V9 v, R, [6 z; N
    //ItisusedtoverifytheretrievedcontentifimportedviaURLs.
+ J7 t+ p) c3 I% T) @% d7 Q# T* E+ W; \0 T( P: t5 L) p. X5 t( G
    "keccak256":"0x123...",
* m2 u! y& M6 k% a/ J- b5 _7 J$ K1 W+ R* M! D. C
    //Required(unless"content"isused,seebelow):URL(s)tothesourcefile.
$ z$ Z. d7 V, I, _% z. n4 g7 f' Y1 l
8 ^. K3 w! L3 P3 Z$ t! O/ v    //URL(s)shouldbeimportedinthisorderandtheresultcheckedagainstthe
! J( q* O& b5 p: Z" r& y) f* m, }( N
    //keccak256hash(ifavailable).Ifthehashdoesn'tmatchornoneofthe6 H5 Q5 s7 ?5 T4 U
2 U) H9 G: Q0 j, k3 ?' h8 d4 T
    //URL(s)resultinsuccess,anerrorshouldberaised.
; D* U  o- M  L6 x* \. ], o8 Y) w$ x, C
    "urls":
' T$ e! x# ]5 `: @( Q0 W  O/ [- X3 F- s" a% {6 }
    [" k6 Q: G6 s4 u' K3 N2 r

, y# h* p: @0 D$ n# u    "bzzr://56ab...",7 T  m$ |3 @4 V! W5 u  E* |# g

+ l. N& \, T4 r# A9 h9 l$ K    "ipfs://Qma...",
! f: q* z1 _' h, J- Z: ?6 K$ ?
5 U0 [5 `1 k4 V) ^$ m" @    "file:///tmp/path/to/file.sol"
8 F$ ~3 F: D, a0 }: M+ b. H( J, B) \: q6 F
    ]
9 Q' L; }) c0 k3 f
/ N- s( Y5 y4 K) m% s    },0 M" t  ~4 l# s

8 `, ?, l5 v& C% h7 y    "mortal":
; d6 }4 Q% X! O; e7 o* f) t8 G( h- S- V% Q2 k
    {8 `0 X: k2 z0 t# m. c' n, X3 \

/ v+ y& ^  o0 q5 E; S    //Optional:keccak256hashofthesourcefile! Y; j: D- Y5 k/ h9 g
( d; U; B! \. v& x0 Q5 K5 Z
    "keccak256":"0x234...",8 r9 ~7 A' [  W1 j  [

  T/ r7 W/ I, M: d! ?  V    //Required(unless"urls"isused):literalcontentsofthesourcefile
6 l$ ?1 c  I- o% x: Z
) r. O  q3 d# s5 K2 i. ?( J    "content":"contractmortalisowned{functionkill(){if(msg.sender==owner)selfdestruct(owner);}}". w9 E# m" s" X1 a& [

9 Z8 V+ R% f- ?* U3 j4 \: `3 O    }0 y5 O0 p- M8 {. J6 \4 Y$ a# O1 T$ m
1 H. p( Z4 Y% d) M( {6 `
    },* w' E) o/ ]2 ^( w4 q+ w+ A
' x8 R. I0 H4 g4 Y3 h  [7 \
    //Optional
% e8 Z2 C2 O1 B9 ^8 @/ {; {# W# q' ?  b1 a: T, V  w" l8 H! g% M
    settings:
4 t2 J6 C( L( q  E
5 [' s& Z0 V. G! y    {
5 [  p$ v% o  O- z, v0 n4 I& q) r% O4 t& X* \( p% c/ S9 l9 C) S
    //Optional:Sortedlistofremappings& I! F+ q# A- \, l7 {% W! B" L% z/ }8 m

. a! j/ f* [+ G. z- H    remappings:[":g/dir"],
* ]7 X( m  h* S% s# t- x9 c, O
    //Optional:Optimizersettings& }8 t+ r  W6 z/ ~

) }4 B; u5 m* _" k% t9 X) g0 p3 B2 c    optimizer:{6 }$ f: d4 b4 \; v* S2 R

$ c3 ~+ v2 E5 ~4 z    //disabledbydefault
# ~; ?  o  W5 \3 J: u
4 ~# A  ]/ y" L3 D    enabled:true,
  q3 ^( X2 _6 I
& G) Z* @' d3 x3 J  ?$ t    //Optimizeforhowmanytimesyouintendtorunthecode.3 d4 ?% q1 h  N% E2 ^
( E" `4 K7 y( _+ L
    //Lowervalueswilloptimizemoreforinitialdeploymentcost,highervalueswilloptimizemoreforhigh-frequencyusage.4 j; h+ o7 L/ A' }: l# L
& O- e" T- s( J: w& x8 a1 m
    runs:200$ ]5 g/ n1 {- N% q4 U
+ g% p! \1 s* ^& z+ G
    },
6 `0 o7 {$ {$ W' n+ K; R" K- b( [4 k# s* t6 M* X$ x( V
    evmVersion:"byzantium",//VersionoftheEVMtocompilefor.Affectstypecheckingandcodegeneration.Canbehomestead,tangerineWhistle,spuriousDragon,byzantiumorconstantinople* I- i: v: `& g8 B; ]6 ~9 ~

! H4 d" k5 N1 D( U    //Metadatasettings(optional)% Q  W4 I( W3 W
$ u- Z5 I7 V/ j" p" [+ b
    metadata:{
  N* G3 `7 o: N% H9 I8 [
: a4 Z- i/ l" b9 O/ B( K    //UseonlyliteralcontentandnotURLs(falsebydefault)
' h- ^* o  l+ V( J$ w  s, V+ b" D2 P/ L3 f- B/ {& t
    useLiteralContent:true7 \# l9 A, A. ~  O( e* ?
2 |* }& I+ C$ T7 C3 N
    },
% H# G  Q9 w3 f' S% \
+ P, y7 s: n+ F+ y2 D    //Addressesofthelibraries.Ifnotalllibrariesaregivenhere,itcanresultinunlinkedobjectswhoseoutputdataisdifferent.
# V3 P4 w$ U# s. v- }  ?5 S, t& b7 Z6 l- E
    libraries:{9 k9 Y( }9 V; g4 u2 D( |/ M
! W0 ]: H& L& Q2 ~3 R. j5 i5 K
    //Thetoplevelkeyisthethenameofthesourcefilewherethelibraryisused.
  ~: P% \" }! |7 ~+ K# K' p1 t: C6 n+ d
    //Ifremappingsareused,thissourcefileshouldmatchtheglobalpathafterremappingswereapplied.
* T* w' B) q6 v& k# w$ P' g2 N2 L! r1 [
    //Ifthiskeyisanemptystring,thatreferstoagloballevel.
0 E8 R9 V1 A6 ^" r5 X/ u6 {0 ]/ ~. q% n# H) O5 A; T' {8 ^
    "myFile.sol":{
' ~: T2 Y" e4 `2 ?/ M
4 p4 _$ `% Z( _- s8 P. C  B! A    "MyLib":"0x123123..."$ N% k1 J+ p) P/ {- }* Q6 ]

( {% M' b- l5 f7 X% ~+ R    }
" c1 @8 p; Y0 Y4 j; I: W! [
. E4 K. Q' E) U7 q& W6 X    }
( @3 V  {! S# ~) o' \$ ^' E  e. O  [8 `8 n- X
    //Thefollowingcanbeusedtoselectdesiredoutputs.
" F5 j2 y1 E% R; ~" ^9 Z# O( l: G% P+ U
    //Ifthisfieldisomitted,thenthecompilerloadsanddoestypechecking,butwillnotgenerateanyoutputsapartfromerrors.
. L& C1 n5 i$ ~2 H" Z' y/ r( w# c& }0 ?+ o$ K
    //Thefirstlevelkeyisthefilenameandthesecondisthecontractname,whereemptycontractnamereferstothefileitself,/ g3 B1 w, Z" v& K% U9 |

5 a" R$ p0 l+ J  v    //whilethestarreferstoallofthecontracts.
* p/ T; i& U' m2 E/ e
4 [4 _0 J; ?3 q, J7 f1 H! z    //& V! R& u6 ?' X9 a5 B

7 a& ]. I6 i& I    //Theavailableoutputtypesareasfollows:
9 ^$ R6 @. u/ M" g
+ i" O9 G3 X) v* p; N3 ^: k0 y    //abi-ABI& L& H* w: v6 e* R- u

; L) o' ?1 B1 F( u' O! b: i    //ast-ASTofallsourcefiles
9 A. X* w# B' Z+ N5 S# A' [9 U$ x/ }4 A" o3 Z% L2 i! w
    //legacyAST-legacyASTofallsourcefiles
' ~& _. z3 k; w
3 c' z& c2 L( i/ v8 Z  K6 q! r    //devdoc-Developerdocumentation(natspec)
* m1 c2 y: n& {! j. q. g; D. k0 i. A" `
    //userdoc-Userdocumentation(natspec)
& p5 ^& ~+ N+ b  \0 q3 k: B
0 G# X  Z- c- `6 h& f1 h6 u0 ~& n    //metadata-Metadata6 e- ~, W% T  g3 _# i4 E
5 d# d0 K5 R( O) B/ j6 A
    //ir-Newassemblyformatbeforedesugaring
. P3 b8 Z) k6 k# O2 G4 F: T1 F5 s+ V; G
    //evm.assembly-Newassemblyformatafterdesugaring  o) x" |, F' v5 P0 R3 V1 @% u

3 v  T  v: o% m9 s    //evm.legacyAssembly-Old-styleassemblyformatinJSON8 l: q( ?/ b0 q# g( @+ x5 |

' M! |; T. ^8 Q/ j, C: R    //evm.bytecode.object-Bytecodeobject; m: ]( S+ C& X# q6 t( X* o
" q" F, R1 I3 ^  m# a
    //evm.bytecode.opcodes-Opcodeslist! d/ x8 Y+ r/ [6 r  r( t
5 b! R0 V$ V' z; V1 V& s3 c
    //evm.bytecode.sourceMap-Sourcemapping(usefulfordebugging)
  T0 ~' t1 U- y8 R
4 f$ k+ F% W1 a' r) ?! C5 D    //evm.bytecode.linkReferences-Linkreferences(ifunlinkedobject)
* V0 X. I- e* S
2 m) j8 T( C. J% H  G  o* S& R    //evm.deployedBytecode*-Deployedbytecode(hasthesameoptionsasevm.bytecode)
+ U  g" X, h, f: }# U! U0 e+ t9 c% {5 K! a
    //evm.methodIdentifiers-Thelistoffunctionhashes* m5 ~3 P7 G' O) T' c) e
' a% u7 j- c& [, N( l
    //evm.gasEstimates-Functiongasestimates" A3 }- ~9 K. F4 k5 W! [

! Q: Y; n  v. d! P' n* Q- c. i& e) y    //ewasm.wast-eWASMS-expressionsformat(notsupportedatm)
# D* |6 V% x1 `# ~8 b
% s  j  H  H0 M8 Z: X    //ewasm.wasm-eWASMbinaryformat(notsupportedatm), C) F7 p4 d$ h- {  M* @  ^
% Q9 Q% M( l$ C6 s, E" Z
    //! z$ C' x% S5 @/ T

" l& g# S, N6 a8 Z    //Notethatusingausing`evm`,`evm.bytecode`,`ewasm`,etc.willselectevery
8 m- V: s' l: c, j! a. X1 j' L! |  o" b4 [5 H
    //targetpartofthatoutput.Additionally,`*`canbeusedasawildcardtorequesteverything.
7 b: H4 T6 t" _" O3 n
- X9 u2 Q' B/ I3 [$ j; c7 b1 T    //
# f' d" T- |0 r; @  J) z' H' O" {" O2 |$ {+ e) N
    outputSelection:{
7 ?( a* w2 _$ }9 y# Z
, d8 M6 D! j% d% y3 f$ J5 U3 T, U2 H    //Enablethemetadataandbytecodeoutputsofeverysinglecontract.) g3 R  P8 K- U/ P  t

5 v1 X  _2 l* w& p7 W    "*":{; V' i* X7 h- y- D  T# N
- Y8 V2 Z+ t' u  H( I# H$ J# i0 E
    "*":["metadata","evm.bytecode"]
# \0 O9 D7 d8 P9 [, {  u
  }1 l7 F8 l' g    },
6 j, G5 D/ |, c" n5 |& y
3 Z# e6 ~) \8 ^# ]; s' h    //EnabletheabiandopcodesoutputofMyContractdefinedinfiledef.; m+ P' D6 t: A1 @( F9 `
0 [6 l7 p; U7 C% h0 ~
    "def":{
" m. q5 ]; J! B' ]+ ^3 ~3 M1 w. s4 }( B( m
    "MyContract":["abi","evm.bytecode.opcodes"]6 }5 G% d7 Q7 p" U3 ~6 O
1 f+ r2 q% x* }; i% Y( s3 `2 o
    },9 m! y/ @7 J. [# R% X
; M  C! d! s" t+ R! p
    //Enablethesourcemapoutputofeverysinglecontract.
3 s1 ~6 k! ^; ?; z1 w# s% c# y+ y+ w- ]: V# a* K
    "*":{
; j# J( x0 K8 y( W2 ~2 A
9 E  Z. o* G- y( ?. u    "*":["evm.bytecode.sourceMap"]
  c6 C1 W9 ?0 P: z+ D- n  v
4 E- `7 S) w# M# H9 i% l8 S0 l    },
3 H! J1 @9 Y* @$ S9 @: M
2 u! J" S+ M( F. j6 W  x5 A% R    //EnablethelegacyASToutputofeverysinglefile.
3 x9 h/ H. @' i
' I4 p6 Q- L" U    "*":{
2 Z( p% m% \- `% [  T- F, i! N; N6 n7 J8 c) X0 Y
    "":["legacyAST"]) X) s4 \5 V8 [! G% x7 d

. \+ b" `) D! H    }8 P: i6 f% B/ ^# {

' h' E, @3 r0 G& I: K- P    }6 ?2 {, S3 L  o# D8 n; {9 k
+ E# m3 x$ X  E4 T
    }
) V, g3 n, ]2 ^) |) V) s4 P
! j% I& ^" Q- z! a) Z    }; K! }' R$ H9 v- S+ y: u+ b
9 [  z# h: o& U& B- C& O0 S6 M
    输出格式说明5 h) L. ~! M. C7 {! p9 S; x  P

0 v9 W2 R4 R1 W# o- q( a% }    {
8 s* ~# C% ~5 S% @$ u/ e& q  \" S+ Z3 _
    //Optional:notpresentifnoerrors/warningswereencountered7 |4 D8 d' ~2 X# v" L9 c

& ~3 r1 x( ^# R    errors:[& s: e* i' l* X. d' A" K
) k! \; J( {  @5 g  d9 @0 r/ c% _& K# H
    {
* n* d: G0 |, K( k' \) e4 G# K6 y& k0 `! T1 {
    //Optional:Locationwithinthesourcefile.
8 p( h* M0 Z$ p$ ^, U( ~
/ ~6 o5 f, c2 A9 E! X% K    sourceLocation:{
; F) C' U4 m: E0 P! G- O. ]$ \( E! Y7 l
    file:"sourceFile.sol",' Y4 |" E+ J& Z9 M2 R; K8 i' C3 f3 Y: D
$ t. M4 ~/ f0 k' U
    start:0,) V1 e4 G. Q5 ~

$ x; c, q) m# W4 I9 a8 u- u    end:100
3 v' X7 k. ~$ ^8 v# b+ K4 |2 l1 e4 t2 d- f
    ],) p+ P/ |$ V2 p1 c$ w
9 }2 }8 L: n. v; ~" w% s9 Q9 M3 r
    //Mandatory:Errortype,suchas"TypeError","InternalCompilerError","Exception",etc.
& G% T( k7 ?/ f
) t: q; N7 A  r& k1 ?    //Seebelowforcompletelistoftypes.7 h! X" ~2 w* P  q( G# r; p
/ w& }6 w* d3 P6 M, F. N# ]* F4 l
    type:"TypeError",; J7 h2 K; w0 O* }* z# l' f- y- e) u
- H: Z0 m. s; U
    //Mandatory:Componentwheretheerrororiginated,suchas"general","ewasm",etc.- M  d! O, E$ Z, X- w2 ^1 c

  _& \- B7 G) w' L    component:"general",
" l5 O1 O, l/ @3 K, W- A  \0 v" J) o
    //Mandatory("error"or"warning"): e* C2 g3 [; F0 w6 I% ]
% R% v/ c8 Z( c- H7 @4 L' A, x
    severity:"error",! j0 ^( q- T8 @/ j3 M

1 d" R+ Z* q3 a9 S7 h2 Y7 g7 C    //Mandatory
2 X6 y' a, h5 S! w% z2 ]& H2 ^4 r. ^0 R' a. Y' b
    message:"Invalidkeyword"1 n# X+ ~! \! H

  b- ^4 [# S& A+ ?$ R. X    //Optional:themessageformattedwithsourcelocation) n1 `' A; B/ Z0 f

- j2 j, B! i( B4 |, E1 P  E; }    formattedMessage:"sourceFile.sol:100:Invalidkeyword"3 h  m  E9 n" D
1 q- M1 q, f! X9 A8 F2 d( A4 k
    }
& J0 P; [) X3 {& e3 p5 n# X
- m1 |9 k( x0 O+ {* M/ c    ],
- e# H9 F5 H9 E0 Y; k
+ S8 u' g- L8 ]/ X1 x  z    //Thiscontainsthefile-leveloutputs.Incanbelimited/filteredbytheoutputSelectionsettings.
9 W4 B" T/ I# V/ ]1 y9 O1 @+ h; Z6 G4 i6 _& n0 j
    sources:{1 p5 E  f" Z( r- _+ u$ V6 P

" W$ p2 x% U! |. U# K    "sourceFile.sol":{" q% Q. }3 u+ h/ ~9 q$ G3 c

9 Q6 _( o& V$ D( R    //Identifier(usedinsourcemaps)
" z, f  r6 ~1 @5 V7 h. I) r6 U* r* U6 e/ u
    id:1,1 a7 l; X  x2 v% t, h* \2 A

9 @" G1 e2 F3 K+ i5 G/ j! p    //TheASTobject5 c# I' Y0 B5 f; J+ H' ?) V1 z

9 v( C" \0 E) n1 k9 P7 [9 y    ast:{},
, _9 u$ K8 r5 ^/ x5 A1 M% F9 L$ y+ P3 R, `% Z* B
    //ThelegacyASTobject
6 t) ^, e* F: w
5 l7 ]1 J, e+ S1 o. `2 f    legacyAST:{}
5 g! `2 X# G7 e- }8 F; |3 `! Z/ f  Z6 g) F* J
    }4 ]% q  w, Z. Z8 Z
' h6 A3 b2 _3 b
    },
) k) ]* o2 W# x$ _4 b. H2 z, {; j/ S! {8 e( N6 ?: ]
    //Thiscontainsthecontract-leveloutputs.Itcanbelimited/filteredbytheoutputSelectionsettings.1 m) V; ?) n. F' Y8 z! @5 ~

& c; {$ b$ S: E' H    contracts:{
' g6 t0 f, T7 a& ]4 Y5 K
8 ^4 D6 R, V* X: W  ~  \    "sourceFile.sol":{
2 \1 n# k" O% L0 G9 G( ]
4 {# }8 O, k1 I1 z& r4 ^! x    //Ifthelanguageusedhasnocontractnames,thisfieldshouldequaltoanemptystring.
8 @* s  \, n* J2 Z8 a7 S2 \5 d; T) b+ t$ a& ~/ `
    "ContractName":{4 I) C  ~) S+ M+ }

4 [+ j# E. S4 O6 v    //TheEthereumContractABI.Ifempty,itisrepresentedasanemptyarray.
  \6 g( x, ], y, _9 q
, X$ r! q" P7 w7 M& y    //Seehttps://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
* i# |% O0 q* S. `7 W6 M
8 g* y: \2 o+ l" s. e! J3 |    abi:[],0 B! |6 k# X% Q* w' b
4 I6 k5 f, a4 B# k& N- U- V2 U  l
    //SeetheMetadataOutputdocumentation(serialisedJSONstring)
# K" ]" P7 ]" G: H8 w8 e- w" F7 `- S6 b# Q$ C
    metadata:"{...}",) p& V0 e/ ^0 B4 y
  z/ w+ L+ H! F5 [: ?! S
    //Userdocumentation(natspec)2 `# `3 J8 q9 Y/ E0 D! f. z

1 l6 h' J# u) F; \    userdoc:{},
9 j  L) N3 o% E$ k- P1 [6 k/ y: F3 u- W! T0 A4 x& t/ _! d8 W1 \
    //Developerdocumentation(natspec)& l( r) ?" n1 W# j) Y3 a3 [

  }. x: I% j5 q1 I  E    devdoc:{},' H9 V" R) S5 R+ ?! e0 x
) \) S3 C" L. r! _. S: n3 @* M
    //Intermediaterepresentation(string)
5 h" H# H8 V! G# V) U8 ]8 e; U( k# c" U
    ir:"",( P' g! m0 ~3 B; r9 k$ {
6 h" D0 I$ e! _9 R+ _2 P* X
    //EVM-relatedoutputs
. P( I% j  o5 d7 i6 q' e& c0 B3 R7 m3 d9 m3 S
    evm:{  v) v+ K' n. Q- |3 d0 r

9 u, Y: x  d$ I2 x5 j1 c    //Assembly(string)
$ b& l* X" l" B) W3 W2 f3 H2 n: A2 b/ F0 a5 u
    assembly:"",
! v; h0 M1 z6 J
  W" `9 I/ G- b. G; n- F8 c! v# c& q    //Old-styleassembly(object)
1 z0 E( Z& g4 x* ^. ?$ I8 w6 ^9 ]2 @% O& G7 ?
    legacyAssembly:{},) `9 V% s' f6 p

( B% `% g% f4 M/ d1 R2 F    //Bytecodeandrelateddetails.+ |, |% j. m: ?! J& T! ~. }3 S& K) N) U

& ^) L/ V$ y9 w4 z    bytecode:{/ X* Q  b2 T2 L0 p
+ Y6 F/ f1 I+ Q9 D. [
    //Thebytecodeasahexstring., d( g- ^1 H, a5 x2 \

, c$ `+ B2 l/ a' Q( @% `    object:"00fe",
$ R, r  M  }2 g0 r/ P
+ M* Z) |+ D2 W, C, K    //Opcodeslist(string)
$ f4 D. H$ o# Y2 Z- ~
4 Z( M! F4 z, ]    opcodes:"",  V3 p/ c3 u* |

% L# E3 D3 d: g  m5 M* T    //Thesourcemappingasastring.Seethesourcemappingdefinition.
/ i- {0 c& V$ `+ w$ @8 f" d, l1 @4 k4 f& T. Y3 g
    sourceMap:"",
$ K; Y3 y/ ]0 O$ }! Z5 Y5 ~3 y, }" L5 U- A7 a" X$ v/ S8 g; a
    //Ifgiven,thisisanunlinkedobject.+ P* x1 w0 g! R( ?: t/ c

0 w, U8 z# ?+ H3 s* E9 M    linkReferences:{
) ^5 e# Q* r/ K9 n5 T/ P7 U' f4 B/ x: l7 {
    "libraryFile.sol":{
7 J2 W; H! s0 ]# P6 X: f# L4 b( N$ y
    //Byteoffsetsintothebytecode.Linkingreplacesthe20byteslocatedthere.
6 b7 p" A) ~9 \, ~6 ?% {  {+ X  x
+ p2 Y0 a/ A; k+ q    "Library1":[
' ~0 n2 d: I1 y6 Y; N2 I5 p. B0 S: H' y* y9 k  b, O
    {start:0,length:20},4 a( H) O7 u( b+ p

+ I/ L+ A% K" R9 v4 L$ X    {start:200,length:20}
8 ~3 H' C) k/ ?( b
0 ~( m. y/ u3 b* p, y    ]
* q$ {% K' {# T& W- z
3 e" I0 |% V3 j    }
) N5 F, L3 O$ q& q8 ?
( R# l/ l- _1 U. q! \    }
  E& n+ o1 J5 K# L0 L
! u8 b* X) }" Z    },* ^- ~3 b3 t3 K  n( C
( l$ _. K$ G9 {0 ~' R7 ]& h* {
    //Thesamelayoutasabove.
; n0 |2 S$ q4 {" S0 z
  q1 ?- `. g8 K+ p8 H    deployedBytecode:{},
- ?+ U% F  D$ N6 F- L: Q
5 n& [' h  L. a! L$ x( _    //Thelistoffunctionhashes
+ g+ |" g+ l. h6 _+ p8 h5 V" u# N9 k* c4 S7 a9 v7 y
    methodIdentifiers:{! K' u$ k: d. f, \
; b  Z& q+ E: k2 w* G; ^3 s% v1 d
    "delegate(address)":"5c19a95c"/ h. k" t' X5 V9 ^1 W+ `* g
1 t# n) Z! c+ ]8 |
    },: j4 w4 j* C' j# e  B' V& x

% W. I1 V# @) S8 E    //Functiongasestimates3 R- v. b+ `8 X- V4 X5 C$ l3 b9 ?

3 w8 F4 g& {, l& h' Z, d    gasEstimates:{
2 S9 {% j0 g0 u9 R) V# M" e* [; I' g) T
    creation:{' W! U  x5 L+ z; h5 m/ [
8 V5 S  _' _# a. E; w* X8 w+ w6 ?4 F
    codeDepositCost:"420000",
- f: D( e- @; {0 E' r$ S0 L* f
! S  N# ^3 g1 E$ w. R/ X    executionCost:"infinite",
, I( I7 j% H% K" l( P' r2 r4 X# k1 w: y. u2 X: T
    totalCost:"infinite"
8 m+ X* p- f( e3 ]& y& J
; w; _' [& ^. n; E, o5 h5 u    },/ s( H+ M0 o2 f- b& o1 q2 O

& c1 N5 i" j0 X7 b% g    external:{
, }8 {; M8 S8 F$ O; N! c- K3 j- v, v  Y( |2 E! d! f
    "delegate(address)":"25000": V- ~7 c5 s6 p1 L  }
' c+ N+ y# T0 ~+ d9 \! d
    },2 ?" \# ?; G0 |' \: H
9 ^2 H# R+ x/ i$ f# o! p- {; I
    internal:{
% ]  G; m, a5 `# a& |# e4 Y! g( E" |& R, a$ B$ \; M9 \  ?7 h
    "heavyLifting()":"infinite"
9 o7 H) J! J; K9 h* D
) A" ^7 k0 Z( [+ S/ j    }- [8 x3 y9 P! Y; `; Z

5 E+ `# K* P. D- W8 C5 e0 u* Z    }
5 }1 M- l+ [0 H+ M! V# I8 [: J( W
3 N$ e0 m0 b8 a: e    },
5 s6 Q( K$ d* M( g; S" j( c
$ a) U$ D% ^" N7 |) g    //eWASMrelatedoutputs
& l1 O% _3 r1 S: Z- @% K) ^
( V3 ]0 B. O; M2 `9 x4 s    ewasm:{' o/ Y2 h- f/ j. Y' i( u" v% G8 k
9 {& W: {2 a3 o( ?" K8 h
    //S-expressionsformat
6 r! ~  i$ \  n& j! Q4 u6 p6 I( G! z5 p9 n' H& L. t' V
    wast:"",7 s, c) R9 x' T' a; O
) S* o1 B3 |. w& Z% A, o
    //Binaryformat(hexstring)
, n1 j8 m2 r0 l% `, Q7 d. G- Z# U/ D& w5 Q+ _
    wasm:""' O5 A6 B- Q) z+ H& u: X' \* U& X# P

6 \6 l6 m) h, y" J! k; Z" Z    }
7 D+ ^. a+ V2 o8 s; C4 z
+ \0 ~- V/ c9 B2 u: k& U    }
9 ?, ^3 t" N) I0 I) {  d6 `; i& O3 N3 q7 z
    }  N1 z  m* Y5 S8 \
% d1 n  E: G- P' W4 N
    }
8 A" r+ p8 v& L/ h, Q7 N1 `: V; z
    }
; b# I! ?( q, Y  G" W
& h6 u/ m5 B; a# x6 q! O    错误类型说明:& R8 O4 X9 k2 J- w8 V7 o
( }5 w8 W  S8 h/ M" {
    3 z* {6 f0 D2 m. ~8 z
) Q& e0 K* M' w
    JSONError:JSON错误,JSON输入不符合要求的格式,例如输入不是JSON对象,不支持语言,等等。
8 ~% [' E7 L) b' W
; ]' u& U8 t. m8 i  N6 h    IOError:IO错误,IO和导入处理错误,如提供的源中的不可解析URL或hash不匹配。9 x  u* m/ [0 N" _9 P. x+ f* Q
) S; S& W. \2 Q! d& X% m
    ParserError:语法f分析错误,源代码不符合语言规则。
% `7 w5 r- v0 P: b8 c1 Z# c" v1 j8 a5 ]* x4 [  u
    DocstringParsingError:文档解析错误,无法解析注释块中的NATSPEC标记。
( _2 Y& e! Q, F- d/ z9 l
/ Q) o9 m1 M& E8 a! q$ O    SytRealError:语法错误,如continue在for循环之外使用。' X7 s: y) L/ r9 L. L
5 U1 F: q& T) M( |9 n+ j
    DeclarationError:声明错误,无效、不可解析或冲突的标识符名称。例如未找到标识符
; ], M2 `4 L- W2 v+ G
+ i* k4 ]2 o! S( t& u    TypeError:类型错误,如无效类型转换、无效赋值等。
  E2 N/ c& m: h1 `
( Y3 `; @7 ?4 h$ V  E1 U    UnimplementedFeatureError:编译器不支持该特性,但希望在将来的版本中得到支持。
- ~9 s: Y* c  M" O: P, O$ b
- P8 w! w: ~7 w5 ^+ }    InternalCompilerError:编译器中触发内部错误,这应该作为一个问题来反馈。
, w# Z; z' M" z! I' |3 o& y7 a8 K2 [- N) H
    Exception:例外,编译过程中未知的故障,这应该作为一个问题反馈。
% F; f* M. @$ h4 b: Q- g! L7 c9 v/ J* W
    CompilerError:编译错误,编译器堆栈的使用无效,这应该作为一个问题来反馈。1 t) F( Q$ Q  T$ F4 x% r# Y, o1 e
/ @: d" {2 y/ a# p% S
    FatalError:致命错误,这应该作为一个问题来反馈。# w1 ]' v; D( e+ ^: U* B: P
! S8 k+ r/ y, I
    Warning:警告并没有停止编译,但如果可能的话,应该加以处理。$ r9 ^/ a* R2 O9 m8 C

$ |0 u; U. Q7 e! K/ E    . H. i# I0 K+ e
  T0 w0 |8 A: d; {* D
    原文请访问:solc
) E% N+ Y" z; F1 }# h  r9 S5 U5 s
    如果你希望马上开始学习以太坊DApp开发,推荐访问一个在线教程:8 ?$ O; q# G& f) ~, Z( Z
0 h& n& M9 L0 h% u; Z3 n
    以太坊智能合约,主要介绍智能合约与dapp应用开发,适合入门。
, U6 u2 s& K' O' G7 L: z; W6 q* u: R
    以太坊开发,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

曲水流觞113 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    4