Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • Daemon

Index

Constructors

  • new Daemon(host: string, port: number, isCacheApi?: boolean, ssl?: boolean): Daemon
  • Parameters

    • host: string

      The host to access the API on. Can be an IP, or a URL, for example, 1.1.1.1, or blockapi.turtlepay.io

    • port: number

      The port to access the API on. Normally 11898 for a TurtleCoin daemon, 80 for a HTTP api, or 443 for a HTTPS api.

    • Optional isCacheApi: boolean

      You can optionally specify whether this API is a blockchain cache API to save a couple of requests. If you're not sure, do not specify this parameter - we will work it out automatically.

    • Optional ssl: boolean

      You can optionally specify whether this API supports ssl/tls/https to save a couple of requests. If you're not sure, do not specify this parameter - we will work it out automatically.

    Returns Daemon

Events

  • on(event: "disconnect", callback: (error: Error) => void): Daemon
  • on(event: "connect", callback: () => void): Daemon
  • on(event: "heightchange", callback: (localDaemonBlockCount: number, networkDaemonBlockCount: number) => void): Daemon
  • on(event: "rawblock", callback: (block: Block) => void): Daemon
  • on(event: "rawtransaction", callback: (transaction: Transaction) => void): Daemon
  • This is emitted whenever the interface fails to contact the underlying daemon. This event will only be emitted on the first disconnection. It will not be emitted again, until the daemon connects, and then disconnects again.

    Example:

    daemon.on('disconnect', (error) => {
    console.log('Possibly lost connection to daemon: ' + error.toString());
    });

    Parameters

    • event: "disconnect"
    • callback: (error: Error) => void
        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    Returns Daemon

  • This is emitted whenever the interface previously failed to contact the underlying daemon, and has now reconnected. This event will only be emitted on the first connection. It will not be emitted again, until the daemon disconnects, and then reconnects again.

    Example:

    daemon.on('connect', () => {
    console.log('Regained connection to daemon!');
    });

    Parameters

    • event: "connect"
    • callback: () => void
        • (): void
        • Returns void

    Returns Daemon

  • This is emitted whenever either the localDaemonBlockCount or the networkDaemonBlockCount changes.

    Example:

    daemon.on('heightchange', (localDaemonBlockCount, networkDaemonBlockCount) => {
    console.log(localDaemonBlockCount, networkDaemonBlockCount);
    });

    Parameters

    • event: "heightchange"
    • callback: (localDaemonBlockCount: number, networkDaemonBlockCount: number) => void
        • (localDaemonBlockCount: number, networkDaemonBlockCount: number): void
        • Parameters

          • localDaemonBlockCount: number
          • networkDaemonBlockCount: number

          Returns void

    Returns Daemon

  • This is emitted every time we download a block from the daemon. Will only be emitted if the daemon is using /getrawblocks (All non blockchain cache daemons should support this).

    This block object is an instance of the Block turtlecoin-utils class. See the Utils docs for further info on using this value.

    Note that a block emitted after a previous one could potentially have a lower height, if a blockchain fork took place.

    Example:

    daemon.on('rawblock', (block) => {
    console.log(`Downloaded new block ${block.hash}`);
    });

    Parameters

    • event: "rawblock"
    • callback: (block: Block) => void
        • (block: Block): void
        • Parameters

          • block: Block

          Returns void

    Returns Daemon

  • This is emitted every time we download a transaction from the daemon. Will only be emitted if the daemon is using /getrawblocks (All non blockchain cache daemons should support this).

    This transaction object is an instance of the Transaction turtlecoin-utils class. See the Utils docs for further info on using this value.

    Note that a transaction emitted after a previous one could potentially have a lower height in the chain, if a blockchain fork took place.

    Example:

    daemon.on('rawtransaction', (block) => {
    console.log(`Downloaded new transaction ${transaction.hash}`);
    });

    Parameters

    • event: "rawtransaction"
    • callback: (transaction: Transaction) => void
        • (transaction: Transaction): void
        • Parameters

          • transaction: Transaction

          Returns void

    Returns Daemon

Properties

blockCount: number = 100

The number of blocks to download per /getwalletsyncdata request

config: Config = ...
connected: boolean = true

Did our last contact with the daemon succeed. Set to true initially so initial failure to connect will fire disconnect event.

feeAddress: string = ''

The address node fees will go to

