Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

EOS智能合约的多索引表table

西门幻雪雪vj
179 0 0
建多索引表是一种为了在RAM快速访问的方法,主要用来来缓存状态和数据。多索引表支持创建、读取、更新和删除(CRUD)业务,区块链不行(它只支持创建和读取)。! n6 W! _& h8 U; u( Z7 d6 k
    多索引表提供了快速访问数据存储接口,是一种存储智能合同中使用的数据的实用的方法。在区块链记录交易信息,你应该使用多索引表存储应用程序数据。1 a+ o0 c4 I/ K8 ]
    使用多索引表,因为他们支持为使用的数据建立多个索引,主索引必须是uint64_t类型和唯一的,但其他的索引,可以有重复的,你可以使用多达16个,类型可以是uint64_t,uint128_t,uint256_t,doubleorlongdouble。
1 e0 u8 d- [* j0 C3 {    如果你想你需要使用一个字符串做索引,需要转换成一个整数型,将结果存储在随后索引的字段中。
9 H* R, m2 }  i9 ^    1.创建一个结构* g% d) V6 k0 Z6 _% C
    创建一个可以存储在多索引表中的结构,并在要索引的字段上定义getter。2 M, V+ J5 c+ e2 b
    请记住,这些getter中必须有一个命名为primary_key(),如果没有这个,编译器eosiocpp将产生一个错误…"itcan’tfindthefieldtouseastheprimarykey"即它找不到任何一个字段被作为主键。( u2 M9 L" g6 g) N
    如果你想要有一个以上的索引,(最多允许16个),然后为你想要索引的任何字段定义一个getter,这时这个名称就不那么重要了,因为你会把getter名称传递给typedef。
. Y+ u: _1 v( R% N    ///@abitable
. _! ^; K: P0 _4 u* A    structmystruct" m7 W; T4 A& g# e* u
    {
# t. d. h% j' ]2 p    uint64_tkey;: }2 C5 p. J& Q0 a
    uint64_tsecondid;. b' E% E# u7 _7 v. i* G" o$ x! R
    std::stringname;
. {# w5 p& ~# s& r    std::stringaccount;$ m! X; c. r2 l- _2 f2 W
    uint64_tprimary_key()const{returnkey;}//getterforprimarykey
6 h7 ~9 c; i$ f9 ^5 U8 F5 K    uint64_tby_id()const{returnsecondid;}//getterforadditionalkey
5 N% j5 G+ }! Y! @' J    };6 Q. }: h$ j, ~
    这里还要注意两件事:
: L6 F! I/ H7 ]7 x: V    1.注释:
; S: \3 h  J" E4 t    ///@abitable
2 r/ T0 U1 |! l, T    编译器需要使用eosiocpp来识别要通过ABI公开该表并使其在智能合约之外可见。$ y9 `, F4 Y- |0 H6 a' y8 V/ o+ `' Z
    2.结构名称少于12个字符,而且所有的字符都要小写字母。+ s% y3 j/ U" E
    2.多索引表和定义索引
) y4 E1 M* W( d, z& T  w    定义多索引表将使用mystruct,告诉它要索引什么,以及如何获取正在索引的数据。主键将自动创建的,所以使用struct后,如果我想要一个只有一个主键的多索引表,我可以定义它为:2 H5 H3 H# M7 i& c' B8 ~
    typedefeosio::multi_indexdatastore;8 V5 W/ T: W2 Q2 R% P/ B
    这定义了多个索引通过表名N(mystruct)和结构名mystruct。N(mystruct)会对结构名编译转换到uint64_t,使用uint64_t来标识属于多索引表的数据。& i' P5 H2 b1 K+ {0 k/ |
    若要添加附加索引或辅助索引,则使用indexed_by模板作为参数,因此定义变为:
0 Q4 I3 j/ ^: j4 V8 R8 W    typedefeosio::multi_index>>datastore;9 J7 D) O5 f; P6 f. g% O
    注意:, b+ h. e5 ?) F1 [: g
    indexed_by>
' M$ x( n5 d2 d  V% ?    参数:
4 q5 |9 ^5 o: Z* k    字段的名称转换为整数,N(secondid): d' \4 V5 [8 I7 {9 @. }
    一个用户定义的密钥调用接口,const_mem_fun
) @3 Q1 X0 q. ?0 [! i' k! Y/ \9 n    来看看有三个索引的情况。3 B* q3 v! u0 }
    ///@abitable
; K) C  C/ M3 t6 u9 U0 Y/ ]    structmystruct
2 ]$ \4 k" R, p  w; {$ f8 p    {+ ~- J  r7 B% c! }! o8 H& \4 m
    uint64_tkey;, R2 [' [2 l2 g5 Q2 ^4 e
    uint64_tsecondid;
4 _" a3 V& h# g% u2 g0 ]8 w/ z8 k    uint64_tanotherid;
  u0 I- {. {# ~) I( s1 x    std::stringname;
. o* _- o$ L3 c; e% {    std::stringaccount;
5 W- M5 W6 U4 ?: D  k/ W, L9 A    uint64_tprimary_key()const{returnkey;}. \' V& c' N* j. Z* g
    uint64_tby_id()const{returnsecondid;}
7 t2 f: ?, H: J    uint64_tby_anotherid()const{returnanotherid;}
# {0 V6 ~! O' \% s$ d5 y3 E3 Y; A    };" G% v" J, n9 o) F
    typedefeosio::multi_index>,indexed_by>>datastore;# j( C: k( o' X7 G% N
    更多的就不列了。
# ^0 d0 |( E) Q) x: i    这里要注意的一个重要事项是,结构名与表名的匹配,并且将出现在ABI文件中的名称遵循规则(12个字符,所有都是小写的字母)。如果它们没有遵循这个规则,则表不会通过ABI可见(当然可以通过编辑ABI文件来绕过这一点)。+ W) h+ Q& R, _
    3.创建定义类型的局部变量
6 ~) z$ D9 Q/ X: A6 W# Z! M    //localinstancesofthemultiindexes
% n" b0 @% Z5 m9 ?$ U5 F( T    pollstable_polls;3 d- o7 D9 d2 U
    votes_votes;
: |3 R5 K0 C' n; }8 s' W+ A    现在我已经定义了一个带有两个索引的多索引表,我可以在我的智能合约中使用它。
( y9 L+ C4 }0 X    如下是一个智能合约使用两个索引的多索引表的例子。在这里你可以看到如何遍历表,如何在同一合约中使用两个表,我们未来将增加额外的教程,利用多索引表。
; S* \9 Q- a  A. a    #include2 H. `2 O' a- U! O# _. y
    usingnamespaceeosio;
1 E+ P9 X1 h$ u    classyouvote:publiccontract{
. j/ ^! n) d' v. M" h    public:
4 q) Y+ p$ d2 p    youvote(account_names):contract(s),_polls(s,s),_votes(s,s)- V) F# x: I5 ]+ X: ^* L) t
    {}
8 |5 K& ]3 y0 s0 o- k4 p0 q) |    //publicmethodsexposedviatheABI. }2 `% w$ V6 Y
    //onpollsTable
