What happens if P2SH redeem script is lost?

Assume Bob creates a complicated Bitcoin Script and asks Alice to make to a payment to a hash of this script. (Using a P2SH transaction)

If Bob loses the script (i.e the source code of the script), is the payment transaction going to be locked forever?

How do I redeem the McAfee antivirus key card?

How do I redeem the McAfee antivirus key card?

.

Where can I redeem my giftcards? | Proxies123.com

Earnings Disclaimer:  All the posts published herein are merely based on individual views, and they do not expressly or by implications represent those of Proxies123.com or its owner. It is hereby made clear that Proxies123.com does not endorse, support, adopt or vouch any views, programs and/or business opportunities posted herein. Proxies123.com also does not give and/or offer any investment advice to any members and/or it’s readers. All members and readers are advised to independently consult their own consultants, lawyers and/or families before making any investment and/or business decisions. This forum is merely a place for general discussions. It is hereby agreed by all members and/or readers that Proxies123.com is in no way responsible and/or liable for any damages and/or losses suffered by anyone of you.

p2sh – Nbitcoin: The redeem provided does not match the scriptPubKey of the coin

Trying to spend litecoin from a p2sh address, i get this error when trying to convert utxos to scriptcoin.

var add1 = "MP3RwwmVDoHw3h25uKHn8PLA8DhjaZtooQ";

var fromadd = BitcoinAddress.Create(add1, network);

    var add2 = "MVVftwwVt2KputjnVb858n4kzz8Wthrk3B";
    var destadd = BitcoinAddress.Create(add2, network);

    var utxos = GetUnSpentCoinsN($"{xpubstring}-(p2sh)").Result;

   // i have tried using the ScriptPubKey of from address and destination address still the same error
    var realredeem = PayToScriptHashTemplate.Instance.GenerateScriptPubKey(fromadd.ScriptPubKey);


  //i get the error at this point - The redeem provided does not match the scriptPubKey of the coin
    var utxoScriptCoin = utxos.Select(a => a.ToScriptCoin(realredeem)).ToList();

SUPPORT – Redeem BMF to perfectmoney | Proxies123.com

Earnings Disclaimer:  All the posts published herein are merely based on individual views, and they do not expressly or by implications represent those of Proxies123.com or its owner. It is hereby made clear that Proxies123.com does not endorse, support, adopt or vouch any views, programs and/or business opportunities posted herein. Proxies123.com also does not give and/or offer any investment advice to any members and/or it’s readers. All members and readers are advised to independently consult their own consultants, lawyers and/or families before making any investment and/or business decisions. This forum is merely a place for general discussions. It is hereby agreed by all members and/or readers that Proxies123.com is in no way responsible and/or liable for any damages and/or losses suffered by anyone of you.

transactions – Redeem script. hash script, witness script and witness program

I have a little confusion about naming in Bitcoin.

Redeem script are the conditions that will be met.
For example P2PKH inside P2SH

OP_DUP OP_HASH160  OP_EQUALVERIFY OP_CHECKSIG == redeem script

In P2SH-P2WPKH the redeem script it is:

The P2SH redeemScript always has 22 bytes. It starts with an OP_0,
followed by a canonical keyhash boost (ie 0x0014 {20 bytes
keyhash}).

At some point it is called a script hash, and during the transaction I need to insert the script to redeem in witnessScript. "witnessScript": "hex", (string) (required for P2WSH or P2SH-P2WSH) witness script

So is script swapping in the segwit environment called swapping script, hash script or token script?

Witness program

A scriptPubKey (or redeem Script as defined in BIP16 / P2SH) consisting of a 1 byte insert operation code (0 to 16) followed by a data insert between 2 and 40 bytes gets a new special meaning.

The token program depends on whether the script can be scriptPubkey or redeem script.

script – How to build and redeem a bip199 htlc with python-bitcoinlib

Playing with this script I would like to understand how to build a bip199 htlc and redeem it, however this script fails in the OP_EQUALVERIFY and I can't seem to understand why.

