Add timestamps to transaction creation process

This commit is contained in:
Jack Grigg
2019-06-20 18:44:18 +02:00
parent f9361b27d9
commit d688445bb1
2 changed files with 21 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ default = ["console_error_panic_hook"]
hex = "0.3" hex = "0.3"
protobuf = "2" protobuf = "2"
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["console"] } web-sys = { version = "0.3", features = ["console", "Performance", "Window"] }
# We don't use these crates directly, but we add it as a dependency so we can # We don't use these crates directly, but we add it as a dependency so we can
# enable necessary features for WASM compatibility. # enable necessary features for WASM compatibility.

View File

@@ -54,6 +54,14 @@ extern "C" {
fn alert(s: &str); fn alert(s: &str);
} }
fn now() -> f64 {
web_sys::window()
.expect("should have a Window")
.performance()
.expect("should have a Performance")
.now()
}
struct BlockData { struct BlockData {
height: i32, height: i32,
hash: BlockHash, hash: BlockHash,
@@ -388,6 +396,13 @@ impl Client {
to: &str, to: &str,
value: u32, value: u32,
) -> Option<Box<[u8]>> { ) -> Option<Box<[u8]>> {
let start_time = now();
log!(
"0: Creating transaction sending {} tazoshis to {}",
value,
to
);
let extsk = &self.extsks[0]; let extsk = &self.extsks[0];
let extfvk = &self.extfvks[0]; let extfvk = &self.extfvks[0];
let ovk = extfvk.fvk.ovk; let ovk = extfvk.fvk.ovk;
@@ -411,6 +426,7 @@ impl Client {
}; };
// Select notes to cover the target value // Select notes to cover the target value
log!("{}: Selecting notes", now() - start_time);
let target_value = value.0 + DEFAULT_FEE.0; let target_value = value.0 + DEFAULT_FEE.0;
let notes: Vec<_> = self let notes: Vec<_> = self
.txs .txs
@@ -446,6 +462,7 @@ impl Client {
} }
// Create the transaction // Create the transaction
log!("{}: Adding {} inputs", now() - start_time, notes.len());
let mut builder = Builder::new(height); let mut builder = Builder::new(height);
for selected in notes.iter() { for selected in notes.iter() {
if let Err(e) = builder.add_sapling_spend( if let Err(e) = builder.add_sapling_spend(
@@ -458,6 +475,7 @@ impl Client {
return None; return None;
} }
} }
log!("{}: Adding output", now() - start_time);
if let Err(e) = match to { if let Err(e) = match to {
address::RecipientAddress::Shielded(to) => { address::RecipientAddress::Shielded(to) => {
builder.add_sapling_output(ovk, to.clone(), value, None) builder.add_sapling_output(ovk, to.clone(), value, None)
@@ -469,6 +487,7 @@ impl Client {
error!("Error adding output: {:?}", e); error!("Error adding output: {:?}", e);
return None; return None;
} }
log!("{}: Building transaction", now() - start_time);
let (tx, _) = match builder.build( let (tx, _) = match builder.build(
consensus_branch_id, consensus_branch_id,
prover::InMemTxProver::new(spend_params, output_params), prover::InMemTxProver::new(spend_params, output_params),
@@ -479,6 +498,7 @@ impl Client {
return None; return None;
} }
}; };
log!("{}: Transaction created", now() - start_time);
log!("Transaction ID: {}", tx.txid()); log!("Transaction ID: {}", tx.txid());
// Mark notes as spent. // Mark notes as spent.