Example #1
0
    def create_inputs(self, numinputs, txsize):
        idx = 0
        sum = 0
        self.inputs = []
        self.txs = {}
        for nr in range(numinputs):
            t = proto_types.TransactionType()
            t.version = 1
            t.lock_time = 0
            i = t.inputs.add()
            i.prev_hash = os.urandom(32)
            i.prev_index = random.randint(0,4)
            i.script_sig = os.urandom(100)
            i.sequence = 0xffffffff
            if (nr % 50 == 0):
                print(nr)
            myout = random.randint(0, txsize-1)
            segwit = 1 #random.randint(0,1)
            for vout in range(txsize):
                o = t.bin_outputs.add()
                o.amount = random.randint(10000,1000000)
                if vout == myout:
                    amount = o.amount
                    sum = sum + o.amount
                    node = self.node
                    path = [0, idx]
                    node = bip32.public_ckd(node, path)
                    idx = idx + 1
                    pubkey = tools.hash_160(node.public_key)
                else:
                    pubkey = os.urandom(20)
                if (segwit):
                    o.script_pubkey = binascii.unhexlify('0014') + pubkey
                else:
                    o.script_pubkey = binascii.unhexlify('76a914') + pubkey + binascii.unhexlify('88ac')

            txser = self.serialize_tx(t)
            txhash = tools.Hash(txser)[::-1]
            if (segwit):
                outi = self.inputs.append(
                    proto_types.TxInputType(
                        address_n=self.client.expand_path("44'/0'/0'/0/"+str(idx)),
                        script_type = proto_types.SPENDWADDRESS,
                        prev_hash=txhash,
                        prev_index = myout,
                        amount = amount
                    ))
            else:
                outi = self.inputs.append(
                    proto_types.TxInputType(
                        address_n=self.client.expand_path("44'/0'/0'/0/"+str(idx)),
                        script_type = proto_types.SPENDADDRESS,
                        prev_hash=txhash,
                        prev_index = myout
                    ))
            #print(binascii.hexlify(txser))
            #print(binascii.hexlify(txhash))
            self.txs[binascii.hexlify(txhash)] = t

        self.outputs = [
            proto_types.TxOutputType(
                amount=sum,
                script_type=proto_types.PAYTOADDRESS,
                address_n=self.client.expand_path("44'/0'/0'/1/0")
            )]
Example #2
0
    def create_inputs(self, numinputs, txsize):
        idx = 0
        sum = 0
        self.inputs = []
        self.txs = {}
        for nr in range(numinputs):
            t = proto_types.TransactionType()
            t.version = 1
            t.lock_time = 0
            i = t.inputs.add()
            i.prev_hash = os.urandom(32)
            i.prev_index = random.randint(0, 4)
            i.script_sig = os.urandom(100)
            i.sequence = 0xffffffff
            if nr % 50 == 0:
                print(nr)
            myout = random.randint(0, txsize - 1)
            segwit = random.randint(0, 2)
            for vout in range(txsize):
                o = t.bin_outputs.add()
                o.amount = random.randint(10000, 1000000)
                if vout == myout:
                    amount = o.amount
                    sum = sum + o.amount
                    node = self.node
                    path = [0, idx]
                    node = bip32.public_ckd(node, path)
                    idx = idx + 1
                    pubkey = tools.hash_160(node.public_key)
                else:
                    pubkey = os.urandom(20)
                if segwit == 2:
                    # p2sh segwit
                    o.script_pubkey = b'\xa9\x14' + hash160(b'\x00\x14' +
                                                            pubkey) + b'\x87'
                elif segwit == 1:
                    o.script_pubkey = b'\x00\x14' + pubkey
                else:
                    o.script_pubkey = b'\x76\xa9\x14' + pubkey + b'\x88\xac'

            txser = self.serialize_tx(t)
            txhash = tools.Hash(txser)[::-1]
            outi = self.inputs.append(
                proto_types.TxInputType(
                    address_n=self.client.expand_path("44'/0'/0'/0/%d" % idx),
                    script_type=(proto_types.SPENDWITNESS if segwit == 1 else
                                 proto_types.SPENDP2SHWITNESS
                                 if segwit == 2 else proto_types.SPENDADDRESS),
                    prev_hash=txhash,
                    prev_index=myout,
                    amount=amount if segwit > 0 else 0))
            # print(binascii.hexlify(txser))
            # print(binascii.hexlify(txhash))
            self.txs[binascii.hexlify(txhash)] = t

        self.outputs = [
            proto_types.TxOutputType(
                amount=sum,
                script_type=proto_types.PAYTOADDRESS,
                address_n=self.client.expand_path("44'/0'/0'/1/0"))
        ]
	depth=0, 
	fingerprint=0,
	child_num=0,
	chain_code=binascii.unhexlify('2fb77e25cd3e2e034bcbafa1f81ec7e4caf927b06c87db296f1186208315525e'),
	public_key=binascii.unhexlify('03f645ec6544a92f951f3bca16a2bc1c56846d065594db222725d59b9902528385')
)
dummyhdnodepath = types.HDNodePathType(
	node=dummyhdnode,
	address_n=[0x0000004c, 0x00000033, 0x0000001E, 0x00000002]
)

dummyMultisig = types.MultisigRedeemScriptType(
	pubkeys=[dummyhdnodepath],
	m=1)

msg = types.TransactionType()
testInput = types.TxInputType(
	address_n=[0x8000004c, 0x80000033, 0x8000001E, 0x00000001],
	prev_hash=binascii.unhexlify('bca17fb40c8c86e7c7acd0d3749af9e5c66575dce86db895b7e3301f7a4b2b84'),
	prev_index=1,
	script_sig=binascii.unhexlify('76a91440afc69e46643de1908c8988ad62214270006c3b88ac'),
	script_type=types.SPENDMULTISIG,
	multisig=dummyMultisig
)
msg.inputs.extend([ testInput ])

res = client.call(proto.TxAck(tx = msg))

if isinstance(res, proto.Failure):
    raise CallException("Signing failed")