How to use the js-xdr.Hyper.fromString function in js-xdr

To help you get started, we’ve selected a few js-xdr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stellar / js-stellar-base / src / operations / bump_sequence.js View on Github external
export function bumpSequence(opts) {
  const attributes = {};

  if (!isString(opts.bumpTo)) {
    throw new Error('bumpTo must be a string');
  }

  try {
    // eslint-disable-next-line no-new
    new BigNumber(opts.bumpTo);
  } catch (e) {
    throw new Error('bumpTo must be a stringified number');
  }

  attributes.bumpTo = Hyper.fromString(opts.bumpTo);

  const bumpSequenceOp = new xdr.BumpSequenceOp(attributes);

  const opAttributes = {};
  opAttributes.body = xdr.OperationBody.bumpSequence(bumpSequenceOp);
  this.setSourceAccount(opAttributes, opts);

  return new xdr.Operation(opAttributes);
}
github stellar / js-stellar-base / src / operations / change_trust.js View on Github external
export function changeTrust(opts) {
  const attributes = {};
  attributes.line = opts.asset.toXDRObject();
  if (!isUndefined(opts.limit) && !this.isValidAmount(opts.limit, true)) {
    throw new TypeError(this.constructAmountRequirementsError('limit'));
  }

  if (opts.limit) {
    attributes.limit = this._toXDRAmount(opts.limit);
  } else {
    attributes.limit = Hyper.fromString(new BigNumber(MAX_INT64).toString());
  }

  if (opts.source) {
    attributes.source = opts.source.masterKeypair;
  }
  const changeTrustOP = new xdr.ChangeTrustOp(attributes);

  const opAttributes = {};
  opAttributes.body = xdr.OperationBody.changeTrust(changeTrustOP);
  this.setSourceAccount(opAttributes, opts);

  return new xdr.Operation(opAttributes);
}
github tokend / new-js-sdk / src / base / operations / open_swap_builder.js View on Github external
opts.feeData.destinationFee.fixed
      ),
      ext: new xdr.FeeExt(xdr.LedgerVersion.emptyVersion())
    })
    attrs.feeData = new xdr.PaymentFeeData({
      sourceFee,
      destinationFee,
      sourcePaysForDest: opts.feeData.sourcePaysForDest,
      ext: new xdr.PaymentFeeDataExt(xdr.LedgerVersion.emptyVersion())
    })

    attrs.details = JSON.stringify(opts.details)
    attrs.sourceBalance = Keypair.fromBalanceId(opts.sourceBalance).xdrBalanceId()
    attrs.amount = BaseOperation._toUnsignedXDRAmount(opts.amount)
    attrs.secretHash = Hasher.hash(opts.secretHash)
    attrs.lockTime = Hyper.fromString(opts.lockTime)

    attrs.ext = new xdr.EmptyExt(xdr.LedgerVersion.emptyVersion())

    return attrs
  }
github tokend / new-js-sdk / src / base / operations / base_operation.js View on Github external
static _toXDRAmount (value) {
    let amount = new BigNumber(value).mul(ONE)
    return Hyper.fromString(amount.toString())
  }
github stellar / js-stellar-base / src / operation.js View on Github external
static _toXDRAmount(value) {
    const amount = new BigNumber(value).mul(ONE);
    return Hyper.fromString(amount.toString());
  }
github stellar / js-stellar-base / src / operations / manage_buy_offer.js View on Github external
if (!this.isValidAmount(opts.buyAmount, true)) {
    throw new TypeError(this.constructAmountRequirementsError('buyAmount'));
  }
  attributes.buyAmount = this._toXDRAmount(opts.buyAmount);
  if (isUndefined(opts.price)) {
    throw new TypeError('price argument is required');
  }
  attributes.price = this._toXDRPrice(opts.price);

  if (!isUndefined(opts.offerId)) {
    opts.offerId = opts.offerId.toString();
  } else {
    opts.offerId = '0';
  }

  attributes.offerId = Hyper.fromString(opts.offerId);
  const manageBuyOfferOp = new xdr.ManageBuyOfferOp(attributes);

  const opAttributes = {};
  opAttributes.body = xdr.OperationBody.manageBuyOffer(manageBuyOfferOp);
  this.setSourceAccount(opAttributes, opts);

  return new xdr.Operation(opAttributes);
}
github tokend / new-js-sdk / src / base / operation.js View on Github external
if (isUndefined(opts.fee.subtype)) {
        opts.fee.subtype = '0'
      }
      if (isUndefined(opts.fee.lowerBound)) {
        opts.fee.lowerBound = '0'
      }
      if (isUndefined(opts.fee.upperBound)) {
        opts.fee.upperBound = BaseOperation.MAX_INT64_AMOUNT
      }

      let feeData = {
        fixedFee: Operation._toXDRAmount(opts.fee.fixedFee),
        percentFee: Operation._toXDRAmount(opts.fee.percentFee),
        feeType: opts.fee.feeType,
        asset: opts.fee.asset,
        subtype: Hyper.fromString(opts.fee.subtype),
        lowerBound: Operation._toXDRAmount(opts.fee.lowerBound),
        upperBound: Operation._toXDRAmount(opts.fee.upperBound),
        ext: new xdr.FeeEntryExt(xdr.LedgerVersion.emptyVersion())
      }
      let data = `type:${opts.fee.feeType.value}asset:${opts.fee.asset}subtype:${opts.fee.subtype.toString()}`
      if (opts.fee.accountId) {
        if (!Keypair.isValidPublicKey(opts.fee.accountId)) {
          throw new TypeError('accountId is invalid')
        } else {
          feeData.accountId = Keypair
            .fromAccountId(opts.fee.accountId)
            .xdrAccountId()
          data += `accountID:${opts.fee.accountId}`
        }
      }
      if (opts.fee.accountRole) {
github stellar / js-stellar-base / src / operations / manage_sell_offer.js View on Github external
if (!this.isValidAmount(opts.amount, true)) {
    throw new TypeError(this.constructAmountRequirementsError('amount'));
  }
  attributes.amount = this._toXDRAmount(opts.amount);
  if (isUndefined(opts.price)) {
    throw new TypeError('price argument is required');
  }
  attributes.price = this._toXDRPrice(opts.price);

  if (!isUndefined(opts.offerId)) {
    opts.offerId = opts.offerId.toString();
  } else {
    opts.offerId = '0';
  }

  attributes.offerId = Hyper.fromString(opts.offerId);
  const manageSellOfferOp = new xdr.ManageSellOfferOp(attributes);

  const opAttributes = {};
  opAttributes.body = xdr.OperationBody.manageSellOffer(manageSellOfferOp);
  this.setSourceAccount(opAttributes, opts);

  return new xdr.Operation(opAttributes);
}

js-xdr

Read/write XDR encoded data structures (RFC 4506)

Apache-2.0
Latest version published 2 months ago

Package Health Score

87 / 100
Full package analysis

Similar packages