@@ -379,6 +379,22 @@ def agCosmosHelper(reactor, opts, config, input, args, retries = 1):
379
379
output = oj
380
380
except :
381
381
pass
382
+ elif stderr [0 :14 ] == b'gas estimate: ' :
383
+ lines = stderr .split (b'\n ' )
384
+ oj = json .loads (lines [1 ].decode ('utf-8' ))
385
+ if oj .get ('type' ) is None :
386
+ # Reformat the message into what --generate-only produces.
387
+ output = {
388
+ 'type' : 'cosmos-sdk/StdTx' ,
389
+ 'value' : {
390
+ 'msg' : oj ['msgs' ],
391
+ 'fee' : oj ['fee' ],
392
+ 'signatures' : None ,
393
+ 'memo' : '' ,
394
+ }}
395
+ else :
396
+ output = oj
397
+ code = 0
382
398
383
399
return code , output
384
400
@@ -403,24 +419,31 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
403
419
missing = False
404
420
break
405
421
elif code == 9 :
422
+ needIngress .append (pkobj )
406
423
missing = True
407
424
except Exception as e :
408
425
missing = False
409
426
print (e )
410
427
411
428
if missing :
412
429
print ('generating transaction for' , pubkey )
413
- args = ['tx' , 'send' , config ['bootstrapAddress' ], pubkey , amountToken , '--generate-only' ]
430
+ # Estimate the gas, with a little bit of padding.
431
+ args = ['tx' , 'send' , config ['bootstrapAddress' ], pubkey , amountToken , '--gas=auto' , '--gas-adjustment=1.05' ]
414
432
code , output = yield agCosmosHelper (reactor , opts , config , b'' , args , 1 )
415
433
if code == 0 :
416
434
txes .append (output )
417
435
418
436
if len (txes ) > 0 :
419
437
tx0 = txes [0 ]
420
438
msgs = tx0 ['value' ]['msg' ]
439
+ # Add up all the gases.
440
+ gas = int (tx0 ['value' ]['fee' ]['gas' ])
421
441
for tx in txes [1 :]:
422
- for msg in tx ['value' ]['msg' ]:
442
+ val = tx ['value' ]
443
+ gas += int (val ['fee' ]['gas' ])
444
+ for msg in val ['msg' ]:
423
445
msgs .append (msg )
446
+ tx0 ['value' ]['fee' ]['gas' ] = str (gas )
424
447
# Create a temporary file that is automatically deleted.
425
448
with NamedTemporaryFile () as temp :
426
449
# Save the amalgamated transaction.
@@ -430,7 +453,7 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
430
453
# Now the temp.name contents are available
431
454
args = [
432
455
'tx' , 'sign' , temp .name , '--from' , config ['bootstrapAddress' ],
433
- '--yes' , '--gas=auto' , '-- append=false' ,
456
+ '--yes' , '--append=false' ,
434
457
]
435
458
436
459
# Use the temp file in the sign request.
@@ -473,7 +496,7 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
473
496
raise Exception ('invalid response code ' + str (resp .code ))
474
497
rawResp = yield treq .json_content (resp )
475
498
if not rawResp .get ('ok' , False ):
476
- raise rawResp
499
+ raise Exception ( 'response not ok ' + str ( rawResp ))
477
500
478
501
def main ():
479
502
o = Options ()
0 commit comments