예제 #1
0
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)
    }
예제 #2
0
def createBRTX(addressOther,balanceSelf,RSMCScript,CTxId,asset_id):

    time_stamp = TransactionAttribute(usage=TransactionAttributeUsage.Remark,
                                      data=bytearray.fromhex(hex(int(time.time()))[2:]))

    outputTo = TransactionAttribute(usage=TransactionAttributeUsage.Remark1, data=ToAddresstHash(addressOther).Data)
    txAttributes = [time_stamp,outputTo]

    tx = ContractTransaction()

    RSMC_inputs=[tx.createInput(preHash=CTxId, preIndex=0)]


    output_to_other= tx.createOutput(assetId=asset_id, amount=balanceSelf,address=addressOther)
    tx.inputs = RSMC_inputs

    tx.outputs = [output_to_other]

    tx.Attributes = txAttributes


    return {
        "txData":tx.get_tx_data(),
        "txId":createTxid(tx.get_tx_data()),
        "witness": "01{blockheight_script}40{signOther}40{signSelf}fd" + createVerifyScript(RSMCScript)
    }
예제 #3
0
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)
    }
예제 #4
0
def createHTDTX(addressHTLC, pubkeySender, HTLCValue, HTLCScript, asset_id):

    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_sender = create_opdata(address_from=addressHTLC,
                                      address_to=pubkeyToAddress(pubkeySender),
                                      value=HTLCValue,
                                      contract_hash=asset_id)

    tx = InvocationTransaction()
    tx.Version = 1
    tx.Attributes = txAttributes
    tx.Script = binascii.unhexlify(op_data_to_sender)

    return {
        "txData":
        tx.get_tx_data(),
        "txId":
        createTxid(tx.get_tx_data()),
        "witness":
        "01{R_script}40{signOther}40{signSelf}fd" +
        createVerifyScript(HTLCScript)
    }
예제 #5
0
def createBRTX(addressRSMC, addressOther, balanceSelf, 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)
    outputTo = TransactionAttribute(usage=TransactionAttributeUsage.Remark1,
                                    data=ToAddresstHash(addressOther).Data)
    txAttributes = [address_hash_RSMC, time_stamp, outputTo]

    op_data_to_other = create_opdata(address_from=addressRSMC,
                                     address_to=addressOther,
                                     value=balanceSelf,
                                     contract_hash=asset_id)

    tx = InvocationTransaction()
    tx.Version = 1
    tx.Attributes = txAttributes
    tx.Script = binascii.unhexlify(op_data_to_other)

    return {
        "txData":
        tx.get_tx_data(),
        "txId":
        createTxid(tx.get_tx_data()),
        "witness":
        "01{blockheight_script}40{signOther}40{signSelf}fd" +
        createVerifyScript(RSMCScript)
    }
예제 #6
0
def createHTDTX(pubkeySender,HTLCValue, HTLCScript,receiver_HCTxId,asset_id):

    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_sender = tx.createOutput(assetId=asset_id, amount=HTLCValue, address=pubkeyToAddress(pubkeySender))

    tx.inputs = HTLC_inputs
    tx.outputs = [output_to_sender]
    tx.Attributes = txAttributes

    return {
        "txData": tx.get_tx_data(),
        "txId": createTxid(tx.get_tx_data()),
        "witness": "01830040{signOther}40{signSelf}fd"+createVerifyScript(HTLCScript) #R is empty
    }
예제 #7
0
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)
    }
예제 #8
0
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)
    }