예제 #1
0
 def input_script(self, txin: PartialTxInput, *, estimate_size=False) -> str:
     assert estimate_size is False
     pubkeys, sig_list = get_siglist(txin, estimate_size=estimate_size)
     script = ''.join(push_script(x) for x in sig_list)
     if txin.script_type == 'p2sh':
         # put op_0 before script
         script = '00' + script
         redeem_script = multisig_script(pubkeys, txin.num_sig)
         script += push_script(redeem_script)
         return script
     elif txin.script_type == 'p2wsh':
         return ''
     raise Exception(f"unexpected type {txin.script_type}")
예제 #2
0
 def input_script(self, txin, estimate_size=False):
     if txin['type'] == 'p2pkh':
         return Transaction.get_preimage_script(txin)
     if txin['type'] == 'p2sh':
         return '00' + push_script(
             Transaction.get_preimage_script(txin))
     raise Exception("unsupported type %s" % txin['type'])
예제 #3
0
 def input_script(self, txin, estimate_size=False):
     if txin['type'] == 'p2pkh':
         return Transaction.get_preimage_script(txin)
     if txin['type'] == 'p2sh':
         # Multisig verification has partial support, but is disabled. This is the
         # expected serialization though, so we leave it here until we activate it.
         return '00' + push_script(Transaction.get_preimage_script(txin))
     raise Exception("unsupported type %s" % txin['type'])
예제 #4
0
 def input_script(self, txin, estimate_size=False):
     if txin['type'] == 'p2pkh':
         return Transaction.get_preimage_script(txin)
     if txin['type'] == 'p2sh':
         # Multisig verification has partial support, but is disabled. This is the
         # expected serialization though, so we leave it here until we activate it.
         return '00' + push_script(Transaction.get_preimage_script(txin))
     raise Exception("unsupported type %s" % txin['type'])
예제 #5
0
 def test_push_script(self):
     # https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#push-operators
     self.assertEqual(push_script(''), bh2u(bytes([opcodes.OP_0])))
     self.assertEqual(push_script('07'), bh2u(bytes([opcodes.OP_7])))
     self.assertEqual(push_script('10'), bh2u(bytes([opcodes.OP_16])))
     self.assertEqual(push_script('81'), bh2u(bytes([opcodes.OP_1NEGATE])))
     self.assertEqual(push_script('11'), '0111')
     self.assertEqual(push_script(75 * '42'), '4b' + 75 * '42')
     self.assertEqual(push_script(76 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('4c' + 76 * '42')))
     self.assertEqual(push_script(100 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('64' + 100 * '42')))
     self.assertEqual(push_script(255 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('ff' + 255 * '42')))
     self.assertEqual(push_script(256 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0001' + 256 * '42')))
     self.assertEqual(push_script(520 * '42'), bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0802' + 520 * '42')))
예제 #6
0
 def test_push_script(self):
     # https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#push-operators
     self.assertEqual(push_script(''), bh2u(bytes([opcodes.OP_0])))
     self.assertEqual(push_script('07'), bh2u(bytes([opcodes.OP_7])))
     self.assertEqual(push_script('10'), bh2u(bytes([opcodes.OP_16])))
     self.assertEqual(push_script('81'), bh2u(bytes([opcodes.OP_1NEGATE])))
     self.assertEqual(push_script('11'), '0111')
     self.assertEqual(push_script(75 * '42'), '4b' + 75 * '42')
     self.assertEqual(
         push_script(76 * '42'),
         bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('4c' + 76 * '42')))
     self.assertEqual(
         push_script(100 * '42'),
         bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('64' + 100 * '42')))
     self.assertEqual(
         push_script(255 * '42'),
         bh2u(bytes([opcodes.OP_PUSHDATA1]) + bfh('ff' + 255 * '42')))
     self.assertEqual(
         push_script(256 * '42'),
         bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0001' + 256 * '42')))
     self.assertEqual(
         push_script(520 * '42'),
         bh2u(bytes([opcodes.OP_PUSHDATA2]) + bfh('0802' + 520 * '42')))
예제 #7
0
 def input_script(self, txin, estimate_size=False):
     if txin['type'] == 'p2pkh':
         return Transaction.get_preimage_script(txin)
     if txin['type'] == 'p2sh':
         return '00' + push_script(Transaction.get_preimage_script(txin))
     raise Exception("unsupported type %s" % txin['type'])
예제 #8
0
from electrum.transaction import TxOutpoint, PartialTxInput, PartialTxOutput, PartialTransaction
from electrum.bitcoin import deserialize_privkey, opcodes, push_script
from electrum.crypto import hash_160, sha256d
from electrum.constants import set_testnet
from electrum.ecc import ECPrivkey

# The basic bitcoinlib utility  scripts
x    = lambda h: bytes.fromhex(h)
lx   = lambda h: bytes.fromhex(h)[::-1]
b2x  = lambda b: (b.hex() if 'hex' in dir(b) else hex(b)).replace('0x','')
b2lx = lambda b: b[::-1].hex().replace('0x','')

# Very simple bitcoin script comiler
compile = lambda s: "".join([
    opcodes[i].hex() if i in dir(opcodes) else push_script(i) for i in s])

# Electrum assumes P2SH is multisig, this subclass corrects that
class P2SHPartialTransaction(PartialTransaction):

    def __init__(self):
        PartialTransaction.__init__(self)
    
    @classmethod
    def get_preimage_script(cls, txin: 'PartialTxInput') -> str:
        return b2x(txin.redeem_script)

# Set testnet
set_testnet()

# I removed the R-value grinding to use "legacy" sig processing