Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactored deploy function
Updated scalecodec
  • Loading branch information
arjanz committed May 8, 2023
commit d619b684f1a246e5dc4705c6723e672985af6beb
7 changes: 3 additions & 4 deletions examples/create_and_exec_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@
print('Deploy contract...')
contract = code.deploy(
keypair=keypair,
endowment=0,
gas_limit={'ref_time': 25990000000, 'proof_size': 11990383647911208550},
constructor="new",
args={'init_value': True},
upload_code=True,
deployment_salt="test2"
value=0,
gas_limit={'ref_time': 25990000000, 'proof_size': 11990383647911208550},
upload_code=True
)

print(f'✅ Deployed @ {contract.contract_address}')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ eth_utils>=1.3.0,<3
pycryptodome>=3.11.0,<4
PyNaCl>=1.0.1,<2

scalecodec>=1.2.2,<1.3
scalecodec>=1.2.3,<1.3
py-sr25519-bindings>=0.2.0,<1
py-ed25519-zebra-bindings>=1.0,<2
py-bip39-bindings>=0.1.9,<1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
'eth_utils>=1.3.0,<3',
'pycryptodome>=3.11.0,<4',
'PyNaCl>=1.0.1,<2',
'scalecodec>=1.2.2,<1.3',
'scalecodec>=1.2.3,<1.3',
'py-sr25519-bindings>=0.2.0,<1',
'py-ed25519-zebra-bindings>=1.0,<2',
'py-bip39-bindings>=0.1.9,<1'
Expand Down
15 changes: 8 additions & 7 deletions substrateinterface/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def upload_wasm(self, keypair: Keypair, storage_deposit_limit: int = None) -> Ex

return self.substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)

def deploy(self, keypair: Keypair, endowment: int, gas_limit: dict, constructor: str, args: dict = None,
def deploy(self, keypair: Keypair, constructor: str, args: dict = None, value: int = 0, gas_limit: dict = None,
deployment_salt: str = None, upload_code: bool = False, storage_deposit_limit: int = None
) -> "ContractInstance":
"""
Expand All @@ -631,10 +631,10 @@ def deploy(self, keypair: Keypair, endowment: int, gas_limit: dict, constructor:
Parameters
----------
keypair
endowment: Initial deposit (`value`) for the newly created contract address
gas_limit: Gas limit as WeightV2 type e.g. {'ref_time': 25990000000, 'proof_size': 11990383647911208550}
constructor: name of the constructor to use, provided in the metadata
args: arguments for the constructor
value: Value sent to created contract address
gas_limit: Gas limit as WeightV2 type. Will default to {'ref_time': 25990000000, 'proof_size': 11990383647911208550}.
deployment_salt: optional string or hex-string that acts as a salt for this deployment
upload_code: When True the WASM blob itself will be uploaded with the deploy, False if the WASM is already present on-chain
storage_deposit_limit: The maximum amount of balance that can be charged to pay for the storage consumed.
Expand All @@ -647,6 +647,9 @@ def deploy(self, keypair: Keypair, endowment: int, gas_limit: dict, constructor:
# Lookup constructor
data = self.metadata.generate_constructor_data(name=constructor, args=args)

if gas_limit is None:
gas_limit = {'ref_time': 25990000000, 'proof_size': 11990383647911208550}

if upload_code is True:

if not self.wasm_bytes:
Expand All @@ -656,8 +659,7 @@ def deploy(self, keypair: Keypair, endowment: int, gas_limit: dict, constructor:
call_module='Contracts',
call_function='instantiate_with_code',
call_params={
'endowment': endowment, # deprecated
'value': endowment,
'value': value,
'gas_limit': gas_limit,
'storage_deposit_limit': storage_deposit_limit,
'code': '0x{}'.format(self.wasm_bytes.hex()),
Expand All @@ -671,8 +673,7 @@ def deploy(self, keypair: Keypair, endowment: int, gas_limit: dict, constructor:
call_module='Contracts',
call_function='instantiate',
call_params={
'endowment': endowment, # deprecated
'value': endowment,
'value': value,
'gas_limit': gas_limit,
'storage_deposit_limit': storage_deposit_limit,
'code_hash': f'0x{self.code_hash.hex()}',
Expand Down