' s+ G3 N; P$ r. z* u% {' I9 N9 u    ///@abiaction
7 ~* x: D0 B: p! P, u) R    voidversion()
# y" @8 G$ M) N$ Q( {+ R' U- k( ~    {! a2 l3 ?4 L$ ]: E* L- M3 a
    print("YouVoteversion0.01");
9 h# E' X3 k/ j: l, `  }; K    };
* K5 }2 ?1 }) T3 q( s/ M& I    ///@abiaction
6 j1 n  |6 a2 K0 p7 M! Y5 c    voidaddpoll(account_names,std::stringpollName)2 [; B* W# d& I2 e! q
    {
: Q0 A) _. D0 s( }, |    //require_auth(s);
1 p( N9 a1 m% |6 x* j6 Y: p    print("Addpoll",pollName);
8 r- e' ~" H1 }* |    //updatethetabletoincludeanewpoll
8 P! S- i; h- ?1 L$ x0 r" H6 u2 |    _polls.emplace(get_self(),[&](auto&p)
+ \% x- T4 a( U/ E" J6 ]. _    {
3 J" A- U* k1 R3 K- x/ v    p.key=_polls.available_primary_key();
2 l7 P4 |  d) ]* `' B% Q    p.pollId=_polls.available_primary_key();9 S) h2 S  h8 y0 b. i! ^, _
    p.pollName=pollName;
$ B1 a) ]8 K3 D3 |5 ^1 u    p.pollStatus=0;% e+ A6 `/ S* P, S( P. Q* S0 |* N$ _
    p.option="";$ I2 B% [: _' @0 e2 X
    p.count=0;- r: k: }( x+ x9 _2 ?8 ]# A
    });+ m, R' `! b6 ^4 y" x
    };$ T6 }) ?4 X' k$ B
    ///@abiaction- N. ]+ A# G" G
    voidrmpoll(account_names,std::stringpollName)! |5 }- g- N2 S" T
    {( |& s' d& m) E' T* ?
    //require_auth(s);
5 t+ J1 X3 K- M  |9 l    print("Removepoll",pollName);
, [0 m* y9 A4 Q& P6 I2 ]! q# Z( N    std::vectorkeysForDeletion;3 o6 ^* b( m9 k2 X( g) K/ B7 P/ G
    //finditemswhichareforthenamedpoll
* s4 e+ l: A0 g9 o) h    for(auto&item:_polls)/ N0 X# u1 ~) R1 x# s" i: @$ Y# C9 L
    {3 u. y  P; Y  F
    if(item.pollName==pollName)
0 P1 ~$ |/ [0 A& e    {
* @) _2 {; t# o' u; l2 }1 U    keysForDeletion.push_back(item.key);
: B- e8 f2 _/ k$ w( l7 n8 Q9 M: V) @    }8 s7 A- o6 q  T! v0 k
    }3 q2 f, `: O! T) V: w
    //nowdeleteeachitemforthatpoll
; ~( h4 b( T- n# H    for(uint64_tkey:keysForDeletion)
& n5 B8 c3 y& {- {. F+ a2 P0 R, {    {
7 C) o. B- R5 q. m: \, C6 [) ]# G    print("removefrom_polls",key);5 H  N: c) ~) ~3 F8 w
    autoitr=_polls.find(key);2 E0 O% x9 u- r! A, i! O( J
    if(itr!=_polls.end())) L( d8 F* f) P4 w% U  F! f8 P
    {
  t9 c9 o3 {" m+ n    _polls.erase(itr);1 D- W9 o2 }* J
    }2 p5 O, m! o" K+ x2 J
    }2 Q( o/ h; I0 e# ]" f
    //addremovevotes...don'tneedittheactionsarepermanentlystoredontheblockchain
$ a" v9 p% C: i9 U. ^2 n    std::vectorkeysForDeletionFromVotes;
' ~' k8 M6 s5 g% x8 N2 S. w    //finditemswhichareforthenamedpoll
- ^; b7 ^& V5 r1 V    for(auto&item:_votes)
/ d+ b6 P4 r  ^& N7 Z- G: ^, n    {
# z3 s, b! F! t" C    if(item.pollName==pollName)
) c- P5 _2 @$ F5 E7 N  m    {
: m% c9 o0 e& Z; n    keysForDeletionFromVotes.push_back(item.key);; ]' U$ L8 [( M
    }* g; [- X' ]) t1 F+ X
    }
! }$ u) @/ N$ [' T& d' F8 y    //nowdeleteeachitemforthatpoll8 W8 n3 G6 e: K$ N  C
    for(uint64_tkey:keysForDeletionFromVotes)
& {! L% o( X; ^2 B) U" }    {
4 n1 g: u- Q, q9 l4 S: v, y5 Z7 T    print("removefrom_votes",key);5 e- @) ]" h" A' C" W2 h/ [+ i* [
    autoitr=_votes.find(key);3 m' u( `- g. g
    if(itr!=_votes.end())
/ C- H- y3 ]$ z5 L# K5 N    {4 M# B8 s* u4 K1 p
    _votes.erase(itr);
( n& B* {+ R( ~& x0 @* H    }# B0 i7 A8 a# i. I
    }
, r4 ?2 k' j6 r! U$ G" }    };6 c+ z; B" P6 |
    ///@abiaction
+ p3 F9 X9 K6 S    voidstatus(std::stringpollName)5 a# E, j- c) w* d: r
    {
' V) K2 `! F, E9 D% `$ i, q    print("Changepollstatus",pollName);
6 V5 @4 _2 \- l8 u' p) a$ \    std::vectorkeysForModify;9 m) J0 n3 g$ X; k# J: m
    //finditemswhichareforthenamedpoll, }& _0 P. ]% \; U; W
    for(auto&item:_polls)
- T6 W* M8 ~5 i' Q; Y7 A    {( v" {  W7 g' m1 _
    if(item.pollName==pollName)5 V; x% V" p9 b8 q
    {
* F% n9 R9 \- x" K' t" k    keysForModify.push_back(item.key);# O2 m" p2 X6 u, |2 V, T
    }
1 X5 ?" u2 q% L    }
% D$ F# R5 S- Y# Z. K: m    //nowgeteachitemandmodifythestatus
+ ^( p. C7 I1 |% y" N    for(uint64_tkey:keysForModify)" i+ m0 s/ q: M$ m, |7 M. n2 X4 T0 g
    {
- _+ H( {# q5 }1 O% w    print("modify_pollsstatus",key);
7 Q# ?0 _6 ^! E! [    autoitr=_polls.find(key);
; X9 B! H; B: c: g& l: U- K% P    if(itr!=_polls.end())' L9 c( A; p  y! |8 |3 H% M
    {
, S. t5 ]6 }$ @# x/ @  K* f    _polls.modify(itr,get_self(),[&](auto&p)- ~) L8 k, s6 s8 G! _
    {
9 o; r* k" u' [  ~# b" o. q    p.pollStatus=p.pollStatus+1;
  [% Z  y+ p: Q7 b6 }/ l# d    });8 y& x) e! e8 J  e( }
    }6 x3 B  p0 s7 H' J7 I" V  V
    }
! F9 h% o$ y$ m) Q    };! f8 J: ]  d, H) C% N" n5 ]
    ///@abiaction
# u# ^6 u; t8 `4 b+ @5 W2 s: z    voidstatusreset(std::stringpollName)4 A/ W* M! w$ S/ z% E
    {8 L1 E; P: h* U
    print("Resetpollstatus",pollName);
; g. O! W; n/ E2 d  Z    std::vectorkeysForModify;) a" g. x* ^" U# B! m
    //findallpollitems
# p$ C8 f* O* Y- g$ ~; U- }" |    for(auto&item:_polls)
( B; ?/ b* p6 D- I8 e0 u    {
2 Q2 U( i' L0 l, V6 v. ]8 t; w: F. u    if(item.pollName==pollName)3 f0 c! g/ a9 }. w  b# o; I9 \
    {
: R. I7 m) n9 I# ~) b* X    keysForModify.push_back(item.key);
4 j4 K% ^% G% e" m" U    }
/ w" t: T+ J6 w% P1 d0 q0 m# k    }! O* b8 @5 ^- k) d8 r4 S
    //updatethestatusineachpollitem& Z+ y( D* g/ j( T4 l1 D
    for(uint64_tkey:keysForModify): y/ T6 s; N. A
    {7 Q  ~, h, N- B- x5 }5 l2 P. n: w
    print("modify_pollsstatus",key);
: ]/ L) B  d6 \( w    autoitr=_polls.find(key);( X5 g% S" H9 h( k) T
    if(itr!=_polls.end())& Y( d/ S  c' c2 ~
    {
- T5 j" j- H8 |: m- s    _polls.modify(itr,get_self(),[&](auto&p)3 b  m, \$ a) u
    {! Y0 X- V) ~9 M6 M) ]8 E4 r
    p.pollStatus=0;
+ ]* l6 o$ T0 e0 o- q; n1 N    });' V$ _2 y& i  M  N% n- p
    }
