From b75da8724e4a13623bf993ba259d72b397204e8a Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Fri, 13 Sep 2019 19:13:09 -0700 Subject: [PATCH] Mark utxos as spent --- rust-lightclient/proto/service.proto | 4 +++- rust-lightclient/src/lightclient.rs | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rust-lightclient/proto/service.proto b/rust-lightclient/proto/service.proto index d6cf040..915cf1d 100644 --- a/rust-lightclient/proto/service.proto +++ b/rust-lightclient/proto/service.proto @@ -27,9 +27,11 @@ message TxFilter { bytes hash = 3; } -// RawTransaction contains the complete transaction data. +// RawTransaction contains the complete transaction data. It also optionally includes +// the block height in which the transaction was included message RawTransaction { bytes data = 1; + uint64 height = 2; } message SendResponse { diff --git a/rust-lightclient/src/lightclient.rs b/rust-lightclient/src/lightclient.rs index e2ef70f..d90eeef 100644 --- a/rust-lightclient/src/lightclient.rs +++ b/rust-lightclient/src/lightclient.rs @@ -369,11 +369,11 @@ impl LightClient { let address = LightWallet::address_from_sk(&self.wallet.tkeys[0]); let wallet = self.wallet.clone(); self.fetch_transparent_txids(address, last_scanned_height, end_height, - move |tx_bytes: &[u8] | { + move |tx_bytes: &[u8], height: u64 | { let tx = Transaction::read(tx_bytes).unwrap(); // Scan this Tx for transparent inputs and outputs - wallet.scan_full_tx(&tx, -1); // TODO: Add the height here! + wallet.scan_full_tx(&tx, height as i32); // TODO: Add the height here! } ); @@ -577,7 +577,7 @@ impl LightClient { pub fn fetch_transparent_txids(&self, address: String, start_height: u64, end_height: u64,c: F) - where F : Fn(&[u8]) { + where F : Fn(&[u8], u64) { let uri: http::Uri = format!("http://127.0.0.1:9067").parse().unwrap(); let dst = Destination::try_from_uri(uri.clone()).unwrap(); @@ -615,7 +615,7 @@ impl LightClient { let inbound = response.into_inner(); inbound.for_each(move |tx| { //let tx = Transaction::read(&tx.into_inner().data[..]).unwrap(); - c(&tx.data); + c(&tx.data, tx.height); Ok(()) }) @@ -653,7 +653,7 @@ impl LightClient { let say_hello = self.make_grpc_client(uri).unwrap() .and_then(move |mut client| { - client.send_transaction(Request::new(RawTransaction {data: tx_bytes.to_vec()})) + client.send_transaction(Request::new(RawTransaction {data: tx_bytes.to_vec(), height: 0})) }) .and_then(move |response| { println!("{:?}", response.into_inner());