Use remote server's latest height when building redeem P2SH transactions, as our latest height may not be correct.

This commit is contained in:
CalDescent
2022-08-07 09:45:43 +01:00
parent dafb7f8a40
commit 4565889110
2 changed files with 10 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::fs::File;
use std::collections::{HashMap};
use std::cmp::{max, min};
use std::convert::TryFrom;
use std::io;
use std::io::prelude::*;
use std::io::{BufReader, Error, ErrorKind};
@@ -1753,10 +1754,14 @@ impl LightClient {
let result = {
let _lock = self.sync_lock.lock().unwrap();
// This will hold the latest block fetched from the RPC
let latest_block_height = fetch_latest_block(&self.get_server_uri())?.height;
let latest_block_height_u32 = u32::try_from(latest_block_height).unwrap();
self.wallet.write().unwrap().redeem_p2sh(
u32::from_str_radix(&self.config.consensus_branch_id, 16).unwrap(),
&self.sapling_spend, &self.sapling_output,
from, addrs, script, txid, lock_time, secret, privkey, fee,
from, addrs, script, txid, lock_time, secret, privkey, fee, latest_block_height_u32,
|txbytes| broadcast_raw_tx(&self.get_server_uri(), txbytes)
)
};

View File

@@ -2787,6 +2787,7 @@ impl LightWallet {
secret: &[u8],
privkey: &[u8],
fee: &u64,
chain_height: u32,
broadcast_fn: F
) -> Result<(String, Vec<u8>), String>
where F: Fn(Box<[u8]>) -> Result<String, String>
@@ -2878,7 +2879,9 @@ impl LightWallet {
})
.collect();
let mut builder = Builder::new(height);
// Use passed-in chain_height as the chain's latest height, as we may not have
// a full sync locally
let mut builder = Builder::new(chain_height);
//set fre
builder.set_fee(Amount::from_u64(*fee).unwrap());