uatom. string

This commit is contained in:
zramsay 2025-05-02 14:14:09 -04:00
parent a8be189229
commit 429bb62cf1
3 changed files with 16 additions and 11 deletions

View File

@ -33,7 +33,7 @@ export async function verifyAtomPayment(
): Promise<{
valid: boolean,
reason?: string,
amount?: number,
amount?: string,
sender?: string,
alreadyUsed?: boolean
}> {
@ -72,7 +72,7 @@ export async function verifyAtomPayment(
// Return cached verification result
return {
valid: true,
amount: txData.amount,
amount: `${txData.amount}uatom`,
sender: txData.sender,
alreadyUsed: txData.used
};
@ -103,7 +103,7 @@ export async function verifyAtomPayment(
// Extract the payment details
const tx = response.data.tx;
let foundValidPayment = false;
let paymentAmount = 0;
let paymentAmountUAtom = '';
let sender = '';
// Get the sender address from the first signer
@ -116,9 +116,14 @@ export async function verifyAtomPayment(
if (msg['@type'] === '/cosmos.bank.v1beta1.MsgSend') {
if (msg.to_address === Config.ATOM_PAYMENT_ADDRESS) {
for (const coin of msg.amount) {
if (coin.denom === 'uatom') { // uatom is the micro ATOM denomination (1 ATOM = 1,000,000 uatom)
paymentAmount = parseInt(coin.amount) / 1000000; // Convert from uatom to ATOM
if (paymentAmount >= requiredAmount) {
if (coin.denom === 'uatom') {
// Get the amount in uatom
paymentAmountUAtom = coin.amount;
// Extract the required amount as an integer from the format like "10uatom"
const requiredAmountUAtom = parseInt(requiredAmount.replace(/[^0-9]/g, ''));
if (parseInt(paymentAmountUAtom) >= requiredAmountUAtom) {
foundValidPayment = true;
}
break;
@ -131,21 +136,21 @@ export async function verifyAtomPayment(
if (!foundValidPayment) {
return {
valid: false,
reason: `Payment amount (${paymentAmount} ATOM) is less than required (${requiredAmount} ATOM) or not sent to the correct address`
reason: `Payment amount (${paymentAmountUAtom || '0'}uatom) is less than required (${requiredAmount}) or not sent to the correct address`
};
}
// Cache the verification result
verifiedTransactions.set(txHash, {
timestamp: Date.now(),
amount: paymentAmount,
amount: parseInt(paymentAmountUAtom),
sender,
used: markAsUsed
});
return {
valid: true,
amount: paymentAmount,
amount: `${paymentAmountUAtom}uatom`,
sender,
alreadyUsed: markAsUsed
};

View File

@ -24,7 +24,7 @@ export const Config = {
OPENPGP_PRIVATE_KEY_FILE: process.env.OPENPGP_PRIVATE_KEY_FILE,
// Cosmos ATOM payment configuration
ATOM_PAYMENT_ADDRESS: process.env.ATOM_PAYMENT_ADDRESS || '',
MIN_ATOM_PAYMENT: parseInt(process.env.MIN_ATOM_PAYMENT || '1'),
MIN_ATOM_PAYMENT: process.env.MIN_ATOM_PAYMENT || '1000000uatom',
COSMOS_RPC_ENDPOINT: process.env.COSMOS_RPC_ENDPOINT || '',
};

View File

@ -137,7 +137,7 @@ export class RegHelper {
const verification = await verifyAtomPayment(request.attributes.payment, minAtomPayment);
if (verification.valid) {
console.log(`ATOM payment verified for request ${request.id} - Amount: ${verification.amount} ATOM`);
console.log(`ATOM payment verified for request ${request.id} - Amount: ${verification.amount}`);
return true;
} else {
console.log(`ATOM payment verification failed for request ${request.id}: ${verification.reason}`);