Search in sources :

Example 1 with Pair

use of duckutil.Pair in project snowblossom by snowblossomcoin.

the class HistoryUtil method printHistory.

public static void printHistory(PrintStream out, WalletDatabase db, NetworkParams params, SnowBlossomClient client) {
    HashSet<AddressSpecHash> all = new HashSet<>();
    all.addAll(WalletUtil.getAddressesByAge(db, params));
    TreeSet<Pair<Integer, ChainHash>> transaction_history = new TreeSet<>();
    TreeSet<ChainHash> mempool_list = new TreeSet<>();
    boolean incomplete_no_history = false;
    // If this gets super slow, parallelize this loop
    for (AddressSpecHash hash : all) {
        HistoryList hl = client.getStub().getAddressHistory(RequestAddress.newBuilder().setAddressSpecHash(hash.getBytes()).build());
        if (hl.getNotEnabled()) {
            incomplete_no_history = true;
        }
        for (HistoryEntry e : hl.getEntriesList()) {
            int height = e.getBlockHeight();
            ChainHash tx_hash = new ChainHash(e.getTxHash());
            transaction_history.add(new Pair(height, tx_hash));
        }
        TransactionHashList tl = client.getStub().getMempoolTransactionList(RequestAddress.newBuilder().setAddressSpecHash(hash.getBytes()).build());
        for (ByteString h : tl.getTxHashesList()) {
            ChainHash tx_hash = new ChainHash(h);
            mempool_list.add(tx_hash);
        }
    }
    if (incomplete_no_history) {
        out.println("THIS HISTORY IS MISSING - CONNECTED NODE DOES NOT SUPPORT ADDRESS HISTORY");
    }
    for (ChainHash tx_hash : mempool_list) {
        Transaction tx = getTx(tx_hash, client);
        out.println(String.format("pending / %s", getSummaryLine(tx, all, params, client)));
    }
    for (Pair<Integer, ChainHash> p : transaction_history.descendingSet()) {
        int block = p.getA();
        ChainHash tx_hash = p.getB();
        Transaction tx = getTx(tx_hash, client);
        out.println(String.format("block %d / %s", block, getSummaryLine(tx, all, params, client)));
    }
}
Also used : ByteString(com.google.protobuf.ByteString) ChainHash(snowblossom.lib.ChainHash) TreeSet(java.util.TreeSet) AddressSpecHash(snowblossom.lib.AddressSpecHash) HashSet(java.util.HashSet) Pair(duckutil.Pair)

Aggregations

ByteString (com.google.protobuf.ByteString)1 Pair (duckutil.Pair)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 AddressSpecHash (snowblossom.lib.AddressSpecHash)1 ChainHash (snowblossom.lib.ChainHash)1