Skip to content

Commit

Permalink
feat: contract creation query
Browse files Browse the repository at this point in the history
depends on ApeWorX/ape#2001
  • Loading branch information
banteg authored and antazoey committed Aug 21, 2024
1 parent e07641a commit 1c8fbba
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ape_etherscan/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Optional

from ape.api import PluginConfig, QueryAPI, QueryType, ReceiptAPI
from ape.api.query import AccountTransactionQuery, ContractCreationQuery
from ape.api.query import AccountTransactionQuery, ContractCreation, ContractCreationQuery
from ape.exceptions import QueryEngineError
from ape.utils import singledispatchmethod

Expand Down Expand Up @@ -121,12 +121,21 @@ def get_account_transactions(self, query: AccountTransactionQuery) -> Iterator[R
yield receipt

@perform_query.register
def get_contract_creation_receipt(self, query: ContractCreationQuery) -> Iterator[ReceiptAPI]:
def get_contract_creation_receipt(
self, query: ContractCreationQuery
) -> Iterator[ContractCreation]:
client = self._client_factory.get_contract_client(query.contract)
creation_data = client.get_creation_data()
if len(creation_data) == 0:
return
elif len(creation_data) != 1:
raise ValueError("Expecting single creation data.")

yield self.chain_manager.get_receipt(creation_data[0].txHash)
receipt = self.chain_manager.get_receipt(creation_data.txHash)
yield ContractCreation(
txn_hash=creation_data.txHash,
deploy_block=receipt.block_number,
deployer=receipt.sender,
# factory is not implemented by this query provider
factory=None,
)

0 comments on commit 1c8fbba

Please sign in to comment.