How to use the stellar-base.Asset.fromOperation function in stellar-base

To help you get started, we’ve selected a few stellar-base 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-sdk / src / server.ts View on Github external
);
                  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 {
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
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())
  };
}
github astroband / astrograph / src / model / factories / offer_factory.ts View on Github external
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
    };
  }
}
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
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())
  };
}
github astroband / astrograph / src / model / factories / offer_values_factory.ts View on Github external
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);
  }
}
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
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())
  };
}
github astroband / astrograph / src / model / factories / offer_values_factory.ts View on Github external
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);
  }
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
function refinePaymentOpXDR(body: any) {
  return {
    destination: publicKeyFromBuffer(body.destination().value()),
    amount: body.amount().toString(),
    asset: Asset.fromOperation(body.asset())
  };
}
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
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())
  };
}
github astroband / astrograph / src / util / xdr_refiner.ts View on Github external
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())
  };
}