Socket
Socket
Sign inDemoInstall

@make-software/ces-js-parser

Package Overview
Dependencies
61
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @make-software/ces-js-parser

Parser for contract-level events encoded with Casper Event Standard (CES)


Version published
Weekly downloads
160
decreased by-11.6%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

CES JS Parser

@make-software/ces-js-parser parses contract-level events that follow the Casper Event Standard.

The library is built on top of the casper-js-sdk and operates on types defined by the SDK.

Prerequisites

  • Node.js Version: >12.22.10
  • OS: Linux, MacOS

Install

npm install --save @make-software/ces-js-parser

Usage

Here is an example of parsing CES events using ces-js-parser from a real Testnet deploy loaded with casper-js-sdk:

import { CasperServiceByJsonRPC } from 'casper-js-sdk';
import { Parser } from '@make-software/ces-js-parser';

const rpcClient = new CasperServiceByJsonRPC(
  `http://${process.env.NODE_ADDRESS}:7777/rpc`
);

const parser = await Parser.create(rpcClient, [
  '0640eb43bd95d5c88b799862bc9fb42d7a241f1a8aae5deaa03170a27ee8eeaa'
]);

const deploy = await rpcClient.getDeployInfo(
  'c1bb9ae27877f5ecf4ef71307e7ee3c403bcace065565c3645b81ec0a9bc8978'
);

const events = await parser.parseExecutionResult(
  deploy.execution_results[0].result as ExecutionResult
);

events.forEach(console.log);

API

CES JS Parser provides several public types and functions:

Parser

Parser that accepts a list of observed contracts and provides possibility to parse CES events out of deploy execution results

create

create is a async factory function that accepts CasperServiceByJsonRPC and contractHashes array and created a Parser instance:

ArgumentTypeDescription
rpcClientCasperServiceByJsonRPCInstance of the CasperServiceByJsonRPC client
contractHashesstring[]List of the observed contract hashes

Example

import { CasperServiceByJsonRPC } from 'casper-js-sdk';
import { Parser } from '@make-software/ces-js-parser';

const rpcClient = new CasperServiceByJsonRPC(
  `http://${process.env.NODE_ADDRESS}:7777/rpc`
);

const parser = await Parser.create(rpcClient, [
  '214a0e730e14501d1e3e03504d3a2f940ef32830b13fa47f9d85a40f73b78161'
]);
parseExecutionResults

parseExecutionResults method that accepts deploy execution results and returns ParseResult[]:

ArgumentTypeDescription
executionResultsExecutionResultsDeploy execution results
fetchContractSchemasBytes

fetchContractSchemasBytes method that accepts contract hash and return bytes representation of stored schema:

ArgumentTypeDescription
contractHashstringContract hash schema want to be fetched
stateRootHashstringState root hash of the data (takes latest if not provided)

parseSchemasFromBytes

parseSchemasFromBytes function that accepts raw CES schema bytes stored under the contract __events_schema URef and returns Schemas:

ArgumentTypeDescription
rawBytesUint8ArrayRaw contract schemas bytes

parseEventNameAndData

Function that accepts raw event bytes and contract event schemas and returns Event, that contains name and data:

ArgumentTypeDescription
rawEventstringRaw event bytes in hex
schemasSchemasThe list of contract schemas

Example

import { decodeBase16 } from 'casper-js-sdk';
import {
  parseSchemasFromBytes,
  parseEventNameAndData
} from '@make-software/ces-js-parser';

const schemas = parseSchemasFromBytes(rawBytes);
const rawEvent = decodeBase16('some real example here');

const event = parseEventNameAndData(rawEvent, schemas);

Event

Type that represents an event:

PropertyTypeDescription
contractHashUint8ArrayEvent ContractHash
contractPackageHashUint8ArrayEvent ContractHash
namestringEvent name
dataRecord<string,CLValue>Event Data

ParseResult

Value-object that represents a parse result. Contains error representing weather parsing was successful or not.

PropertyTypeDescription
errorstringParse result error
eventEventces Event

Schema

Schema is slice of PropertyDefinition - value-object that represents an schema item.

PropertyTypeDescription
PropertystringName of the schema property
ValueCLTypecasper CLType

Schemas

Schemas represent a map of event name and its Schema.

Tests

To run unit tests for the library, make sure you are in the root of the library:

npm run test

License

This project is licensed under the terms of the Apache-2.0 license.

Contributing

We welcome contributions from anyone interested in improving this project. Before getting started, please take a moment to read our contributing guidelines to learn more about how to contribute to this project, including how to report bugs, suggest enhancements, and submit pull requests.

We look forward to collaborating with you!

Keywords

FAQs

Last updated on 04 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc