def _createOutput(assetId, amount, address): assetId = UInt256(data=binascii.unhexlify(hex_reverse(assetId))) f8amount = Fixed8.TryParse(amount, require_positive=True) address_hash = ToAddresstHash(address) return TransactionOutput(AssetId=assetId, Value=f8amount, script_hash=address_hash)
def createHERDTX(addressReceiver, HTLCValue, HETxId, RSMCScript,asset_id): time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex(hex(int(time.time()))[2:])) pre_txid = TransactionAttribute(usage=TransactionAttributeUsage.Remark1, data=bytearray.fromhex( hex_reverse(HETxId))) outputTo = TransactionAttribute(usage=TransactionAttributeUsage.Remark2, data=ToAddresstHash(addressReceiver).Data) txAttributes = [time_stamp, pre_txid, outputTo] tx = ContractTransaction() RSMC_inputs = [tx.createInput(preHash=HETxId, preIndex=0)] output_to_receiver = tx.createOutput(assetId=asset_id, amount=HTLCValue, address=addressReceiver) tx.inputs = RSMC_inputs tx.outputs = [output_to_receiver] tx.Attributes = txAttributes return { "txData": tx.get_tx_data(), "txId": createTxid(tx.get_tx_data()), "witness": "01{blockheight_script}40{signReceiver}40{signSender}fd"+createVerifyScript(RSMCScript) }
def createHERDTX(addressRSMC, addressReceiver, HTLCValue, HETxId, RSMCScript, asset_id): time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex( hex(int(time.time()))[2:])) address_hash_RSMC = TransactionAttribute( usage=TransactionAttributeUsage.Script, data=ToAddresstHash(addressRSMC).Data) pre_txid = TransactionAttribute(usage=TransactionAttributeUsage.Remark1, data=bytearray.fromhex( hex_reverse(HETxId))) outputTo = TransactionAttribute(usage=TransactionAttributeUsage.Remark2, data=ToAddresstHash(addressReceiver).Data) txAttributes = [address_hash_RSMC, time_stamp, pre_txid, outputTo] op_data_to_receiver = create_opdata(address_from=addressRSMC, address_to=addressReceiver, value=HTLCValue, contract_hash=asset_id) tx = InvocationTransaction() tx.Version = 1 tx.Attributes = txAttributes tx.Script = binascii.unhexlify(op_data_to_receiver) return { "txData": tx.get_tx_data(), "txId": createTxid(tx.get_tx_data()), "witness": "01{blockheight_script}40{signReceiver}40{signSender}fd" + createVerifyScript(RSMCScript) }
def _createInput(preHash, preIndex): pre_hash = UInt256(data=binascii.unhexlify(hex_reverse(preHash))) return TransactionInput(prevHash=pre_hash, prevIndex=preIndex)