def compareConstructedTX(self): # def test_online(self): # self.maxDiff = None op = operations.CommentOptions( **{ "author": "xeroc", "permlink": "piston", "max_accepted_payout": "1000000.000 HBD", "percent_hive_dollars": 10000, "allow_votes": True, "allow_curation_rewards": True, "extensions": [] }) ops = [operations.Operation(op)] tx = SignedTransaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=self.hive.chain_params) tx_wire = hexlify(compat_bytes(tx)).decode("ascii") # todo rpc = self.hive.commit.wallet compare = rpc.serialize_transaction(tx.json()) self.assertEqual(compare[:-130], tx_wire[:-130])
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. """ # We need to set the default prefix, otherwise pubkeys are # presented wrongly! if self.hived: operations.default_prefix = self.hived.chain_params["prefix"] elif "blockchain" in self: operations.default_prefix = self["blockchain"]["prefix"] try: signedtx = SignedTransaction(**self.json()) except Exception as e: # noqa FIXME(sneak) raise e if not any(self.wifs): raise MissingKeyError signedtx.sign(self.wifs, chain=self.hived.chain_params) self["signatures"].extend(signedtx.json().get("signatures"))
def test_Transfer(self): op = operations.Transfer(**{ "from": "foo", "to": "baar", "amount": "111.110 HIVE", "memo": "Fooo" }) ops = [operations.Operation(op)] tx = SignedTransaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=self.hive.chain_params) tx_wire = hexlify(compat_bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c80457010203666f6f046261617206b201000000" "000003535445454d000004466f6f6f00012025416c234dd5ff15d8" "b45486833443c128002bcafa57269cada3ad213ef88adb5831f63a" "58d8b81bbdd92d494da01eeb13ee1786d02ce075228b25d7132f8f" "3e") live = self.hive.database_api.get_transaction_hex(tx.json()) self.assertEqual(live[:-130], compare[:-130]) self.assertEqual(unhexlify(live[:-130]), unhexlify(tx_wire[:-130])) self.assertEqual(live[:-130], tx_wire[:-130]) self.assertEqual(compare[:-130], tx_wire[:-130])
def constructTx(self): if isinstance(self.op, list): ops = [Operation(o) for o in self.op] else: ops = [Operation(self.op)] expiration = fmt_time_from_now(self.expiration) ref_block_num, ref_block_prefix = get_block_params(self.hived) tx = SignedTransaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) super(TransactionBuilder, self).__init__(tx.json())