Exemple #1
0
 def history_callback(self, msg_id, msg, param):
     for each in param:
         TxStore().add(msg['params'][0], each['tx_hash'], each['height'])
     for tx, height in TxStore().unverify_tx_list:
         NetWorkManager().add_message(GetMerkle([tx, height]), self.get_merkle_callback)
     for tx in TxStore().unfetch_tx:
         NetWorkManager().add_message(Get([tx]), self.get_tx_callback)
Exemple #2
0
 def get_merkle_callback(self, msg_id, msg, param):
     tx_hash = msg['params'][0]
     height = msg['params'][1]
     block_root = BlockChain().get_block_root(height)
     if block_root is not None:
         result = TxStore().verify_merkle(tx_hash, param, block_root)
         if result:
             TxStore().verified_tx(tx_hash)
Exemple #3
0
 def get_tx_callback(self, msg_id, msg, param):
     tx_hash = msg['params'][0]
     tx = Transaction(param)
     try:
         tx.deserialize()
         TxStore().add_tx_detail(tx_hash, tx)
         global EVENT_QUEUE
         if len(self.wallet_tx_changed_event) > 0:
             for event in set(self.wallet_tx_changed_event):
                 EVENT_QUEUE.put(event)
         print self.address, 'balance', TxStore().get_balance(self.address)
     except Exception as ex:
         self.print_msg("cannot deserialize transaction, skipping", tx_hash)
         return
Exemple #4
0
 def get_txs(self):
     txs = TxStore().get_all_txs(self.get_addresses())
     receives = {row[0]: row[1] for row in TxStore().get_all_tx_receive(self.get_addresses())}
     spents = {row[0]: row[1] for row in TxStore().get_all_tx_spent(self.get_addresses())}
     result = []
     for row in txs:
         receive = 0
         if row[0] in receives:
             receive = receives[row[0]]
         spent = 0
         if row[0] in spents:
             spent = spents[row[0]]
         delta = receive - spent
         result.append(
             {'tx_hash': row[0], 'tx_time': row[1], 'tx_delta': delta, 'tx_receive': receive,
              'tx_spent': spent})
     return result
Exemple #5
0
 def get_utxo(self):
     utxo = reduce(lambda x, y: x + y, [[
         Input({'prevout_hash': e[0], 'prevout_n': e[1],
                'scriptSig': e[2], 'value': e[3],
                'address': e[4],
                'coinbase': False,
                'height': e[5]}) for e in
         TxStore().get_unspend_outs(address=address)] for
         address in self.get_addresses()], [])
     return utxo
Exemple #6
0
 def get_tx_callback(self, msg_id, msg, param):
     tx_hash = msg['params'][0]
     tx = Transaction(param)
     try:
         tx.deserialize()
         TxStore().add_tx_detail(tx_hash, tx)
         # print self.address, 'balance', TxStore().get_balance(self.address)
     except Exception:
         self.print_msg("cannot deserialize transaction, skipping", tx_hash)
         return
Exemple #7
0
def test_cold_hot_wallet():
    global network, hot_wallet
    set_testnet()
    logging.config.fileConfig('logging.conf')
    # drop()
    init()
    network = NetWorkManager()
    network.start_ioloop()
    network.start_client()
    BlockChain().init_header()

    network.add_message(Version(["2.8.2", "0.10"]))

    network.add_message(GetHistory(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj']))
    network.add_message(GetMempool(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj']))
    network.add_message(GetBalance(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj']))
    network.add_message(Listunspent(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj']))
    network.add_message(address_subscribe(
        ['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj']))  # 'mmXqJTLjjyD6Xp2tJ7syCeZTcwvRjcojLz'
    hot_wallet = WatchOnlySimpleWallet(WalletConfig(store_path='watch_only_simple_wallet.json'))
    secret = '\x20\x12\x10\x09' + '\x09' * 28
    if hot_wallet.keystore is None:
        hot_wallet.init_key_store(
            WatchOnlySimpleKeyStore.create(public_key_from_private_key(secret)))
    # hot_wallet.sync()
    inputs = [
        {'prevout_hash': e[0], 'prevout_n': e[1], 'scriptSig': e[2], 'value': e[3], 'address': e[4],
         'coinbase': False,
         'height': 10000} for e in TxStore().get_unspend_outs('mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj')]
    outputs = []
    outputs.append(Output((TYPE_ADDRESS, 'mkp8FGgySzhh5mmmHDcxRxmeS3X5fXm68i', 100000)))
    tx = hot_wallet.make_unsigned_transaction(inputs, outputs, {})
    print tx
    cold_wallet = ColdSimpleWallet(WalletConfig(store_path='cold_simple_wallet.json'))
    if cold_wallet.keystore is None:
        cold_wallet.init_key_store(SimpleKeyStore.create(SecretToASecret(secret, True), None))
    cold_wallet.sign_transaction(tx, None)
    # SecretToASecret('\x11'*16, True)
    print tx
Exemple #8
0
def test_hd_wallet():
    global network, hot_wallet
    set_testnet()
    logging.config.fileConfig('logging.conf')
    # drop()
    init()
    network = NetWorkManager()
    network.start_ioloop()
    network.start_client()
    network.add_message(Version(["2.8.2", "0.10"]))
    hot_wallet = HDWallet(WalletConfig(store_path='hd_wallet.json'))
    if hot_wallet.keystore is None:
        hot_wallet.init_key_store(from_seed(u'reopen panel title aerobic wheat fury blame cement swarm wheel ball where', None))
    hot_wallet.sync()
    hot_wallet.synchronize()
    print hot_wallet.get_change_addresses()
    print hot_wallet.get_receiving_addresses()
    inputs = [
        {'prevout_hash': e[0], 'prevout_n': e[1], 'scriptSig': e[2], 'value': e[3], 'address': e[4],
         'coinbase': False,
         'height': 10000} for e in TxStore().get_unspend_outs('mipTN4UeM9Ab9PH5dU9XA5MjwAJnzkwCpX')]
    outputs = []
    outputs.append((TYPE_ADDRESS, 'mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj', 100000))
Exemple #9
0
 def address_is_old(self, address, age_limit=2):
     tx_age = TxStore().get_max_tx_block(address)
     if tx_age > 0:
         return BlockStore().height - tx_age > age_limit
     else:
         return False
Exemple #10
0
 def accept(self):
     self.tx_detail_view.tx._inputs = None
     self.tx_detail_view.tx.deserialize()
     TxStore().add_unconfirm_tx(self.tx_detail_view.tx)
     # Wallet().current_wallet.broadcast(self.tx_detail_view.tx)
     self.close()
Exemple #11
0
 def balance(self):
     return TxStore().get_balance(self.address)
Exemple #12
0
 def get_txs(self):
     return TxStore().get_txs(self.address)