Esempio n. 1
0
 def __init__(self, sdk: OntologySdk, abi: dict, hex_contract_address: str):
     if not isinstance(sdk, OntologySdk):
         raise PotException(PotError.invalid_sdk)
     if not isinstance(abi, dict):
         raise PotException(PotError.invalid_abi_type)
     if not isinstance(hex_contract_address, str):
         raise PotException(PotError.invalid_contract_address_hex_type)
     if len(hex_contract_address) != 40:
         raise PotException(PotError.invalid_contract_address_hex_len)
     self.__sdk = sdk
     self.__contract_address_hex = hex_contract_address
     self.__contract_address_bytearray = bytearray(
         binascii.a2b_hex(hex_contract_address))
     self.__contract_address_bytearray.reverse()
     self.__abi = abi
     entry_point = self.__abi.get('entrypoint', '')
     functions = self.__abi['abi']['functions']
     events = self.__abi.get('events', list())
     self.__abi_info = AbiInfo(hex_contract_address, entry_point, functions,
                               events)
Esempio n. 2
0
 def take_ong_out(self, from_acct: Account, gas_limit: int, gas_price: int):
     take_ong_out = self.__abi_info.get_function('take_ong_out')
     take_ong_out.set_params_value((from_acct.get_address().to_array(), ))
     try:
         tx_hash = self.__sdk.neo_vm().send_transaction(
             self.__contract_address_bytearray, from_acct, from_acct,
             gas_limit, gas_price, take_ong_out, False)
         return tx_hash
     except SDKException as e:
         if 'vm execute state fault' in e.args[1]:
             return False
         else:
             raise PotException(PotError.create_ong_pot_failed)
Esempio n. 3
0
 def saving_ong(self, from_acct: Account, amount: int, gas_limit: int,
                gas_price: int):
     saving_ong = self.__abi_info.get_function('saving_ong')
     saving_ong.set_params_value(
         (from_acct.get_address().to_array(), amount))
     try:
         return self.__sdk.neo_vm().send_transaction(
             self.__contract_address_bytearray, from_acct, from_acct,
             gas_limit, gas_price, saving_ong, False)
     except SDKException as e:
         if 'vm execute state fault' in e.args[1]:
             return False
         else:
             raise PotException(PotError.create_ong_pot_failed)
Esempio n. 4
0
 def get_ont_pot_tx_hash(self, bytearray_address: bytearray):
     get_ont_pot_tx_hash = self.__abi_info.get_function(
         'get_ont_pot_tx_hash')
     get_ont_pot_tx_hash.set_params_value((bytearray_address, ))
     try:
         data = self.__sdk.neo_vm().send_transaction(
             self.__contract_address_bytearray, None, None, 0, 0,
             get_ont_pot_tx_hash, True)
         data = binascii.a2b_hex(data).decode('ascii')
         return data
     except SDKException as e:
         if 'vm execute state fault' in e.args[1]:
             return False
         else:
             raise PotException(PotError.create_ong_pot_failed)
Esempio n. 5
0
 def put_ong_pot_tx_hash(self, from_acct: Account, tx_hash: str,
                         gas_limit: int, gas_price: int):
     put_ont_pot_tx_hash = self.__abi_info.get_function(
         'put_ong_pot_tx_hash')
     put_ont_pot_tx_hash.set_params_value(
         (from_acct.get_address().to_array(), tx_hash))
     try:
         return self.__sdk.neo_vm().send_transaction(
             self.__contract_address_bytearray, from_acct, from_acct,
             gas_limit, gas_price, put_ont_pot_tx_hash, False)
     except SDKException as e:
         if 'vm execute state fault' in e.args[1]:
             return False
         else:
             raise PotException(PotError.create_ong_pot_failed)
Esempio n. 6
0
 def create_ont_pot(self,
                    from_acct: Account,
                    time_limit: int,
                    gas_limit: int = 20000000,
                    gas_price: int = 500):
     create_function = self.__abi_info.get_function('create_ont_pot')
     create_function.set_params_value(
         (from_acct.get_address().to_array(), time_limit))
     try:
         tx_hash = self.__sdk.neo_vm().send_transaction(
             self.__contract_address_bytearray, from_acct, from_acct,
             gas_limit, gas_price, create_function, False)
         return tx_hash
     except SDKException as e:
         if 'vm execute state fault' in e.args[1]:
             return False
         else:
             raise PotException(PotError.create_ont_pot_failed)