Exemplo n.º 1
0
 public List<byte[]> exists(List<byte[]> blockHashes) {
   List<byte[]> exists = new ArrayList<byte[]>();
   List<Block> blockItems = getAllBlocks();
   for (Block blockItm : blockItems) {
     for (byte[] bytes : exists) {
       if (Arrays.equals(bytes, blockItm.getBlockHash())) {
         exists.add(bytes);
         break;
       }
     }
   }
   return exists;
 }
Exemplo n.º 2
0
 private void applyContentValues(Block item, ContentValues cv) {
   cv.put(AbstractDb.BlocksColumns.BLOCK_BITS, item.getBlockBits());
   cv.put(AbstractDb.BlocksColumns.BLOCK_HASH, Base58.encode(item.getBlockHash()));
   cv.put(AbstractDb.BlocksColumns.BLOCK_NO, item.getBlockNo());
   cv.put(AbstractDb.BlocksColumns.BLOCK_NONCE, item.getBlockNonce());
   cv.put(AbstractDb.BlocksColumns.BLOCK_PREV, Base58.encode(item.getBlockPrev()));
   cv.put(AbstractDb.BlocksColumns.BLOCK_ROOT, Base58.encode(item.getBlockRoot()));
   cv.put(AbstractDb.BlocksColumns.BLOCK_TIME, item.getBlockTime());
   cv.put(AbstractDb.BlocksColumns.BLOCK_VER, item.getBlockVer());
   cv.put(AbstractDb.BlocksColumns.IS_MAIN, item.isMain() ? 1 : 0);
 }
Exemplo n.º 3
0
 public void addBlock(Block item) {
   boolean blockExists = blockExists(item.getBlockHash());
   if (!blockExists) {
     SQLiteDatabase db = this.mDb.getWritableDatabase();
     ContentValues cv = new ContentValues();
     applyContentValues(item, cv);
     db.insert(AbstractDb.Tables.BLOCKS, null, cv);
   }
 }