def add_channel(local_node, remote_peer, input_tx_id, input_tx_index):

    tx_in = TxIn(bytes.fromhex(input_tx_id), input_tx_index)
    local_amount = tx_in.value()
    remote_amount = 0

    # Construct the output: amount, scriptPubKey = 2-of-2 Bare Multisig  = Script([op_1, pubkey1, pubkey2, op_2, op_checkmultisig])
    scriptPubKey = Script([
        0x52,
        local_node.public_key.sec(),
        remote_peer.public_key.sec(), 0x52, 0xae
    ])
    tx_out = TxOut(amount=local_amount, script_pubkey=scriptPubKey)

    # Construct the transaction object
    funding_tx = Tx(1, [tx_in], [tx_out], 0, True)

    # Sign the input
    funding_tx.sign_input(0, local_node.private_key)

    #send channel request
    new_channel = Channel(remote_peer, local_amount, remote_amount, funding_tx)
    remote_peer.send(str.encode(new_channel.toJSON()))

    return new_channel
Ejemplo n.º 2
0
 def test_input_value(self):
     tx_hash = 'd1c789a9c60383bf715f3f6ad9d14b91fe55f3deb369fe5d9280cb1a01793f81'
     index = 0
     want = 42505594
     tx_in = TxIn(
         prev_tx=unhexlify(tx_hash),
         prev_index=index,
         script_sig=b'',
         sequence=0,
     )
     self.assertEqual(tx_in.value(), want)
Ejemplo n.º 3
0
# Receiver Information
receiver_address = createAddress(b'some salt for this receiver address')

# What is in our wallet that we can spend? (this one has 0.01 tBTC)
tx_in_id = 'acf22005638e60379aa43d4cd2a5eb47a0fa1fefc5883eecf83329a607431d50'
tx_in_index = 1
tx_input = TxIn(bytes.fromhex(tx_in_id), tx_in_index)

# Checking spentness of the inputs. Should be False
print("Spentness of input " + str(tx_in_index) + ": " +
      str(is_unspent(tx_in_id, tx_in_index, p)))

# How much BTC?
sat_in_bit = 100000000
fee = 0.0001 * sat_in_bit
input_amount = tx_input.value(testnet=True)

#creating the target output
target_amount = int(0.005 * sat_in_bit)
target_h160 = decode_base58(sender_address)
target_script = p2pkh_script(target_h160)
target_output = TxOut(amount=target_amount, script_pubkey=target_script)

#creating the change output
change_amount = int(input_amount - target_amount - fee)
change_160 = decode_base58(receiver_address)
change_script = p2pkh_script(change_160)
change_output = TxOut(amount=change_amount, script_pubkey=change_script)

#create the Tx object
tx_obj = Tx(1, [tx_input], [change_output, target_output], 0, True)