@@ -36,24 +36,54 @@ class BridgeContractConfig:
36
36
)
37
37
38
38
39
+ def ensure_contract (name : str , url : str ) -> str :
40
+ contract_path = f".contract/{ name } .wasm"
41
+ if not os .path .exists (".contract" ):
42
+ os .mkdir (".contract" )
43
+ try :
44
+ temp = open (contract_path , "rb" )
45
+ temp .close ()
46
+ except OSError :
47
+ contract_request = requests .get (url )
48
+ with open (contract_path , "wb" ) as file :
49
+ file .write (contract_request .content )
50
+ finally :
51
+ return contract_path
52
+
53
+
54
+ class DeployTestContract (LedgerContract ):
55
+
56
+ def __init__ (self , client : LedgerClient , admin : Wallet ):
57
+ """ Using a slightly older version of CW20 contract as a test contract - as this will still be classified as the
58
+ CW20 interface, but is different enough to allow a unique store_code message during testing."""
59
+ url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.14.0/cw20_base.wasm"
60
+ contract_path = ensure_contract ("test_contract" , url )
61
+ super ().__init__ (contract_path , client )
62
+
63
+ self .deploy ({
64
+ "name" : "test coin" ,
65
+ "symbol" : "TEST" ,
66
+ "decimals" : 6 ,
67
+ "initial_balances" : [{
68
+ "amount" : "3000000000000000000000000" ,
69
+ "address" : str (admin .address ())
70
+ }],
71
+ "mint" : {"minter" : str (admin .address ())}
72
+ },
73
+ admin ,
74
+ store_gas_limit = 3000000
75
+ )
76
+
77
+
39
78
class Cw20Contract (LedgerContract ):
40
79
admin : Wallet = None
41
80
gas_limit : int = 3000000
42
81
43
82
def __init__ (self , client : LedgerClient , admin : Wallet ):
44
83
self .admin = admin
45
84
url = "https://github.com/CosmWasm/cw-plus/releases/download/v0.16.0/cw20_base.wasm"
46
- if not os .path .exists (".contract" ):
47
- os .mkdir (".contract" )
48
- try :
49
- temp = open (".contract/cw20.wasm" , "rb" )
50
- temp .close ()
51
- except :
52
- contract_request = requests .get (url )
53
- with open (".contract/cw20.wasm" , "wb" ) as file :
54
- file .write (contract_request .content )
55
-
56
- super ().__init__ (".contract/cw20.wasm" , client )
85
+ contract_path = ensure_contract ("cw20" , url )
86
+ super ().__init__ (contract_path , client )
57
87
58
88
def _store (self ) -> int :
59
89
assert self .admin is not None
@@ -81,20 +111,12 @@ def _instantiate(self, code_id) -> Address:
81
111
82
112
class BridgeContract (LedgerContract ):
83
113
def __init__ (self , client : LedgerClient , admin : Wallet , cfg : BridgeContractConfig ):
84
- url = "https://github.com/fetchai/fetch-ethereum-bridge-v1/releases/download/v0.2.0/bridge.wasm"
85
- if not os .path .exists (".contract" ):
86
- os .mkdir (".contract" )
87
- try :
88
- temp = open (".contract/bridge.wasm" , "rb" )
89
- temp .close ()
90
- except :
91
- contract_request = requests .get (url )
92
- with open (".contract/bridge.wasm" , "wb" ) as file :
93
- file .write (contract_request .content )
114
+ url = "https://github.com/fetchai/contract-agent-almanac/releases/download/v0.1.0/contract_agent_almanac.wasm"
115
+ contract_path = ensure_contract ("bridge" , url )
94
116
95
117
# LedgerContract will attempt to discover any existing contract having the same bytecode hash
96
118
# see https://github.com/fetchai/cosmpy/blob/master/cosmpy/aerial/contract/__init__.py#L74
97
- super ().__init__ (".contract/bridge.wasm" , client )
119
+ super ().__init__ (contract_path , client )
98
120
99
121
# deploy will store the contract only if no existing contracts was found during init.
100
122
# and it will instantiate the contract only if contract.address is None
0 commit comments