From: github-actions Date: Fri, 23 Sep 2022 10:14:43 +0000 (+0000) Subject: Publish autogenerated nightly docs X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/chain_graph/enum.InsertTxError.html?a=commitdiff_plain;h=ccd5192411184d82d32458627454293a065d3c8f;p=bitcoindevkit.org Publish autogenerated nightly docs --- diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/struct.SqliteDatabase.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/struct.SqliteDatabase.html index 891eaaa4c7..593cd783ae 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/struct.SqliteDatabase.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/struct.SqliteDatabase.html @@ -6,7 +6,7 @@ logo

SqliteDatabase

logo
pub struct SqliteDatabase {
+    

Struct bdk::database::SqliteDatabase

source · []
pub struct SqliteDatabase {
     pub path: PathBuf,
     pub connection: Connection,
 }
Expand description

Sqlite database stored on filesystem

@@ -14,41 +14,41 @@ crate::database

Fields

path: PathBuf

Path on the local filesystem to store the sqlite file

connection: Connection

A rusqlite connection object to the sqlite database

-

Implementations

Instantiate a new SqliteDatabase instance by creating a connection +

Implementations

Instantiate a new SqliteDatabase instance by creating a connection to the database stored at path

-

Trait Implementations

Container for the operations

-

Create a new batch container

-

Consume and apply a batch of operations

-

Store a script_pubkey along with its keychain and child number.

-

Store a LocalUtxo

-

Store a raw transaction

-

Store the metadata of a transaction

-

Store the last derivation index for a given keychain.

-

Store the sync time

-

Delete a script_pubkey given the keychain and its child number.

-

Delete the data related to a specific script_pubkey, meaning the keychain and the child +

Trait Implementations

Container for the operations

+

Create a new batch container

+

Consume and apply a batch of operations

+

Store a script_pubkey along with its keychain and child number.

+

Store a LocalUtxo

+

Store a raw transaction

+

Store the metadata of a transaction

+

Store the last derivation index for a given keychain.

+

Store the sync time

+

Delete a script_pubkey given the keychain and its child number.

+

Delete the data related to a specific script_pubkey, meaning the keychain and the child number. Read more

-

Delete a LocalUtxo given its [OutPoint]

-

Delete a raw transaction given its [Txid]

-

Delete the metadata of a transaction and optionally the raw transaction itself

-

Delete the last derivation index for a keychain.

-

Reset the sync time to None Read more

+

Delete a LocalUtxo given its [OutPoint]

+

Delete a raw transaction given its [Txid]

+

Delete the metadata of a transaction and optionally the raw transaction itself

+

Delete the last derivation index for a keychain.

+

Reset the sync time to None Read more

Type that contains the configuration

Create a new instance given a configuration

-

Read and checks the descriptor checksum for a given keychain. Read more

-

Return the list of script_pubkeys

-

Return the list of LocalUtxos

-

Return the list of raw transactions

-

Return the list of transactions metadata

-

Fetch a script_pubkey given the child number of a keychain.

-

Fetch the keychain and child number of a given script_pubkey

-

Fetch a LocalUtxo given its [OutPoint]

-

Fetch a raw transaction given its [Txid]

-

Fetch the transaction metadata and optionally also the raw transaction

-

Return the last derivation index for a keychain.

-

Return the sync time, if present

-

Increment the last derivation index for a keychain and return it Read more

-

Formats the value using the given formatter. Read more

+

Read and checks the descriptor checksum for a given keychain. Read more

+

Return the list of script_pubkeys

+

Return the list of LocalUtxos

+

Return the list of raw transactions

+

Return the list of transactions metadata

+

Fetch a script_pubkey given the child number of a keychain.

+

Fetch the keychain and child number of a given script_pubkey

+

Fetch a LocalUtxo given its [OutPoint]

+

Fetch a raw transaction given its [Txid]

+

Fetch the transaction metadata and optionally also the raw transaction

+

Return the last derivation index for a keychain.

+

Return the sync time, if present

+

Increment the last derivation index for a keychain and return it Read more

+

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchDatabase.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchDatabase.html index 36965935e0..cf16ab2af9 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchDatabase.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchDatabase.html @@ -15,5 +15,5 @@

Associated Types

Container for the operations

Required methods

Create a new batch container

Consume and apply a batch of operations

-

Implementations on Foreign Types

Implementors

+

Implementations on Foreign Types

Implementors

\ No newline at end of file diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchOperations.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchOperations.html index 96a245fef3..b85568ebbc 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchOperations.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.BatchOperations.html @@ -38,5 +38,5 @@ number.

Delete the last derivation index for a keychain.

Reset the sync time to None

Returns the removed value

-

Implementations on Foreign Types

Implementors

+

Implementations on Foreign Types

Implementors

\ No newline at end of file diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.Database.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.Database.html index 83cf9284ef..3a49d6f2df 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.Database.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/bdk/database/trait.Database.html @@ -39,5 +39,5 @@ next time.

Return the sync time, if present

Increment the last derivation index for a keychain and return it

It should insert and return 0 if not present in the database

-

Implementations on Foreign Types

Implementors

+

Implementations on Foreign Types

Implementors

\ No newline at end of file diff --git a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/src/bdk/database/sqlite.rs.html b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/src/bdk/database/sqlite.rs.html index ff02b1ce1f..65e4a986be 100644 --- a/docs/.vuepress/public/docs-rs/bdk/nightly/latest/src/bdk/database/sqlite.rs.html +++ b/docs/.vuepress/public/docs-rs/bdk/nightly/latest/src/bdk/database/sqlite.rs.html @@ -1086,6 +1086,24 @@ 1079 1080 1081 +1082 +1083 +1084 +1085 +1086 +1087 +1088 +1089 +1090 +1091 +1092 +1093 +1094 +1095 +1096 +1097 +1098 +1099
// Bitcoin Dev Kit
 // Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
 //
@@ -1140,6 +1158,11 @@
     "DELETE FROM transactions;",
     "DELETE FROM utxos;",
     "DROP INDEX idx_txid_vout;",
+    "CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);",
+    "ALTER TABLE utxos RENAME TO utxos_old;",
+    "CREATE TABLE utxos (value INTEGER, keychain TEXT, vout INTEGER, txid BLOB, script BLOB, is_spent BOOLEAN DEFAULT 0);",
+    "INSERT INTO utxos SELECT value, keychain, vout, txid, script, is_spent FROM utxos_old;",
+    "DROP TABLE utxos_old;",
     "CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);"
 ];
 
