Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed May 3, 2024
1 parent 715ef32 commit 0a039a6
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 62 deletions.
65 changes: 63 additions & 2 deletions docs/datatxmap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
function dataToTx(data) {
async function dataToTx(data, amountUnit, provider) {
console.log(moment().format("HH:mm:ss") + " dataToTx: " + JSON.stringify(data, bigNumberReplacer, 2));
let tx = null;
return tx;
const errors = {};
if (data.action == "ethtransfer") {
let from = null;
if (data.from) {
try {
from = ethers.utils.getAddress(data.from);
} catch (e) {
errors.from = "Invalid";
}
} else {
errors.complete = false;
}
let to = null;
if (data.to) {
try {
to = ethers.utils.getAddress(data.to);
} catch (e) {
errors.to = "Invalid";
}
} else {
errors.complete = false;
}
let value = null;
if (data.amount) {
try {
value = ethers.utils.parseUnits(data.amount, amountUnit);
} catch (e) {
errors.amount = "Invalid";
}
} else {
errors.complete = false;
}
tx = {
from,
to,
value,
data: null,
};
} else if (data.action == "erc20transfer") {
const contract = new ethers.Contract(data.token, ERC20ABI, provider);
const tokens = ethers.utils.parseUnits(data.tokens, 18); // TODO: Decimals
// let tokens = null;
if (data.tokens) {
try {
tokens = ethers.utils.parseUnits(data.tokens, amountUnit);
} catch (e) {
errors.tokens = "Invalid";
}
} else {
errors.complete = false;
}
const tokenData = await contract.populateTransaction.transfer(data.to, tokens.toString());
tx = {
from: data.from,
to: data.token,
value: 0,
data: tokenData,
};
} else {
errors.complete = false;
}
return { tx, errors };
}

function txToData(tx, oldData) {
Expand Down
Loading

0 comments on commit 0a039a6

Please sign in to comment.