示例#1
0
 def _privmsg(self, nick, cmd, message):
     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(nick, m + trailer)
def make_wallets(n,
                 wallet_structures=None,
                 mean_amt=1,
                 sdev_amt=0,
                 start_index=0,
                 fixed_seeds=None,
                 wallet_cls=SegwitLegacyWallet,
                 mixdepths=5,
                 populate_internal=False):
    '''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:..,}
       '''
    # FIXME: this is basically the same code as test/common.py
    assert mixdepths > 0
    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(BIP32Wallet.ENTROPY_BYTES *
                                        n)).decode('ascii'),
            BIP32Wallet.ENTROPY_BYTES * 2)
    else:
        seeds = fixed_seeds
    wallets = {}
    for i in range(n):
        assert len(seeds[i]) == BIP32Wallet.ENTROPY_BYTES * 2

        w = open_test_wallet_maybe(seeds[i],
                                   seeds[i],
                                   mixdepths - 1,
                                   test_wallet_cls=wallet_cls)

        wallets[i + start_index] = {'seed': seeds[i], 'wallet': w}
        for j in range(mixdepths):
            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(
                    w.get_new_addr(j, populate_internal), amt)
    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 = Wallet(seeds[i], passwords[i], max_mix_depth=5)
        else:
            w = Wallet(seeds[i], None, 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