Use witness scaling constant in get_weight
This commit is contained in:
parent
09c0e7fbde
commit
3624ee82c8
|
@ -30,6 +30,7 @@ use hashes::{self, Hash, sha256d};
|
||||||
use hashes::hex::FromHex;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
use util::endian;
|
use util::endian;
|
||||||
|
use blockdata::constants::WITNESS_SCALE_FACTOR;
|
||||||
#[cfg(feature="bitcoinconsensus")] use blockdata::script;
|
#[cfg(feature="bitcoinconsensus")] use blockdata::script;
|
||||||
use blockdata::script::Script;
|
use blockdata::script::Script;
|
||||||
use consensus::{encode, serialize, Decodable, Encodable};
|
use consensus::{encode, serialize, Decodable, Encodable};
|
||||||
|
@ -391,7 +392,7 @@ impl Transaction {
|
||||||
let mut input_weight = 0;
|
let mut input_weight = 0;
|
||||||
let mut inputs_with_witnesses = 0;
|
let mut inputs_with_witnesses = 0;
|
||||||
for input in &self.input {
|
for input in &self.input {
|
||||||
input_weight += 4*(32 + 4 + 4 + // outpoint (32+4) + nSequence
|
input_weight += WITNESS_SCALE_FACTOR*(32 + 4 + 4 + // outpoint (32+4) + nSequence
|
||||||
VarInt(input.script_sig.len() as u64).len() +
|
VarInt(input.script_sig.len() as u64).len() +
|
||||||
input.script_sig.len());
|
input.script_sig.len());
|
||||||
if !input.witness.is_empty() {
|
if !input.witness.is_empty() {
|
||||||
|
@ -418,9 +419,9 @@ impl Transaction {
|
||||||
// lock_time
|
// lock_time
|
||||||
4;
|
4;
|
||||||
if inputs_with_witnesses == 0 {
|
if inputs_with_witnesses == 0 {
|
||||||
non_input_size * 4 + input_weight
|
non_input_size * WITNESS_SCALE_FACTOR + input_weight
|
||||||
} else {
|
} else {
|
||||||
non_input_size * 4 + input_weight + self.input.len() - inputs_with_witnesses + 2
|
non_input_size * WITNESS_SCALE_FACTOR + input_weight + self.input.len() - inputs_with_witnesses + 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue