Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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);
}
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
}
static _toXDRAmount (value) {
let amount = new BigNumber(value).mul(ONE)
return Hyper.fromString(amount.toString())
}
static _toXDRAmount(value) {
const amount = new BigNumber(value).mul(ONE);
return Hyper.fromString(amount.toString());
}
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);
}
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) {
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);
}