mirror of
https://github.com/basicswap/basicswap.git
synced 2026-03-19 16:27:22 +01:00
estimate witness stack size for multiple inputs
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import threading
|
||||
|
||||
from enum import IntEnum
|
||||
from typing import List
|
||||
|
||||
from basicswap.chainparams import (
|
||||
chainparams,
|
||||
@@ -180,13 +181,16 @@ class CoinInterface:
|
||||
|
||||
|
||||
class AdaptorSigInterface:
|
||||
def getScriptLockTxDummyWitness(self, script: bytes):
|
||||
def getP2WPKHDummyWitness(self) -> List[bytes]:
|
||||
return [bytes(72), bytes(33)]
|
||||
|
||||
def getScriptLockTxDummyWitness(self, script: bytes) -> List[bytes]:
|
||||
return [b"", bytes(72), bytes(72), bytes(len(script))]
|
||||
|
||||
def getScriptLockRefundSpendTxDummyWitness(self, script: bytes):
|
||||
def getScriptLockRefundSpendTxDummyWitness(self, script: bytes) -> List[bytes]:
|
||||
return [b"", bytes(72), bytes(72), bytes((1,)), bytes(len(script))]
|
||||
|
||||
def getScriptLockRefundSwipeTxDummyWitness(self, script: bytes):
|
||||
def getScriptLockRefundSwipeTxDummyWitness(self, script: bytes) -> List[bytes]:
|
||||
return [bytes(72), b"", bytes(len(script))]
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2024 tecnovert
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -828,7 +828,7 @@ class BTCInterface(Secp256k1Interface):
|
||||
|
||||
def getScriptDummyWitness(self, script: bytes) -> List[bytes]:
|
||||
if self.isScriptP2WPKH(script):
|
||||
return [bytes(72), bytes(33)]
|
||||
return self.getP2WPKHDummyWitness()
|
||||
raise ValueError("Unknown script type")
|
||||
|
||||
def createSCLockRefundTx(
|
||||
@@ -1943,9 +1943,16 @@ class BTCInterface(Secp256k1Interface):
|
||||
raise ValueError("Unimplemented")
|
||||
|
||||
def getWitnessStackSerialisedLength(self, witness_stack):
|
||||
length = getCompactSizeLen(len(witness_stack))
|
||||
for e in witness_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
length: int = 0
|
||||
if len(witness_stack) > 0 and isinstance(witness_stack[0], list):
|
||||
for input_stack in witness_stack:
|
||||
length += getCompactSizeLen(len(input_stack))
|
||||
for e in input_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
else:
|
||||
length += getCompactSizeLen(len(witness_stack))
|
||||
for e in witness_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
|
||||
# See core SerializeTransaction
|
||||
length += 1 # vinDummy
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2024 tecnovert
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -137,7 +137,7 @@ class PARTInterface(BTCInterface):
|
||||
|
||||
def getScriptDummyWitness(self, script: bytes) -> List[bytes]:
|
||||
if self.isScriptP2WPKH(script) or self.isScriptP2PKH(script):
|
||||
return [bytes(72), bytes(33)]
|
||||
return self.getP2WPKHDummyWitness()
|
||||
raise ValueError("Unknown script type")
|
||||
|
||||
def formatStealthAddress(self, scan_pubkey, spend_pubkey) -> str:
|
||||
@@ -146,9 +146,16 @@ class PARTInterface(BTCInterface):
|
||||
return encodeStealthAddress(prefix_byte, scan_pubkey, spend_pubkey)
|
||||
|
||||
def getWitnessStackSerialisedLength(self, witness_stack) -> int:
|
||||
length: int = getCompactSizeLen(len(witness_stack))
|
||||
for e in witness_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
length: int = 0
|
||||
if len(witness_stack) > 0 and isinstance(witness_stack[0], list):
|
||||
for input_stack in witness_stack:
|
||||
length += getCompactSizeLen(len(input_stack))
|
||||
for e in input_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
else:
|
||||
length += getCompactSizeLen(len(witness_stack))
|
||||
for e in witness_stack:
|
||||
length += getWitnessElementLen(len(e))
|
||||
return length
|
||||
|
||||
def getWalletRestoreHeight(self) -> int:
|
||||
|
||||
Reference in New Issue
Block a user