Skip to content

Commit

Permalink
refactor: rename deploy_block to block
Browse files Browse the repository at this point in the history
  • Loading branch information
banteg committed Apr 12, 2024
1 parent 709b2a6 commit 456887b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/ape/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ def check_start_nonce_before_stop_nonce(cls, values: Dict) -> Dict:
class ContractCreationQuery(_BaseQuery):
"""
A ``QueryType`` that obtains information about contract deployment.
Returns ``ContractCreation(txn_hash, deploy_block, deployer, factory)``.
Returns ``ContractCreation(txn_hash, block, deployer, factory)``.
"""

contract: AddressType


class ContractCreation(BaseModel):
txn_hash: str
deploy_block: int
block: int
deployer: AddressType
factory: Optional[AddressType] = None

Expand Down
2 changes: 1 addition & 1 deletion src/ape/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def receipt(self) -> ReceiptAPI:
@cached_property
def creation(self) -> ContractCreation:
"""
Contract creation details: txn_hash, deployer, factory, deploy_block.
Contract creation details: txn_hash, block, deployer, factory.
"""
data = self.chain_manager.contracts.get_creation_metadata(self.address)
if data is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def get_proxy_info(self, address: AddressType) -> Optional[ProxyInfoAPI]:

def get_creation_metadata(self, address: AddressType) -> Optional[ContractCreation]:
"""
Get contract creation metadata containing txn_hash, deployer, factory, deploy_block.
Get contract creation metadata containing txn_hash, deployer, factory, block.
Args:
address (AddressType): The address of the contract.
Expand Down
10 changes: 4 additions & 6 deletions src/ape/managers/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ def find_creation_block(lo, hi):
if not self.provider.get_code(query.contract):
return None

deploy_block = find_creation_block(0, self.chain_manager.blocks.height)
deploy_block_traces = self.provider._make_request(
"trace_replayBlockTransactions", [deploy_block, ["trace"]]
)
block = find_creation_block(0, self.chain_manager.blocks.height)
traces = self.provider._make_request("trace_replayBlockTransactions", [block, ["trace"]])

# iterate over transaction traces in a block to find the deploy transaction
# this method also supports contract factories
for tx in deploy_block_traces:
for tx in traces:
for trace in tx["trace"]:
if (
"error" not in trace
Expand All @@ -117,9 +115,9 @@ def find_creation_block(lo, hi):
creator = self.conversion_manager.convert(trace["action"]["from"], AddressType)
yield ContractCreation(
txn_hash=tx["transactionHash"],
block=block,
deployer=receipt.sender,
factory=creator if creator != receipt.sender else None,
deploy_block=deploy_block,
)

@perform_query.register
Expand Down
2 changes: 1 addition & 1 deletion src/ape_geth/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_contract_creation_receipt(
receipt = self.provider.get_receipt(ots["hash"])
yield ContractCreation(
txn_hash=ots["hash"],
block=receipt.block_number,
deployer=receipt.sender,
factory=creator if creator != receipt.sender else None,
deploy_block=receipt.block_number,
)

0 comments on commit 456887b

Please sign in to comment.