Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed May 2, 2024
1 parent caa4328 commit df4c671
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
73 changes: 73 additions & 0 deletions docs/datatxmap.js
Original file line number Diff line number Diff line change
@@ -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;
}
28 changes: 26 additions & 2 deletions docs/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script src="globals.js"></script>
<script src="chains.js"></script>
<script src="deploymentData.js"></script>
<script src="datatxmap.js"></script>

<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
Expand Down Expand Up @@ -572,6 +573,7 @@
to: null,
amount: null,
amountUnit: "ether",
tokens: null,
data: null,
chainId: null,
nonce: null,
Expand Down Expand Up @@ -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]);
},
Expand Down
3 changes: 2 additions & 1 deletion docs/online.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script src="globals.js"></script>
<script src="chains.js"></script>
<script src="deploymentData.js"></script>
<script src="datatxmap.js"></script>

<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit df4c671

Please sign in to comment.