How to use the stellar-base.Asset 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 astroband / astrograph / src / model / factories / asset_factory.ts View on Github external
public static fromId(id: AssetID) {
    if (id === "native") {
      return stellar.Asset.native();
    }

    const [code, issuer] = id.split("-");

    if (!issuer) {
      throw new Error(`Invalid asset id "${id}"`);
    }

    return new stellar.Asset(code, issuer);
  }
github astroband / astrograph / src / model / factories / asset_factory.ts View on Github external
public static fromTrustline(type: number, code: string, issuer: string): stellar.Asset {
    return type === stellar.xdr.AssetType.assetTypeNative().value
      ? stellar.Asset.native()
      : new stellar.Asset(code, issuer);
  }
github astroband / astrograph / src / model / factories / operation_data_mapper / horizon.ts View on Github external
private mapManageOffer(): IManageSellOfferOperation | IManageBuyOfferOperation {
    const assetBuying =
      this.data.buying_asset_type === "native"
        ? Asset.native()
        : new Asset(this.data.buying_asset_code, this.data.buying_asset_issuer);

    const assetSelling =
      this.data.selling_asset_type === "native"
        ? Asset.native()
        : new Asset(this.data.selling_asset_code, this.data.selling_asset_issuer);

    return {
      ...this.baseData,
      ...{
        offerId: this.data.offer_id.toString(),
        amount: this.data.amount,
        price: this.data.price,
        priceComponents: {
          n: this.data.price_r.n,
          d: this.data.price_r.d
        },
github astroband / astrograph / src / model / factories / operation_data_mapper / horizon.ts View on Github external
private mapPathPayment(): IPathPaymentOperation {
    const destinationAsset =
      this.data.asset_type === "native" ? Asset.native() : new Asset(this.data.asset_code, this.data.asset_issuer);
    const sourceAsset =
      this.data.source_asset_type === "native"
        ? Asset.native()
        : new Asset(this.data.source_asset_code, this.data.source_asset_issuer);

    return {
      ...this.baseData,
      ...{
        sendMax: this.data.source_max,
        amountSent: this.data.source_amount,
        amountReceived: this.data.amount,
        destinationAccount: this.data.to,
        destinationAsset,
        sourceAccount: this.data.from,
        sourceAsset
      }
    };
  }
github astroband / astrograph / src / model / factories / operation_data_mapper / horizon.ts View on Github external
private mapAllowTrust(): IAllowTrustOperation {
    return {
      ...this.baseData,
      ...{
        trustor: this.data.trustor,
        authorize: this.data.authorize,
        asset: new Asset(this.data.asset_code, this.baseData.sourceAccount)
      }
    };
  }
github astroband / astrograph / src / util / extract_operation.ts View on Github external
index: number
): Operation {
  const opXDR = tx.operationsXDR[index];

  if (!opXDR) {
    throw new Error(`No operation with index ${index} in this transaction`);
  }

  const opObject = refineOperationXDR(opXDR);
  opObject.dateTime = ledgerInfo.closeTime;
  opObject.id = buildOperationId(ledgerInfo.ledgerSeq, tx.index, index + 1);

  const opSource = opObject.source || tx.sourceAccount;

  if (opObject.type === OperationType.AllowTrust) {
    opObject.asset = new Asset(opObject.asset, opSource);
  }

  if (opObject.type === OperationType.PathPayment && tx.success) {
    opObject.amountSent = getSentAmount(tx, index, opSource);
  }

  if (opObject.type === OperationType.PathPaymentStrictSend && tx.success) {
    opObject.amountReceived = getReceivedAmount(tx, index, opObject.destinationAccount);
  }

  delete opObject.source;

  return {
    sourceAccount: opSource,
    tx: new Transaction(tx),
    index,