From 45adb0af4af6e43d89103ac884dbd3fa44cee578 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 7 Feb 2019 14:39:50 +0000 Subject: [PATCH] Store creation time and expiry height in transactions table - Creation time can be used in the UI before a transaction gets mined. - Expiry height enables the UI to indicate expired transactions. --- Cargo.lock | 1 + Cargo.toml | 1 + src/main/rust/lib.rs | 1 + src/main/rust/sql.rs | 14 +++++++++++--- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c138948..464861a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,6 +738,7 @@ dependencies = [ "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rusqlite 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "zcash_client_backend 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)", "zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)", "zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)", diff --git a/Cargo.toml b/Cargo.toml index 3e5cac5a..9980dd8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ log-panics = "2.0.0" protobuf = "2" rand = "0.4" rusqlite = { version = "0.15", features = ["bundled"] } +time = "0.1" [dependencies.ff] git = "https://github.com/str4d/librustzcash.git" diff --git a/src/main/rust/lib.rs b/src/main/rust/lib.rs index c16b5b27..891066d4 100644 --- a/src/main/rust/lib.rs +++ b/src/main/rust/lib.rs @@ -11,6 +11,7 @@ extern crate pairing; extern crate protobuf; extern crate rusqlite; extern crate sapling_crypto; +extern crate time; extern crate zcash_client_backend; extern crate zcash_primitives; extern crate zip32; diff --git a/src/main/rust/sql.rs b/src/main/rust/sql.rs index 867018f1..e36393c6 100644 --- a/src/main/rust/sql.rs +++ b/src/main/rust/sql.rs @@ -54,8 +54,10 @@ pub fn init_data_database(db_data: &str) -> rusqlite::Result<()> { "CREATE TABLE IF NOT EXISTS transactions ( id_tx INTEGER PRIMARY KEY, txid BLOB NOT NULL UNIQUE, + created TEXT, block INTEGER, tx_index INTEGER, + expiry_height INTEGER, raw BLOB, FOREIGN KEY (block) REFERENCES blocks(height) )", @@ -574,15 +576,21 @@ pub fn send_to_address( let (tx, tx_metadata) = builder.build(consensus_branch_id, prover)?; // We only called add_sapling_output() once. let output_index = tx_metadata.output_index(0).unwrap() as i64; + let created = time::get_time(); // Save the transaction in the database. let mut raw_tx = vec![]; tx.write(&mut raw_tx)?; let mut stmt_insert_tx = data.prepare( - "INSERT INTO transactions (txid, raw) - VALUES (?, ?)", + "INSERT INTO transactions (txid, created, expiry_height, raw) + VALUES (?, ?, ?, ?)", )?; - stmt_insert_tx.execute(&[&tx.txid().0[..], &raw_tx[..]])?; + stmt_insert_tx.execute(&[ + tx.txid().0.to_sql()?, + created.to_sql()?, + tx.expiry_height.to_sql()?, + raw_tx.to_sql()?, + ])?; let id_tx = data.last_insert_rowid(); // Save the sent note in the database.