8 J( A% {5 t* Z4 O( q    }
6 |3 W" M! p& Z1 Z4 U) f/ `    };* l4 O4 r) o6 t- e# Y) g& t+ ]4 @" F
    ///@abiaction$ A1 P2 f& O! m- d$ T
    voidaddpollopt(std::stringpollName,std::stringoption)7 F& @* U2 t6 A4 B0 i, H3 D
    {
2 ?: r3 u& j5 W4 X5 E    print("Addpolloption",pollName,"option",option);+ p# |& b$ \% N! s
    //findthepollId,from_polls,usethistoupdatethe_pollswithanewoption. @, l' N+ G. _
    for(auto&item:_polls)
  V8 f/ ^( T! Y9 D$ _: d9 l    {( B/ e- Y' s/ r' m% i: J
    if(item.pollName==pollName)) r0 n. E/ J" @8 @& {5 h4 o
    {3 W- E! V& h1 Y
    //canonlyaddifthepollisnotstartedorfinished
2 S6 ?8 N! e. `- `    if(item.pollStatus==0)' G- G- z( Q9 {5 k! X% T1 C
    {. N; c' K* P: B2 p0 J7 |  N6 \
    _polls.emplace(get_self(),[&](auto&p)
3 B# P$ P. I; A) Y" n- t+ s/ f    {, E2 X; {& ?1 ~* g) ?
    p.key=_polls.available_primary_key();
" B' r: p9 g  u$ d/ B    p.pollId=item.pollId;& d3 z, B, o3 P0 `3 T  @0 U
    p.pollName=item.pollName;
5 M" ~* c7 t8 j4 j7 ^4 `9 S    p.pollStatus=0;
% }8 s( u. D1 t" G+ a' }    p.option=option;" f3 s* S  q2 M9 D/ l" @5 A! b
    p.count=0;5 G3 X* A8 z' \- j/ H) v
    });* @8 A3 R3 w+ w1 @+ }' d
    }
2 X, ~$ t, L" c& `, t" \    else
* O8 B; w6 F- R* ^: Q3 G    {
: b, M2 K; @% }( K    print("Cannotaddpolloption",pollName,"option",option,"Pollhasstartedorisfinished.");
5 K/ h* ?8 n% ]    }
1 m- {% U9 P+ i; t) r    break;//soyouonlyadditonce
2 d0 {8 \8 \" q2 Y) K    }
) G4 f; ^! T* c) `! Z$ l+ X) Q    }+ l0 l8 b. C: |, Z
    };: J- [4 V4 T) _
    ///@abiaction
# a  \: S7 p& s, c    voidrmpollopt(std::stringpollName,std::stringoption)! m. G5 p; g7 {8 t" C4 m# i
    {
! b% m. r/ G9 ?    print("Removepolloption",pollName,"option",option);
; b4 S" s5 p  x+ k8 U# z    std::vectorkeysForDeletion;
3 _6 F  i# O) F. O) h! w: Z    //findandremovethenamedpoll
+ g  ~+ P7 t- U7 R. Z1 B    for(auto&item:_polls)
8 F; y0 O5 o& r. N1 `  ?    {
4 s% _0 c! b3 X    if(item.pollName==pollName)
" F, I* S$ \! H7 y7 t    {4 c4 R6 a; j8 F" t  P6 E8 u  S
    keysForDeletion.push_back(item.key);$ }1 k" ?* h( C  \: V' c+ O
    }
