def main(address, depth, message, tag, uri, value): # Ensure seed is not displayed in cleartext. seed = get_seed() # Create the API instance. api = Iota(uri, seed) if not seed: print('A random seed has been generated. Press return to see it.') output_seed(api.seed) print('Starting transfer.') # For more information, see :py:meth:`Iota.send_transfer`. api.send_transfer( depth=depth, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address(address), # Amount of IOTA to transfer. # By default this is a zero value transfer. value=value, # Optional tag to attach to the transfer. tag=Tag(tag), # Optional message to include with the transfer. message=TryteString.from_string(message), ), ], ) print('Transfer complete.')
def main(): # Ensure seed is not displayed in cleartext. #seed = get_seed() # Create the API instance. while(1): api = Iota("http://localhost:14265") #if not seed: # print('A random seed has been generated. Press return to see it.') # output_seed(api.seed) #print('Starting transfer.') # For more information, see :py:meth:`Iota.send_transfer`. api.send_transfer( depth=3, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address("RECEIVINGWALLETADDRESSGOESHERE9WITHCHECKSUMANDSECURITYLEVELB999999999999999999999999999999"), # Amount of IOTA to transfer. # By default this is a zero value transfer. value=0, # Optional tag to attach to the transfer. tag=Tag(b'KITTEHS'), # Optional message to include with the transfer. message=TryteString.from_unicode('thx fur cheezburgers'), ), ], min_weight_magnitude=1 )
def sendToAddress(self, message, address, depth, tag, value): api = Iota("http://iota.av.it.pt:14265") # Sample Data # address = b'RECEIVINGWALLETADDRESSGOESHERE9WITHCHECKSUMANDSECURITYLEVELB999999999999999999999RQXIUOZMD' # depth = 3 # tag = b'IOTAPASS' # value = 0 # For more information, see :py:meth:`Iota.send_transfer`. try: api.send_transfer( depth=depth, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address(address), # Amount of IOTA to transfer. # By default this is a zero value transfer. value=value, # Optional tag to attach to the transfer. tag=Tag(tag), # Optional message to include with the transfer. message=TryteString.from_string(message), ), ], ) return True except: return False
def run(self): node_a_ip = self.node_a.ip node_b_ip = self.node_b.ip print_t(node_a_ip, "Starting thread...") print_t( node_a_ip, "Adding node {0} as a neighbour to {1}".format( node_b_ip, node_a_ip)) print_t( node_a_ip, "Attempting to connect to node: http://{0}:14265".format( node_a_ip)) try_again = True while try_again and self.retries > 0: try: api = Iota("http://{0}:14265".format(node_a_ip)) api.add_neighbors(["udp://{0}:14777".format(node_b_ip)]) self.node_a.connected_nodes.append(node_b_ip) print_t( node_a_ip, "Added node {0} as a neighbour to {1}".format( node_b_ip, node_a_ip)) try_again = False except: self.retries -= 1 print_t(node_a_ip, ERROR_MSG.format(node_a_ip, self.delay, self.retries)) try_again = True if self.retries != 0: time.sleep(self.delay) print_t(node_a_ip, "Exiting thread.")
def addressGenerator(seed): api = Iota( iotaNode, seed ) # The iota nodes IP address must always be supplied, even if it actually isn't used in this case. gna_result = api.get_new_addresses( count=numberOfAddresses ) # This is the function to generate the address. addresses = gna_result['addresses'] i = 0 #int for number of addresses #print("Checking seed: " + seed) while i < numberOfAddresses: address = [addresses[i]] #print(" checking address : " + str(address[0])) i += 1 if address[ 0] == known_recieving_value: # If the address is equal to the recieving address then.. (Address without checksum) print("Bruteforcer Finished") print("The seed is: " + seed) file = open("seed.txt", "w") #Open file. file.write("Bingo. The seed is: " + seed) #print out bingo and the correct seed. file.close() #Close the file to save changes. #if it finds the correct address stop the program. increment( seed ) #increase counter by 1 and check if seed needs to be saved into log.
class Car: def __init__(self, seed): self.api = Iota('https://iotanode.us:443', seed) def getAddress(self, count=1): new_address = self.api.get_new_addresses(count=count) print(new_address) return new_address def sendiota(self, address, amount): self.api.send_transfer( depth=100, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address( address, ), # Amount of IOTA to transfer. # This value may be zero. value=amount, # Optional tag to attach to the transfer. tag=Tag(b'EXAMPLEK'), # Optional message to include with the transfer. message=TryteString.from_string('Hello!'), ), ], ) def __getAPI(self): return self.api
def checkAddresses(seed): # use IOTA api to get first n addresses of the seed api = Iota(iotaNode, seed) apiAdresses = api.get_new_addresses(count=numberOfAddresses) addresses = apiAdresses['addresses'] # check if one of the addresses matches the public known transaction address i = 0 while i < numberOfAddresses: address = str([addresses[i]][0]) if (publicTransactionAddress.startswith(address)): if (numberOfAddresses == 1): print( "\nAs we only checked one (i.e. the first) address of a seed, there can only be one result." ) print( "Please try to login with the following seed and check your balance:\n\n" + seed + "\n") printDonation() sys.exit() else: print("\nTry to login with this seed (others may follow): " + seed + "\n") seedCandidates.append(seed) i += 1
def add_txn_to_queue(request_data): request_command = json.loads(request_data) node_url = request_command['node_url'] address = request_command['address'] tag = request_command['tag'] messages = request_command['messages'] values = request_command['values'] bundle_hash = "" prepared_transferes = [] api = Iota(node_url, SEED) txn = \ ProposedTransaction( address = Address(address), message = TryteString.from_string(messages), tag = Tag(tag), value = int(values), ) prepared_transferes.append(txn) try: bundle_hash = api.send_transfer( depth = 7, transfers = prepared_transferes, min_weight_magnitude = 14 ) except Exception as e: print(e) return 0 print(bundle_hash['bundle'].hash) append_log(bundle_hash['bundle'].hash, LOG_HISTORY_TXN) return 0
def main(): api = Iota("http://localhost:14265") # For more information, see :py:meth:`Iota.send_transfer`. ti = time.time() a = api.send_transfer( depth=3, transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address( "RECEIVINGWALLETADDRESSGOESHERE9WITHCHECKSUMANDSECURITYLEVELB999999999999999999999999999999" ), value=0, # Optional tag to attach to the transfer. tag=Tag(b'KITTEHS'), # Optional message to include with the transfer. message=TryteString.from_unicode('thx fur cheezburgers'), ), ], min_weight_magnitude=1) k = 0 for k in a["bundle"]: print(k)
def test_backward_compatibility(self): """ Test that the local_pow feature is backward compatible. That is, if `local_pow` argument is omitted, it takes no effect and the pow extension package is not called. """ with patch('pow.ccurl_interface.attach_to_tangle', MagicMock(return_value=self.ccurl_bundle)) as mocked_ccurl: self.adapter = MockAdapter() self.adapter.seed_response('attachToTangle',{ 'trytes': self.bundle, }) # No `local_pow` argument is passed to the api! api = Iota(self.adapter) result = api.attach_to_tangle( self.trunk, self.branch, self.bundle, self.mwm) # Ccurl interface was not called self.assertFalse(mocked_ccurl.called) # Result is the one returned by MockAdapter self.assertEqual(result['trytes'], self.bundle) # And not by mocked pow pkg self.assertNotEqual(result['trytes'], self.ccurl_bundle)
def __init__(self, config, index, jspath): self.index = index self.api = Iota(config.getNodeUrl(), config.getSeed()) self.secLvl = config.getSecLvl() self.checksum = config.getChecksum() self.jspath = jspath self.owner = config.getOwner()
def sendTX(msg): ''' PURPOSE: send transaction to the Tangle INPUT: address from a seed different than the one in this script OUTPUT: TX to devnet ''' seed = 'SEED99999999999999999999999999999999999999999999999999999999999999999999999999999' address = 'ADDRESS9FROM9DIFFERENT9SEED999999999999999999999999999999999999999999999999999999' api = Iota('https://nodes.devnet.iota.org:443', seed) tx = ProposedTransaction(address=Address(address), message=TryteString.from_unicode(msg), tag=Tag('YOURTAG'), value=0) try: tx = api.prepare_transfer(transfers=[tx]) except Exception as e: print("Check prepare_transfer ", e) raise try: result = api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=9) except: print("Check send_trytes")
def gen_account_info(account_idx, seed, nb_addrs): # api connection api = Iota('http://localhost:14265', seed) # account info account_data = api.get_account_data(stop=nb_addrs) fund = account_data['balance'] addrs = account_data['addresses'] addrs_fund = api.getBalances(addresses=addrs)['balances'] # generate account_info = \ """ //! //! Account %d //! static const std::string ACCOUNT_%d_SEED = "%s"; static const int64_t ACCOUNT_%d_FUND = %d; """ % (account_idx, account_idx, seed, account_idx, fund) for i in range(0, len(addrs)): addr_idx = i + 1 account_info += \ """ static const std::string ACCOUNT_%d_ADDRESS_%d_HASH = "%s"; static const std::string ACCOUNT_%d_ADDRESS_%d_HASH_WITHOUT_CHECKSUM = "%s"; static const int64_t ACCOUNT_%d_ADDRESS_%d_FUND = %d; """ % (account_idx, addr_idx, addrs[i].with_valid_checksum(), account_idx, addr_idx, addrs[i], account_idx, addr_idx, addrs_fund[i]) return account_info + '\n'
def load_wallet(self, wallet): config = configparser.ConfigParser() config.read(wallet) iota_seed_e = config['wallet']['iotaSeed'] iota_seed = self.key_f.decrypt( iota_seed_e.encode('utf-8')).decode('utf-8') api = Iota(self.node, iota_seed) inputs = api.get_inputs() addresses = inputs['inputs'] config['wallet']['index'] = str(len(addresses)) if len(addresses) == 0: print("No address found. Generating...") gna_result = api.get_new_addresses(count=1) addresses = gna_result['addresses'] config['wallet']['activeAddress'] = str(addresses[-1]) config['wallet']['totalBalance'] = str(inputs['totalBalance']) for i, address in enumerate(addresses): config['addresses']['Address ' + str(i)] = str(address) with open(wallet, 'w') as configfile: config.write(configfile) return api, inputs
class FSend: def __init__(self, config, index, jspath): self.index = index self.api = Iota(config.getNodeUrl(), config.getSeed()) self.secLvl = config.getSecLvl() self.checksum = config.getChecksum() self.jspath = jspath self.owner = config.getOwner() # search for addresses with inputs def get_value_addresses(self): response = self.api.get_inputs(start=0, stop=self.index, security_level=self.secLvl) self.value_addresses = response['inputs'] self.summary = response['totalBalance'] if self.summary == 0: pass else: self.send_funds() # prepare tx and send funds def send_funds(self): tx = ProposedTransaction( address=Address(self.owner), message=TryteString.from_unicode('IOTAPay Device V1'), tag=Tag('IOTAPAYTRANSACTION'), value=self.summary ) tx = self.api.prepare_transfer(transfers=[tx], inputs=self.value_addresses, change_address=self.owner) result = self.api.send_trytes(tx['trytes'], depth=3, min_weight_magnitude=14) print('Transaction with:', self.summary, 'iota sent to the tangle!')
def main(): # Ensure seed is not displayed in cleartext. seed = 'SEED99999999999999999999999999999999999999999999999999999999999999999999999999999' # Create the API instance. api = Iota("http://localhost:14265", seed) t1 = time.time() print('Starting transfer.') # For more information, see :py:meth:`Iota.send_transfer`. api.send_transfer( depth=3, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address( 'RECEIVINGWALLETADDRESSGOESHERE9WITHCHECKSUMANDSECURITYLEVELB999999999999999999999999999999' ), # Amount of IOTA to transfer. # By default this is a zero value transfer. value=42, # Optional tag to attach to the transfer. tag=Tag(b'EXAMPLE'), # Optional message to include with the transfer. message=TryteString.from_string('Hello World!'), ), ], min_weight_magnitude=9, security_level=2) print('Transfer complete.', time.time() - t1)
def send_message(address, depth, message, tag, uri, value): # Ensure seed is not displayed in cleartext. seed = iota_seed # Create the API instance. api = Iota(uri, seed) print('Starting transfer please wait...\n') # For more information, see :py:meth:`Iota.send_transfer`. bundle = api.send_transfer( depth=depth, # One or more :py:class:`ProposedTransaction` objects to add to the # bundle. transfers=[ ProposedTransaction( # Recipient of the transfer. address=Address(address), # Amount of IOTA to transfer. # By default this is a zero value transfer. value=value, # Optional tag to attach to the transfer. tag=Tag(tag), # Optional message to include with the transfer. message=TryteString.from_string(message), ), ], ) tx_hash = bundle['bundle'].transactions[0].hash return tx_hash
def create_api(self, seed, route_pow) -> Iota: """Creates an Iota object to interact with the tangle :param seed: The seed of the device :param route_pow: Boolean to state whether PoW is outsourced :return: An Iota object """ try: if route_pow is True: self.api = \ Iota( RoutingWrapper(self.iota_node) .add_route('attachToTangle', self.pow_node) .add_route('interruptAttachingToTangle', self.pow_node), seed=seed ) else: self.api = Iota(self.iota_node, seed) # Uncomment to test node after creating an API # self.test_node() return self.api except ConnectionRefusedError as e: print(e) print("Ensure all nodes are working correctly before connecting")
class balance(): def __init__(self): self.seed = seed self.IOTA_connection = Iota(IOTA_node_URI_conf, seed=seed) self.mysql_connection = MySQLdb.Connection(host=mysql_conf_hostname, user=mysql_conf_user, passwd=mysql_conf_passwd, db=mysql_conf_db) self.cursor = self.mysql_connection.cursor() self.cursor.execute('select trancount from tranCount') self.trancount = int(self.cursor.fetchone()[0]) addresses = self.getAddresses(addressCount=self.trancount) balance = self.getBalance(addresses) iota_to_be_delivered = balance * int(percentage_conf) / 100 print 'balance is: ', balance print 'percentage for Faucet: ', percentage_conf print 'iota to be delivered: ', iota_to_be_delivered #Get balances for a list of addresses def getBalance(self, addresses): balances = self.IOTA_connection.get_balances(addresses) balance = sum(balances['balances']) return balance def getAddresses(self, addressCount): addresses = self.IOTA_connection.get_new_addresses( count=self.trancount) addresses_aux = [str(address) for address in addresses['addresses']] #print len(addresses_aux) return addresses_aux
def transfer(address, tag, message, value): recipient_address = address sender_message = message sender_tag = tag prepared_transferes = [] api = Iota(URL_NODE, SEED) sender_tag = bytes(sender_tag) transfer_value = int(value) txn = \ ProposedTransaction( address = Address( recipient_address ), message = TryteString.from_string(sender_message), tag = Tag(sender_tag), value = transfer_value, ) prepared_transferes.append(txn) dict_raw_trytes_tx = api.prepare_transfer(prepared_transferes) len_tx = len(dict_raw_trytes_tx['trytes']) for index in range(len_tx): print str(dict_raw_trytes_tx['trytes'][index]) return True
def write_data_to_tangle(data): # Iota instance api = Iota(NODE_URL, SEED) # Txn description txn = ProposedTransaction( address = Address(receiver_address), message = TryteString.from_string(json.dumps(data)), tag = Tag(txn_tag), value = value, ) # Send transaction prepared_transferes = [] bundle = "" prepared_transferes.append(txn) try: bundle = api.send_transfer( depth = DEPTH, transfers = prepared_transferes, min_weight_magnitude = MIN_WEIGHT_MAGNITUDE ) except Exception as e: print(e) return e print(bundle['bundle'].hash) return {"status":200, "bundle":bundle['bundle'].hash}
def gen_account_bundles_list(account_idx, seed): # api api = Iota('http://localhost:14265', seed) # account info account_data = api.get_account_data() bundles = account_data['bundles'] account_bundles_list = \ """ //! //! Account 1 Detailed transactions //! """ for i in range(0, len(bundles)): bundle_idx = i + 1 bundle = bundles[i] for j in range(0, len(bundle.transactions)): trx_idx = j + 1 trx = bundle.transactions[j] account_bundles_list += \ """ static const std::string ACCOUNT_%s_BUNDLE_%s_TRX_%s_TRYTES = "%s"; """ % (account_idx, bundle_idx, trx_idx, trx.as_tryte_string()) return account_bundles_list
def addressGenerator(seed, iota_node, n_addresses): api = Iota(iota_node, seed) gna_result = api.get_new_addresses( count=n_addresses ) # This is the actual function to generate the addresses addresses = gna_result['addresses'] total = 0 i = 0 founds = [] while i < n_addresses: address = [addresses[i]] balance = addressBalance(address, iota_node) print("Address " + str(address[0]) + " has a balance of: " + str(balance)) total += balance i += 1 if balance: founds.append(address) if total > 0: print("The above addresses have a total balance of " + str(total) + " Iota tokens!!!") return founds else: print("No balance on those addresses!") return False
def __init__(self): conf = ConfigParser() path = os.path.join(os.path.dirname(__file__), 'config/config.txt') conf.read(path) self.iota = Iota(conf.get('IOTA', 'node'), conf.get('IOTA', 'seed')) self.generator = AddressGenerator(self.iota.seed) self.match_making_addr = self.generator.get_addresses(1) self.memcached = base.Client(('127.0.0.1', 11211))
def get_milestoneStartIndex(url): try: api = Iota(url) node_info = api.get_node_info() return int(node_info["milestoneStartIndex"]) except: return 0
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
def get_transfers(full_history, print_history=True): account_history_executing = True api = Iota(iota_node, seed) address_count = len(address_data) all_txn_hashes = [] saved_txn_hashes = [] new_txn_hashes = [] i = 0 while i < address_count: address = address_data[i]["address"] address_as_bytes = [bytes(address)] raw_transfers = api.find_transactions(addresses=address_as_bytes) transactions_to_check = raw_transfers["hashes"] for txn_hash in transactions_to_check: txn_hash = str(txn_hash) all_txn_hashes.append(txn_hash) i += 1 for txn_hash in transfers_data: txn_hash = str(txn_hash['transaction_hash']) saved_txn_hashes.append(txn_hash) for txn_hash in all_txn_hashes: if txn_hash not in saved_txn_hashes: new_txn_hashes.append(txn_hash) if len(new_txn_hashes) > 0: print("Retreaving and saving transfer data from " + str(len(new_txn_hashes)) + " transaction(s)!\n" "Please wait...\n") for txn_hash in new_txn_hashes: txn_hash_as_bytes = bytes(txn_hash) li_result = api.get_latest_inclusion([ txn_hash_as_bytes ]) # Needs to be integrated into new transactions as well is_confirmed = li_result['states'][txn_hash] print(li_result) gt_result = api.get_trytes([txn_hash_as_bytes]) trytes = str(gt_result['trytes'][0]) txn = Transaction.from_tryte_string(trytes) timestamp = str(txn.timestamp) tag = str(txn.tag) address = str(txn.address) message = "some message" # Placeholder untill message decoding is added value = str(txn.value) bundle = str(txn.bundle_hash) write_transfers_data(txn_hash, is_confirmed, timestamp, tag, address, message, value, bundle) if full_history: print_transaction_history(full_history, print_history) elif not full_history: print_transaction_history(full_history, print_history)
def __init__(self, node='https://nodes.thetangle.org:443', seed=None): #Get Seed if seed is None: self.seed = self.getSeed() else: self.seed = seed #Setup API self.api = Iota(node, self.seed)
def get_avl_address(): api = Iota(node, b'NO9SEED9REQUIRED999999999999999999999999999') # Find the first unused address, starting with index 0: avl_address = api.get_new_addresses(index=0, count=None) address = bytes(avl_address['addresses'][0]) return address
def getNewAddress(seed): # 获取IOTA api函数接口 api = Iota(ip, seed=seed, testnet=True) # 设置信息传输安全等级 security_level = os.getenv('SECURITY_LEVEL', 1) # 获取可用的交易地址 address = api.get_new_addresses( index=0, count=1, security_level=security_level)['addresses'][0] return str(address)