-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sqlite module and test, update README
- Loading branch information
1 parent
aac23fa
commit 18dd296
Showing
8 changed files
with
712 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
|
||
*.sqlite | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
# bdk-sqlx | ||
|
||
|
||
## Testing | ||
|
||
1. Install postgresql with `psql` tool. For example (macos): | ||
``` | ||
brew update | ||
brew install postgresql | ||
``` | ||
2. Create empty test database: | ||
``` | ||
psql postgres | ||
postgres=# create database test_bdk_wallet; | ||
``` | ||
3. Set DATABASE_URL to test database: | ||
``` | ||
export DATABASE_TEST_URL=postgresql://localhost/test_bdk_wallet | ||
``` | ||
4. Run tests: | ||
``` | ||
cargo test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
-- Schema version control | ||
CREATE TABLE IF NOT EXISTS version ( | ||
version INTEGER PRIMARY KEY | ||
); | ||
|
||
-- Network is the valid network for all other table data | ||
CREATE TABLE IF NOT EXISTS network ( | ||
wallet_name TEXT PRIMARY KEY, | ||
name TEXT NOT NULL | ||
); | ||
|
||
-- Keychain is the json serialized keychain structure as JSONB, | ||
-- descriptor is the complete descriptor string, | ||
-- descriptor_id is a sha256::Hash id of the descriptor string w/o the checksum, | ||
-- last revealed index is a u32 | ||
CREATE TABLE IF NOT EXISTS keychain ( | ||
wallet_name TEXT NOT NULL, | ||
keychainkind TEXT NOT NULL, | ||
descriptor TEXT NOT NULL, | ||
descriptor_id BLOB NOT NULL, | ||
last_revealed INTEGER DEFAULT 0, | ||
PRIMARY KEY (wallet_name, keychainkind) | ||
|
||
); | ||
|
||
-- Hash is block hash hex string, | ||
-- Block height is a u32 | ||
CREATE TABLE IF NOT EXISTS block ( | ||
wallet_name TEXT, | ||
hash TEXT NOT NULL, | ||
height INTEGER NOT NULL, | ||
PRIMARY KEY (wallet_name, hash) | ||
); | ||
CREATE INDEX idx_block_height ON block (height); | ||
|
||
-- Txid is transaction hash hex string (reversed) | ||
-- Whole_tx is a consensus encoded transaction, | ||
-- Last seen is a u64 unix epoch seconds | ||
CREATE TABLE IF NOT EXISTS tx ( | ||
wallet_name TEXT, | ||
txid TEXT NOT NULL, | ||
whole_tx BLOB, | ||
last_seen INTEGER, | ||
PRIMARY KEY (wallet_name, txid) | ||
); | ||
|
||
-- Outpoint txid hash hex string (reversed) | ||
-- Outpoint vout | ||
-- TxOut value as SATs | ||
-- TxOut script consensus encoded | ||
CREATE TABLE IF NOT EXISTS txout ( | ||
wallet_name TEXT, | ||
txid TEXT NOT NULL, | ||
vout INTEGER NOT NULL, | ||
value INTEGER NOT NULL, | ||
script BLOB NOT NULL, | ||
PRIMARY KEY (wallet_name, txid, vout) | ||
); | ||
|
||
-- Join table between anchor and tx | ||
-- Block hash hex string | ||
-- Anchor is a json serialized Anchor structure as JSONB, | ||
-- Txid is transaction hash hex string (reversed) | ||
CREATE TABLE IF NOT EXISTS anchor_tx ( | ||
wallet_name TEXT, | ||
block_hash TEXT NOT NULL, | ||
anchor BLOB NOT NULL, | ||
txid TEXT NOT NULL, | ||
PRIMARY KEY (wallet_name, block_hash, txid), | ||
FOREIGN KEY (wallet_name, block_hash) REFERENCES block(wallet_name, hash), | ||
FOREIGN KEY (wallet_name, txid) REFERENCES tx(wallet_name, txid) | ||
); | ||
CREATE INDEX idx_anchor_tx_txid ON anchor_tx (txid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#![warn(missing_docs)] | ||
|
||
mod postgres; | ||
mod sqlite; | ||
|
||
#[cfg(test)] | ||
mod test; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.