js-stellar-base/src/operations/bump_sequence.js

  1. import { Hyper } from '@stellar/js-xdr';
  2. import BigNumber from 'bignumber.js';
  3. import xdr from '../xdr';
  4. /**
  5. * This operation bumps sequence number.
  6. * @function
  7. * @alias Operation.bumpSequence
  8. * @param {object} opts Options object
  9. * @param {string} opts.bumpTo - Sequence number to bump to.
  10. * @param {string} [opts.source] - The optional source account.
  11. * @returns {xdr.BumpSequenceOp} Operation
  12. */
  13. export function bumpSequence(opts) {
  14. const attributes = {};
  15. if (typeof opts.bumpTo !== 'string') {
  16. throw new Error('bumpTo must be a string');
  17. }
  18. try {
  19. // eslint-disable-next-line no-new
  20. new BigNumber(opts.bumpTo);
  21. } catch (e) {
  22. throw new Error('bumpTo must be a stringified number');
  23. }
  24. attributes.bumpTo = Hyper.fromString(opts.bumpTo);
  25. const bumpSequenceOp = new xdr.BumpSequenceOp(attributes);
  26. const opAttributes = {};
  27. opAttributes.body = xdr.OperationBody.bumpSequence(bumpSequenceOp);
  28. this.setSourceAccount(opAttributes, opts);
  29. return new xdr.Operation(opAttributes);
  30. }