Exemplo n.º 1
0
    def get_seq(self, address: PlatformAddress, block_number: int = None):
        if not PlatformAddress.check(address):
            raise ValueError(
                f"Expected the first argument of getSeq to be a PlatformAddress value but found {address}"
            )
        if block_number is not None and block_number >= 0:
            raise ValueError(
                f"Expected the second argument of getSeq to be a number but found ${block_number}"
            )

        return self.rpc.send_rpc_request("chain", "get_seq",
                                         str(PlatformAddress.ensure(address)),
                                         block_number)
Exemplo n.º 2
0
    def approve_transaction(
        self,
        account: Union[str, PlatformAddress],
        transaction: AssetTransaction,
        keystore=None,
        passphrase="",
    ):
        if not is_keystore(keystore):
            raise ValueError(
                f"Expected keyStore param to be a KeyStore instance but found {keystore}"
            )

        if not PlatformAddress.check(account):
            raise ValueError(
                f"Expected account param to be a PlatformAddress value but found {account}"
            )

        account_id = PlatformAddress.ensure(account).account_id

        return keystore.platform.sign(account_id.to_string(),
                                      transaction.tracker(), passphrase)
Exemplo n.º 3
0
    def send_transaction(
        self,
        tx: Transaction,
        account: PlatformAddress = None,
        passphrase: str = None,
        seq: Union[int, None] = None,
        fee: U64 = None,
        block_number: int = None,
    ):
        if not isinstance(tx, Transaction):
            raise ValueError(
                f"Expected the first argument of sendTransaction to be a Transaction but found {tx}"
            )

        account = self.transaction_signer if account is None else account
        fee = (self.get_mint_transaction_fee(
            tx.transaction_type(), block_number) if fee is None else fee)

        if account is None:
            raise ValueError("The account to sign the tx is not specified")
        elif not PlatformAddress.check(account):
            raise ValueError(
                f"Expected account param of sendTransaction to be a PlatformAddress value but found {account}"
            )

        seq = self.get_seq(account) if seq is None else seq

        tx.seq = seq

        if fee is None:
            raise ValueError("The fee of the tx is not specified")

        tx.fee = fee

        address = PlatformAddress.ensure(account)
        sig = self.rpc.account.sign(tx.unsigned_hash(), address, passphrase)

        return self.send_signed_transaction(SignedTransaction(tx, sig))
Exemplo n.º 4
0
    def sign_transaction(
        self,
        tx: Transaction,
        account: Union[PlatformAddress, str],
        fee: Union[U64, str, int],
        seq: int,
        keystore=None,
        passphrase="",
    ):
        if not isinstance(tx, Transaction):
            raise ValueError(
                f"Expected the first argument of signTransaction to be a Transaction instance but found {tx}"
            )

        keystore = self.ensure_keystore()
        if not is_keystore(keystore):
            raise ValueError(
                f"Expected keyStore param to be a KeyStore instance but found {keystore}"
            )
        if not PlatformAddress.check(account):
            raise ValueError(
                f"Expected account param to be a PlatformAddress value but found {account}"
            )
        if not U64.check(fee):
            raise ValueError(
                f"Expected fee param to be a U64 value but found {fee}")
        if not isinstance(seq, int):
            raise ValueError(
                f"Expected seq param to be a number value but found {seq}")
        tx.fee = fee
        tx.seq = seq
        account_id = PlatformAddress.ensure(account).account_id
        sig = keystore.platform.sign(account_id.to_string(),
                                     tx.unsigned_hash(), passphrase)

        return SignedTransaction(tx, sig)
Exemplo n.º 5
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.º 6
0
def check_registrar(registrar: Union[None, PlatformAddress]):
    if registrar is not None and not PlatformAddress.check(registrar):
        raise ValueError(
            f"Expected registrar param to be either null or a PlatformAddress value but found ${registrar}"
        )
Exemplo n.º 7
0
def check_approver(approver: Union[None, PlatformAddress]):
    if approver is not None and not PlatformAddress.check(approver):
        raise ValueError(
            f"Expected approver param to be either null or a PlatformAddress value but found ${approver}"
        )