Exemplo n.º 1
0
 def from_base58addr(base58addrstr):
     try:
         bytestr = decode_base58check(base58addrstr, True)
     except Exception as e:
         raise InvalidBitcoinAddress("Unable to decode base58check : %s" % (str(e)))
     if len(bytestr) != 21:
         raise InvalidBitcoinAddress("Invalid length : %d" % (len(bytestr)))
     return BitcoinAddress.from_bytestring(bytestr)
Exemplo n.º 2
0
 def from_base58addr(base58addrstr):
     try:
         bytestr = decode_base58check(base58addrstr, True)
     except Exception as e:
         raise InvalidBitcoinAddress("Unable to decode base58check : %s" %
                                     (str(e)))
     if len(bytestr) != 21:
         raise InvalidBitcoinAddress("Invalid length : %d" % (len(bytestr)))
     return BitcoinAddress.from_bytestring(bytestr)
Exemplo n.º 3
0
 def found_nick(self, nick):
     if nick[0] == 'u': #routable 
         try:
             hostaddr = decode_base58check(nick[1:])
             ip = ".".join([str(struct.unpack(">B", x)[0]) for x in hostaddr[:4]])
             port = struct.unpack(">H", hostaddr[4:])[0]
         except:
             self.log.info("Error unpacking nickname (errorneous peer): %s" % (nick))
             return
         self.fire(self.EVT_FOUND_PEER, peeraddress=SockAddr(ip, port))
Exemplo n.º 4
0
    from coinpy.model.constants.bitcoin import COIN
    from coinpy.lib.vm.vm import TxValidationVM

    import os

    runmode = TESTNET
    wallet_filename = "D:\\repositories\\coinpy\\coinpy-client\\src\\data\\testnet\\wallet_testnet.dat"
    directory, filename = os.path.split(wallet_filename)
    bsddb_env = BSDDBEnv(directory)
    wallet = Wallet(None, BSDDBWalletDatabase(bsddb_env, filename), runmode)

    selector = CoinSelector()
    amount, fee = 145.0065 * COIN, 0 * COIN
    #list of (txhash, tx, index, txout)
    outputs = list(wallet.iter_my_outputs())
    selected_outputs = selector.select_coins(outputs, amount + fee)
    tx = create_pubkeyhash_transaction(
        selected_outputs,
        decode_base58check("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo"),
        decode_base58check("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo"), amount, fee)
    sign_transaction(tx, selected_outputs)
    vm = TxValidationVM()
    print tx
    print len(selected_outputs)
    print vm.validate(tx, 0, selected_outputs[0].txout.script,
                      tx.in_list[0].script)
    print vm.validate(tx, 1, selected_outputs[1].txout.script,
                      tx.in_list[1].script)
    print vm.validate(tx, 2, selected_outputs[2].txout.script,
                      tx.in_list[2].script)
Exemplo n.º 5
0
    from coinpy.model.constants.bitcoin import COIN
    from coinpy.lib.vm.vm import TxValidationVM

    import os

    runmode = TESTNET
    wallet_filename = "D:\\repositories\\coinpy\\coinpy-client\\src\\data\\testnet\\wallet_testnet.dat"
    directory, filename = os.path.split(wallet_filename)
    bsddb_env = BSDDBEnv(directory)
    wallet = Wallet(None, BSDDBWalletDatabase(bsddb_env, filename), runmode)

    selector = CoinSelector()
    amount, fee = 145.0065 * COIN, 0 * COIN
    # list of (txhash, tx, index, txout)
    outputs = list(wallet.iter_my_outputs())
    selected_outputs = selector.select_coins(outputs, amount + fee)
    tx = create_pubkeyhash_transaction(
        selected_outputs,
        decode_base58check("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo"),
        decode_base58check("n4MsBRWD7VxKGsqYRSLaFZC6hQrsrKLaZo"),
        amount,
        fee,
    )
    sign_transaction(tx, selected_outputs)
    vm = TxValidationVM()
    print tx
    print len(selected_outputs)
    print vm.validate(tx, 0, selected_outputs[0].txout.script, tx.in_list[0].script)
    print vm.validate(tx, 1, selected_outputs[1].txout.script, tx.in_list[1].script)
    print vm.validate(tx, 2, selected_outputs[2].txout.script, tx.in_list[2].script)