def test_wireup(self): """ Verify that the command is wired up correctly. The API method indeed calls the appropiate command. """ with patch( 'iota.commands.core.were_addresses_spent_from.WereAddressesSpentFromCommand.__call__', MagicMock(return_value='You found me!')) as mocked_command: api = Iota(self.adapter) # Don't need to call with proper args here. response = api.were_addresses_spent_from('addresses') self.assertTrue(mocked_command.called) self.assertEqual(response, 'You found me!')
from iota import Iota from iota import ProposedTransaction from iota import Address from iota import Tag from iota import TryteString from iota.crypto.types import Seed node1 = 'https://nodes.comnet.thetangle.org:443' node2 = 'http://localhost:14265' seed = Seed.random() print('Your seed is', seed) api = Iota(node2, seed, testnet=True) security_level = 2 address = api.get_new_addresses(index=0, count=1, security_level=security_level)['addresses'][0] is_spent = api.were_addresses_spent_from([address])['states'][0] if is_spent: print('Address %s is spent!' % address) else: print('Your address is: %s' % address)
class IotaControl: # init and set startup vars def __init__(self, config, hjson, index): self.api = Iota(config.getNodeUrl(), config.getSeed()) self.secLvl = config.getSecLvl() self.checksum = config.getChecksum() self.jspath = config.getJsonPath() self.json = hjson self.index = index # generate new address, check if it was spent from def generate_new_address(self): if os.path.isfile(self.jspath): self.index = self.json.get_last_index() else: self.index = 0 new_add = self.api.get_new_addresses(index=self.index, count=1, security_level=self.secLvl, checksum=self.checksum) print('generating address with index: ', self.index) self.new_address = str(new_add['addresses'][0]) self.check_spent() # check if address has spent before def check_spent(self): # get rid of the checksum to pass to were_addresses_spent_from self.address_to_check = [self.new_address[0:81]] sp = self.api.were_addresses_spent_from(self.address_to_check) self.spent = sp['states'][0] print('address has spent before: ', self.spent) self.write_to_file() # write to file def write_to_file(self): no = self.index spent = self.spent address = self.new_address if os.path.isfile(self.jspath): self.json.write_json(no, spent, address) self.index += 1 else: self.json.construct_json(no, spent, address) self.index += 1 if spent is True: self.index += 1 self.generate_new_address() else: pass