How to use the gear.utils.compat.ThorTransaction function in gear

To help you get started, we’ve selected a few gear examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vechain / web3-gear / gear / utils / compat.py View on Github external
def __init__(self, chain_tag, blk_ref, eth_tx):
        receiver = b"" if "to" not in eth_tx else decode_hex(eth_tx["to"])
        clauses = [
            Clause(
                receiver,
                eth_tx.get("value", 0),
                decode_hex(eth_tx.get("data", "")),
            )
        ]
        super(ThorTransaction, self).__init__(chain_tag, blk_ref, (2 ** 32) - 1, clauses, 0, eth_tx.get("gas", 3000000), b"", 0, [], b"")
github vechain / web3-gear / gear / utils / compat.py View on Github external
def sign(self, key):
        '''Sign this transaction with a private key.

        A potentially already existing signature would be overridden.
        '''
        h = blake2b(digest_size=32)
        h.update(rlp.encode(self, ThorTransaction.exclude(["Signature"])))
        rawhash = h.digest()

        if key in (0, "", b"\x00" * 32, "0" * 64):
            raise Exception("Zero privkey cannot sign")

        if len(key) == 64:
            key = to_bytes(hexstr=key)  # we need a binary key
        pk = keys.PrivateKey(key)

        self.Signature = pk.sign_msg_hash(rawhash).to_bytes()
github vechain / web3-gear / gear / thor / client.py View on Github external
async def send_transaction(self, transaction):
        chain_tag = int((await thor.get_block(0))["hash"][-2:], 16)
        blk_ref = int(strip_0x((await thor.get_block("best"))["hash"])[:8], 16)
        tx = ThorTransaction(chain_tag, blk_ref, transaction)
        tx.sign(self.account_manager.get_priv_by_addr(transaction["from"]))
        raw = "0x{}".format(encode_hex(rlp.encode(tx)))
        return await self.send_raw_transaction(raw)