def makeTransaction(self, tx, account):
"""Make Transaction"""
if tx.outputs == None:
raise ValueError, 'Not correct Address, wrong length.'
if tx.attributes == None:
tx.attributes = []
coins = self.findUnSpentCoins(account.scriptHash)
tx.inputs, tx.outputs = self.selectInputs(tx.outputs, coins, account, tx.systemFee)
# Make transaction
stream = MemoryStream()
writer = BinaryWriter(stream)
tx.serializeUnsigned(writer)
reg_tx = stream.toArray()
tx.ensureHash()
txid = tx.hash
# RedeenScript
contract = Contract()
contract.createSignatureContract(account.publicKey)
Redeem_script = contract.redeemScript
# Add Signature
sk = SigningKey.from_string(binascii.unhexlify(account.privateKey), curve=NIST256p, hashfunc=hashlib.sha256)
signature = binascii.hexlify(sk.sign(binascii.unhexlify(reg_tx),hashfunc=hashlib.sha256))
regtx = reg_tx + '014140' + signature + '23' + Redeem_script
# sendRawTransaction
print regtx
response = self.node.sendRawTransaction(regtx)
import json
print response
return txid
评论列表
文章目录