Skip to content

Commit

Permalink
Save block height as well
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Aug 6, 2018
1 parent 4b14166 commit 515ee42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
7 changes: 2 additions & 5 deletions node/src/BlockIngestor.java
@@ -1,6 +1,5 @@
package snowblossom.node;

import com.google.common.collect.TreeMultimap;
import com.google.protobuf.ByteString;
import duckutil.TimeRecord;
import duckutil.TimeRecordAuto;
Expand All @@ -11,7 +10,6 @@
import snowblossom.proto.BlockSummary;
import snowblossom.proto.Transaction;
import snowblossom.lib.trie.HashUtils;
import snowblossom.lib.trie.ByteStringComparator;

import java.io.FileOutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -119,14 +117,13 @@ public boolean ingestBlock(Block blk)
{
ByteString block_hash_str = blockhash.getBytes();
HashMap<ByteString, Transaction> tx_map = new HashMap<>();
TreeMultimap<ByteString, ByteString> tx_block_map = TreeMultimap.create(new ByteStringComparator(), new ByteStringComparator());
for(Transaction tx : blk.getTransactionsList())
{
tx_map.put(tx.getTxHash(), tx);
tx_block_map.put(tx.getTxHash(), block_hash_str);
}
db.getTransactionMap().putAll(tx_map);
db.getTransactionBlockMap().addAll(tx_block_map);

TransactionMapUtil.saveTransactionMap(blk, db);
}
}
if (addr_index)
Expand Down
40 changes: 40 additions & 0 deletions node/src/TransactionMapUtil.java
@@ -0,0 +1,40 @@
package snowblossom.node;

import snowblossom.lib.db.DB;
import snowblossom.proto.*;
import snowblossom.lib.Globals;

import snowblossom.lib.trie.ByteStringComparator;
import com.google.common.collect.TreeMultimap;
import com.google.protobuf.ByteString;
import java.nio.ByteBuffer;

public class TransactionMapUtil
{
public static void saveTransactionMap(Block blk, DB db)
{
TreeMultimap<ByteString, ByteString> tx_block_map = TreeMultimap.create(new ByteStringComparator(), new ByteStringComparator());
ByteString value = getValue(blk);

for(Transaction tx : blk.getTransactionsList())
{
tx_block_map.put(tx.getTxHash(),value);
}

db.getTransactionBlockMap().addAll(tx_block_map);

}

public static ByteString getValue(Block blk)
{
byte[] buff = new byte[4 + Globals.BLOCKCHAIN_HASH_LEN];

ByteBuffer bb = ByteBuffer.wrap(buff);
bb.putInt(blk.getHeader().getBlockHeight());
bb.put(blk.getHeader().getSnowHash().toByteArray());

return ByteString.copyFrom(buff);

}

}

0 comments on commit 515ee42

Please sign in to comment.