mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
fix wallet tests, chain test output
This commit is contained in:
parent
94322c796c
commit
836d5441e6
4 changed files with 42 additions and 45 deletions
|
@ -636,6 +636,7 @@ impl Chain {
|
||||||
Ok(b) => {
|
Ok(b) => {
|
||||||
count += 1;
|
count += 1;
|
||||||
batch.delete_block(&b.hash())?;
|
batch.delete_block(&b.hash())?;
|
||||||
|
//TODO: Validation seems to fail as block markers are being deleted?
|
||||||
batch.delete_block_marker(&b.hash())?;
|
batch.delete_block_marker(&b.hash())?;
|
||||||
batch.delete_block_input_bitmap(&b.hash())?;
|
batch.delete_block_input_bitmap(&b.hash())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ impl<'a> Batch<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get block
|
/// get block
|
||||||
fn get_block(&self, h: &Hash) -> Result<Block, Error> {
|
pub fn get_block(&self, h: &Hash) -> Result<Block, Error> {
|
||||||
option_to_not_found(self.db.get_ser(&to_key(BLOCK_PREFIX, &mut h.to_vec())))
|
option_to_not_found(self.db.get_ser(&to_key(BLOCK_PREFIX, &mut h.to_vec())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -356,8 +356,12 @@ fn spend_in_fork_and_compact() {
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.validate(false).unwrap();
|
chain.validate(false).unwrap();
|
||||||
chain.compact().unwrap();
|
if let Err(e) = chain.compact() {
|
||||||
chain.validate(false).unwrap();
|
panic!("Error compacting chain: {:?}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = chain.validate(false) {
|
||||||
|
panic!("Validation error after compacting chain: {:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_block<K>(kc: &K, prev: &BlockHeader, chain: &Chain, diff: u64) -> Block
|
fn prepare_block<K>(kc: &K, prev: &BlockHeader, chain: &Chain, diff: u64) -> Block
|
||||||
|
|
|
@ -28,7 +28,8 @@ use core::core::hash::Hashed;
|
||||||
use core::core::{Output, OutputFeatures, OutputIdentifier, Transaction, TxKernel};
|
use core::core::{Output, OutputFeatures, OutputIdentifier, Transaction, TxKernel};
|
||||||
use core::{consensus, global, pow};
|
use core::{consensus, global, pow};
|
||||||
use keychain::ExtKeychain;
|
use keychain::ExtKeychain;
|
||||||
use wallet::file_wallet::{FileWallet, WalletConfig};
|
use wallet::file_wallet::FileWallet;
|
||||||
|
use wallet::WalletConfig;
|
||||||
use wallet::libwallet::internal::updater;
|
use wallet::libwallet::internal::updater;
|
||||||
use wallet::libwallet::types::{BlockFees, BlockIdentifier, MerkleProofWrapper, OutputStatus,
|
use wallet::libwallet::types::{BlockFees, BlockIdentifier, MerkleProofWrapper, OutputStatus,
|
||||||
WalletBackend};
|
WalletBackend};
|
||||||
|
@ -78,40 +79,35 @@ where
|
||||||
T: WalletBackend<K>,
|
T: WalletBackend<K>,
|
||||||
K: keychain::Keychain,
|
K: keychain::Keychain,
|
||||||
{
|
{
|
||||||
let ret_val = wallet.read_wallet(|wallet_data| {
|
let mut unspent_total = 0;
|
||||||
let mut unspent_total = 0;
|
let mut unspent_but_locked_total = 0;
|
||||||
let mut unspent_but_locked_total = 0;
|
let mut unconfirmed_total = 0;
|
||||||
let mut unconfirmed_total = 0;
|
let mut locked_total = 0;
|
||||||
let mut locked_total = 0;
|
let keychain = wallet.keychain().clone();
|
||||||
let keychain = wallet_data.keychain().clone();
|
for out in wallet.iter()
|
||||||
for out in wallet_data
|
.filter(|out| out.root_key_id == keychain.root_key_id())
|
||||||
.outputs()
|
{
|
||||||
.values()
|
if out.status == OutputStatus::Unspent {
|
||||||
.filter(|out| out.root_key_id == keychain.root_key_id())
|
unspent_total += out.value;
|
||||||
{
|
if out.lock_height > height {
|
||||||
if out.status == OutputStatus::Unspent {
|
unspent_but_locked_total += out.value;
|
||||||
unspent_total += out.value;
|
|
||||||
if out.lock_height > height {
|
|
||||||
unspent_but_locked_total += out.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if out.status == OutputStatus::Unconfirmed && !out.is_coinbase {
|
|
||||||
unconfirmed_total += out.value;
|
|
||||||
}
|
|
||||||
if out.status == OutputStatus::Locked {
|
|
||||||
locked_total += out.value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if out.status == OutputStatus::Unconfirmed && !out.is_coinbase {
|
||||||
|
unconfirmed_total += out.value;
|
||||||
|
}
|
||||||
|
if out.status == OutputStatus::Locked {
|
||||||
|
locked_total += out.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
unspent_total + unconfirmed_total, //total
|
unspent_total + unconfirmed_total, //total
|
||||||
unconfirmed_total, //amount_awaiting_confirmation
|
unconfirmed_total, //amount_awaiting_confirmation
|
||||||
unspent_but_locked_total, // confirmed but locked
|
unspent_but_locked_total, // confirmed but locked
|
||||||
unspent_total - unspent_but_locked_total, // currently spendable
|
unspent_total - unspent_but_locked_total, // currently spendable
|
||||||
locked_total, // locked total
|
locked_total, // locked total
|
||||||
))
|
))
|
||||||
});
|
|
||||||
ret_val
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an output from the chain locally and present it back as an API output
|
/// Get an output from the chain locally and present it back as an API output
|
||||||
|
@ -183,16 +179,12 @@ where
|
||||||
let output_id = OutputIdentifier::from_output(&coinbase_tx.0.clone());
|
let output_id = OutputIdentifier::from_output(&coinbase_tx.0.clone());
|
||||||
let m_proof = chain.get_merkle_proof(&output_id, &chain.head_header().unwrap());
|
let m_proof = chain.get_merkle_proof(&output_id, &chain.head_header().unwrap());
|
||||||
let block_id = Some(BlockIdentifier(chain.head_header().unwrap().hash()));
|
let block_id = Some(BlockIdentifier(chain.head_header().unwrap().hash()));
|
||||||
let _ = wallet.with_wallet(|wallet_data| {
|
let mut output = wallet.get(&fees.key_id.unwrap()).unwrap();
|
||||||
if let Entry::Occupied(mut output) = wallet_data
|
output.block = block_id;
|
||||||
.outputs()
|
output.merkle_proof = Some(MerkleProofWrapper(m_proof.unwrap()));
|
||||||
.entry(fees.key_id.as_ref().unwrap().to_hex())
|
let mut batch = wallet.batch().unwrap();
|
||||||
{
|
batch.save(output).unwrap();
|
||||||
let output = output.get_mut();
|
batch.commit().unwrap();
|
||||||
output.block = block_id;
|
|
||||||
output.merkle_proof = Some(MerkleProofWrapper(m_proof.unwrap()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// adds many block rewards to a wallet, no transactions
|
/// adds many block rewards to a wallet, no transactions
|
||||||
|
|
Loading…
Reference in a new issue