How to use the @cityofzion/neon-core.logging.default function in @cityofzion/neon-core

To help you get started, we’ve selected a few @cityofzion/neon-core 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 CityOfZion / neon-js / packages / neon-api / src / provider / neonDB / class.ts View on Github external
import { logging, rpc, settings, u, wallet } from "@cityofzion/neon-core";
import { PastTransaction, Provider } from "../common";
import {
  getBalance,
  getClaims,
  getHeight,
  getMaxClaimAmount,
  getRPCEndpoint,
  getTransactionHistory
} from "./core";
const log = logging.default("api");

export class NeonDB implements Provider {
  private url: string;

  public get name() {
    return `NeonDB[${this.url}]`;
  }

  private rpc: rpc.RPCClient | null = null;
  private cacheExpiry: Date | null = null;

  public constructor(url: string) {
    if (settings.networks[url] && settings.networks[url].extra.neonDB) {
      this.url = settings.networks[url].extra.neonDB;
    } else {
      this.url = url;
github CityOfZion / neon-js / packages / neon-api / src / provider / neoCli / class.ts View on Github external
import { logging, rpc, u, wallet } from "@cityofzion/neon-core";
import { PastTransaction, Provider } from "../common";
import { getBalance, getClaims, getMaxClaimAmount } from "./core";

const log = logging.default("api");

export class NeoCli implements Provider {
  public get name() {
    return `NeoCli[${this.url}]`;
  }
  private url: string;

  private rpc: rpc.RPCClient;

  public constructor(url: string) {
    this.url = url;
    this.rpc = new rpc.RPCClient(url);
    log.info(`Created NeoCli Provider: ${this.url}`);
  }
  public getRPCEndpoint(noCache?: boolean | undefined): Promise {
    return Promise.resolve(this.url);
github CityOfZion / neon-js / packages / neon-api / src / provider / neoscan / core.ts View on Github external
findGoodNodesFromHeight,
  getBestUrl,
  PastTransaction,
  RpcNode
} from "../common";
import {
  NeoscanBalance,
  NeoscanClaim,
  NeoscanPastTx,
  NeoscanTx,
  NeoscanV1GetBalanceResponse,
  NeoscanV1GetClaimableResponse,
  NeoscanV1GetHeightResponse,
  NeoscanV1GetUnclaimedResponse
} from "./responses";
const log = logging.default("api");

function parseUnspent(unspentArr: NeoscanTx[]): wallet.CoinLike[] {
  return unspentArr.map(coin => {
    return {
      index: coin.n,
      txid: coin.txid,
      value: coin.value
    };
  });
}
function parseClaims(claimArr: NeoscanClaim[]): wallet.ClaimItemLike[] {
  return claimArr.map(c => {
    return {
      start: c.start_height,
      end: c.end_height,
      index: c.n,
github CityOfZion / neon-js / packages / neon-api / src / provider / neoCli / core.ts View on Github external
import { CONST, logging, rpc, u, wallet } from "@cityofzion/neon-core";
import axios from "axios";
import {
  NeoCliClaimable,
  NeoCliGetClaimableResponse,
  NeoCliGetUnclaimedResponse,
  NeoCliGetUnspentsResponse,
  NeoCliTx
} from "./responses";
const log = logging.default("api");

const BASE_REQ = CONST.DEFAULT_REQ;

function throwRpcError(err: rpc.RPCErrorResponse): void {
  throw new Error(`Encounter error code ${err.code}: ${err.message}`);
}

export function getRPCEndpoint(url: string): string {
  return url;
}

function convertNeoCliTx(tx: NeoCliTx): wallet.CoinLike {
  return { index: tx.n, txid: tx.txid, value: tx.value };
}

function convertNeoCliClaimable(c: NeoCliClaimable): wallet.ClaimItemLike {
github CityOfZion / neon-js / packages / neon-api / src / funcs / main.ts View on Github external
import { fillBalance, fillClaims, fillSigningFunction, fillUrl } from "./fill";
import { addAttributeForMintToken, addSignatureForMintToken } from "./mint";
import { applyTxToBalance, sendTx } from "./send";
import { signTx } from "./sign";
import {
  addAttributeIfExecutingAsSmartContract,
  addSignatureIfExecutingAsSmartContract
} from "./smartcontract";
import {
  ClaimGasConfig,
  DoInvokeConfig,
  SendAssetConfig,
  SetupVoteConfig
} from "./types";

const log = logging.default("api");

/**
 * The core API methods are series of methods defined to aid conducting core functionality while making it easy to modify any parts of it.
 * The core functionality are sendAsset, claimGas and doInvoke.
 * These methods are designed to be modular in nature and intended for developers to create their own custom methods.
 * The methods revolve around a configuration object in which everything is placed. Each method will take in the configuration object, check for its required fields and perform its operations, adding its results to the configuration object and returning it.
 * For example, the getBalanceFrom function requires net and address fields and appends the url and balance fields to the object.
 */

/**
 * Function to construct and execute a ContractTransaction.
 * @param config Configuration object.
 * @return Configuration object.
 */
export async function sendAsset(
  config: SendAssetConfig
github CityOfZion / neon-js / packages / neon-api / src / provider / neonDB / core.ts View on Github external
import axios from "axios";
import { settings as internalSettings } from "../../settings";
import {
  filterHttpsOnly,
  findGoodNodesFromHeight,
  getBestUrl,
  PastTransaction,
  RpcNode
} from "../common";
import {
  NeonDbBalance,
  NeonDbClaims,
  NeonDbHistory,
  NeonDbNode
} from "./responses";
const log = logging.default("api");

/**
 * Returns an appropriate RPC endpoint retrieved from a neonDB endpoint.
 * @param url - URL of a neonDB service.
 * @returns URL of a good RPC endpoint.
 */
export async function getRPCEndpoint(url: string): Promise {
  const response = await axios.get(url + "/v2/network/nodes");
  const data = response.data.nodes as NeonDbNode[];
  let nodes = data
    .filter(d => d.status)
    .map(d => ({ height: d.block_height, url: d.url } as RpcNode));

  if (internalSettings.httpsOnly) {
    nodes = filterHttpsOnly(nodes);
  }
github CityOfZion / neon-js / packages / neon-nep5 / src / main.ts View on Github external
import { logging, rpc, sc, u, wallet } from "@cityofzion/neon-core";
import * as abi from "./abi";
const log = logging.default("nep5");

export interface TokenInfo {
  name: string;
  symbol: string;
  decimals: number;
  totalSupply: number;
  balance?: u.Fixed8;
}

const parseTokenInfo = rpc.buildParser(
  rpc.StringParser,
  rpc.StringParser,
  rpc.IntegerParser,
  rpc.Fixed8Parser
);
github CityOfZion / neon-js / packages / neon-domain / src / provider / NeoNS / class.ts View on Github external
import { logging } from "@cityofzion/neon-core";
import { DomainProvider } from "../common";
import { resolveDomain } from "./core";

const log = logging.default("neon-domain");

export class NeoNS implements DomainProvider {
  private contract: string;

  public get name() {
    return `NeoNs[${this.contract}]`;
  }

  public constructor(contract: string) {
    this.contract = contract;
    log.info(`Created NeoNS Provider: ${this.contract}`);
  }

  public resolveDomain(url: string, domain: string): Promise {
    return resolveDomain(url, this.contract, domain);
  }
github CityOfZion / neon-js / packages / neon-api / src / provider / neoscan / class.ts View on Github external
import { logging, rpc, settings, u, wallet } from "@cityofzion/neon-core";
import { PastTransaction, Provider } from "../common";
import {
  getBalance,
  getClaims,
  getHeight,
  getMaxClaimAmount,
  getRPCEndpoint,
  getTransactionHistory
} from "./core";
const log = logging.default("api");

export class Neoscan implements Provider {
  private url: string;

  public get name(): string {
    return `Neoscan[${this.url}]`;
  }

  private rpc: rpc.RPCClient | null = null;
  private cacheExpiry: Date | null = null;

  public constructor(url: string) {
    if (settings.networks[url] && settings.networks[url].extra.neoscan) {
      this.url = settings.networks[url].extra.neoscan;
    } else {
      this.url = url;
github CityOfZion / neon-js / packages / neon-domain / src / provider / NeoNS / core.ts View on Github external
import { logging, rpc, sc, u } from "@cityofzion/neon-core";

const log = logging.default("neon-domain");

const operation = "resolve";

/**
 * Resolve a domain to a public address.
 * @param url - URL of an NEO RPC service.
 * @param contract - the contract used to resolve
 * @param domain - the domain to resolve.
 * @return public address as string
 */

export async function resolveDomain(
  url: string,
  contract: string,
  domain: string
): Promise {