コード例 #1
0
    def createFundingTx(self, funder_amount, funder_pubkey, fundee_pubkey, change_address=None):
        if not self.input_utxo_specified:
            sys.exit("Did not specify source of funds.")
        msig_addr, funding_redeem_script = createMultiSigAddress(funder_pubkey, fundee_pubkey, verbose=self.verbose)
        # create tx input
        tx_ins = [tb.make_legacy_input(outpoint=self.outpoint, stack_script=b"", redeem_script=self.scriptsig,
                                       sequence=0xFFFFFFFF)]
        if self.verbose: print("Input: ", tx_ins)
        tx_outs = [simple.output(address=msig_addr, value=funder_amount)]
        if self.verbose: print("Output: ", tx_outs)

        need_change_output = True if self.utxo_amount > funder_amount else False
        if need_change_output:
            change_output_amount = self.utxo_amount - funder_amount - self.network_fee
            tx_outs += [simple.output(address=self.change_address, value=change_output_amount)]

        if BITCOIN in self.network:
            unsigned_tx = simple.unsigned_legacy_tx(tx_ins, tx_outs)
        elif ZCASH in self.network:
            unsigned_tx = simple.unsigned_legacy_tx(tx_ins, tx_outs)

        script_code1 = b'\x19' + addresses.to_output_script(msig_addr)

        # TODO: computing sighash_all => verify that this is done correctly
        sighash = unsigned_tx.sighash_all(index=0, script=script_code1,
                                          prevout_value=utils.i2le_padded(funder_amount, 8))
        # NOTE: for dual-funded channel, funder_bal = funder_amount + fundee_amount
        funding_tx = {'funding_tx_id': unsigned_tx.tx_id.hex(), 'funding_bal': funder_amount,
                      'funding_address': str(msig_addr), 'funding_witness_script': funding_redeem_script}

        return funding_tx, unsigned_tx.hex()
コード例 #2
0
def unsigned_input(outpoint, sequence=0xFFFFFFFE):  # noqa: F811
    '''
    Outpoint, byte-like, int -> TxIn
    '''
    return tb.make_legacy_input(outpoint=outpoint,
                                stack_script=b'',
                                redeem_script=b'',
                                sequence=sequence)
コード例 #3
0
def unsigned_input(outpoint, sequence=0xFFFFFFFE):  # noqa: F811
    '''
    Some overloads are not documented by Sphinx

    Outpoint, byte-like, int -> TxIn
    '''
    return tb.make_legacy_input(outpoint=outpoint,
                                stack_script=b'',
                                redeem_script=b'',
                                sequence=sequence)
コード例 #4
0
    def test_make_legacy_input(self):
        outpoint = tb.make_outpoint(
            tx_id_le=helpers.P2PKH1['ser']['ins'][0]['hash'],
            index=helpers.P2PKH1['human']['ins'][0]['index'])

        tx_in = tb.make_legacy_input(
            outpoint=outpoint,
            stack_script=helpers.P2PKH1['ser']['ins'][0]['stack_script'],
            redeem_script=helpers.P2PKH1['ser']['ins'][0]['redeem_script'],
            sequence=helpers.P2PKH1['human']['ins'][0]['sequence'])

        self.assertEqual(tx_in, helpers.P2PKH1['ser']['tx']['in'])
コード例 #5
0
def createSingleFundingTransaction(network, funder_outpoint, funder_amount, funder_pubkey, fundee_pubkey):
    """network -> bitcoin or zcash
       script -> { stack_script :
                 , redeem_script : if spending a P2SH, then this should be set }
       funder_outpoint -> specific tx output consisting of (txid, output-index)
       funder_amount -> amount from unspent tx
       funder_pubkey -> pub key for the funder
       fundee_pubkey -> pub key of the fundee (or counterparty)
    """
    # create the multi-signature address
    # fee = 10000

    msig_addr, funding_redeem_script = createMultiSigAddress(funder_pubkey, fundee_pubkey)
    print("Output address: ", msig_addr)
    print("Redeem script: ", funding_redeem_script) # for closing
    # create tx input
    _redeem_script = bytes.fromhex("48304502210090587b6201e166ad6af0227d3036a9454223d49a1f11839c1a362184340ef0240220577f7cd5cca78719405cbf1de7414ac027f0239ef6e214c90fcaab0454d84b3b012103535b32d5eb0a6ed0982a0479bbadc9868d9836f6ba94dd5a63be16d875069184")
    #tx_ins = [simple.unsigned_input(outpoint=funder_outpoint, redeem_script=_redeem_script)]
    tx_ins = [tb.make_legacy_input(outpoint=funder_outpoint, stack_script=b"", redeem_script=_redeem_script, sequence=0xFFFFFFFF)]
    print("Input: ", tx_ins)
    tx_outs = [simple.output(address=msig_addr, value=funder_amount)]
    print("Output: ", tx_outs)

    if network == "bitcoin":
        unsigned_tx = simple.unsigned_legacy_tx(tx_ins, tx_outs)
    elif network == "zcash":
        unsigned_tx = simple.unsigned_legacy_tx(tx_ins, tx_outs)

    script_code1 = b'\x19' + addresses.to_output_script(msig_addr)

    # TODO: computing sighash_all => verify that this is done correctly
    sighash = unsigned_tx.sighash_all(index=0, script=script_code1, prevout_value=utils.i2le_padded(funder_amount, 8))
    # TODO: add signing of the sighash
    print("sighash hex: ", sighash.hex())

    # NOTE: for dual-funded channel, funder_bal = funder_amount + fundee_amount
    funding_tx = {'funding_tx_id': unsigned_tx.tx_id.hex(), 'funding_bal': funder_amount, 'funding_addr': str(msig_addr)}

    return funding_tx, unsigned_tx.hex(), funding_redeem_script