Esempio n. 1
0
    def create_account(
        self,
        originator,
        account_id,
        amount,
        account_public_key,
    ):
        if not account_public_key:
            account_public_key = self._get_public_key()

        nonce = self._get_nonce(originator)

        create_account = signed_transaction_pb2.CreateAccountTransaction()
        create_account.nonce = nonce
        create_account.originator = originator
        create_account.new_account_id = account_id
        create_account.amount = amount
        create_account.public_key = b58.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(originator)
        return self._submit_transaction(signed_transaction)
Esempio n. 2
0
    def schedule_function_call(
        self,
        originator,
        contract_name,
        method_name,
        amount,
        args=None,
    ):
        if args is None:
            args = "{}"

        nonce = self._get_nonce(originator)
        function_call = signed_transaction_pb2.FunctionCallTransaction()
        function_call.nonce = nonce
        function_call.originator = originator
        function_call.contract_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(originator)
        return self._submit_transaction(signed_transaction)
Esempio n. 3
0
    def stake(self, originator, amount):
        nonce = self._get_nonce(originator)

        stake = signed_transaction_pb2.StakeTransaction()
        stake.nonce = nonce
        stake.originator = originator
        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(originator)
        return self._submit_transaction(signed_transaction)
Esempio n. 4
0
    def send_money(self, originator, receiver, amount):
        nonce = self._get_nonce(originator)

        send_money = signed_transaction_pb2.SendMoneyTransaction()
        send_money.nonce = nonce
        send_money.originator = originator
        send_money.receiver = 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(originator)
        return self._submit_transaction(signed_transaction)
Esempio n. 5
0
    def deploy_contract(self, contract_name, wasm_file):
        with open(wasm_file, 'rb') as f:
            wasm_byte_array = f.read()

        nonce = self._get_nonce(contract_name)

        deploy_contract = signed_transaction_pb2.DeployContractTransaction()
        deploy_contract.nonce = nonce
        deploy_contract.contract_id = contract_name
        deploy_contract.wasm_byte_array = wasm_byte_array

        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(contract_name)
        return self._submit_transaction(signed_transaction)
Esempio n. 6
0
    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 = account
        swap_key.cur_key = b58.b58decode(current_key)
        swap_key.new_key = b58.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)