-
-
Save shirriff/b00515b8583064487ff3 to your computer and use it in GitHub Desktop.
Transaction-generating utilities for Bitcoin. See full file at https://github.com/shirriff/bitcoin-code/blob/master/txnUtils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeSignedTransaction(privateKey, outputTransactionHash, sourceIndex, scriptPubKey, outputs): | |
myTxn_forSig = (makeRawTransaction(outputTransactionHash, sourceIndex, scriptPubKey, outputs) | |
+ "01000000") # hash code | |
s256 = hashlib.sha256(hashlib.sha256(myTxn_forSig.decode('hex')).digest()).digest() | |
sk = ecdsa.SigningKey.from_string(privateKey.decode('hex'), curve=ecdsa.SECP256k1) | |
sig = sk.sign_digest(s256, sigencode=ecdsa.util.sigencode_der) + '\01' # 01 is hashtype | |
pubKey = keyUtils.privateKeyToPublicKey(privateKey) | |
scriptSig = utils.varstr(sig).encode('hex') + utils.varstr(pubKey.decode('hex')).encode('hex') | |
signed_txn = makeRawTransaction(outputTransactionHash, sourceIndex, scriptSig, outputs) | |
verifyTxnSignature(signed_txn) | |
return signed_txn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment