From 519d29e90c28c3e36b93a1906b4f76a02809004a Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Sat, 25 Mar 2017 16:31:46 +0200 Subject: [PATCH] add primitive p2sh tx estimation support --- jmbitcoin/jmbitcoin/secp256k1_main.py | 11 +++++++++-- jmclient/jmclient/__init__.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jmbitcoin/jmbitcoin/secp256k1_main.py b/jmbitcoin/jmbitcoin/secp256k1_main.py index 317e673..fe2b79f 100644 --- a/jmbitcoin/jmbitcoin/secp256k1_main.py +++ b/jmbitcoin/jmbitcoin/secp256k1_main.py @@ -433,9 +433,16 @@ def estimate_tx_size(ins, outs, txtype='p2pkh'): out: 8+1+3+2+20=34, in: 1+32+4+1+1+~73+1+1+33=147, ver:4,seq:4, +2 (len in,out) total ~= 34*len_out + 147*len_in + 10 (sig sizes vary slightly) + Assuming p2sh M of N multisig: + "ins" must contain M, N so ins= (numins, M, N) (crude assuming all same) + 74*M + 34*N + 45 per input, so total ins ~ len_ins * (45+74M+34N) + so total ~ 34*len_out + (45+74M+34N)*len_in + 10 ''' if txtype == 'p2pkh': return 10 + ins * 147 + 34 * outs + elif txtype == 'p2shMofN': + ins, M, N = ins + return 10 + (45 + 74*M + 34*N) * ins + 34 * outs else: - raise NotImplementedError("Non p2pkh transaction size estimation not" + - "yet implemented") + raise NotImplementedError("Transaction size estimation not" + + "yet implemented for type: " + txtype) diff --git a/jmclient/jmclient/__init__.py b/jmclient/jmclient/__init__.py index 16d512b..34ab45f 100644 --- a/jmclient/jmclient/__init__.py +++ b/jmclient/jmclient/__init__.py @@ -21,7 +21,7 @@ from .wallet import (AbstractWallet, BitcoinCoreInterface, Wallet, create_wallet_file) from .configure import (load_program_config, jm_single, get_p2pk_vbyte, get_network, jm_single, get_network, validate_address, get_irc_mchannels, - check_utxo_blacklist, get_blockchain_interface_instance) + check_utxo_blacklist, get_blockchain_interface_instance, get_p2sh_vbyte) from .blockchaininterface import (BlockrInterface, BlockchainInterface, sync_wallet, RegtestBitcoinCoreInterface, BitcoinCoreInterface) from .electruminterface import ElectrumInterface