7
7
import pandas as pd
8
8
from ethpm_types import ContractType
9
9
10
- from ape .api import Address , BlockAPI , ReceiptAPI
10
+ from ape .api import BlockAPI , ReceiptAPI
11
11
from ape .api .address import BaseAddress
12
12
from ape .api .networks import LOCAL_NETWORK_NAME , NetworkAPI , ProxyInfoAPI
13
13
from ape .api .query import BlockQuery , validate_and_expand_columns
@@ -618,16 +618,27 @@ def get(
618
618
619
619
return contract_type
620
620
621
+ def get_container (self , contract_type : ContractType ) -> ContractContainer :
622
+ """
623
+ Get a contract container for the given contract type.
624
+
625
+ Args:
626
+ contract_type (ContractType): The contract type to wrap.
627
+
628
+ Returns:
629
+ ContractContainer: A container object you can deploy.
630
+ """
631
+
632
+ return ContractContainer (contract_type )
633
+
621
634
def instance_at (
622
635
self , address : Union [str , "AddressType" ], contract_type : Optional [ContractType ] = None
623
- ) -> BaseAddress :
636
+ ) -> ContractInstance :
624
637
"""
625
638
Get a contract at the given address. If the contract type of the contract is known,
626
639
either from a local deploy or a :class:`~ape.api.explorers.ExplorerAPI`, it will use that
627
640
contract type. You can also provide the contract type from which it will cache and use
628
- next time. If the contract type is not known, returns a
629
- :class:`~ape.api.address.BaseAddress` object; otherwise returns a
630
- :class:`~ape.contracts.ContractInstance` (subclass).
641
+ next time.
631
642
632
643
Raises:
633
644
TypeError: When passing an invalid type for the `contract_type` arguments
@@ -640,9 +651,7 @@ def instance_at(
640
651
in case it is not already known.
641
652
642
653
Returns:
643
- :class:`~ape.api.address.BaseAddress`: Will be a
644
- :class:`~ape.contracts.ContractInstance` if the contract type is discovered,
645
- which is a subclass of the ``BaseAddress`` class.
654
+ :class:`~ape.contracts.base.ContractInstance`
646
655
"""
647
656
648
657
try :
@@ -653,15 +662,15 @@ def instance_at(
653
662
address = self .provider .network .ecosystem .decode_address (address )
654
663
contract_type = self .get (address , default = contract_type )
655
664
656
- if contract_type :
657
- if not isinstance (contract_type , ContractType ):
658
- raise TypeError (
659
- f"Expected type '{ ContractType .__name__ } ' for argument 'contract_type'."
660
- )
665
+ if not contract_type :
666
+ raise ChainError (f"Failed to get contract type for address '{ address } '." )
661
667
662
- return self .create_contract (address , contract_type )
668
+ elif not isinstance (contract_type , ContractType ):
669
+ raise TypeError (
670
+ f"Expected type '{ ContractType .__name__ } ' for argument 'contract_type'."
671
+ )
663
672
664
- return Address (address )
673
+ return ContractInstance (address , contract_type )
665
674
666
675
def get_deployments (self , contract_container : ContractContainer ) -> List [ContractInstance ]:
667
676
"""
@@ -704,10 +713,6 @@ def get_deployments(self, contract_container: ContractContainer) -> List[Contrac
704
713
instance = self .instance_at (
705
714
contract_addresses [deployment_index ], contract_container .contract_type
706
715
)
707
-
708
- if not isinstance (instance , ContractInstance ):
709
- continue
710
-
711
716
deployments .append (instance )
712
717
713
718
return deployments
0 commit comments