import bitcoin
import bitcoin.rpc
from bitcoin import SelectParams
from bitcoin.core import b2x, lx, b2lx, COIN, COutPoint, CMutableTxOut, CMutableTxIn, CMutableTransaction, Hash160
from bitcoin.core.script import CScript, OP_DUP, OP_IF, OP_ELSE, OP_ENDIF, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG, SignatureHash, SIGHASH_ALL
from bitcoin.core.script import OP_DROP, OP_CHECKLOCKTIMEVERIFY, OP_SHA256, OP_TRUE
from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH
from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret

import hashlib
from hashlib import sha256

SelectParams('regtest')
proxy = bitcoin.rpc.Proxy()

preimage = bytes(b'preimage'.hex(), 'utf8')
h = sha256(preimage).digest()

recipientpubkey = proxy.getnewaddress()
senderpubkey = proxy.getnewaddress()
seckey = proxy.dumpprivkey(recipientpubkey)

lockduration = 10
blocknum = proxy.getblockcount()
redeemblocknum = blocknum + lockduration

txin_redeemScript = CScript((
            OP_IF,
                OP_SHA256, h, OP_EQUALVERIFY,OP_DUP, OP_HASH160, recipientpubkey,
            OP_ELSE,
                redeemblocknum, OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_DUP, OP_HASH160, bytes(Hash160(seckey.pub)),
            OP_ENDIF,
                OP_EQUALVERIFY, OP_CHECKSIG
          ))


txin_scriptPubKey = txin_redeemScript.to_p2sh_scriptPubKey()

txin_p2sh_address = CBitcoinAddress.from_scriptPubKey(txin_scriptPubKey)
p2sh = str(txin_p2sh_address)

amount = 1.0*COIN

fund_tx = proxy.sendtoaddress(txin_p2sh_address, amount)

txinfo = proxy.gettransaction(fund_tx)
details = txinfo('details')(0)
vout = details('vout')

txin = CMutableTxIn(COutPoint(fund_tx, vout))

default_fee = 0.001*COIN
txout = CMutableTxOut(amount - default_fee, recipientpubkey.to_scriptPubKey())

tx = CMutableTransaction((txin), (txout))

sighash = SignatureHash(txin_redeemScript, tx, 0, SIGHASH_ALL)

sig = seckey.sign(sighash) + bytes((SIGHASH_ALL))

txin.scriptSig = CScript((sig, seckey.pub, preimage, preimage, txin_redeemScript))

VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))

txid = proxy.sendrawtransaction(tx)

transactions – P2sh redeem script hash

1. Unique signature of Bitcoin P2SH:

Redeem Script Template = "(PubKey) OP_CHECKSIG"

Work examples:

% echo "(020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) checksig" | bx script-encode

21020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73ac (Script)

% echo "(020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) checksig" | bx script-encode | bx sha256 | bx ripemd160

49e266a68641d2caa6696b00696f00f0a5706350 (Hash response)

% echo "(020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) checksig" | bx script-encode | bx sha256 | bx ripemd160 | bx base58check-encode -v 5

38RgUAR367PFbFFgS57BYcERHkpqHEMBvA (Speaks to)

or more simply,

% echo "(020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) checksig" | bx script-to-address -v 5

38RgUAR367PFbFFgS57BYcERHkpqHEMBvA

2. Bitcoin BIP16 multisig:

2 of 3 Redeem Script Template = "OP_2 (PubKey1) (PubKey2) (PubKey3) OP_3 OP_CHECKMULTISIG"

Work examples:

% echo "2 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) (03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1) (029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6) 3 checkmultisig" | bx script-encode

Know more (Script)

% echo "2 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) (03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1) (029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6) 3 checkmultisig" | bx script-encode | bx bitcoin160

7e580c3a86432d96dd60784e99f5a94e463414fe (Hash response)

