def sign_and_finish(self, wallet, jsn): context = ContractParametersContext.FromJson(jsn) if context is None: print("Failed to parse JSON") return None wallet.Sign(context) if context.Completed: print("Signature complete, relaying...") tx = context.Verifiable tx.scripts = context.GetScripts() wallet.SaveTransaction(tx) print("will send tx: %s " % json.dumps(tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(tx) if relayed: print("Relayed Tx: %s " % tx.Hash.ToString()) self.wait_for_tx(tx) return ('success') else: print("Could not relay tx %s " % tx.Hash.ToString()) return ('fail') else: print("Transaction signed, but the signature is still incomplete") return (json.dumps(context.ToJson(), separators=(',', ':')))
def sign_and_finish(wallet, jsn): context = ContractParametersContext.FromJson(jsn) if context is None: print("Failed to parse JSON") return None wallet.Sign(context) if context.Completed: print("Signature complete, relaying...") tx = context.Verifiable tx.scripts = context.GetScripts() wallet.SaveTransaction(tx) print("will send tx: %s " % json.dumps(tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(tx) if relayed: print("Relayed Tx: %s " % tx.Hash.ToString()) foundtx = False count = 0 while foundtx == False and count < 100: _tx, height = Blockchain.Default().GetTransaction( tx.Hash.ToString()) if height > -1: foundtx = True print( "Waiting for tx {} to show up on blockchain...".format( tx.Hash.ToString())) time.sleep(3) count += 1 if foundtx == True: return ('success') else: print( "Transaction was relayed but never accepted by consensus node" ) return ('fail') else: print("Could not relay tx %s " % tx.Hash.ToString()) return ('fail') else: print("Transaction signed, but the signature is still incomplete") return (json.dumps(context.ToJson(), separators=(',', ':')))
def parse_and_sign(wallet, jsn): try: context = ContractParametersContext.FromJson(jsn) if context is None: print("Failed to parse JSON") return wallet.Sign(context) if context.Completed: print("Signature complete, relaying...") tx = context.Verifiable tx.scripts = context.GetScripts() wallet.SaveTransaction(tx) print("will send tx: %s " % json.dumps(tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(tx) if relayed: print("Relayed Tx: %s " % tx.Hash.ToString()) else: print("Could not relay tx %s " % tx.Hash.ToString()) return else: print("Transaction initiated, but the signature is incomplete") print(json.dumps(context.ToJson(), separators=(',', ':'))) return except Exception as e: print("could not send: %s " % e) traceback.print_stack() traceback.print_exc()