From c1432a381021bf12428e25e866099bdf907f00ca Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Wed, 25 Sep 2019 17:45:25 -0700 Subject: [PATCH] Fetch consensusBranchId from server --- proto/service.proto | 11 +---------- src/lightclient.rs | 3 ++- src/lightwallet/mod.rs | 45 ++++++++++++++---------------------------- src/main.rs | 1 + 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/proto/service.proto b/proto/service.proto index 21c77e3..e15e676 100644 --- a/proto/service.proto +++ b/proto/service.proto @@ -50,6 +50,7 @@ message LightdInfo { bool taddrSupport = 3; string chainName = 4; uint64 saplingActivationHeight = 5; + string consensusBranchId = 6; // This should really be u32 or []byte, but string for readability } message TransparentAddress { @@ -61,15 +62,6 @@ message TransparentAddressBlockFilter { BlockRange range = 2; } -message Utxo { - TransparentAddress address = 1; - bytes txid = 2; - uint64 outputIndex = 3; - bytes script = 4; - uint64 value = 5; - uint64 height = 6; -} - service CompactTxStreamer { // Compact Blocks rpc GetLatestBlock(ChainSpec) returns (BlockID) {} @@ -81,7 +73,6 @@ service CompactTxStreamer { rpc SendTransaction(RawTransaction) returns (SendResponse) {} // t-Address support - rpc GetUtxos(TransparentAddress) returns (stream Utxo) {} rpc GetAddressTxids(TransparentAddressBlockFilter) returns (stream RawTransaction) {} // Misc diff --git a/src/lightclient.rs b/src/lightclient.rs index 57dc254..2bf96ca 100644 --- a/src/lightclient.rs +++ b/src/lightclient.rs @@ -41,6 +41,7 @@ pub struct LightClientConfig { pub server : String, pub chain_name : String, pub sapling_activation_height : u64, + pub consensus_branch_id : String, } impl LightClientConfig { @@ -724,7 +725,7 @@ impl LightClient { pub fn do_send(&self, addr: &str, value: u64, memo: Option) -> String { info!("Creating transaction"); let rawtx = self.wallet.send_to_address( - u32::from_str_radix("2bb40e60", 16).unwrap(), // Blossom ID + u32::from_str_radix(&self.config.consensus_branch_id, 16).unwrap(), // Blossom ID &self.sapling_spend, &self.sapling_output, &addr, value, memo ); diff --git a/src/lightwallet/mod.rs b/src/lightwallet/mod.rs index d3495c8..ce22a36 100644 --- a/src/lightwallet/mod.rs +++ b/src/lightwallet/mod.rs @@ -1461,11 +1461,7 @@ pub mod tests { #[test] fn z_balances() { - let wallet = LightWallet::new(None, &LightClientConfig { - server: "0.0.0.0:0".to_string(), - chain_name: "test".to_string(), - sapling_activation_height: 0 - }).unwrap(); + let wallet = LightWallet::new(None, &get_test_config()).unwrap(); const AMOUNT1:u64 = 5; // Address is encoded in bech32 @@ -1504,11 +1500,7 @@ pub mod tests { #[test] fn z_change_balances() { - let wallet = LightWallet::new(None, &LightClientConfig { - server: "0.0.0.0:0".to_string(), - chain_name: "test".to_string(), - sapling_activation_height: 0 - }).unwrap(); + let wallet = LightWallet::new(None, &get_test_config()).unwrap(); // First, add an incoming transaction const AMOUNT1:u64 = 5; @@ -1557,11 +1549,7 @@ pub mod tests { let mut rng = OsRng; let secp = Secp256k1::new(); - let wallet = LightWallet::new(None, &LightClientConfig { - server: "0.0.0.0:0".to_string(), - chain_name: "test".to_string(), - sapling_activation_height: 0 - }).unwrap(); + let wallet = LightWallet::new(None, &get_test_config()).unwrap(); let pk = PublicKey::from_secret_key(&secp, &wallet.tkeys[0]); let taddr = wallet.address_from_sk(&wallet.tkeys[0]); @@ -1627,11 +1615,7 @@ pub mod tests { let mut rng = OsRng; let secp = Secp256k1::new(); - let wallet = LightWallet::new(None, &LightClientConfig { - server: "0.0.0.0:0".to_string(), - chain_name: "test".to_string(), - sapling_activation_height: 0 - }).unwrap(); + let wallet = LightWallet::new(None, &get_test_config()).unwrap(); let pk = PublicKey::from_secret_key(&secp, &wallet.tkeys[0]); let taddr = wallet.address_from_sk(&wallet.tkeys[0]); @@ -1698,11 +1682,7 @@ pub mod tests { #[test] fn test_serialization() { let secp = Secp256k1::new(); - let config = LightClientConfig { - server: "0.0.0.0:0".to_string(), - chain_name: "test".to_string(), - sapling_activation_height: 0 - }; + let config = get_test_config(); let wallet = LightWallet::new(None, &config).unwrap(); @@ -1808,13 +1788,18 @@ pub mod tests { } } - // Get a test wallet already setup with a single note - fn get_test_wallet(amount: u64) -> (LightWallet, LightClientConfig, TxId, BlockHash) { - let config = LightClientConfig { + fn get_test_config() -> LightClientConfig { + LightClientConfig { server: "0.0.0.0:0".to_string(), chain_name: "test".to_string(), - sapling_activation_height: 0 - }; + sapling_activation_height: 0, + consensus_branch_id: "000000".to_string(), + } + } + + // Get a test wallet already setup with a single note + fn get_test_wallet(amount: u64) -> (LightWallet, LightClientConfig, TxId, BlockHash) { + let config = get_test_config(); let wallet = LightWallet::new(None, &config).unwrap(); diff --git a/src/main.rs b/src/main.rs index 209d15a..a6783c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,7 @@ pub fn main() { server, chain_name : info.chain_name, sapling_activation_height : info.sapling_activation_height, + consensus_branch_id : info.consensus_branch_id, }; let lightclient = match LightClient::new(seed, &config) {