-
Couldn't load subscription status.
- Fork 11
Add sqlite module #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
notmandatory
merged 9 commits into
bitcoindevkit:master
from
notmandatory:add_sqlite_module
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
df3735a
refactor: move postgres specific code to new module
notmandatory 30dc6dd
feat: add sqlite module and test, update README
notmandatory 51ffef2
refactor: remove unneeded Arc Mutex for pool
notmandatory 01f38c0
test: update all to check postgres and sqlite
notmandatory 1bb34e1
refactor: embed migrations, move bin to examples crate, cleanup depen…
notmandatory e624074
rebase(tests): remove unneeded dependencies, fix rebase
notmandatory 7388cfe
test: fix example cargo config
notmandatory 9997ce7
refactor: remove default wallet name; fix README for example
notmandatory 39650cb
refactor: do migrate only for new store
notmandatory File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||
| target | ||
| Cargo.lock | ||
|
|
||
| *.sqlite | ||
| .env |
This file contains hidden or 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,34 +1,24 @@ | ||
| [package] | ||
| name = "bdk-sqlx" | ||
| name = "bdk_sqlx" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| name = "bdk_sqlx" | ||
| path = "src/lib.rs" | ||
|
|
||
| [[bin]] | ||
| name = "async_wallet_bdk_sqlx" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| sqlx = { version = "0.8.1", default-features = false, features = ["runtime-tokio", "tls-rustls-ring","derive", "postgres", "json", "chrono", "uuid", "sqlx-macros", "migrate"] } | ||
| thiserror = "1" | ||
| tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } | ||
| bdk_wallet = { version = "1.0.0-beta.5" } | ||
| serde = { version = "1.0.208", features = ["derive"] } | ||
| serde_json = "1.0.125" | ||
| better-panic = "0.3.0" | ||
| rustls = "0.23.12" | ||
| sqlx = { version = "0.8.1", default-features = false, features = ["runtime-tokio", "tls-rustls-ring","derive", "postgres", "sqlite", "json", "chrono", "uuid", "sqlx-macros", "migrate"] } | ||
| thiserror = "1" | ||
| tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } | ||
| tracing = "0.1.40" | ||
| tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde_json", "json"] } | ||
| anyhow = "1.0.86" | ||
| rand = "0.8.5" | ||
| uuid = "1.10.0" | ||
| assert_matches = "1.5.0" | ||
| pg-embed = { version = "0.7.1", features = ["default"] } | ||
|
|
||
| [dev-dependencies] | ||
| assert_matches = "1.5.0" | ||
| anyhow = "1.0.89" | ||
| bdk_electrum = { version = "0.19.0"} | ||
| rustls = "0.23.14" | ||
|
|
||
| bdk_wallet = { git = "https://github.com/bitcoindevkit/bdk", tag = "v1.0.0-beta.2", features = ["std"], default-features = false } | ||
| bdk_chain = { git = "https://github.com/bitcoindevkit/bdk", tag = "v1.0.0-beta.2" } | ||
| bdk_electrum = { git = "https://github.com/bitcoindevkit/bdk", tag = "v1.0.0-beta.2" } | ||
| bdk_testenv = { git = "https://github.com/bitcoindevkit/bdk", tag = "v1.0.0-beta.2" } | ||
| [[example]] | ||
| name = "bdk_sqlx_postgres" | ||
| path = "examples/bdk_sqlx_postgres.rs" | ||
This file contains hidden or 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,43 @@ | ||
| # bdk-sqlx | ||
|
|
||
| ## Status | ||
|
|
||
| This crate is still **EXPERIMENTAL** do not use with mainnet wallets. | ||
|
|
||
| ## 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, must use a single test thread since we reuse the postgres db: | ||
| ``` | ||
| cargo test -- --test-threads=1 | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| 1. Create empty test database: | ||
| ``` | ||
| psql postgres | ||
| postgres=# create database example_bdk_wallet; | ||
| postgres=# \q | ||
| ``` | ||
| 2. Set DATABASE_URL to test database: | ||
| ``` | ||
| export DATABASE_URL=postgresql://localhost/example_bdk_wallet | ||
| ``` | ||
| 3. Run example: | ||
| ``` | ||
| cargo run --example bdk_sqlx_postgres | ||
| ``` |
This file contains hidden or 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 hidden or 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 hidden or 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 NOT NULL, | ||
| 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 NOT NULL, | ||
| 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 NOT NULL, | ||
| 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 NOT NULL, | ||
| 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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.