From c166d30f1515b3d1a58a4ac98a6000d1a95b780a Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Fri, 9 Jun 2023 10:56:23 +0530 Subject: [PATCH] Added smart contract deposit tx parsing --- index.html | 93 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 9528729..a496fe1 100644 --- a/index.html +++ b/index.html @@ -1079,6 +1079,51 @@ `; }, + contractDepositCard(obj) { + const { hash, blockHeight, token, sender, receiver, amount, type, time, contractAddress, contractName } = obj; + let title = 'Contract deposit'; + return html` +
  • + transfer +
    +
    ${title}
    + ${token} +
    +
    + +
    +
    +
    Sender
    + + ${sender} + +
    +
    +
    Receiver
    + + ${receiver} + +
    +
    +
    +
    Contract name
    +

    ${contractName}

    +
    +
    +
    Amount
    +

    ${formatAmount(amount, token.toLowerCase() === 'rupee' ? 'inr' : 'usd')} ${token}

    +
    +
    +
    +
    Transaction ID
    + +
    + View details +
    +
    +
  • + `; + }, contractTransferCard(obj) { const { hash, token, sender, receiver, amount, contractName, userChoice, time } = obj; return html` @@ -1334,6 +1379,9 @@ case 'nfttransfer': return render.tokenTransferCard(tx) break; + case 'contractdeposit': + return render.contractDepositCard(tx) + break; case 'contracttransfer': return render.contractTransferCard(tx); break; @@ -1528,7 +1576,10 @@ txList.forEach(tx => { const { transactionDetails: { - txid, blockHeight, vin, vout, time }, + txid, blockHeight, vin, vout, time, + receiverAddress, + senderAddress, + }, parsedFloData: { contractAddress, contractType, @@ -1541,7 +1592,8 @@ contractName, triggerCondition, userChoice, - nftHash + nftHash, + depositAmount, } } = tx; let obj = { @@ -1556,8 +1608,8 @@ case 'transfer': if (transferType == "token" || transferType == 'nft') { obj = Object.assign({}, obj, { - sender: vin[0]["addr"], - receiver: getReceiver(vin, vout), + sender: senderAddress, + receiver: receiverAddress, amount: tokenAmount, type: transferType == "token" ? "tokentransfer" : "nfttransfer", }); @@ -1566,8 +1618,8 @@ } else if (transferType == 'smartContract') { // smart contract transfer obj = Object.assign({}, obj, { - sender: vin[0]["addr"], - receiver: getReceiver(vin, vout), + sender: senderAddress, + receiver: receiverAddress, amount: tokenAmount, contractName, userChoice, @@ -1580,7 +1632,7 @@ // token incorporation // smart contract incorporation obj = Object.assign({}, obj, { - incAddress: vin[0]["addr"], + incAddress: senderAddress, supply: tokenAmount, type: "tokenincorp", }); @@ -1619,33 +1671,38 @@ case 'nftIncorporation': // nft incorporation obj = Object.assign({}, obj, { - incAddress: vin[0]["addr"], + incAddress: senderAddress, supply: tokenAmount, type: "nftincorp", nftHash }); latestTxArray.push(obj); break; + case 'smartContractDeposit': + // smart contract deposit + obj = Object.assign({}, obj, { + contractName, + contractAddress, + contractType, + amount: depositAmount, + type: "contractdeposit", + sender: senderAddress, + receiver: receiverAddress, + }); + latestTxArray.push(obj); + break; } } else { // transaction is a FLO Smart Contract Committee trigger - let receiver = "", sender = vin[0]['addr']; - for (const output of vout) { - if (output["scriptPubKey"]["addresses"][0] !== vin[0]["addr"]) { - receiverAddress = output["scriptPubKey"]["addresses"][0]; - break; - } - } - obj = Object.assign({}, obj, { hash: txid, blockHeight, contractName, - contractAddress: receiver, + contractAddress: receiverAddress, winningChoice: triggerCondition, - committeeAddress: sender, + committeeAddress: senderAddress, type: 'contracttrigger' }); latestTxArray.push(obj);