How to use the stellar-base.xdr 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 / changes_extractor.ts View on Github external
export enum ChangeType {
  Created = "created",
  Updated = "updated",
  Removed = "removed",
  State = "state"
}

export enum EntryType {
  Account = "account",
  Trustline = "trustline",
  Data = "datum",
  Offer = "offer"
}

const changeType = stellar.xdr.LedgerEntryChangeType;
const ledgerEntryType = stellar.xdr.LedgerEntryType;

export interface IChange {
  type: string;
  entry: string;
  data: any;
  seq: number;
  tx: Transaction;
  accountChanges?: string[];
  prevState?: any;
}

export class ChangesExtractor {
  public static call(tx: TransactionWithXDR) {
    return new ChangesExtractor(tx).call();
  }
github astroband / astrograph / _experimental / model / account_flags.ts View on Github external
constructor(value: number) {
    const fl = stellar.xdr.AccountFlags;

    this.authRequired = (value & fl.authRequiredFlag().value) > 0;
    this.authRevokable = (value & fl.authRevocableFlag().value) > 0;
    this.authImmutable = (value & fl.authImmutableFlag().value) > 0;
  }
github astroband / astrograph / src / model / factories / transaction_with_xdr_factory.ts View on Github external
public static fromHorizon(data: IHorizonTransactionData): TransactionWithXDR {
    const bodyXDR = stellar.xdr.TransactionEnvelope.fromXDR(data.envelope_xdr, "base64");
    const result = stellar.xdr.TransactionResult.fromXDR(data.result_xdr, "base64");
    const metaXDR = stellar.xdr.TransactionMeta.fromXDR(data.result_meta_xdr, "base64");
    const feeMetaXDR = stellar.xdr.OperationMeta.fromXDR(data.fee_meta_xdr, "base64");

    const body = bodyXDR.tx();

    const memo = stellar.Memo.fromXDRObject(body.memo());

    const timeBounds = this.parseTimeBounds(body.timeBounds());

    const resultCode = result.result().switch().value;
    const success = resultCode === stellar.xdr.TransactionResultCode.txSuccess().value;
    const feeAmount = body.fee().toString();
    const feeCharged = result.feeCharged().toString();
    const sourceAccount = publicKeyFromBuffer(body.sourceAccount().value());
github astroband / astrograph / src / model / factories / account_thresholds_factory.ts View on Github external
public static fromValue(value: string): AccountThresholds {
    const t = Buffer.from(value, "base64");
    const ti = stellar.xdr.ThresholdIndices;

    const data: IAccountThresholds = {
      masterWeight: t[ti.thresholdMasterWeight().value],
      low: t[ti.thresholdLow().value],
      medium: t[ti.thresholdMed().value],
      high: t[ti.thresholdHigh().value]
    };

    return new AccountThresholds(data);
  }
}
github astroband / astrograph / _experimental / model / trust_line.ts View on Github external
constructor(data: {
    accountid: string;
    assettype: number;
    issuer: string;
    assetcode: string;
    tlimit: string;
    balance: string;
    flags: number;
    lastmodified: number;
  }) {
    this.accountID = data.accountid;
    this.limit = toFloatAmountString(data.tlimit);
    this.balance = toFloatAmountString(data.balance);
    this.lastModified = data.lastmodified;
    this.authorized = (data.flags & stellar.xdr.TrustLineFlags.authorizedFlag().value) > 0;

    this.asset =
      data.assettype === stellar.xdr.AssetType.assetTypeNative().value
        ? Asset.native()
        : new Asset(data.assetcode, data.issuer);
  }
}
github astroband / astrograph / src / changes_extractor.ts View on Github external
export enum ChangeType {
  Created = "created",
  Updated = "updated",
  Removed = "removed",
  State = "state"
}

export enum EntryType {
  Account = "account",
  Trustline = "trustline",
  Data = "datum",
  Offer = "offer"
}

const changeType = stellar.xdr.LedgerEntryChangeType;
const ledgerEntryType = stellar.xdr.LedgerEntryType;

export interface IChange {
  type: string;
  entry: string;
  data: any;
  seq: number;
  tx: Transaction;
  accountChanges?: string[];
  prevState?: any;
}

export class ChangesExtractor {
  public static call(tx: TransactionWithXDR) {
    return new ChangesExtractor(tx).call();
  }
github astroband / astrograph / src / model / transaction_memo.ts View on Github external
constructor(xdr: any) {
    const memoType = stellar.xdr.MemoType;
    const memoValue = xdr.value();

    switch (xdr.switch()) {
      case memoType.memoNone():
        this.type = MemoType.None;
        break;
      case memoType.memoId():
        this.value = parseInt(memoValue, 10);
        this.type = MemoType.Id;
        break;
      case memoType.memoText():
        this.value = memoValue;
        this.type = MemoType.Text;
        break;
      case memoType.memoHash():
        this.value = memoValue.toString("hex");
github astroband / astrograph / src / transaction_fee / transaction_fee.model.ts View on Github external
public fromXDR() {
    return stellar.xdr.OperationMeta.fromXDR(Buffer.from(this.changes, "base64"));
  }
}
github stellar / js-stellar-sdk / lib / server.js View on Github external
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

Object.defineProperty(exports, "__esModule", {
    value: true
});

var TransactionResult = require("./transaction_result").TransactionResult;

var _errors = require("./errors");

var NotFoundError = _errors.NotFoundError;
var NetworkError = _errors.NetworkError;

var _stellarBase = require("stellar-base");

var xdr = _stellarBase.xdr;
var Account = _stellarBase.Account;

var axios = require("axios");
var toBluebird = require("bluebird").resolve;
var URI = require("URIjs");
var URITemplate = require("URIjs/src/URITemplate");

var EventSource = typeof window === "undefined" ? require("eventsource") : window.EventSource;

/**
* @class Server
*/

var Server = exports.Server = (function () {
    /**
    * Server handles a network connection to a Horizon instance and exposes an
github astroband / astrograph / _experimental / model / account_thresholds.ts View on Github external
constructor(value: string) {
    const t = Buffer.from(value, "base64");
    const ti = stellar.xdr.ThresholdIndices;

    this.masterWeight = t[ti.thresholdMasterWeight().value];
    this.low = t[ti.thresholdLow().value];
    this.medium = t[ti.thresholdMed().value];
    this.high = t[ti.thresholdHigh().value];
  }