def __privmsg(self, nick, cmd, message): log.debug('>>privmsg ' + 'nick=' + nick + ' cmd=' + cmd + ' msg=' + message) # should we encrypt? box, encrypt = self.__get_encryption_box(cmd, nick) # encrypt before chunking if encrypt: if not box: log.debug('error, dont have encryption box object for ' + nick + ', dropping message') return message = encrypt_encode(message, box) header = "PRIVMSG " + nick + " :" max_chunk_len = MAX_PRIVMSG_LEN - len(header) - len(cmd) - 4 # 1 for command prefix 1 for space 2 for trailer if len(message) > max_chunk_len: message_chunks = chunks(message, max_chunk_len) else: message_chunks = [message] for m in message_chunks: trailer = ' ~' if m == message_chunks[-1] else ' ;' if m == message_chunks[0]: m = COMMAND_PREFIX + cmd + ' ' + m self.send_raw(header + m + trailer)
def query_utxo_set(self, txout, includeconf=False): if not isinstance(txout, list): txout = [txout] txids = [h[:64] for h in txout] txids = list(set(txids)) # remove duplicates # self.BLOCKR_MAX_ADDR_REQ_COUNT = 2 if len(txids) > self.BLOCKR_MAX_ADDR_REQ_COUNT: txids = chunks(txids, self.BLOCKR_MAX_ADDR_REQ_COUNT) else: txids = [txids] data = [] for ids in txids: blockr_url = 'https://' + self.blockr_domain + '.blockr.io/api/v1/tx/info/' blockr_data = json.loads( btc.make_request(blockr_url + ','.join(ids)))['data'] if not isinstance(blockr_data, list): blockr_data = [blockr_data] data += blockr_data result = [] for txo in txout: txdata = [d for d in data if d['tx'] == txo[:64]][0] vout = [v for v in txdata['vouts'] if v['n'] == int(txo[65:])][0] if "is_spent" in vout and vout['is_spent'] == 1: result.append(None) else: result_dict = { 'value': int(Decimal(vout['amount']) * Decimal('1e8')), 'address': vout['address'], 'script': vout['extras']['script'] } if includeconf: result_dict['confirms'] = int(txdata['confirmations']) result.append(result_dict) return result
def make_wallets(n, wallet_structures=None, mean_amt=1, sdev_amt=0, start_index=0): '''n: number of wallets to be created wallet_structure: array of n arrays , each subarray specifying the number of addresses to be populated with coins at each depth (for now, this will only populate coins into 'receive' addresses) mean_amt: the number of coins (in btc units) in each address as above sdev_amt: if randomness in amouts is desired, specify here. Returns: a dict of dicts of form {0:{'seed':seed,'wallet':Wallet object},1:..,}''' if len(wallet_structures) != n: raise Exception("Number of wallets doesn't match wallet structures") seeds = chunks(binascii.hexlify(os.urandom(15 * n)), n) wallets = {} for i in range(n): wallets[i + start_index] = { 'seed': seeds[i], 'wallet': Wallet(seeds[i], max_mix_depth=5) } for j in range(5): for k in range(wallet_structures[i][j]): deviation = sdev_amt * random.random() amt = mean_amt - sdev_amt / 2.0 + deviation if amt < 0: amt = 0.001 jm_single().bc_interface.grab_coins( wallets[i + start_index]['wallet'].get_external_addr(j), amt) return wallets
def query_utxo_set(self, txout): if not isinstance(txout, list): txout = [txout] txids = [h[:64] for h in txout] txids = list(set(txids)) # remove duplicates # self.BLOCKR_MAX_ADDR_REQ_COUNT = 2 if len(txids) > self.BLOCKR_MAX_ADDR_REQ_COUNT: txids = chunks(txids, self.BLOCKR_MAX_ADDR_REQ_COUNT) else: txids = [txids] data = [] for ids in txids: blockr_url = 'https://' + self.blockr_domain + '.blockr.io/api/v1/tx/info/' blockr_data = json.loads( btc.make_request(blockr_url + ','.join(ids)))['data'] if not isinstance(blockr_data, list): blockr_data = [blockr_data] data += blockr_data result = [] for txo in txout: txdata = [d for d in data if d['tx'] == txo[:64]][0] vout = [v for v in txdata['vouts'] if v['n'] == int(txo[65:])][0] if vout['is_spent'] == 1: result.append(None) else: result.append({'value': int(Decimal(vout['amount']) * Decimal( '1e8')), 'address': vout['address'], 'script': vout['extras']['script']}) return result
def _privmsg(self, nick, cmd, message): """Send a privmsg to an irc counterparty, using chunking as appropriate for long messages. """ header = "PRIVMSG " + nick + " :" max_chunk_len = MAX_PRIVMSG_LEN - len(header) - len(cmd) - 4 # 1 for command prefix 1 for space 2 for trailer if len(message) > max_chunk_len: message_chunks = chunks(message, max_chunk_len) else: message_chunks = [message] for m in message_chunks: trailer = ' ~' if m == message_chunks[-1] else ' ;' if m == message_chunks[0]: m = COMMAND_PREFIX + cmd + ' ' + m self.send_raw(header + m + trailer)
def make_wallets(n, wallet_structures=None, mean_amt=1, sdev_amt=0, start_index=0, fixed_seeds=None, test_wallet=False, passwords=None): '''n: number of wallets to be created wallet_structure: array of n arrays , each subarray specifying the number of addresses to be populated with coins at each depth (for now, this will only populate coins into 'receive' addresses) mean_amt: the number of coins (in btc units) in each address as above sdev_amt: if randomness in amouts is desired, specify here. Returns: a dict of dicts of form {0:{'seed':seed,'wallet':Wallet object},1:..,} Default Wallet constructor is joinmarket.Wallet, else use TestWallet, which takes a password parameter as in the list passwords. ''' if len(wallet_structures) != n: raise Exception("Number of wallets doesn't match wallet structures") if not fixed_seeds: seeds = chunks(binascii.hexlify(os.urandom(15 * n)), 15 * 2) else: seeds = fixed_seeds wallets = {} for i in range(n): if test_wallet: w = TestWallet(seeds[i], max_mix_depth=5, pwd=passwords[i]) else: w = Wallet(seeds[i], max_mix_depth=5) wallets[i + start_index] = {'seed': seeds[i], 'wallet': w} for j in range(5): for k in range(wallet_structures[i][j]): deviation = sdev_amt * random.random() amt = mean_amt - sdev_amt / 2.0 + deviation if amt < 0: amt = 0.001 amt = float(Decimal(amt).quantize(Decimal(10)**-8)) jm_single().bc_interface.grab_coins( wallets[i + start_index]['wallet'].get_external_addr(j), amt) #reset the index so the coins can be seen if running in same script wallets[ i + start_index]['wallet'].index[j][0] -= wallet_structures[i][j] return wallets
def make_wallets( n, wallet_structures=None, mean_amt=1, sdev_amt=0, start_index=0, fixed_seeds=None, test_wallet=False, passwords=None, ): """n: number of wallets to be created wallet_structure: array of n arrays , each subarray specifying the number of addresses to be populated with coins at each depth (for now, this will only populate coins into 'receive' addresses) mean_amt: the number of coins (in btc units) in each address as above sdev_amt: if randomness in amouts is desired, specify here. Returns: a dict of dicts of form {0:{'seed':seed,'wallet':Wallet object},1:..,} Default Wallet constructor is joinmarket.Wallet, else use TestWallet, which takes a password parameter as in the list passwords. """ if len(wallet_structures) != n: raise Exception("Number of wallets doesn't match wallet structures") if not fixed_seeds: seeds = chunks(binascii.hexlify(os.urandom(15 * n)), 15 * 2) else: seeds = fixed_seeds wallets = {} for i in range(n): if test_wallet: w = TestWallet(seeds[i], max_mix_depth=5, pwd=passwords[i]) else: w = Wallet(seeds[i], max_mix_depth=5) wallets[i + start_index] = {"seed": seeds[i], "wallet": w} for j in range(5): for k in range(wallet_structures[i][j]): deviation = sdev_amt * random.random() amt = mean_amt - sdev_amt / 2.0 + deviation if amt < 0: amt = 0.001 amt = float(Decimal(amt).quantize(Decimal(10) ** -8)) jm_single().bc_interface.grab_coins(wallets[i + start_index]["wallet"].get_external_addr(j), amt) # reset the index so the coins can be seen if running in same script wallets[i + start_index]["wallet"].index[j][0] -= wallet_structures[i][j] return wallets
def setUp(self): #create 7 new random wallets. #put about 10 coins in each, spread over random mixdepths #in units of 0.5 seeds = chunks(binascii.hexlify(os.urandom(15 * 7)), 7) self.wallets = {} for i in range(7): self.wallets[i] = {'seed': seeds[i], 'wallet': Wallet(seeds[i], max_mix_depth=5)} #adding coins somewhat randomly, spread over all 5 depths for i in range(7): w = self.wallets[i]['wallet'] for j in range(5): for k in range(4): base = 0.001 if i == 6 else 2.0 amt = base + random.random( ) #average is 0.5 for tumbler, else 1.5 jm_single().bc_interface.grab_coins( w.get_external_addr(j), amt)
def make_wallets(n, wallet_structures=None, mean_amt=1, sdev_amt=0, start_index=0): '''n: number of wallets to be created wallet_structure: array of n arrays , each subarray specifying the number of addresses to be populated with coins at each depth (for now, this will only populate coins into 'receive' addresses) mean_amt: the number of coins (in btc units) in each address as above sdev_amt: if randomness in amouts is desired, specify here. Returns: a dict of dicts of form {0:{'seed':seed,'wallet':Wallet object},1:..,}''' if len(wallet_structures) != n: raise Exception("Number of wallets doesn't match wallet structures") seeds = chunks(binascii.hexlify(os.urandom(15 * n)), n) wallets = {} for i in range(n): wallets[i+start_index] = {'seed': seeds[i], 'wallet': Wallet(seeds[i], max_mix_depth=5)} for j in range(5): for k in range(wallet_structures[i][j]): deviation = sdev_amt * random.random() amt = mean_amt - sdev_amt / 2.0 + deviation if amt < 0: amt = 0.001 jm_single().bc_interface.grab_coins( wallets[i+start_index]['wallet'].get_external_addr(j), amt) return wallets