feeAmount: number = 0

The amount of the node fee in atomic units

host: string

Daemon/API host

httpAgent: Agent = ...
httpsAgent: Agent = ...
isCacheApi: boolean = false

Whether we're talking to a conventional daemon, or a blockchain cache API

isCacheApiDetermined: boolean = false

Have we determined if this is a cache API or not?

lastKnownHashrate: number = 0

The hashrate of the last known local block

lastUpdatedLocalHeight: Date = ...

Last time the daemon height updated. If this goes over the configured limit, we'll emit deadnode.

lastUpdatedNetworkHeight: Date = ...

Last time the network height updated. If this goes over the configured limit, we'll emit deadnode.

localDaemonBlockCount: number = 0

The amount of blocks the daemon we're connected to has

networkBlockCount: number = 0

The amount of blocks the network has

peerCount: number = 0

The amount of peers we have, incoming+outgoing

port: number

Daemon/API port

ssl: boolean = true

Whether we should use https for our requests

sslDetermined: boolean = false

Have we determined if we should be using ssl or not?

useRawBlocks: boolean = true

Should we use /getrawblocks instead of /getwalletsyncdata

captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

  • getCancelledTransactions(transactionHashes: string[]): Promise<string[]>
  • Parameters

    • transactionHashes: string[]

    Returns Promise<string[]>

  • getConnectionString(): string
  • getGlobalIndexesForRange(startHeight: number, endHeight: number): Promise<Map<string, number[]>>
  • Parameters

    • startHeight: number
    • endHeight: number

    Returns Promise<Map<string, number[]>>

    Returns a mapping of transaction hashes to global indexes

    Get global indexes for the transactions in the range [startHeight, endHeight]

  • getLocalDaemonBlockCount(): number
  • Get the amount of blocks the daemon we're connected to has

    Returns number

  • getMaxListeners(): number
  • Returns number

  • getNetworkBlockCount(): number
  • getRandomOutputsByAmount(amounts: number[], requestedOuts: number): Promise<[number, [number, string][]][]>
  • Gets random outputs for the given amounts. requestedOuts per. Usually mixin+1.

    Parameters

    • amounts: number[]
    • requestedOuts: number

    Returns Promise<[number, [number, string][]][]>

    Returns an array of amounts to global indexes and keys. There should be requestedOuts indexes if the daemon fully fulfilled our request.

  • getWalletSyncData(blockHashCheckpoints: string[], startHeight: number, startTimestamp: number): Promise<[Block[], boolean | TopBlock]>
  • Parameters

    • blockHashCheckpoints: string[]

      Hashes of the last known blocks. Later blocks (higher block height) should be ordered at the front of the array.

    • startHeight: number

      Height to start taking blocks from

    • startTimestamp: number

      Block timestamp to start taking blocks from

      Gets blocks from the daemon. Blocks are returned starting from the last known block hash (if higher than the startHeight/startTimestamp)

    Returns Promise<[Block[], boolean | TopBlock]>

  • init(): Promise<void>
  • Initialize the daemon and the fee info

    Returns Promise<void>

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • makeGetRequest(endpoint: string): Promise<any>
  • makePostRequest(endpoint: string, body: any): Promise<any>
  • makeRequest(endpoint: string, method: string, body?: any): Promise<any>
  • Makes a get request to the given endpoint

    Parameters

    • endpoint: string
    • method: string
    • Optional body: any

    Returns Promise<any>

  • nodeFee(): [string, number]
  • off(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • once(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • rawBlocksToBlocks(rawBlocks: any): Promise<Block[]>
  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

  • removeAllListeners(event?: string | symbol): Daemon
  • Parameters

    • Optional event: string | symbol

    Returns Daemon

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Daemon
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Daemon

  • sendTransaction(rawTransaction: string): Promise<[boolean, undefined | string]>
  • Parameters

    • rawTransaction: string

    Returns Promise<[boolean, undefined | string]>

  • setMaxListeners(n: number): Daemon
  • Parameters

    • n: number

    Returns Daemon

  • updateConfig(config: IConfig): void
  • updateDaemonInfo(): Promise<void>
  • updateFeeInfo(): Promise<void>
  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

  • on(emitter: EventEmitter, event: string): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string

    Returns AsyncIterableIterator<any>

  • once(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string

    Returns Promise<any[]>

Generated using TypeDoc