& i5 R' a. [0 Z    }
- I9 O. L" y2 s, B* {7 M    for(uint64_tkey:keysForDeletion)4 _$ e& J2 W# n
    {
' `0 o+ X) U# X' S: |    print("removefrom_polls",key);
; s7 s8 b1 N% x- v* D) i7 s. W    autoitr=_polls.find(key);
0 A3 U# k, |$ y8 e    if(itr!=_polls.end())
; h0 v- m; W: y    {
/ E8 c. u; f- \) Y    if(itr->option==option)( N+ |0 k, @' v' U% C; @
    {; s8 b1 W, [' o2 b
    _polls.erase(itr);% Q- ~+ {: V4 R+ r& c/ f3 B
    }1 K5 b" h) `" r0 q3 Q# H; r) M3 S
    }( `9 x7 x# `! w) S# q6 d* D# `
    }+ ~+ t& ~6 P% |6 x& a( k! W
    };
9 J3 b2 P/ y) ^3 o7 y    ///@abiaction* y" t/ M. a' [
    voidvote(std::stringpollName,std::stringoption,std::stringaccountName)
  B' [3 a8 T+ I( e2 i* f3 P- j6 X( c4 T    {
3 h# p. Y& E* V    print("votefor",option,"inpoll",pollName,"by",accountName);
9 n2 p  }+ c2 ]& W" V( m    //isthepollopen' @' P8 j+ n- q5 Z) n! M5 Z/ B$ p2 o( p
    for(auto&item:_polls)5 o) o, I  L' m4 c+ n8 b$ n% d) |
    {
! C$ q2 f( t" b7 f    if(item.pollName==pollName)' `6 _% L) x, t9 d  s- G2 i9 _
    {
- h+ p2 m' ]5 i: \& A    if(item.pollStatus!=1)8 T& O; @$ J  L% |+ S! F
    {% N7 j  ?  o' b3 y  \% ]" [; ?
    print("Poll",pollName,"isnotopen");
' Z1 F4 `. C/ w) F% l) Z    return;
, `3 w" d5 n$ E2 b    }
( D1 P* q# r! b0 W" l9 o) q    break;//onlyneedtocheckstatusonce4 N1 [' l: q" b
    }
/ N/ v7 i) [/ G: @' q    }2 d+ T8 ?8 z' \- L: k
    //hasaccountnamealreadyvoted?
" e1 D" r) F, Q6 y: w    for(auto&vote:_votes)
& `2 p* k! L9 r% C- x4 g    {3 u# G( P0 W) Q! }+ Q! Q
    if(vote.pollName==pollName&&vote.account==accountName)( x% I: k* V* ?
    {, `& b' O- @. ?  [" y' E: a
    print(accountName,"hasalreadyvotedinpoll",pollName);3 Q) Y% D) N- f4 ~; {( W5 j
    //eosio_assert(true,"AlreadyVoted");- L( @" O+ W4 P
    return;& `# X3 B  @7 g/ l+ U
    }6 [7 |+ m  Q! x/ B2 W" T
    }1 f3 P; n# s8 ]8 r' M9 }
    uint64_tpollId=99999;//getthepollIdforthe_votestable+ b, ~+ E  i2 M! P
    //findthepollandtheoptionandincrementthecount" S$ `* X" [# _& Q* D* n: G
    for(auto&item:_polls)* Z5 M6 ^' G* D* j* K% O- Z: |1 c, p/ o
    {: C% o2 G. j* N) u: v- r% `; E; N  _# C
    if(item.pollName==pollName&&item.option==option)
# f- W3 S! n  \( \8 O0 o% p3 R    {! ]2 m  q9 W6 i2 F
    pollId=item.pollId;//forrecordingvoteinthispoll' q3 G9 J" {3 H
    _polls.modify(item,get_self(),[&](auto&p)
9 {% a9 Z& \8 E3 z9 m1 M    {$ G+ U+ W' u3 ]8 m: q
    p.count=p.count+1;. {* J* H0 |; J- C, T1 P3 A
    });
9 c0 }( v' ]) ]* Y5 O3 W    }/ c* ?; Z! k% y6 Z( [
    }' T$ k% V" o& m: T) t9 I/ [
    //recordthataccountNamehasvoted
2 {- N/ E1 e9 J2 B/ o- }    _votes.emplace(get_self(),[&](auto&pv)
7 |' c1 M+ F3 `$ l; I    {
0 P3 V) y" |5 e; c    pv.key=_votes.available_primary_key();- _; G+ J( A0 m! E' p, f
    pv.pollId=pollId;2 T4 S7 {; j  o! a7 i' {
    pv.pollName=pollName;
4 e" q8 A8 k6 g    pv.account=accountName;* `/ o% V9 {2 N, j
    });
3 y/ @+ y: Z* a) U$ v% R2 @: l# [    };
& w8 T7 ]% M) I7 w, Y    private:
, t  ?" f3 d2 T" |: P# x    //createthemultiindextablestostorethedata( G+ m# Y  M8 ?6 C
    ///@abitable3 A+ ~8 \9 y3 y+ B# W0 e9 `
    structpoll7 l, G" R6 Y6 _# U% L
    {) n3 d( u) C! Y" f( \
    uint64_tkey;//primarykey
( W% ?9 g) ^. _6 ~8 w, Q* v5 P    uint64_tpollId;//secondkey,non-unique,thistablewillhaveduprowsforeachpollbecauseofoption
% E/ h7 N% Q) B8 t8 R# S1 @    std::stringpollName;//nameofpoll- O1 m& k4 R3 p; _. f
    uint8_tpollStatus=0;//stauswhere0=closed,1=open,2=finished5 X& B" w+ _, V7 O4 n* f
    std::stringoption;//theitemyoucanvotefor
* l/ z. f( G% L* E2 j% `    uint32_tcount=0;//thenumberofvotesforeachitme--thistobepulledouttosepartetable.
- F1 n9 \( @5 L. P    uint64_tprimary_key()const{returnkey;}
8 ]; f4 W( x5 `; A! b    uint64_tby_pollId()const{returnpollId;}% M# P! ]4 N! \8 Z, B/ k& b
    };+ j; ]8 X- d3 T3 {7 j
    typedefeosio::multi_index>>pollstable;3 G: S! U9 ?' C/ u* p7 Y: d
    ///@abitable# _8 }& x$ [3 z% a" w
    structpollvotes3 T+ B& V: s  p
    {
7 I7 j; C. k3 z; s2 ?5 l    uint64_tkey;
3 H. Y8 Y' x% f) f) L) T    uint64_tpollId;$ d$ v; g7 }: h4 x
    std::stringpollName;//nameofpoll
% K- Y0 K9 L, F2 v3 v    std::stringaccount;//thisaccounthasvoted,usethistomakesurenoonevotes>1- a3 y9 Q6 D6 j* }& u
    uint64_tprimary_key()const{returnkey;}+ q1 |) Y5 H$ ?3 S
    uint64_tby_pollId()const{returnpollId;}
2 m7 Q: i8 U5 Z( {5 Y; w, b+ e    };% V1 x/ N! @. ?2 A
    typedefeosio::multi_index>>votes;
# S5 d5 Y/ o( D. i5 b& O* I    //localinstancesofthemultiindexes9 u& {# O  J8 u6 B
    pollstable_polls;7 C' [/ {, }; t# A3 \
    votes_votes;
( L: B( S9 D1 O, w: o    };( l9 I% W" v) K9 [- ^
    EOSIO_ABI(youvote,(version)(addpoll)(rmpoll)(status)(statusreset)(addpollopt)(rmpollopt)(vote))
. j/ q* n. F$ z5 ~1 l2 c    注意EOSIO_ABI调用,它通过ABI公开函数,重要的是函数名与ABI函数名规则一定要匹配。
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

西门幻雪雪vj 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    10