From 5d0089f1d078c74f2c0c7b699df7c90c7f05a5e5 Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Tue, 7 May 2024 15:18:49 -0700 Subject: [PATCH] Proposed rename to extendFootprintTtl operation --- CHANGELOG.md | 3 +++ src/operation.js | 2 +- src/operations/extend_footprint_ttl.js | 16 +++++++++------- test/unit/operations/extend_restore_test.js | 6 +++--- types/index.d.ts | 4 ++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 178618c9..a9b417d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Breaking Changes +* `Operation.extendFootprintTtl`'s `extendTo` field is now named `minimumTtl` for clarity: the value is a quantity of ledgers relative to the last-closed ledger. + ## [`v11.1.0`](https://github.com/stellar/js-stellar-base/compare/v11.0.1...v11.1.0) diff --git a/src/operation.js b/src/operation.js index 3a02141e..c6a29777 100644 --- a/src/operation.js +++ b/src/operation.js @@ -383,7 +383,7 @@ export class Operation { } case 'extendFootprintTtl': { result.type = 'extendFootprintTtl'; - result.extendTo = attrs.extendTo(); + result.minimumTtl = attrs.extendTo(); break; } case 'restoreFootprint': { diff --git a/src/operations/extend_footprint_ttl.js b/src/operations/extend_footprint_ttl.js index 7e03f33e..3b43cddd 100644 --- a/src/operations/extend_footprint_ttl.js +++ b/src/operations/extend_footprint_ttl.js @@ -2,8 +2,9 @@ import xdr from '../xdr'; /** * Builds an operation to bump the time-to-live of a footprint (read and written - * ledger keys). Its only parameter is the new, absolute ledger sequence number - * at which the entry will expire. + * ledger keys). Its only parameter is the number of ledgers (N) **relative** to + * the last-closed ledger (LCL) at which the entry will be archived, i.e. it + * will be archived at a ledger >= LCL+N. These are the entries' time to live. * * The footprint itself is derived from the transaction (see * {@link TransactionBuilder}'s `opts.sorobanData` parameter, which is a @@ -14,21 +15,22 @@ import xdr from '../xdr'; * @alias Operation.extendFootprintTtl * * @param {object} opts - object holding operation parameters - * @param {number} opts.extendTo - the absolute ledger sequence number at which - * the transaction's ledger keys will now expire + * @param {number} opts.minimumTtl - the number of ledgers relative to the + * last-closed ledger that the footprint entry should live for (note that + * this value has to be below the network's `max_entry_ttl` setting) * @param {string} [opts.source] - an optional source account * * @returns {xdr.Operation} an Extend Footprint TTL operation * (xdr.ExtendFootprintTTLOp) */ export function extendFootprintTtl(opts) { - if ((opts.extendTo ?? -1) <= 0) { - throw new RangeError("extendTo isn't a ledger quantity (uint32)"); + if ((opts.minimumTtl ?? -1) <= 0) { + throw new RangeError("minimumTtl isn't a ledger quantity (uint32)"); } const extendFootprintOp = new xdr.ExtendFootprintTtlOp({ ext: new xdr.ExtensionPoint(0), - extendTo: opts.extendTo + extendTo: opts.minimumTtl }); const opAttributes = { diff --git a/test/unit/operations/extend_restore_test.js b/test/unit/operations/extend_restore_test.js index 4e96b9b0..de4456ee 100644 --- a/test/unit/operations/extend_restore_test.js +++ b/test/unit/operations/extend_restore_test.js @@ -3,17 +3,17 @@ const { Operation } = StellarBase; describe('Operation', function () { describe('.extendFootprintTtl()', function () { it('creates operation', function () { - const op = StellarBase.Operation.extendFootprintTtl({ extendTo: 1234 }); + const op = StellarBase.Operation.extendFootprintTtl({ minimumTtl: 1234 }); const xdr = op.toXDR('hex'); const operation = StellarBase.xdr.Operation.fromXDR(xdr, 'hex'); expect(operation.body().switch().name).to.equal('extendFootprintTtl'); const obj = StellarBase.Operation.fromXDRObject(operation); expect(obj.type).to.be.equal('extendFootprintTtl'); - expect(obj.extendTo).to.equal(1234); + expect(obj.minimumTtl).to.equal(1234); expect(() => { - StellarBase.Operation.extendFootprintTtl({ extendTo: 0 }); + StellarBase.Operation.extendFootprintTtl({ minimumTtl: 0 }); }).to.throw(/ledger quantity/i); }); }); diff --git a/types/index.d.ts b/types/index.d.ts index 92ea2263..70b994d1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -571,7 +571,7 @@ export namespace OperationOptions { } interface ExtendFootprintTTL extends BaseOptions { - extendTo: number; + minimumTtl: number; } type RestoreFootprint = BaseOptions; } @@ -904,7 +904,7 @@ export namespace Operation { options: OperationOptions.ExtendFootprintTTL ): xdr.Operation; interface ExtendFootprintTTL extends BaseOperation { - extendTo: number; + minimumTtl: number; } function restoreFootprint(options: OperationOptions.RestoreFootprint):