% echo "2 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73) (03664d528eb80096671ef9011c533ceb5df133238e3690d88f2960c786398b86b1) (029a449ea4a2155ea10002d704604bb3e8606631d35af20889a74b82b2dab572f6) 3 checkmultisig" | bx script-to-address -v 5

3DD4YP2T75TQtf84KrHzYVLYgNAeaHWqxq (Speaks to)

3. Bitcoin P2WPKH-nested-in-P2SH:

Redeem Script Template = "0 (PubKey)"

Work examples:

% echo "0 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73)" | bx script-encode

0021020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73 (Script)

% echo "0 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73)" | bx script-encode | bx bitcoin160

7138cbb443e9ed635d3dd02a3e450884e3f9f0c8 (Hash response)

% echo "0 (020ae29f86f404e4b302cfa17ff15d93149af6a54c80a4172d47e41f55f6a78d73)" | bx script-to-address -v 5

3C1gKTRSAwSLj8Ft1eYooLkWxwJ5cqDdpb (Speaks to)

Can you redeem a demon or demon?

Alignment is an essential part of the nature of
Heavenly and demons. A demon does not choose to be
legal evil, and does not tend towards legal evil, but
rather it is a legal evil in its essence. If somehow
It stopped being a legal evil, it would stop being a demon.

Angels can fall. The Monster Manual has an explicit note on situations in which this can happen, and in doing so, they retain their powers, but are free to make their own way. If a demon or demon chose to do something inherently against his nature by accident or intention, are there similar rules about what would happen? Are there specific cases in the game where this has happened? This is based on the information available in 5e, but the tradition or rules of any edition of D&D would be useful.

Transactions – How to redeem a basic Tx?

In this response, I will follow the steps necessary to redeem the second exit of the transaction mentioned above. The response will be limited to redeeming an exit of the particular type present in this transaction (an exit that requires providing a new signed transaction with a private key whose corresponding public key becomes hash in the script of the output in question), as this response It is already quite long, even without considering other types of output.

Short summary: We begin by building a new transaction, with a scriptSig that contains the scriptPubKey of the output we want to redeem. The scriptPubKey of this transaction will contain a script that pays a hash of a public key (Bitcoin address). We performed a double SHA256 hash on this transaction with the four-byte hash code type SIGHASH_ALL added at the end. We signed this hash with the private key provided above. The scriptSig of this new transaction is replaced by a script that first pushes the DER encoded signature, plus the hash code of a SIGHASH_ALL type byte, to the stack, followed by the corresponding public key of the DER encoded private key.

Step by step description:

