Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
const claimedOfferAmountSold = new BigNumber(
// amountBought is a js-xdr hyper
offerClaimed.amountSold().toString(),
);
// This is an offer that was filled by the one just submitted.
// So this offer has an _opposite_ bought/sold frame of ref
// than from what we just submitted!
// So add this claimed offer's bought to the SOLD count and vice v
amountBought = amountBought.add(claimedOfferAmountSold);
amountSold = amountSold.add(claimedOfferAmountBought);
const sold = Asset.fromOperation(offerClaimed.assetSold());
const bought = Asset.fromOperation(
offerClaimed.assetBought(),
);
const assetSold = {
type: sold.getAssetType(),
assetCode: sold.getCode(),
issuer: sold.getIssuer(),
};
const assetBought = {
type: bought.getAssetType(),
assetCode: bought.getCode(),
issuer: bought.getIssuer(),
};
return {
function refinePathPaymentOpXDR(body: any) {
return {
sendMax: body.sendMax().toString(),
amountReceived: body.destAmount().toString(),
destinationAccount: publicKeyFromBuffer(body.destination().value()),
destinationAsset: Asset.fromOperation(body.destAsset()),
sourceAsset: Asset.fromOperation(body.sendAsset())
};
}
public static fromXDR(xdr: any): IOfferBase {
const priceN = xdr.price().n();
const priceD = xdr.price().d();
return {
id: xdr.offerId().toInt(),
seller: xdr.sellerId().value(),
selling: Asset.fromOperation(xdr.selling()),
buying: Asset.fromOperation(xdr.buying()),
amount: xdr.amount().toInt(),
priceN,
priceD,
price: calculateOfferPrice(priceN, priceD),
passive: (xdr.flags() && XDR.OfferEntryFlags.passiveFlag().value) > 0
};
}
}
function refinePathPaymentStrictSendOpXDR(body: any) {
return {
destinationMin: body.destMin().toString(),
amountSent: body.sendAmount().toString(),
destinationAccount: publicKeyFromBuffer(body.destination().value()),
destinationAsset: Asset.fromOperation(body.destAsset()),
sourceAsset: Asset.fromOperation(body.sendAsset())
};
}
public static fromXDR(xdr: any): OfferValues {
const seller = publicKeyFromBuffer(xdr.sellerId().value());
const selling = Asset.fromOperation(xdr.selling());
const buying = Asset.fromOperation(xdr.buying());
const data: IOfferValues = {
id: xdr.offerId(),
seller,
selling,
buying,
amount: xdr.amount(),
price: xdr.price().toString(),
priceN: xdr.price().n(),
priceD: xdr.price().d(),
passive: (xdr.flags().value && XDR.OfferEntryFlags.passiveFlag().value) > 0
};
return new OfferValues(data);
}
}
function refinePathPaymentOpXDR(body: any) {
return {
sendMax: body.sendMax().toString(),
amountReceived: body.destAmount().toString(),
destinationAccount: publicKeyFromBuffer(body.destination().value()),
destinationAsset: Asset.fromOperation(body.destAsset()),
sourceAsset: Asset.fromOperation(body.sendAsset())
};
}
public static fromXDR(xdr: any): OfferValues {
const seller = publicKeyFromBuffer(xdr.sellerId().value());
const selling = Asset.fromOperation(xdr.selling());
const buying = Asset.fromOperation(xdr.buying());
const data: IOfferValues = {
id: xdr.offerId(),
seller,
selling,
buying,
amount: xdr.amount(),
price: xdr.price().toString(),
priceN: xdr.price().n(),
priceD: xdr.price().d(),
passive: (xdr.flags().value && XDR.OfferEntryFlags.passiveFlag().value) > 0
};
return new OfferValues(data);
}
function refinePaymentOpXDR(body: any) {
return {
destination: publicKeyFromBuffer(body.destination().value()),
amount: body.amount().toString(),
asset: Asset.fromOperation(body.asset())
};
}
function refineManageSellOfferOpXDR(body: any) {
return {
amount: body.amount().toString(),
offerId: body.offerId().toString(),
price: new BigNumber(body.price().n()).div(body.price().d()).toString(),
priceComponents: { n: body.price().n(), d: body.price().d() },
assetBuying: Asset.fromOperation(body.buying()),
assetSelling: Asset.fromOperation(body.selling())
};
}
function refineManageBuyOfferOpXDR(body: any) {
return {
amount: body.buyAmount().toString(),
offerId: body.offerId().toString(),
price: new BigNumber(body.price().n()).div(body.price().d()).toString(),
priceComponents: { n: body.price().n(), d: body.price().d() },
assetBuying: Asset.fromOperation(body.buying()),
assetSelling: Asset.fromOperation(body.selling())
};
}