def test_7_import_token(self): wallet = self.GetWallet1() token_hash = b'31730cc9a1844891a3bafd1aa929a4142860d8d3' contract = Blockchain.Default().GetContract(token_hash) token = NEP5Token(binascii.hexlify(contract.Code.Script)) token.Query() self.assertEqual(token.name, 'NEX Template V4') self.assertEqual(token.decimals, 8) self.assertEqual(token.symbol, 'NXT4') wallet.AddNEP5Token(token) wallet = self.GetWallet1(recreate=True) # re-open wallet self.assertEqual(len(wallet.GetTokens()), 1) wallet.DeleteNEP5Token(token.ScriptHash) wallet = self.GetWallet1(recreate=True) # re-open wallet self.assertEqual(len(wallet.GetTokens()), 0)
def test_7_import_token(self): wallet = self.GetWallet1() token_hash = b'f8d448b227991cf07cb96a6f9c0322437f1599b9' contract = Blockchain.Default().GetContract(token_hash) token = NEP5Token(binascii.hexlify(contract.Code.Script)) token.Query() self.assertEqual(token.name, 'NEP5 Standard') self.assertEqual(token.decimals, 8) self.assertEqual(token.symbol, 'NEP5') wallet.AddNEP5Token(token) wallet = self.GetWallet1(recreate=True) # re-open wallet self.assertEqual(len(wallet.GetTokens()), 1) wallet.DeleteNEP5Token(token.ScriptHash) wallet = self.GetWallet1(recreate=True) # re-open wallet self.assertEqual(len(wallet.GetTokens()), 0)
def get_nep5token_id(contract_hash): hash_ar = bytearray(binascii.unhexlify(contract_hash)) hash_ar.reverse() hash = UInt160(data=hash_ar) token = NEP5Token() token.SetScriptHash(hash) # token.symbol = "TNC" token.decimals = 8 return token
def DeserializePayload(self, reader): if self.event_type in [SmartContractEvent.CONTRACT_CREATED, SmartContractEvent.CONTRACT_MIGRATED]: self.contract = ContractState() self.contract.Deserialize(reader) try: from neo.Wallets.NEP5Token import NEP5Token token = NEP5Token(binascii.hexlify(self.contract.Code.Script)) token.Deserialize(reader) self.token = token except Exception as e: logger.debug("Couldnt deserialize token %s " % e)
def DetermineIsNEP5(self): """ Determines if this Smart contract is an NEP5 Token or not. Returns: bool """ from neo.Wallets.NEP5Token import NEP5Token self._is_nep5 = False token = NEP5Token(binascii.hexlify(self.Code.Script)) if token.Query(): self._nep_token = token self._is_nep5 = True return self._is_nep5
def DeleteToken(wallet, contract_hash): contract = Blockchain.Default().GetContract(contract_hash) if contract: hex_script = binascii.hexlify(contract.Code.Script) token = NEP5Token(script=hex_script) success = wallet.DeleteNEP5Token(token) if success: print("Deleted token %s " % contract_hash) else: print("error deleting token %s " % contract_hash) else: print("Contract %s not found " % contract_hash) return False
def ImportToken(wallet, contract_hash): if wallet is None: print("please open a wallet") return False contract = Blockchain.Default().GetContract(contract_hash) if contract: hex_script = binascii.hexlify(contract.Code.Script) token = NEP5Token(script=hex_script) result = token.Query() if result: wallet.AddNEP5Token(token) print("added token %s " % json.dumps(token.ToJson(), indent=4)) else: print("Could not import token")