@@ -2004,8 +2027,8 @@
 }
 
 pub fn get_connection<T: AsRef<Path>>(path: &T) -> Result<Connection, Error> {
-    let connection = Connection::open(path)?;
-    migrate(&connection)?;
+    let mut connection = Connection::open(path)?;
+    migrate(&mut connection)?;
     Ok(connection)
 }
 
@@ -2040,28 +2063,41 @@
     )
 }
 
-pub fn migrate(conn: &Connection) -> rusqlite::Result<()> {
+pub fn migrate(conn: &mut Connection) -> Result<(), Error> {
     let version = get_schema_version(conn)?;
     let stmts = &MIGRATIONS[(version as usize)..];
-    let mut i: i32 = version;
 
-    if version == MIGRATIONS.len() as i32 {
+    // begin transaction, all migration statements and new schema version commit or rollback
+    let tx = conn.transaction()?;
+
+    // execute every statement and return `Some` new schema version
+    // if execution fails, return `Error::Rusqlite`
+    // if no statements executed returns `None`
+    let new_version = stmts
+        .iter()
+        .enumerate()
+        .map(|version_stmt| {
+            log::info!(
+                "executing db migration {}: `{}`",
+                version + version_stmt.0 as i32 + 1,
+                version_stmt.1
+            );
+            tx.execute(version_stmt.1, [])
+                // map result value to next migration version
+                .map(|_| version_stmt.0 as i32 + version + 1)
+        })
+        .last()
+        .transpose()?;
+
+    // if `Some` new statement version, set new schema version
+    if let Some(version) = new_version {
+        set_schema_version(&tx, version)?;
+    } else {
         log::info!("db up to date, no migration needed");
-        return Ok(());
     }
 
-    for stmt in stmts {
-        let res = conn.execute(stmt, []);
-        if res.is_err() {
-            println!("migration failed on:\n{}\n{:?}", stmt, res);
-            break;
-        }
-
-        i += 1;
-    }
-
-    set_schema_version(conn, i)?;
-
+    // commit transaction
+    tx.commit()?;
     Ok(())
 }