@@ -35,7 +35,7 @@ def _cleos(arguments, *, output=True):
3535    except  subprocess .CalledProcessError  as  e :
3636        import  sys 
3737        (exception , traceback ) =  (e , sys .exc_info ()[2 ])
38-      
38+ 
3939    msg  =  str (exception ) +  ' with output:\n '  +  exception .output 
4040    raise  Exception (msg ).with_traceback (traceback )
4141
@@ -47,7 +47,7 @@ def cleos(arguments, *, keys=None):
4747        return  _cleos ("push transaction -j --skip-sign '%s'"  %  trx , output = False )
4848    else :
4949        return  _cleos (arguments )
50-      
50+ 
5151
5252def  pushAction (code , action , actor , args , * , additional = '' , delay = None , expiration = None , providebw = None , keys = None ):
5353    additional  +=  ' --delay-sec %d'  %  delay  if  delay  else  '' 
@@ -76,6 +76,38 @@ def removeRootKeys():
7676def  unlockWallet ():
7777    cleos ('wallet unlock --password %s'  %  args .wallet_password )
7878
79+ def  parseAuthority (auth ):
80+     if  type (auth ) ==  type ([]):
81+         return  [parseAuthority (a ) for  a  in  auth ]
82+     d  =  auth .split ('@' ,2 )
83+     if  len (d ) ==  1 :
84+         d .extend (['active' ])
85+     return  {'actor' :d [0 ], 'permission' :d [1 ]}
86+ 
87+ def  createAction (contract , action , actors , args ):
88+     data  =  cleos ("convert pack_action_data {contract} {action} {args}" .format (
89+             contract = contract , action = action , args = jsonArg (args ))).rstrip ()
90+     return  {
91+         'account' :contract ,
92+         'name' :action ,
93+         'authorization' :parseAuthority (actors  if  type (actors )== type ([]) else  [actors ]),
94+         'data' :data 
95+     }
96+ 
97+ class  Trx :
98+     def  __init__ (self , expiration = None ):
99+         additional  =  '--skip-sign --dont-broadcast' 
100+         if  expiration :
101+             additional  +=  ' --expiration {exp}' .format (exp = expiration )
102+         self .trx  =  pushAction ('cyber' , 'checkwin' , 'cyber' , {}, additional = additional )
103+         self .trx ['actions' ] =  []
104+ 
105+     def  addAction (self , contract , action , actors , args ):
106+         self .trx ['actions' ].append (createAction (contract , action , actors , args ))
107+ 
108+     def  getTrx (self ):
109+         return  self .trx 
110+ 
79111# --------------------- EOSIO functions --------------------------------------- 
80112
81113def  createAuthority (keys , accounts ):
@@ -162,9 +194,19 @@ def createPost(author, permlink, category, header, body, *, beneficiaries=[], pr
162194            'jsonmetadata' :'' 
163195        }, providebw = providebw , keys = keys )
164196
165- def  createComment (author , permlink , pauthor , ppermlink , header , body , * , beneficiaries = []):
166-     return  pushAction ('gls.publish' , 'createmssg' , author ,
167-         [author , permlink , pauthor , ppermlink , beneficiaries , 0 , False , header , body , 'ru' , [], '' ])
197+ def  createComment (author , permlink , pauthor , ppermlink , header , body , * , beneficiaries = [], providebw = None , keys = None ):
198+     return  pushAction ('gls.publish' , 'createmssg' , author , {
199+             'message_id' :{'author' :author , 'permlink' :permlink }, 
200+             'parent_id' :{'author' :pauthor , 'permlink' :ppermlink }, 
201+             'beneficiaries' :beneficiaries ,
202+             'tokenprop' :0 ,
203+             'vestpayment' :False ,
204+             'headermssg' :header ,
205+             'bodymssg' :body ,
206+             'languagemssg' :'ru' ,
207+             'tags' :[],
208+             'jsonmetadata' :'' 
209+         }, providebw = providebw , keys = keys )
168210
169211def  upvotePost (voter , author , permlink , weight , * , providebw = None , keys = None ):
170212    return  pushAction ('gls.publish' , 'upvote' , voter , {'voter' :voter , 'message_id' :{'author' :author , 'permlink' :permlink }, 'weight' :weight }, providebw = providebw , keys = keys )
0 commit comments