Set approximate wallet fee to avoid LowFeeTransaction (#163)

Set approximate wallet fee when building a transaction so we avoid getting a LowFeeTransaction error from the pool

* rustfmt
This commit is contained in:
AntiochP 2017-10-10 13:30:34 -04:00 committed by Ignotus Peverell
parent d0160811dd
commit dc0dbc62be
2 changed files with 13 additions and 5 deletions

View file

@ -567,6 +567,11 @@ where
// TODO evict old/large transactions instead
return Err(PoolError::OverCapacity);
}
// for a basic transaction (1 input, 2 outputs) -
// (-1 * 1) + (4 * 2) + 1 = 8
// 8 * 10 = 80
//
if self.config.accept_fee_base > 0 {
let mut tx_weight = -1 * (tx.inputs.len() as i32) + (4 * tx.outputs.len() as i32) + 1;
if tx_weight < 1 {
@ -1055,7 +1060,7 @@ mod tests {
fn test_setup(dummy_chain: &Arc<DummyChainImpl>) -> TransactionPool<DummyChainImpl> {
TransactionPool {
config: PoolConfig{
config: PoolConfig {
accept_fee_base: 0,
max_pool_size: 10_000,
},

View file

@ -234,10 +234,13 @@ fn receive_transaction(
let derivation = wallet_data.next_child(fingerprint.clone());
let pubkey = keychain.derive_pubkey(derivation)?;
// TODO - replace with real fee calculation
// TODO - note we are not enforcing this in consensus anywhere yet
// Note: consensus rules require this to be an even value so it can be split
let fee_amount = 10;
// from pool.rs
// (-1 * num_inputs) + (4 * num_outputs) + 1
// then multiply by accept_fee_base==10
// so 80 is basically the minimum fee for a basic transaction
// so lets use 100 for now (revisit this)
let fee_amount = 100;
let out_amount = amount - fee_amount;
let (tx_final, _) = build::transaction(vec![