def createCTX(balanceSelf,balanceOther,pubkeySelf,pubkeyOther,fundingScript,asset_id,fundingTxId): RSMCContract=createRSMCContract(hashSelf=pubkeyToAddressHash(pubkeySelf.strip()),pubkeySelf=pubkeySelf.strip(), hashOther=pubkeyToAddressHash(pubkeyOther.strip()), pubkeyOther=pubkeyOther.strip(),magicTimestamp=time.time()) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex(hex(int(time.time()))[2:])) txAttributes = [time_stamp] tx = ContractTransaction() funding_inputs=[tx.createInput(preHash=fundingTxId, preIndex=0)] output_to_RSMC= tx.createOutput(assetId=asset_id, amount=balanceSelf,address=RSMCContract["address"]) output_to_other= tx.createOutput(assetId=asset_id, amount=balanceOther,address=pubkeyToAddress(pubkeyOther)) tx.inputs = funding_inputs tx.outputs = [output_to_RSMC,output_to_other] tx.Attributes = txAttributes return { "txData":tx.get_tx_data(), "addressRSMC":RSMCContract["address"], "scriptRSMC":RSMCContract["script"], "txId":createTxid(tx.get_tx_data()), "witness":"018240{signSelf}40{signOther}da"+fundingScript }
def createHETX(pubkeySender,pubkeyReceiver,HTLCValue, HTLCScript,receiver_HCTxId,asset_id): RSMCContract = createRSMCContract(hashSelf=pubkeyToAddressHash(pubkeyReceiver), pubkeySelf=pubkeyReceiver, hashOther=pubkeyToAddressHash(pubkeySender), pubkeyOther=pubkeySender, magicTimestamp=time.time()) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex(hex(int(time.time()))[2:])) txAttributes = [time_stamp] tx = ContractTransaction() HTLC_inputs = [tx.createInput(preHash=receiver_HCTxId, preIndex=2)] output_to_RSMC = tx.createOutput(assetId=asset_id, amount=HTLCValue, address=RSMCContract["address"]) tx.inputs = HTLC_inputs tx.outputs = [output_to_RSMC] tx.Attributes = txAttributes return { "txData": tx.get_tx_data(), "txId": createTxid(tx.get_tx_data()), "addressRSMC": RSMCContract["address"], "RSMCscript": RSMCContract["script"], "witness": "01{R_script}40{signOther}40{signSelf}fd"+createVerifyScript(HTLCScript) }
def create_sender_HCTX(pubkeySender, pubkeyReceiver, HTLCValue, balanceSender, balanceReceiver, hashR, addressFunding, fundingScript, asset_id): RSMCContract = createRSMCContract( hashSelf=pubkeyToAddressHash(pubkeySender), pubkeySelf=pubkeySender, hashOther=pubkeyToAddressHash(pubkeyReceiver), pubkeyOther=pubkeyReceiver, magicTimestamp=time.time()) HTLCContract = createHTLCContract(pubkeySelf=pubkeySender, pubkeyOther=pubkeyReceiver, futureTimestamp=int(time.time()) + 600, hashR=hashR) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex( hex(int(time.time()))[2:])) address_hash_funding = TransactionAttribute( usage=TransactionAttributeUsage.Script, data=ToAddresstHash(addressFunding).Data) txAttributes = [address_hash_funding, time_stamp] op_data_to_HTLC = create_opdata(address_from=addressFunding, address_to=HTLCContract["address"], value=HTLCValue, contract_hash=asset_id) op_data_to_RSMC = create_opdata(address_from=addressFunding, address_to=RSMCContract["address"], value=balanceSender, contract_hash=asset_id) op_data_to_receiver = create_opdata( address_from=addressFunding, address_to=pubkeyToAddress(pubkeyReceiver), value=balanceReceiver, contract_hash=asset_id) tx = InvocationTransaction() tx.Version = 1 tx.Attributes = txAttributes tx.Script = binascii.unhexlify(op_data_to_RSMC + op_data_to_receiver + op_data_to_HTLC) return { "txData": tx.get_tx_data(), "addressRSMC": RSMCContract["address"], "addressHTLC": HTLCContract["address"], "RSMCscript": RSMCContract["script"], "HTLCscript": HTLCContract["script"], "txId": createTxid(tx.get_tx_data()), "witness": "018240{signSelf}40{signOther}da" + fundingScript }
def create_sender_HCTX(pubkeySender, pubkeyReceiver, HTLCValue, balanceSender, balanceReceiver, hashR, addressFunding, fundingScript,asset_id): RSMCContract = createRSMCContract(hashSelf=pubkeyToAddressHash(pubkeySender), pubkeySelf=pubkeySender, hashOther=pubkeyToAddressHash(pubkeyReceiver), pubkeyOther=pubkeyReceiver, magicTimestamp=time.time()) HTLCContract = createHTLCContract(pubkeySelf=pubkeySender, pubkeyOther=pubkeyReceiver, futureTimestamp=int(time.time()) + 600, hashR=hashR) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex(hex(int(time.time()))[2:])) txAttributes = [time_stamp] tx = ContractTransaction() funding_vouts=get_vout_by_address(addressFunding,balanceSender+balanceReceiver+HTLCValue,asset_id) if not funding_vouts: return None funding_inputs=[tx.createInput(preHash=item[0], preIndex=item[2]) for item in funding_vouts ] output_to_RSMC= tx.createOutput(assetId=asset_id, amount=balanceSender,address=RSMCContract["address"]) output_to_HTLC= tx.createOutput(assetId=asset_id, amount=HTLCValue,address=HTLCContract["address"]) output_to_receiver= tx.createOutput(assetId=asset_id, amount=balanceReceiver,address=pubkeyToAddress(pubkeyReceiver)) tx.inputs = funding_inputs tx.outputs = [output_to_RSMC,output_to_receiver,output_to_HTLC] tx.Attributes = txAttributes return { "txData": tx.get_tx_data(), "addressRSMC": RSMCContract["address"], "addressHTLC": HTLCContract["address"], "RSMCscript": RSMCContract["script"], "HTLCscript": HTLCContract["script"], "txId": createTxid(tx.get_tx_data()), "witness": "018240{signSelf}40{signOther}da" + fundingScript }
def createHETX(addressHTLC, pubkeySender, pubkeyReceiver, HTLCValue, HTLCScript, asset_id): RSMCContract = createRSMCContract( hashSelf=pubkeyToAddressHash(pubkeyReceiver), pubkeySelf=pubkeyReceiver, hashOther=pubkeyToAddressHash(pubkeySender), pubkeyOther=pubkeySender, magicTimestamp=time.time()) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex( hex(int(time.time()))[2:])) address_hash_HTLC = TransactionAttribute( usage=TransactionAttributeUsage.Script, data=ToAddresstHash(addressHTLC).Data) txAttributes = [address_hash_HTLC, time_stamp] op_data_to_RSMC = create_opdata(address_from=addressHTLC, address_to=RSMCContract["address"], value=HTLCValue, contract_hash=asset_id) tx = InvocationTransaction() tx.Version = 1 tx.Attributes = txAttributes tx.Script = binascii.unhexlify(op_data_to_RSMC) return { "txData": tx.get_tx_data(), "txId": createTxid(tx.get_tx_data()), "addressRSMC": RSMCContract["address"], "RSMCscript": RSMCContract["script"], "witness": "01{R_script}40{signOther}40{signSelf}fd" + createVerifyScript(HTLCScript) }
def createCTX(addressFunding, balanceSelf, balanceOther, pubkeySelf, pubkeyOther, fundingScript, asset_id): RSMCContract = createRSMCContract( hashSelf=pubkeyToAddressHash(pubkeySelf.strip()), pubkeySelf=pubkeySelf.strip(), hashOther=pubkeyToAddressHash(pubkeyOther.strip()), pubkeyOther=pubkeyOther.strip(), magicTimestamp=time.time()) time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark, data=bytearray.fromhex( hex(int(time.time()))[2:])) address_hash_funding = TransactionAttribute( usage=TransactionAttributeUsage.Script, data=ToAddresstHash(addressFunding).Data) txAttributes = [address_hash_funding, time_stamp] op_data_to_RSMC = create_opdata(address_from=addressFunding, address_to=RSMCContract["address"], value=balanceSelf, contract_hash=asset_id) op_data_to_other = create_opdata(address_from=addressFunding, address_to=pubkeyToAddress(pubkeyOther), value=balanceOther, contract_hash=asset_id) tx = InvocationTransaction() tx.Version = 1 tx.Attributes = txAttributes tx.Script = binascii.unhexlify(op_data_to_RSMC + op_data_to_other) return { "txData": tx.get_tx_data(), "addressRSMC": RSMCContract["address"], "scriptRSMC": RSMCContract["script"], "txId": createTxid(tx.get_tx_data()), "witness": "018240{signSelf}40{signOther}da" + fundingScript }