We begin to create a new unprocessed transaction that we haveh and sign.

  1. Add four byte version field: 01000000
  2. One-byte varint that specifies the number of entries: 01
  3. 32-byte hash of the transaction from which we want to redeem an exit: eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2
  4. Four-byte field denoting the output index that we want to redeem from the transaction with the previous hash (output number 2 = output index 1): 01000000
  5. Now comes the scriptSig. In order to sign the transaction, this is temporarily filled with the scriptPubKey of the output we want to redeem. First we write a one-byte varint that denotes the length of the scriptSig (0x19 = 25 bytes): 19
  6. Then, we write the temporary Sig script which, again, is the outputPubKey script that we want to redeem: 76a914010966776006953d5567439e5e39f86a0d273bee88ac
  7. Then we write a four-byte field that denotes the sequence. Currently, this is always set to 0xffffffff: ffffffff
  8. Then comes a one-byte link that contains the number of outputs in our new transaction. We will set this to 1 in this example: 01
  9. Then we write an 8-byte field (64-bit integer) that contains the amount we want to redeem for the specified output. I will set this in the total amount available at the exit minus a fee of 0.001 BTC (0.999 BTC or 99900000 Satoshis): 605af40500000000
  10. Then we begin to write the output of our transaction. We start with a one-byte varint that denotes the length of the output script (0x19 or 25 bytes): 19
  11. Then the actual output script: 76a914097072524438d003d23a2f23edb65aae1bb3e46988ac
  12. Then we write the "blocking time" field of four bytes: 00000000
  13. And finally, we write a "type of hash code" of four bytes (1 in our case): 01000000

    We now have the following raw transaction data:

    01000000
    01
    eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2
    01000000
    19
    76a914010966776006953d5567439e5e39f86a0d273bee88ac
    ffffffff
    01
    605af40500000000
    19
    76a914097072524438d003d23a2f23edb65aae1bb3e46988ac
    00000000
    01000000
    
  14. (signature stage) Now we duplicate the SHA256 hash of this entire structure, which produces the hash 9302bda273a887cb40c13e02a50b4071a31fd3aae3ae04021b0b843dd61ad18e

  15. Then we create a public / private key pair from the private key provided. We signed the hash of step 14 with the private key, which produces the following signature coded with DER (this signature will be different in your case): 30460221009e0339f72c793a89e664a8a932df073962a3f84eda0bd9e02084a6a9567f75aa022100bd9cbaca2e5ec195751efdfac164b76250b1e21302e51ca86dd7ebd7020cdc06 To this signature we add the one-byte hash code type: 01. The public key is: 0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6
  16. We build the final SigS script by concatenating:

    • OPCODE one-byte script containing the length of the encoded signature DER plus 1 (the length of the one-byte hash code type)
    • The real DER encoded signature plus the one-byte hash code type
    • OPCODE one-byte script that contains the length of the public key
    • The real public key
  17. Then we replace the one-byte varint length field from step 5 with the data length from step 16. The length is 140 bytes, or 0x8C bytes: 8c

  18. And we replace the temporary SIG script from Step 6 with the data structure built in step 16. This becomes: 4930460221009e0339f72c793a89e664a8a932df073962a3f84eda0bd9e02084a6a9567f75aa022100bd9cbaca2e5ec195751efdfac164b76250b1e21302e51ca86dd7ebd7020cdc0601410450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6
  19. We finish by removing the type of four-byte hash code that we added in step 13, and we end with the following byte stream, which is the final transaction:

    01000000
    01
    eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2
    01000000
    8c
    4930460221009e0339f72c793a89e664a8a932df073962a3f84eda0bd9e02084a6a9567f75aa022100bd9cbaca2e5ec195751efdfac164b76250b1e21302e51ca86dd7ebd7020cdc0601410450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6
    ffffffff
    01
    605af40500000000
    19
    76a914097072524438d003d23a2f23edb65aae1bb3e46988ac
    00000000
    

Python sample code:

I have created an example Python script that does all of the above. It is intentionally as detailed as possible and very commented, with as few functions as possible, to resemble the previous step-by-step guide. The number of lines of code can be easily reduced by half, but I choose to publish it in this detailed format since I consider it the easiest to follow (i.e. not & # 39; jump & # 39; back and forth to through the functions). The script contains 76 non-empty lines, without comments.
The script depends on bitcointools (to serialize and deserialize transactions, and base58 encoding / decoding) and ecdsa_ssl.py from my fork in the brutus de joric repository (to build pairs of public / private EC keys and ECDSA signature). The easiest way to run the script is to clone bitcointools in a folder and place ecdsa_ssl.py from the previous URL in the same folder along with this script, and run the script from there.
You must replace the address in the SEND_TO_ADDRESS variable in this script with the address to which you want to send the coins, unless you feel generous :).

#bitcointools
from deserialize import parse_Transaction, opcodes
from BCDataStream import BCDataStream
from base58 import bc_address_to_hash_160, b58decode, public_key_to_bc_address, hash_160_to_bc_address

import ecdsa_ssl

import Crypto.Hash.SHA256 as sha256
import Crypto.Random

