Page 1 of 1

Sendmax flag

Posted: Tue May 19, 2026 4:39 am
by wroomwroom
sendmax flag addition

Change following:

Code: Select all

const result = await evernodeMgr.acquire(
    host,
    options.moments || 1,
    userKeys.publicKey,
    options.contractId,
    options.image,
    appenv.hpInitCfg || {});
to following:

Code: Select all

const result = await evernodeMgr.acquire(
    host,
    options.moments || 1,
    userKeys.publicKey,
    options.contractId,
    options.image,
    appenv.hpInitCfg || {},
    { sendMax: options.sendmax });

Change following:

Code: Select all

const result = await this.#tenantClient.acquireLease(hostAddress, requirement, { leaseOfferIndex: options.leaseIndex, transactionOptions: { sequence: options.tenantSequence } });

To following

Code: Select all

const acquireOptions = {
    leaseOfferIndex: options.leaseIndex,
    transactionOptions: { sequence: options.tenantSequence }
};

if (options.sendMax !== undefined && options.sendMax !== null)
    acquireOptions.sendMax = options.sendMax;

const result = await this.#tenantClient.acquireLease(hostAddress, requirement, acquireOptions);

Change following:

Code: Select all

async acquireLeaseSubmit(hostAddress, requirement, options = {}) {

    const preparedAcquireTxn = await this.prepareAcquireLeaseTransaction(hostAddress, requirement, options);
    return await this.xrplAcc.signAndSubmit(preparedAcquireTxn);
}

To following:

Code: Select all

async acquireLeaseSubmit(hostAddress, requirement, options = {}) {

    const preparedAcquireTxn = await this.prepareAcquireLeaseTransaction(hostAddress, requirement, options);

    const sendMax = options.sendMax ?? options.sendmax;

    if (sendMax !== undefined && sendMax !== null) {
        const amount = preparedAcquireTxn.Amount;

        if (preparedAcquireTxn.TransactionType !== 'URITokenBuy')
            throw { reason: 'SENDMAX_NOT_SUPPORTED', error: 'sendmax is only supported for acquire / URITokenBuy.' };

        if (!amount || typeof amount !== 'object')
            throw { reason: 'INVALID_ACQUIRE_AMOUNT', error: 'Acquire amount is not an issued EVR amount.' };

        if (amount.currency !== 'EVR')
            throw { reason: 'INVALID_ACQUIRE_CURRENCY', error: `Acquire amount is ${amount.currency}, not EVR.` };

        const offerValue = Number(amount.value);
        const maxValue = Number(sendMax);

        if (!Number.isFinite(offerValue) || !Number.isFinite(maxValue) || maxValue < 0)
            throw { reason: 'INVALID_SENDMAX', error: `Invalid sendmax value: ${sendMax}` };

        if (offerValue > maxValue)
            throw {
                reason: 'ACQUIRE_PRICE_TOO_HIGH',
                error: `Acquire price ${amount.value} EVR exceeds sendmax ${sendMax} EVR. Transaction not submitted.`
            };
    }

    return await this.xrplAcc.signAndSubmit(preparedAcquireTxn);
}


In following section:

Code: Select all

.option('-m, --moments [moments]', 'Life moments')
.option('-c, --contract-id [contract-id]', 'Contract id')
.option('-i, --image [image]', 'Instance image')
.action(acquire);
Add following:

Code: Select all

.option('-s, --sendmax [evr]', 'Maximum EVR allowed for acquiring the instance')

You can now add -s flag to set a max amount that u send!