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.
This commit is contained in:
Jack Grigg 2019-02-07 14:39:50 +00:00
parent bc88f5cd2a
commit 45adb0af4a
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
4 changed files with 14 additions and 3 deletions

1
Cargo.lock generated
View File

@ -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)",

View File

@ -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"

View File

@ -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;

View File

@ -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.