Beispiel #1
0
 def new_transfer_multi_tx(self, transfer_list: list,
                           payer: Union[str, bytes,
                                        Address], gas_price: int,
                           gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which can
     transfer amount of token from from-account to to-account multiple times.
     """
     func = NeoInvokeFunction('transferMulti')
     for index, item in enumerate(transfer_list):
         if not isinstance(item[2], int):
             raise SDKException(
                 ErrorCode.param_err(
                     'the data type of value should be int.'))
         if item[2] < 0:
             raise SDKException(
                 ErrorCode.param_err(
                     'the value should be equal or great than 0.'))
         transfer_list[index] = [
             Address.b58decode(item[0]),
             Address.b58decode(item[1]), item[2]
         ]
     for item in transfer_list:
         func.add_params_value(item)
     params = InvokeTransaction.generate_neo_vm_invoke_code(
         self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx
Beispiel #2
0
 def new_total_supply_tx(self) -> InvokeTransaction:
     """
     This interface is used to generate transaction which can get the total token supply.
     """
     tx = InvokeTransaction()
     tx.add_invoke_code(self._contract_address, InvokeFunction('totalSupply'))
     return tx
Beispiel #3
0
 def new_commit_tx(self, claim_id: str, issuer_address: Union[str, bytes, Address], owner_ont_id: str,
                   payer_address: Union[str, bytes, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     func = NeoInvokeFunction('Commit')
     func.set_params_value(claim_id, Address.b58decode(issuer_address), owner_ont_id)
     tx = InvokeTransaction(Address.b58decode(payer_address), gas_price, gas_limit)
     tx.add_invoke_code(self.__hex_contract_address, func)
     return tx
Beispiel #4
0
 def new_revoke_tx(self, claim_id: str, issuer: Union[str, bytes, Address], payer: Union[str, bytes, Address],
                   gas_price: int, gas_limit: int):
     func = NeoInvokeFunction('Revoke')
     func.set_params_value(claim_id, Address.b58decode(issuer))
     tx = InvokeTransaction(Address.b58decode(payer), gas_price, gas_limit)
     tx.add_invoke_code(self.__hex_contract_address, func)
     return tx
Beispiel #5
0
 def new_allowance_tx(self, owner: Union[str, bytes, Address],
                      spender: Union[str, bytes, Address]) -> InvokeTransaction:
     func = InvokeFunction('allowance')
     func.set_params_value(Address.b58decode(owner), Address.b58decode(spender))
     tx = InvokeTransaction()
     tx.add_invoke_code(self._contract_address, func)
     return tx
Beispiel #6
0
 def new_init_tx(self, payer: Union[str, bytes, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to call the TotalSupply method in ope4
     that initialize smart contract parameter.
     """
     tx = InvokeTransaction(payer, gas_price, gas_limit)
     tx.add_invoke_code(self._contract_address, InvokeFunction('init'))
     return tx
Beispiel #7
0
 def make_invoke_transaction(contract_address: Union[str, bytes, bytearray, Address],
                             func: Union[AbiFunction, InvokeFunction],
                             payer: Union[str, bytes, Address] = b'',
                             gas_price: int = 0,
                             gas_limit: int = 0) -> InvokeTransaction:
     tx = InvokeTransaction(payer, gas_price, gas_limit)
     tx.add_invoke_code(contract_address, func)
     return tx
Beispiel #8
0
 def make_invoke_transaction(contract_address: Union[str, bytes, bytearray, Address],
                             func: WasmInvokeFunction,
                             payer: Union[str, bytes, Address] = b'',
                             gas_price: int = 0,
                             gas_limit: int = 0) -> InvokeTransaction:
     payload = InvokeTransaction.generate_wasm_vm_invoke_code(contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, payload, TxType.InvokeWasmVm)
     return tx
Beispiel #9
0
 def new_balance_of_tx(self, owner: Union[str, bytes, Address]) -> InvokeTransaction:
     """
     This interface is used to generate transaction which can get the account balance of another account with owner address.
     """
     func = InvokeFunction('balanceOf')
     func.set_params_value(Address.b58decode(owner))
     tx = InvokeTransaction()
     tx.add_invoke_code(self._contract_address, func)
     return tx
Beispiel #10
0
 def __add_signature(self, tx: InvokeTransaction, signer_address_list: List[str], payer_address: str = ''):
     if len(payer_address) == 34:
         payer = self.get_acct_by_address(payer_address)
         tx.sign_transaction(payer)
     for signer_address in signer_address_list:
         if signer_address == payer_address:
             continue
         signer = self.get_acct_by_address(signer_address)
         tx.add_sign_transaction(signer)
     return tx
Beispiel #11
0
 def new_transfer_tx(self, from_address: Union[str, Address], to_address: Union[str, Address], amount: int,
                     payer: Union[str, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which can transfer amount of tokens to to_address.
     """
     func = InvokeFunction('transfer')
     func.set_params_value(Address.b58decode(from_address), Address.b58decode(to_address), amount)
     params = InvokeTransaction.generate_invoke_code(self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx
Beispiel #12
0
 def new_transfer_from_tx(self, spender: Union[str, bytes, Address], owner: Union[str, bytes, Address],
                          to_address: Union[str, bytes, Address], value: int, payer: Union[str, bytes, Address],
                          gas_price: int, gas_limit: int) -> InvokeTransaction:
     func = InvokeFunction('transferFrom')
     if not isinstance(value, int):
         raise SDKException(ErrorCode.param_err('the data type of value should be int.'))
     func.set_params_value(Address.b58decode(spender), Address.b58decode(owner), Address.b58decode(to_address),
                           value)
     tx = InvokeTransaction(payer, gas_price, gas_limit)
     tx.add_invoke_code(self._contract_address, func)
     return tx
Beispiel #13
0
 def new_approve_tx(self, owner: Union[str, bytes, Address], spender: Union[str, bytes, Address], amount: int,
                    payer: Union[str, bytes, Address], gas_price: int, gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a transaction which allows spender to
     withdraw from owner account multiple times, up to the _value amount.
     If this function is called again it overwrites the current allowance with amount value.
     """
     if not isinstance(amount, int):
         raise SDKException(ErrorCode.param_err('the data type of amount should be int.'))
     if amount < 0:
         raise SDKException(ErrorCode.param_err('the amount should be equal or great than 0.'))
     func = InvokeFunction('approve')
     func.set_params_value(Address.b58decode(owner), Address.b58decode(spender), amount)
     params = InvokeTransaction.generate_invoke_code(self._contract_address, func)
     tx = InvokeTransaction(payer, gas_price, gas_limit, params)
     return tx
Beispiel #14
0
 def new_balance_of_tx(self, owner: Union[str,
                                          Address]) -> InvokeTransaction:
     owner = Address.b58decode(owner)
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'balanceOf',
                                            owner)
     return InvokeTransaction(payload=invoke_code)
Beispiel #15
0
 def new_allowance_tx(self, from_address: Union[str, Address],
                      to_address: Union[str, Address]) -> InvokeTransaction:
     args = dict(from_address=Address.b58decode(from_address),
                 to_address=Address.b58decode(to_address))
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'allowance',
                                            args)
     return InvokeTransaction(payload=invoke_code)
Beispiel #16
0
 def new_transfer_from_tx(self, spender: Union[str, Address],
                          from_address: Union[str, Address],
                          receiver: Union[str, Address], amount: int,
                          payer: Union[str, Address], gas_price: int,
                          gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a Transaction object that allow one account to transfer
     a amount of ONT or ONG Asset to another account, in the condition of the first account had been approved.
     """
     args = dict(spender=Address.b58decode(spender),
                 from_address=Address.b58decode(from_address),
                 to_address=Address.b58decode(receiver),
                 amount=amount)
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'transferFrom',
                                            args)
     return InvokeTransaction(Address.b58decode(payer), gas_price,
                              gas_limit, invoke_code)
Beispiel #17
0
 def new_approve_tx(self, approver: Union[str,
                                          Address], spender: Union[str,
                                                                   Address],
                    amount: int, payer: Union[str, Address], gas_price: int,
                    gas_limit: int) -> Transaction:
     """
     This interface is used to generate a Transaction object for approve.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     args = dict(sender=Address.b58decode(approver),
                 receiver=Address.b58decode(spender),
                 amount=amount)
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'approve', args)
     return InvokeTransaction(Address.b58decode(payer), gas_price,
                              gas_limit, invoke_code)
Beispiel #18
0
 def new_transfer_tx(self, from_address: Union[str, Address],
                     to_address: Union[str, Address], amount: int,
                     payer: Union[str, Address], gas_price: int,
                     gas_limit: int) -> Transaction:
     """
     This interface is used to generate a Transaction object for transfer.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     state = [{
         'from': Address.b58decode(from_address),
         'to': Address.b58decode(to_address),
         'amount': amount
     }]
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'transfer',
                                            state)
     return InvokeTransaction(Address.b58decode(payer), gas_price,
                              gas_limit, invoke_code)
Beispiel #19
0
 def new_withdraw_tx(self, claimer: Union[str, Address],
                     receiver: Union[str, Address], amount: int,
                     payer: Union[str, Address], gas_price: int,
                     gas_limit: int) -> InvokeTransaction:
     """
     This interface is used to generate a Transaction object that
     allow one account to withdraw an amount of ong and transfer them to receive address.
     """
     if amount <= 0:
         raise SDKException(
             ErrorCode.other_error(
                 'the amount should be greater than than zero.'))
     payer = Address.b58decode(payer)
     ont_contract = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
     args = dict(claimer=Address.b58decode(claimer),
                 from_address=ont_contract,
                 to_address=Address.b58decode(receiver),
                 value=amount)
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, 'transferFrom',
                                            args)
     return InvokeTransaction(payer, gas_price, gas_limit, invoke_code)
Beispiel #20
0
 def _new_token_setting_tx(self, func_name: str) -> InvokeTransaction:
     invoke_code = build_native_invoke_code(self._invoke_address,
                                            self._version, func_name,
                                            bytearray())
     return InvokeTransaction(payload=invoke_code)
Beispiel #21
0
 def __new_token_setting_tx(self, func_name: str) -> InvokeTransaction:
     func = InvokeFunction(func_name)
     tx = InvokeTransaction()
     tx.add_invoke_code(self._contract_address, func)
     return tx
Beispiel #22
0
 def make_invoke_transaction(code_addr: bytearray, params: bytearray,
                             payer: bytes, gas_limit: int, gas_price: int):
     params += bytearray([0x67])
     params += code_addr
     invoke_tx = InvokeTransaction()
     invoke_tx.version = 0
     invoke_tx.sigs = bytearray()
     invoke_tx.attributes = bytearray()
     unix_time_now = int(time())
     invoke_tx.nonce = unix_time_now
     invoke_tx.code = params
     invoke_tx.gas_limit = gas_limit
     invoke_tx.gas_price = gas_price
     if isinstance(payer, bytes) and payer != b'':
         invoke_tx.payer = payer
     else:
         invoke_tx.payer = Address(ZERO_ADDRESS).to_array()
     return invoke_tx
Beispiel #23
0
 def _generate_transaction(self, method: str, args: dict, payer: Union[str, bytes, Address], gas_price: int,
                           gas_limit: int) -> InvokeTransaction:
     invoke_code = build_vm.build_native_invoke_code(self._contract_address, self._version, method, args)
     return InvokeTransaction(payer, gas_price, gas_limit, invoke_code)
Beispiel #24
0
 def new_get_status_tx(self, claim_id: str) -> InvokeTransaction:
     func = NeoInvokeFunction('GetStatus')
     func.set_params_value(claim_id)
     tx = InvokeTransaction()
     tx.add_invoke_code(self.__hex_contract_address, func)
     return tx