Source

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

  1. import xdr from '../xdr';
  2. import { validateClaimableBalanceId } from './claim_claimable_balance';
  3. /**
  4. * Creates a clawback operation for a claimable balance.
  5. *
  6. * @function
  7. * @alias Operation.clawbackClaimableBalance
  8. * @param {object} opts - Options object
  9. * @param {string} opts.balanceId - The claimable balance ID to be clawed back.
  10. * @param {string} [opts.source] - The source account for the operation. Defaults to the transaction's source account.
  11. *
  12. * @return {xdr.ClawbackClaimableBalanceOp}
  13. *
  14. * @example
  15. * const op = Operation.clawbackClaimableBalance({
  16. * balanceId: '00000000da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be',
  17. * });
  18. *
  19. * @link https://github.com/stellar/stellar-protocol/blob/master/core/cap-0035.md#clawback-claimable-balance-operation
  20. */
  21. export function clawbackClaimableBalance(opts = {}) {
  22. validateClaimableBalanceId(opts.balanceId);
  23. const attributes = {
  24. balanceId: xdr.ClaimableBalanceId.fromXDR(opts.balanceId, 'hex')
  25. };
  26. const opAttributes = {
  27. body: xdr.OperationBody.clawbackClaimableBalance(
  28. new xdr.ClawbackClaimableBalanceOp(attributes)
  29. )
  30. };
  31. this.setSourceAccount(opAttributes, opts);
  32. return new xdr.Operation(opAttributes);
  33. }