#transaction, from which we want to redeem an output
HEX_TRANSACTION="010000000126c07ece0bce7cda0ccd14d99e205f118cde27e83dd75da7b141fe487b5528fb000000008b48304502202b7e37831273d74c8b5b1956c23e79acd660635a8d1063d413c50b218eb6bc8a022100a10a3a7b5aaa0f07827207daf81f718f51eeac96695cf1ef9f2020f21a0de02f01410452684bce6797a0a50d028e9632be0c2a7e5031b710972c2a3285520fb29fcd4ecfb5fc2bf86a1e7578e4f8a305eeb341d1c6fc0173e5837e2d3c7b178aade078ffffffff02b06c191e010000001976a9143564a74f9ddb4372301c49154605573d7d1a88fe88ac00e1f505000000001976a914010966776006953d5567439e5e39f86a0d273bee88ac00000000"
#output to redeem. must exist in HEX_TRANSACTION
OUTPUT_INDEX=1
#address we want to send the redeemed coins to.
#REPLACE WITH YOUR OWN ADDRESS, unless you're feeling generous 
SEND_TO_ADDRESS="1L4xtXCdJNiYnyqE6UsB8KSJvqEuXjz6aK"
#fee we want to pay (in BTC)
TX_FEE=0.001
#constant that defines the number of Satoshis per BTC
COIN=100000000
#constant used to determine which part of the transaction is hashed.
SIGHASH_ALL=1
#private key whose public key hashes to the hash contained in scriptPubKey of output number *OUTPUT_INDEX* in the transaction described in HEX_TRANSACTION
PRIVATE_KEY=0x18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

def dsha256(data):
   return sha256.new(sha256.new(data).digest()).digest()

tx_data=HEX_TRANSACTION.decode('hex_codec')
tx_hash=dsha256(tx_data)

#here we use bitcointools to parse a transaction. this gives easy access to the various fields of the transaction from which we want to redeem an output
stream = BCDataStream()
stream.write(tx_data)
tx_info = parse_Transaction(stream)

if len(tx_info('txOut')) < (OUTPUT_INDEX+1):
   raise RuntimeError, "there are only %d output(s) in the transaction you're trying to redeem from. you want to redeem output index %d" % (len(tx_info('txOut')), OUTPUT_INDEX)

#this dictionary is used to store the values of the various transaction fields
#  this is useful because we need to construct one transaction to hash and sign
#  and another that will be the final transaction
tx_fields = {}

##here we start creating the transaction that we hash and sign
sign_tx = BCDataStream()
##first we write the version number, which is 1
tx_fields('version') = 1
sign_tx.write_int32(tx_fields('version'))
##then we write the number of transaction inputs, which is one
tx_fields('num_txin') = 1
sign_tx.write_compact_size(tx_fields('num_txin'))

##then we write the actual transaction data
#'prevout_hash'
tx_fields('prevout_hash') = tx_hash
sign_tx.write(tx_fields('prevout_hash')) #hash of the the transaction from which we want to redeem an output
#'prevout_n'
tx_fields('output_index') = OUTPUT_INDEX
sign_tx.write_uint32(tx_fields('output_index')) #which output of the transaction with tx id 'prevout_hash' do we want to redeem?

##next comes the part of the transaction input. here we place the script of the *output* that we want to redeem
tx_fields('scriptSigHash') = tx_info('txOut')(OUTPUT_INDEX)('scriptPubKey')
#first write the size
sign_tx.write_compact_size(len(tx_fields('scriptSigHash')))
#then the data
sign_tx.write(tx_fields('scriptSigHash'))

#'sequence'
tx_fields('sequence') = 0xffffffff
sign_tx.write_uint32(tx_fields('sequence'))

##then we write the number of transaction outputs. we'll just use a single output in this example
tx_fields('num_txout') = 1
sign_tx.write_compact_size(tx_fields('num_txout'))
##then we write the actual transaction output data
#we'll redeem everything from the original output minus TX_FEE
tx_fields('value') = tx_info('txOut')(OUTPUT_INDEX)('value')-(TX_FEE*COIN)
sign_tx.write_int64(tx_fields('value'))
##this is where our scriptPubKey goes (a script that pays out to an address)
#we want the following script:
#"OP_DUP OP_HASH160  OP_EQUALVERIFY OP_CHECKSIG"
address_hash = bc_address_to_hash_160(SEND_TO_ADDRESS)
#chr(20) is the length of the address_hash (20 bytes or 160 bits)
scriptPubKey = chr(opcodes.OP_DUP) + chr(opcodes.OP_HASH160) + 
   chr(20) + address_hash + chr(opcodes.OP_EQUALVERIFY) + chr(opcodes.OP_CHECKSIG)
