def __init_debot(self, keypair: KeyPair) -> Tuple[str, str]: """ Deploy debot and target """ signer = Signer.Keys(keys=keypair) debot_abi = Abi.from_path( path=os.path.join(SAMPLES_DIR, 'Debot.abi.json')) with open(os.path.join(SAMPLES_DIR, 'Debot.tvc'), 'rb') as fp: debot_tvc = base64.b64encode(fp.read()).decode() # Deploy target call_set = CallSet(function_name='constructor') deploy_set = DeploySet(tvc=self.target_tvc) encode_params = ParamsOfEncodeMessage( abi=self.target_abi, signer=signer, deploy_set=deploy_set, call_set=call_set) message = async_custom_client.abi.encode_message(params=encode_params) # Check if target contract does not exists target_address = self.__check_address(address=message.address) if not target_address: process_params = ParamsOfProcessMessage( message_encode_params=encode_params, send_events=False) target = async_custom_client.processing.process_message( params=process_params) target_address = target.transaction['account_addr'] # Deploy debot call_set = CallSet( function_name='constructor', input={ 'targetAbi': self.target_abi.value.encode().hex(), 'targetAddr': target_address }) deploy_set = DeploySet(tvc=debot_tvc) encode_params = ParamsOfEncodeMessage( abi=debot_abi, signer=signer, deploy_set=deploy_set, call_set=call_set) message = async_custom_client.abi.encode_message(params=encode_params) # Check if debot contract does not exists debot_address = self.__check_address(address=message.address) if not debot_address: process_params = ParamsOfProcessMessage( message_encode_params=encode_params, send_events=False) debot = async_custom_client.processing.process_message( params=process_params) debot_address = debot.transaction['account_addr'] # Set ABI call_set = CallSet( function_name='setAbi', input={'debotAbi': debot_abi.value.encode().hex()}) async_custom_client.processing.process_message( params=ParamsOfProcessMessage( message_encode_params=ParamsOfEncodeMessage( abi=debot_abi, signer=Signer.NoSigner(), address=debot_address, call_set=call_set), send_events=False)) return debot_address, target_address
def send_grams(address: str): giver_abi = Abi.from_path(path=os.path.join(SAMPLES_DIR, 'Giver.abi.json')) call_set = CallSet(function_name='grant', input={'dest': address}) encode_params = ParamsOfEncodeMessage(abi=giver_abi, signer=Signer.NoSigner(), address=GIVER_ADDRESS, call_set=call_set) process_params = ParamsOfProcessMessage( message_encode_params=encode_params, send_events=False) async_custom_client.processing.process_message(params=process_params)
def __init_debot5(self, count: int) -> Tuple[List[str], str]: debot_abi = Abi.from_path( path=os.path.join(SAMPLES_DIR, 'Debot5.abi.json')) with open(os.path.join(SAMPLES_DIR, 'Debot5.tvc'), 'rb') as fp: debot_tvc = base64.b64encode(fp.read()).decode() result = async_custom_client.boc.get_code_from_tvc( params=ParamsOfGetCodeFromTvc(tvc=debot_tvc)) result = async_custom_client.boc.get_boc_hash( params=ParamsOfGetBocHash(boc=result.code)) contract_hash = result.hash call_set = CallSet( function_name='constructor', input={'codeHash': f'0x{contract_hash}'}) deploy_set = DeploySet(tvc=debot_tvc) deploy_params = ParamsOfEncodeMessage( abi=debot_abi, deploy_set=deploy_set, call_set=call_set, signer=Signer.NoSigner()) addresses = [] for i in range(count): # Set signer for deploy params keypair = async_custom_client.crypto.generate_random_sign_keys() deploy_params.signer = Signer.Keys(keys=keypair) # Calculate address message = async_custom_client.abi.encode_message( params=deploy_params) self.__check_address(address=message.address) # Deploy address process_params = ParamsOfProcessMessage( message_encode_params=deploy_params, send_events=False) result = async_custom_client.processing.process_message( params=process_params) debot_address = result.transaction['account_addr'] addresses.append(debot_address) if i > 0: continue # Set ABI call_set = CallSet( function_name='setABI', input={'dabi': debot_abi.value.encode().hex()}) async_custom_client.processing.process_message( params=ParamsOfProcessMessage( message_encode_params=ParamsOfEncodeMessage( abi=debot_abi, signer=deploy_params.signer, address=debot_address, call_set=call_set), send_events=False)) return addresses, contract_hash