Exemplo n.º 1
0
    def contains_transaction(self, tx_hash: H256):
        if not H256.check(tx_hash):
            raise ValueError(
                f"Expected the first argument of containsTransaction to be an H256 value but found {tx_hash}"
            )

        result = self.rpc.send_rpc_request("chain", "contains_transaction",
                                           "0x" + str(H256(tx_hash)))
        return result
Exemplo n.º 2
0
 def from_json(data):
     return Asset(
         H256(data["tracker"]),
         data["transactionOutputIndex"],
         H160(data["assetType"]),
         data["shardId"],
         U64(data["quantity"]),
         H160(data["lockScriptHash"]),
         list(map(lambda x: bytes.fromhex(x), data["parameters"])),
         None if data["orderHash"] is None else H256(data["orderHash"]),
     )
Exemplo n.º 3
0
    def get_transaction_results_by_tracker(self,
                                           tracker: H256,
                                           timeout: int = None):
        if not H256.check(tracker):
            raise ValueError(
                f"Expected the first argument of getTransactionResultsByTracker to be an H256 value but found {tracker}"
            )

        if timeout is not None:
            raise ValueError("Not implemented")

        return self.rpc.send_rpc_request("mempool",
                                         "get_transaction_results_by_tracker",
                                         "0x" + str(H256(tracker)))
Exemplo n.º 4
0
    def import_raw(self, secret: H256, passphrase: str = None):
        if not H256.check(secret):
            raise ValueError(
                f"Expected the first argument to be an H256 value but found {secret}"
            )
        if passphrase is not None and not isinstance(passphrase, str):
            raise ValueError(
                f"Expected the second argument to be a string but found {passphrase}"
            )

        result = self.rpc.send_rpc_request("account", "import_raw",
                                           H256(secret).to_string(prefix=True),
                                           passphrase)

        return str(PlatformAddress.ensure(result))
Exemplo n.º 5
0
 def from_json(data: AssetOutPointJSON):
     return AssetOutPoint(
         H256(data.tracker),
         data.index,
         H160(data.asset_type),
         data.shard_id,
         U64(data.quantity),
         None if data.lock_script_hash is None else H160(data.lock_script_hash),
         None
         if data.parameters is None
         else list(map(lambda x: bytes.fromhex(x), data.parameters)),
     )
Exemplo n.º 6
0
    def sign(self,
             message_digest: H256,
             address: PlatformAddress,
             passphrase: str = None):
        if not H256.check(message_digest):
            raise ValueError(
                f"Expected the first argument to be an H256 value but found {message_digest}"
            )
        if not PlatformAddress.check(address):
            raise ValueError(
                f"Expected the second argument to be a PlatformAddress value but found {address}"
            )
        if passphrase is not None and not isinstance(passphrase, str):
            raise ValueError(
                f"Expected the third argument to be a string but found {passphrase}"
            )

        return self.rpc.send_rpc_request(
            "account",
            "sign",
            "0x" + str(H256(message_digest)),
            str(PlatformAddress.ensure(address)),
            passphrase,
        )
Exemplo n.º 7
0
def from_json_to_signed_transaction(data: SignedTransactionJSON):

    if not isinstance(data.sig, str):
        raise ValueError("Unexpected type of sig")

    if (data.block_number is not None and data.block_hash is not None
            and data.transaction_index is not None):
        return SignedTransaction(
            from_json_to_transaction(data),
            data.sig,
            data.block_number,
            H256(data.block_hash),
            data.transaction_index,
        )
    else:
        return SignedTransaction(from_json_to_transaction(data), data.sig)
Exemplo n.º 8
0
 def tracker(self):
     return H256(blake256(self._transaction.rlp_bytes()))
Exemplo n.º 9
0
 def hash(self):
     return H256(blake256(self.rlp_bytes()))