@@ -35,7 +35,7 @@ def _cleos(arguments, *, output=True):
35
35
except subprocess .CalledProcessError as e :
36
36
import sys
37
37
(exception , traceback ) = (e , sys .exc_info ()[2 ])
38
-
38
+
39
39
msg = str (exception ) + ' with output:\n ' + exception .output
40
40
raise Exception (msg ).with_traceback (traceback )
41
41
@@ -47,7 +47,7 @@ def cleos(arguments, *, keys=None):
47
47
return _cleos ("push transaction -j --skip-sign '%s'" % trx , output = False )
48
48
else :
49
49
return _cleos (arguments )
50
-
50
+
51
51
52
52
def pushAction (code , action , actor , args , * , additional = '' , delay = None , expiration = None , providebw = None , keys = None ):
53
53
additional += ' --delay-sec %d' % delay if delay else ''
@@ -76,6 +76,38 @@ def removeRootKeys():
76
76
def unlockWallet ():
77
77
cleos ('wallet unlock --password %s' % args .wallet_password )
78
78
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
+
79
111
# --------------------- EOSIO functions ---------------------------------------
80
112
81
113
def createAuthority (keys , accounts ):
@@ -162,9 +194,19 @@ def createPost(author, permlink, category, header, body, *, beneficiaries=[], pr
162
194
'jsonmetadata' :''
163
195
}, providebw = providebw , keys = keys )
164
196
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 )
168
210
169
211
def upvotePost (voter , author , permlink , weight , * , providebw = None , keys = None ):
170
212
return pushAction ('gls.publish' , 'upvote' , voter , {'voter' :voter , 'message_id' :{'author' :author , 'permlink' :permlink }, 'weight' :weight }, providebw = providebw , keys = keys )
0 commit comments