diff --git a/docs/datatxmap.js b/docs/datatxmap.js new file mode 100644 index 0000000..cbb5735 --- /dev/null +++ b/docs/datatxmap.js @@ -0,0 +1,73 @@ +function dataToTx(data) { + console.log(moment().format("HH:mm:ss") + " dataToTx: " + JSON.stringify(data, bigNumberReplacer, 2)); + let tx = null; + return tx; +} + +function txToData(tx, oldData) { + console.log(moment().format("HH:mm:ss") + " txToData: " + JSON.stringify(tx, bigNumberReplacer, 2)); + let data = null; + + // ERC-20 transfer + if (tx.data && tx.data.length == 138 && tx.data.substring(0, 10) == "0xa9059cbb") { + const tokensTo = ethers.utils.getAddress(tx.data.substring(34, 74)); + const tokens = ethers.BigNumber.from("0x" + tx.data.substring(75, 138)); + data = { + action: "erc20transfer", + token: tx.to, + from: tx.from, + to: tokensTo, + amount: null, + amountUnit: oldData && oldData.amountUnit || "ether", // TODO: Move out of data into settings + tokens: tokens.toString(), + data: null, + chainId: tx.chainId, + nonce: tx.nonce, + gasLimit: tx.gasLimit, + transactionType: tx.type, + + // gasPrice: null, + // maxFeePerGas: null, + // maxPriorityFeePerGas: null, + // maxFeePerGasUnit: "gwei", + // maxPriorityFeePerGasUnit: "gwei", + // gasPriceUnit: "gwei", + // signedTx: null, + // decodedSignedTx: null, + // error: null, + + }; + // ETH tx + } else if (tx.data == null || tx.data == "0x") { + data = { + action: "ethtransfer", + token: null, + from: tx.from, + to: tx.to, + amount: tx.value.toString(), + amountUnit: oldData && oldData.amountUnit || "ether", // TODO: Move out of data into settings + tokens: null, + data: null, + chainId: tx.chainId, + nonce: tx.nonce, + gasLimit: tx.gasLimit, + transactionType: tx.type, + + // gasPrice: null, + // maxFeePerGas: null, + // maxPriorityFeePerGas: null, + // maxFeePerGasUnit: "gwei", + // maxPriorityFeePerGasUnit: "gwei", + // gasPriceUnit: "gwei", + // signedTx: null, + // decodedSignedTx: null, + // error: null, + + }; + } else { + alert("Unknown transaction"); + } + console.log("data: " + JSON.stringify(data, bigNumberReplacer, 2)); + + return data; +} diff --git a/docs/offline.html b/docs/offline.html index f6ac6c5..117a1a0 100644 --- a/docs/offline.html +++ b/docs/offline.html @@ -22,6 +22,7 @@ + @@ -572,6 +573,7 @@ to: null, amount: null, amountUnit: "ether", + tokens: null, data: null, chainId: null, nonce: null, @@ -897,8 +899,30 @@ this.loadTx = {}; const t = this; reader.onload = function (event) { - const data = event.target.result; - t.loadTx = JSON.parse(data); + const unsignedTx = JSON.parse(event.target.result); + console.log(moment().format("HH:mm:ss") + " loadJSON - unsignedTx: " + JSON.stringify(unsignedTx, bigNumberReplacer, 2)); + + // console.log("unsignedTx.data.length: " + unsignedTx.data.length); + if (unsignedTx.data == "0x") { + unsignedTx.data = null; + } + // 0xa9059cbb0000000000000000000000005d446d064757cc92efe92548f2d7b7a3eab303620000000000000000000000000000000000000000000000000de0b6b3a7640000 + // 1 2 3 4 5 6 7 8 9 10 11 12 13 + // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 + + const txData = txToData(unsignedTx); + // ERC-20 transfer + if (unsignedTx.data && unsignedTx.data.length == 138 && unsignedTx.data.substring(0, 10) == "0xa9059cbb") { + const to = ethers.utils.getAddress(unsignedTx.data.substring(34, 74)); + // console.log("to: " + to); + const tokens = ethers.BigNumber.from("0x" + unsignedTx.data.substring(75, 138)); + // console.log("tokens: " + tokens); + // ETH tx + } else if (unsignedTx.data == null) { + } else { + alert("Unknown transaction"); + } + t.loadTx = unsignedTx.data; }; await reader.readAsText(fileList[0]); }, diff --git a/docs/online.html b/docs/online.html index 9c055f3..35edb3a 100644 --- a/docs/online.html +++ b/docs/online.html @@ -22,6 +22,7 @@ + @@ -1031,7 +1032,7 @@ var encodedUri = encodeURI(jsonContent); var link = document.createElement("a"); link.setAttribute("href", encodedUri); - link.setAttribute("download", "topsecrets_online_-" + moment().format("YYYY-MM-DD-HH-mm-ss") + ".json"); + link.setAttribute("download", "topsecrets_online_" + moment().format("YYYY-MM-DD-HH-mm-ss") + ".json"); document.body.appendChild(link); // Required for FF link.click(); // This will download the data with the specified file name },