Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.
/ cashedDB Public archive

An indexedDB schema for an SPV web-wallet

Notifications You must be signed in to change notification settings

2qx/cashedDB

Repository files navigation

cashedDB

DEPRRECATED

With upgrades to the Bitcoin Cash network, bchd is no longer a compatible node software as of May 15th 2023.

An experimental client database for Bitcoin Cash.

This database wrapper is indended for use with grpc-bchd clients.

It utilizes dexie as a wrapper for IndexedDB.

Design

Minimal information is stored to validate blocks and transactions. Data are generally stored in the marshalled form provided by grpc-bchrpc-browser—so all hashes are little-endian base64 strings, while numeric data are stored as numbers. Both transactions and blocks have a numeric field to indicated whether the record has been validated by the client.

Usage

The following code gets the first 10 block headers, stores them in bulk, then gets the 5th block from the database

import { GrpcClient } from "../../grpc-bchrpc-browser";
const locatorHashes = ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="] // the first dummy hash
const res = await mainnet.getHeaders(
    {
        blockLocatorHashes: locatorHashes,
        stopHash: "6RXZpHjjrfMYbAfGGiIiixD9h980PJJ4LswFLAAAAAA=" // the 10th block header
    }, null);
let blockDocs = (await res.getHeadersList()).map(x => BlockDocFromObject(x.toObject()))
try{
    let insertedBlockPromises = await global.casheddb.collections.block.bulkInsert(blockDocs)
} catch(error){
    console.log(error)
}
let block5 = await (await global.casheddb.collections.block.find().where("height").eq(5).exec()).pop()

Mocha browser tests provide some working examples.

Releases

No releases published

Packages

No packages published

Languages