Skip to content

PinkLoggerContractPromise

The contract instance interact with the logger of the cluster.

Usage

In most of cases, you can get the logger instance from the client instance.

const logger = client.loggerContract

If you don't want to connect to the chain RPC and use offchain mode only, check out this demo.

create

The static method to create a new instance of PinkLoggerContractPromise.

Parameters

client

OnChainRegistry

systemContract (optional)

SystemContract

pair (optional)

KeyringPair

constructor

Parameters

phactory

PhactoryAPI

The PhactoryAPI instance.

remoteKey

string

The pubkey of the PRuntime node.

pair

KeyringPair

The keyring pair of the user.

contractId

string

The contract id of the logger contract.

systemContractId (optional)

string

The contract id of the system contract.

Returns

PinkLoggerContractPromise

address

string

The address of the logger contract.

Methods

getLog

Deprecated. Use tail or head instead.

Parameters

contract

string | AccountId

from

number

count

number

Returns

Promise<GetLogResponse>

getInfo

Retrieve the log server stats.

Returns

Promise<LogServerInfo>

The LogServerInfo include follow up fields:

  • programVersion: number[]
  • nextSequence: number
  • memoryCapacity: number
  • memoryUsage: number
  • currentNumberOfRecords: number
  • estimatedCurrentSize: number

tail

Retrieve the latest logs. This method has overloading with following implementations:

async tail(): Promise<GetLogResponse>
async tail(counts: number): Promise<GetLogResponse>
async tail(request: Partial<GetLogRequest>): Promise<GetLogResponse>
async tail(counts: number, from: number): Promise<GetLogResponse>
async tail(counts: number, request: Omit<GetLogRequest, 'from' | 'count'>): Promise<GetLogResponse>
async tail(counts: number, from: number, request?: Omit<GetLogRequest, 'from' | 'count'>): Promise<GetLogResponse>

See GetLogRequest for detailed information.

Returns

Promise<GetLogResponse>

head

Retrieve the oldest logs. This method has overloading with following implementations:

async head(): Promise<GetLogResponse>
async head(counts: number): Promise<GetLogResponse>
async head(request: Partial<GetLogRequest>): Promise<GetLogResponse>
async head(counts: number, from: number): Promise<GetLogResponse>
async head(counts: number, request: Omit<GetLogRequest, 'from' | 'count'>): Promise<GetLogResponse>
async head(counts: number, from: number, request?: Omit<GetLogRequest, 'from' | 'count'>): Promise<GetLogResponse>

See GetLogRequest for detailed information.

Returns

Promise<GetLogResponse>

setSystemContract

Parameters

Set the system contract id.

tailSystemLog

Retrieve the latest system logs.

Parameters

  • count: number (optional) The number of logs to retrieve. Default is 10.
  • from: number (optional) The start index of logs to retrieve. Default is fetch last 10 records.

Returns

Promise<GetLogResponse>

headSystemLog

Retrieve the oldest system logs.

Parameters

  • count: number (optional) The number of logs to retrieve. Default is 10.
  • from: number (optional) The start index of logs to retrieve. Default is fetch first 10 records.

Returns

Promise<GetLogResponse>

GetLogRequest

The plain object for a query to retrieve logs. It includes following fields:

  • contract: number (optional) Only retrieve logs related to this contract ID.
  • from: number
  • count: number
  • block_number: number (optional) Only retrieve logs for this block number.
  • type: string | string[] (optional) Only retrieve logs of this type. THere are five types of logs: Log, Event, MessageOutput, QueryIn, TooLarge.
  • topic: For Event type of log, you can specified the topic for the contract event. Topic is is readable string look System::Event, the contract name in PascalCase, split by ::, and then the event name.
  • abi: ABI | string (optional) The ABI of the contract. If specified, the SDK will try decode contract log and error with the ABI.
  • nonce: string (optional) The nonce of the in-cluster tranaction. See exec for more details.

GetLogResponse

The plain object for the response of the log query. It includes following fields:

  • logs: SerMessage[]
  • next: number

Depends on different type of logs, SerMessage can be one of following types:

SerMessageLog

  • type: Always Log.
  • seuqence: number
  • blockNumber: number The associated block number of the message.
  • contract: string
  • entry: string
  • execMode: string
  • timestamp: number
  • level: number
  • message: string

SerMessageErrorWithDecoded<TEvent>

  • type: Always Event.
  • seuqence: number
  • blockNumber: number The associated block number of the message.
  • contract: string
  • topics: string[]. If you specified the abi in query, the SDK will try to decode the topics with the ABI.
  • payload: string
  • decoded: DecodedEvent. If you specified the abi in query, the SDK will try to decode the payload with the ABI and provides the decoded event data here.

SerMessageMessageOutput

  • type: Always MessageOutput.
  • seuqence: number
  • blockNumber: number The associated block number of the message.
  • origin: string
  • contract: string
  • nonce: string
  • output
    • gasConsumed
      • refTime: number
      • proofSize: number
    • gasRequired
      • refTime: number
      • proofSize: number
    • storageDeposit
      • charge: number
    • debugMessage: string
    • result: One of Ok and Error.
      • ok:
        • falgs: string[]
        • data: data
      • err
        • module
          • error: string
          • index: number
        • other: string

SerMessageQueryIn

  • type: Always QueryIn.
  • seuqence: number
  • user: string

SerMessageTooLarge

  • type: Always TooLarge.