Ejemplo n.º 1
0
    def recover_message(
        identifier: str,
        message: bytes,
        signature: str,
        is_deprecated_mode: bool = False,
    ) -> Tuple[Address, ...]:
        """
        Recover the addresses from the hash.

        :param identifier: ledger identifier.
        :param message: the message we expect
        :param signature: the transaction signature
        :param is_deprecated_mode: if the deprecated signing was used
        :return: the recovered addresses
        """
        enforce(
            identifier in ledger_apis_registry.supported_ids,
            "Not a registered ledger api identifier.",
        )
        api_class = make_ledger_api_cls(identifier)
        addresses = api_class.recover_message(
            message=message,
            signature=signature,
            is_deprecated_mode=is_deprecated_mode)
        return addresses
Ejemplo n.º 2
0
    def is_transaction_valid(
        identifier: str,
        tx: Any,
        seller: Address,
        client: Address,
        tx_nonce: str,
        amount: int,
    ) -> bool:
        """
        Check whether the transaction is valid.

        :param identifier: Ledger identifier
        :param tx:  the transaction
        :param seller: the address of the seller.
        :param client: the address of the client.
        :param tx_nonce: the transaction nonce.
        :param amount: the amount we expect to get from the transaction.
        :return: True if is valid , False otherwise
        """
        enforce(
            identifier in ledger_apis_registry.supported_ids,
            "Not a registered ledger api identifier.",
        )
        api_class = make_ledger_api_cls(identifier)
        is_valid = api_class.is_transaction_valid(tx, seller, client, tx_nonce,
                                                  amount)
        return is_valid
Ejemplo n.º 3
0
    def is_valid_address(identifier: str, address: Address) -> bool:
        """
        Check if the address is valid.

        :param address: the address to validate
        """
        identifier = (identifier
                      if identifier in ledger_apis_registry.supported_ids else
                      DEFAULT_LEDGER)
        api_class = make_ledger_api_cls(identifier)
        result = api_class.is_valid_address(address=address)
        return result
Ejemplo n.º 4
0
    def get_hash(identifier: str, message: bytes) -> str:
        """
        Get the hash of a message.

        :param identifier: ledger identifier.
        :param message: the message to be hashed.
        :return: the hash of the message.
        """
        identifier = (identifier
                      if identifier in ledger_apis_registry.supported_ids else
                      DEFAULT_LEDGER)
        api_class = make_ledger_api_cls(identifier)
        digest = api_class.get_hash(message=message)
        return digest
Ejemplo n.º 5
0
    def is_transaction_settled(identifier: str, tx_receipt: Any) -> bool:
        """
        Check whether the transaction is settled and correct.

        :param identifier: the identifier of the ledger
        :param tx_receipt: the transaction digest
        :return: True if correctly settled, False otherwise
        """
        assert (
            identifier in ledger_apis_registry.supported_ids
        ), "Not a registered ledger api identifier."
        api_class = make_ledger_api_cls(identifier)
        is_settled = api_class.is_transaction_settled(tx_receipt)
        return is_settled
Ejemplo n.º 6
0
    def generate_tx_nonce(identifier: str, seller: Address, client: Address) -> str:
        """
        Generate a random str message.

        :param identifier: ledger identifier.
        :param seller: the address of the seller.
        :param client: the address of the client.
        :return: return the hash in hex.
        """
        assert (
            identifier in ledger_apis_registry.supported_ids
        ), "Not a registered ledger api identifier."
        api_class = make_ledger_api_cls(identifier)
        tx_nonce = api_class.generate_tx_nonce(seller=seller, client=client)
        return tx_nonce
Ejemplo n.º 7
0
def _load_contract_interfaces(
    configuration: ContractConfig, ) -> Dict[str, Dict[str, str]]:
    """Get the contract interfaces."""
    if configuration.directory is None:  # pragma: nocover
        raise ValueError(
            "Set contract configuration directory before calling.")
    contract_interfaces = {}  # type: Dict[str, Dict[str, str]]
    for identifier, path in configuration.contract_interface_paths.items():
        full_path = Path(configuration.directory, path)
        if identifier not in ledger_apis_registry.supported_ids:
            raise ValueError(  # pragma: nocover
                "No ledger api registered for identifier {}.")
        ledger_api = make_ledger_api_cls(identifier)
        contract_interface = ledger_api.load_contract_interface(full_path)
        contract_interfaces[identifier] = contract_interface
    return contract_interfaces