File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 10
10
11
11
from test_framework .descriptors import descsum_create
12
12
from test_framework .key import ECKey
13
+ from test_framework .messages import (
14
+ ser_compact_size ,
15
+ WITNESS_SCALE_FACTOR ,
16
+ )
13
17
from test_framework .test_framework import BitcoinTestFramework
14
18
from test_framework .util import (
15
19
assert_approx ,
@@ -655,10 +659,11 @@ def test_psbt_input_keys(psbt_input, keys):
655
659
break
656
660
psbt_in = dec ["inputs" ][input_idx ]
657
661
# Calculate the input weight
658
- # (prevout + sequence + length of scriptSig + 2 bytes buffer) * 4 + len of scriptwitness
662
+ # (prevout + sequence + length of scriptSig + scriptsig + 1 byte buffer) * WITNESS_SCALE_FACTOR + num scriptWitness stack items + (length of stack item + stack item) * N stack items + 1 byte buffer
659
663
len_scriptsig = len (psbt_in ["final_scriptSig" ]["hex" ]) // 2 if "final_scriptSig" in psbt_in else 0
660
- len_scriptwitness = len (psbt_in ["final_scriptwitness" ]["hex" ]) // 2 if "final_scriptwitness" in psbt_in else 0
661
- input_weight = ((41 + len_scriptsig + 2 ) * 4 ) + len_scriptwitness
664
+ len_scriptsig += len (ser_compact_size (len_scriptsig )) + 1
665
+ len_scriptwitness = (sum ([(len (x ) // 2 ) + len (ser_compact_size (len (x ) // 2 )) for x in psbt_in ["final_scriptwitness" ]]) + len (psbt_in ["final_scriptwitness" ]) + 1 ) if "final_scriptwitness" in psbt_in else 0
666
+ input_weight = ((40 + len_scriptsig ) * WITNESS_SCALE_FACTOR ) + len_scriptwitness
662
667
low_input_weight = input_weight // 2
663
668
high_input_weight = input_weight * 2
664
669
Original file line number Diff line number Diff line change 10
10
from test_framework .authproxy import JSONRPCException
11
11
from test_framework .descriptors import descsum_create
12
12
from test_framework .key import ECKey
13
+ from test_framework .messages import (
14
+ ser_compact_size ,
15
+ WITNESS_SCALE_FACTOR ,
16
+ )
13
17
from test_framework .test_framework import BitcoinTestFramework
14
18
from test_framework .util import (
15
19
assert_equal ,
@@ -526,10 +530,11 @@ def run_test(self):
526
530
break
527
531
psbt_in = dec ["inputs" ][input_idx ]
528
532
# Calculate the input weight
529
- # (prevout + sequence + length of scriptSig + 2 bytes buffer) * 4 + len of scriptwitness
533
+ # (prevout + sequence + length of scriptSig + scriptsig + 1 byte buffer) * WITNESS_SCALE_FACTOR + num scriptWitness stack items + (length of stack item + stack item) * N stack items + 1 byte buffer
530
534
len_scriptsig = len (psbt_in ["final_scriptSig" ]["hex" ]) // 2 if "final_scriptSig" in psbt_in else 0
531
- len_scriptwitness = len (psbt_in ["final_scriptwitness" ]["hex" ]) // 2 if "final_scriptwitness" in psbt_in else 0
532
- input_weight = ((41 + len_scriptsig + 2 ) * 4 ) + len_scriptwitness
535
+ len_scriptsig += len (ser_compact_size (len_scriptsig )) + 1
536
+ len_scriptwitness = (sum ([(len (x ) // 2 ) + len (ser_compact_size (len (x ) // 2 )) for x in psbt_in ["final_scriptwitness" ]]) + len (psbt_in ["final_scriptwitness" ]) + 1 ) if "final_scriptwitness" in psbt_in else 0
537
+ input_weight = ((40 + len_scriptsig ) * WITNESS_SCALE_FACTOR ) + len_scriptwitness
533
538
534
539
# Input weight error conditions
535
540
assert_raises_rpc_error (
You can’t perform that action at this time.
0 commit comments