def create_account( self, sender, account_alias, amount, account_public_key, ): if not account_public_key: account_public_key = self._get_public_key() nonce = self._get_nonce(sender) create_account = signed_transaction_pb2.CreateAccountTransaction() create_account.nonce = nonce create_account.originator = _get_account_id(sender) create_account.new_account_id = _get_account_id(account_alias) create_account.amount = amount create_account.public_key = b58decode(account_public_key) signature = self._sign_transaction_body(create_account) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.create_account.CopyFrom(create_account) signed_transaction.signature = signature self._update_nonce(sender) return self._submit_transaction(signed_transaction)
def schedule_function_call( self, sender, contract_name, method_name, amount, args=None, ): if args is None: args = "{}" nonce = self._get_nonce(sender) function_call = signed_transaction_pb2.FunctionCallTransaction() function_call.nonce = nonce function_call.originator = _get_account_id(sender) function_call.contract_id = _get_account_id(contract_name) function_call.method_name = method_name.encode('utf-8') function_call.args = args.encode('utf-8') function_call.amount = amount signature = self._sign_transaction_body(function_call) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.function_call.CopyFrom(function_call) signed_transaction.signature = signature self._update_nonce(sender) return self._submit_transaction(signed_transaction)
def send_money(self, receiver, amount, wait=False): self._nonce += 1 send_money = signed_transaction.SendMoneyTransaction() send_money.nonce = self._nonce send_money.originator = self._account_id send_money.receiver = receiver send_money.amount = amount signature = self._sign_transaction_body(send_money) transaction = signed_transaction.SignedTransaction() transaction.send_money.CopyFrom(send_money) transaction.signature = signature return self._rpc.send_transaction(transaction, wait=wait)
def stake(self, sender, amount): nonce = self._get_nonce(sender) stake = signed_transaction_pb2.StakeTransaction() stake.nonce = nonce stake.originator = _get_account_id(sender) stake.amount = amount signature = self._sign_transaction_body(stake) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.stake.CopyFrom(stake) signed_transaction.signature = signature self._update_nonce(sender) return self._submit_transaction(signed_transaction)
def send_money(self, sender, receiver, amount): nonce = self._get_nonce(sender) send_money = signed_transaction_pb2.SendMoneyTransaction() send_money.nonce = nonce send_money.originator = _get_account_id(sender) send_money.receiver = _get_account_id(receiver) send_money.amount = amount signature = self._sign_transaction_body(send_money) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.send_money.CopyFrom(send_money) signed_transaction.signature = signature self._update_nonce(sender) return self._submit_transaction(signed_transaction)
def deploy_contract(self, sender, contract_name, wasm_file): with open(wasm_file, 'rb') as f: wasm_byte_array = f.read() nonce = self._get_nonce(sender) deploy_contract = signed_transaction_pb2.DeployContractTransaction() deploy_contract.nonce = nonce deploy_contract.originator = _get_account_id(sender) deploy_contract.contract_id = _get_account_id(contract_name) deploy_contract.wasm_byte_array = wasm_byte_array deploy_contract.public_key = b58decode(self._get_public_key()) signature = self._sign_transaction_body(deploy_contract) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.deploy_contract.CopyFrom(deploy_contract) signed_transaction.signature = signature self._update_nonce(sender) return self._submit_transaction(signed_transaction)
def swap_key( self, account, current_key, new_key, ): nonce = self._get_nonce(account) swap_key = signed_transaction_pb2.SwapKeyTransaction() swap_key.nonce = nonce swap_key.originator = _get_account_id(account) swap_key.cur_key = b58decode(current_key) swap_key.new_key = b58decode(new_key) signature = self._sign_transaction_body(swap_key) signed_transaction = signed_transaction_pb2.SignedTransaction() signed_transaction.swap_key.CopyFrom(swap_key) signed_transaction.signature = signature self._update_nonce(account) return self._submit_transaction(signed_transaction)