Browse Source

add primitive p2sh tx estimation support

master
Adam Gibson 9 years ago
parent
commit
519d29e90c
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 11
      jmbitcoin/jmbitcoin/secp256k1_main.py
  2. 2
      jmclient/jmclient/__init__.py

11
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, 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) ver:4,seq:4, +2 (len in,out)
total ~= 34*len_out + 147*len_in + 10 (sig sizes vary slightly) 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': if txtype == 'p2pkh':
return 10 + ins * 147 + 34 * outs return 10 + ins * 147 + 34 * outs
elif txtype == 'p2shMofN':
ins, M, N = ins
return 10 + (45 + 74*M + 34*N) * ins + 34 * outs
else: else:
raise NotImplementedError("Non p2pkh transaction size estimation not" + raise NotImplementedError("Transaction size estimation not" +
"yet implemented") "yet implemented for type: " + txtype)

2
jmclient/jmclient/__init__.py

@ -21,7 +21,7 @@ from .wallet import (AbstractWallet, BitcoinCoreInterface, Wallet,
create_wallet_file) create_wallet_file)
from .configure import (load_program_config, jm_single, get_p2pk_vbyte, from .configure import (load_program_config, jm_single, get_p2pk_vbyte,
get_network, jm_single, get_network, validate_address, get_irc_mchannels, 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, from .blockchaininterface import (BlockrInterface, BlockchainInterface, sync_wallet,
RegtestBitcoinCoreInterface, BitcoinCoreInterface) RegtestBitcoinCoreInterface, BitcoinCoreInterface)
from .electruminterface import ElectrumInterface from .electruminterface import ElectrumInterface

Loading…
Cancel
Save