def compareConstructedTX(self): # FIXME: Bet cancel does not serialize properly op = operations.Bet_cancel( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "bettor_id": "1.2.5555", "bet_to_cancel": "1.22.1111", "prefix": prefix, }) ops = [Operation(op)] tx = Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], prefix) txWire = hexlify(bytes(tx)).decode("ascii") print("=" * 80) pprint(tx.json()) print("=" * 80) from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) compare = rpc.serialize_transaction(tx.json()) print(compare[:-130]) print(txWire[:-130]) print(txWire[:-130] == compare[:-130]) self.assertEqual(compare[:-130], txWire[:-130])
def constructTx(self): """ Construct the actual transaction and store it in the class's dict store """ if self.muse.proposer: ops = [operations.Op_wrapper(op=o) for o in list(self.ops)] proposer = Account(self.muse.proposer, muse_instance=self.muse) ops = operations.Proposal_create( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "fee_paying_account": proposer["id"], "expiration_time": transactions.formatTimeFromNow( self.muse.proposal_expiration), "proposed_ops": [o.json() for o in ops], "extensions": [] }) ops = [Operation(ops)] else: ops = [Operation(o) for o in list(self.ops)] ops = transactions.addRequiredFees(self.muse.rpc, ops) expiration = transactions.formatTimeFromNow(self.muse.expiration) ref_block_num, ref_block_prefix = transactions.getBlockParams( self.muse.rpc) tx = Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) super(TransactionBuilder, self).__init__(tx.json())
def sign(self): """ Sign a provided transaction witht he provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions. """ self.constructTx() # If we are doing a proposal, obtain the account from the proposer_id if self.muse.proposer: proposer = Account(self.muse.proposer, muse_instance=self.muse) self.wifs = [] self.appendSigner(proposer["id"], "active") # We need to set the default prefix, otherwise pubkeys are # presented wrongly! if self.muse.rpc: operations.default_prefix = self.muse.rpc.chain_params["prefix"] elif "blockchain" in self: operations.default_prefix = self["blockchain"]["prefix"] try: signedtx = Signed_Transaction(**self.json()) except: raise ValueError("Invalid TransactionBuilder Format") if not any(self.wifs): raise MissingKeyError signedtx.sign(self.wifs, chain=self.muse.rpc.chain_params) self["signatures"].extend(signedtx.json().get("signatures"))