#first write the length of this lump of data
tx_fields('scriptPubKey') = scriptPubKey
sign_tx.write_compact_size(len(tx_fields('scriptPubKey')))
#then the data
sign_tx.write(tx_fields('scriptPubKey'))

#write locktime (0)
tx_fields('locktime') = 0
sign_tx.write_uint32(tx_fields('locktime'))
#and hash code type (1)
tx_fields('hash_type') = SIGHASH_ALL
sign_tx.write_int32(tx_fields('hash_type'))

#then we obtain the hash of the signature-less transaction (the hash that we sign using our private key)
hash_scriptless = dsha256(sign_tx.input)

##now we begin with the ECDSA stuff.
## we create a private key from the provided private key data, and sign hash_scriptless with it
## we also check that the private key's corresponding public key can actually redeem the specified output

k = ecdsa_ssl.KEY()
k.generate(('%064x' % PRIVATE_KEY).decode('hex'))

#here we retrieve the public key data generated from the supplied private key
pubkey_data = k.get_pubkey()
#then we create a signature over the hash of the signature-less transaction
sig_data=k.sign(hash_scriptless)
#a one byte "hash type" is appended to the end of the signature (https://en.bitcoin.it/wiki/OP_CHECKSIG)
sig_data = sig_data + chr(SIGHASH_ALL)

#let's check that the provided privat key can actually redeem the output in question
if (bc_address_to_hash_160(public_key_to_bc_address(pubkey_data)) != tx_info('txOut')(OUTPUT_INDEX)('scriptPubKey')(3:-2)):
   bytes = b58decode(SEND_TO_ADDRESS, 25)
   raise RuntimeError, "The supplied private key cannot be used to redeem output index %dnYou need to supply the private key for address %s" % 
                           (OUTPUT_INDEX, hash_160_to_bc_address(tx_info('txOut')(OUTPUT_INDEX)('scriptPubKey')(3:-2), bytes(0)))

##now we begin creating the final transaction. this is a duplicate of the signature-less transaction,
## with the scriptSig filled out with a script that pushes the signature plus one-byte hash code type, and public key from above, to the stack

final_tx = BCDataStream()
final_tx.write_int32(tx_fields('version'))
final_tx.write_compact_size(tx_fields('num_txin'))
final_tx.write(tx_fields('prevout_hash'))
final_tx.write_uint32(tx_fields('output_index'))

##now we need to write the actual scriptSig.
## this consists of the DER-encoded values r and s from the signature, a one-byte hash code type, and the public key in uncompressed format
## we also need to prepend the length of these two data pieces (encoded as a single byte
## containing the length), before each data piece. this length is a script opcode that tells the
## Bitcoin script interpreter to push the x following bytes onto the stack

scriptSig = chr(len(sig_data)) + sig_data + chr(len(pubkey_data)) + pubkey_data
#first write the length of this data
final_tx.write_compact_size(len(scriptSig))
#then the data
final_tx.write(scriptSig)

##and then we simply write the same data after the scriptSig that is in the signature-less transaction,
#  leaving out the four-byte hash code type (as this is encoded in the single byte following the signature data)

final_tx.write_uint32(tx_fields('sequence'))
final_tx.write_compact_size(tx_fields('num_txout'))
final_tx.write_int64(tx_fields('value'))
final_tx.write_compact_size(len(tx_fields('scriptPubKey')))
final_tx.write(tx_fields('scriptPubKey'))
final_tx.write_uint32(tx_fields('locktime'))

#prints out the final transaction in hex format (can be used as an argument to bitcoind's sendrawtransaction)
print final_tx.input.encode('hex')