Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Implement get_transactions_by_block() API #25

Closed
antazoey opened this issue Jun 13, 2022 · 0 comments · Fixed by #33
Closed

Implement get_transactions_by_block() API #25

antazoey opened this issue Jun 13, 2022 · 0 comments · Fixed by #33
Assignees

Comments

@antazoey
Copy link
Member

Overview

As of https://github.com/ApeWorX/ape/pull/776/files, there is a new API method to implement in the provider that should get the transactions in a block.

Specification

What have I drafted so far:

provider.py changes:

    def get_transactions_by_block(self, block_id: HexBytes) -> Iterator[TransactionAPI]:
        block = self._get_block(block_id)
        for txn in block.transactions:
            yield self.network.ecosystem.create_transaction(**txn)

Starknet ecosystem API changes:

    def create_transaction(self, **kwargs) -> TransactionAPI:
        txn_type = kwargs.pop("type", kwargs.pop("tx_type"))
        txn_cls: Union[Type[InvokeFunctionTransaction], Type[DeployTransaction]]
        if txn_type == TransactionType.INVOKE_FUNCTION:
            txn_cls = InvokeFunctionTransaction
        elif txn_type == TransactionType.DEPLOY:
            txn_cls = DeployTransaction

        txn_data = {**kwargs}
        if "max_fee" in txn_data and not isinstance(txn_data["max_fee"], int):
            txn_data["max_fee"] = self.encode_primitive_value(txn_data["max_fee"])

        if "signature" in txn_data and not isinstance(txn_data["signature"], TransactionSignature):
            txn_data["signature"] = TransactionSignature(
                v=0, r=HexBytes(txn_data["signature"][0]), s=HexBytes(txn_data["signature"][1])
            )

        # if "method_abi" not in txn_data:
        #     contract = self.chain_manager.contracts.get(txn_data["contract_address"])

        return txn_cls(**txn_data)

I believe this will require https://github.com/ApeWorX/ape-cairo/issues/20

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant