1
- # JS CES Parser
1
+ # CES JS Parser
2
2
3
- ` @make-software/ces-js-parser ` parses contract-level events that follow
4
- the [ Casper Event Standard] ( https://github.com/make-software/casper-event-standard ) .
3
+ ` @make-software/ces-js-parser ` parses contract-level events that follow the [ Casper Event Standard] ( https://github.com/make-software/casper-event-standard ) .
5
4
6
5
The library is built on top of the [ casper-js-sdk] ( https://github.com/casper-ecosystem/casper-js-sdk ) and operates on types defined by the SDK.
7
6
8
7
## Install
9
8
10
- ``
11
- npm install --save @make-software/ces-js-parser
12
- ``
9
+ ` npm install --save @make-software/ces-js-parser `
13
10
14
11
## Usage
15
12
16
- Here is an example of parsing CES events using ` ces-js-parser ` from a real Testnet deploy loaded
17
- with ` casper-js-sdk ` :
13
+ Here is an example of parsing CES events using ` ces-js-parser ` from a real Testnet deploy loaded with ` casper-js-sdk ` :
18
14
19
15
``` typescript
20
16
import { CasperServiceByJsonRPC } from ' casper-js-sdk' ;
21
17
import { Parser } from ' @make-software/ces-js-parser' ;
22
18
23
- const rpcClient = new CasperServiceByJsonRPC (
24
- ` http://${process .env .NODE_ADDRESS }:7777/rpc ` ,
19
+ const rpcClient = new CasperServiceByJsonRPC (
20
+ ` http://${process .env .NODE_ADDRESS }:7777/rpc `
25
21
);
26
22
27
23
const parser = await Parser .create (rpcClient , [
28
- ' 214a0e730e14501d1e3e03504d3a2f940ef32830b13fa47f9d85a40f73b78161' ,
24
+ ' 214a0e730e14501d1e3e03504d3a2f940ef32830b13fa47f9d85a40f73b78161'
29
25
]);
30
26
31
- const deploy = await rpcClient .getDeployInfo (' 19ee17d9e3b4c1527b433598e647b69aa9a153864eb12433489f99224bfc9442' );
27
+ const deploy = await rpcClient .getDeployInfo (
28
+ ' 19ee17d9e3b4c1527b433598e647b69aa9a153864eb12433489f99224bfc9442'
29
+ );
32
30
33
31
const events = await parser .parseExecutionResult (
34
- deploy .execution_results [0 ].result as ExecutionResult ,
32
+ deploy .execution_results [0 ].result as ExecutionResult
35
33
);
36
34
37
35
events .forEach (console .log );
38
36
```
39
37
40
38
## API
41
39
42
- JS CES Parser provides several public types and functions:
40
+ CES JS Parser provides several public types and functions:
43
41
44
- - [ JS CES Parser] ( #js- ces-parser )
42
+ - [ CES JS Parser] ( #ces-js -parser )
45
43
- [ Install] ( #install )
46
44
- [ Usage] ( #usage )
47
45
- [ API] ( #api )
@@ -59,17 +57,16 @@ JS CES Parser provides several public types and functions:
59
57
60
58
### ` Parser `
61
59
62
- Parser that accepts a list of observed contracts and provides possibility to parse CES events out of deploy execution
63
- results
60
+ Parser that accepts a list of observed contracts and provides possibility to parse CES events out of deploy execution results
64
61
65
62
#### ` create `
66
63
67
64
` create ` is a async factory function that accepts ` CasperServiceByJsonRPC ` and ` contractHashes ` array and created a ` Parser ` instance:
68
65
69
- | Argument | Type | Description |
70
- | ---------------- | ------------------------ | -------------------------------------------- --- |
71
- | ` rpcClient ` | ` CasperServiceByJsonRPC ` | Instance of the ` CasperServiceByJsonRPC ` client |
72
- | ` contractHashes ` | ` string[] ` | List of the observed contract hashes |
66
+ | Argument | Type | Description |
67
+ | --- | --- | --- |
68
+ | ` rpcClient ` | ` CasperServiceByJsonRPC ` | Instance of the ` CasperServiceByJsonRPC ` client |
69
+ | ` contractHashes ` | ` string[] ` | List of the observed contract hashes |
73
70
74
71
** Example**
75
72
@@ -78,11 +75,11 @@ import { CasperServiceByJsonRPC } from 'casper-js-sdk';
78
75
import { Parser } from ' @make-software/ces-js-parser' ;
79
76
80
77
const rpcClient = new CasperServiceByJsonRPC (
81
- ` http://${process .env .NODE_ADDRESS }:7777/rpc ` ,
78
+ ` http://${process .env .NODE_ADDRESS }:7777/rpc `
82
79
);
83
80
84
81
const parser = await Parser .create (rpcClient , [
85
- ' 214a0e730e14501d1e3e03504d3a2f940ef32830b13fa47f9d85a40f73b78161' ,
82
+ ' 214a0e730e14501d1e3e03504d3a2f940ef32830b13fa47f9d85a40f73b78161'
86
83
]);
87
84
```
88
85
@@ -98,15 +95,14 @@ const parser = await Parser.create(rpcClient, [
98
95
99
96
` fetchContractSchemasBytes ` method that accepts contract hash and return bytes representation of stored schema:
100
97
101
- | Argument | Type | Description |
102
- | --------------- | -------- | ------------------------------------------------------- --- |
103
- | ` contractHash ` | ` string ` | Contract hash schema want to be fetched |
98
+ | Argument | Type | Description |
99
+ | --- | --- | --- |
100
+ | ` contractHash ` | ` string ` | Contract hash schema want to be fetched |
104
101
| ` stateRootHash ` | ` string ` | State root hash of the data (takes latest if not provided) |
105
102
106
103
### ` parseSchemasFromBytes `
107
104
108
- ` parseSchemasFromBytes ` function that accepts raw CES schema bytes stored under the contract ` __events_schema ` URef and
109
- returns ` Schemas ` :
105
+ ` parseSchemasFromBytes ` function that accepts raw CES schema bytes stored under the contract ` __events_schema ` URef and returns ` Schemas ` :
110
106
111
107
| Argument | Type | Description |
112
108
| ---------- | ------------ | -------------------------- |
@@ -125,10 +121,13 @@ Function that accepts raw event bytes and contract event schemas and returns `Ev
125
121
126
122
``` typescript
127
123
import { decodeBase16 } from ' casper-js-sdk' ;
128
- import { parseSchemasFromBytes , parseEventNameAndData } from ' @make-software/ces-js-parser' ;
124
+ import {
125
+ parseSchemasFromBytes ,
126
+ parseEventNameAndData
127
+ } from ' @make-software/ces-js-parser' ;
129
128
130
129
const schemas = parseSchemasFromBytes (rawBytes );
131
- const rawEvent = decodeBase16 (" some real example here" )
130
+ const rawEvent = decodeBase16 (' some real example here' );
132
131
133
132
const event = parseEventNameAndData (rawEvent , schemas );
134
133
```
@@ -137,12 +136,12 @@ const event = parseEventNameAndData(rawEvent, schemas);
137
136
138
137
Type that represents an event:
139
138
140
- | Property | Type | Description |
141
- | --------------------- | ------------------------ | --------------- --- |
142
- | ` contractHash ` | ` Uint8Array ` | Event ContractHash |
143
- | ` contractPackageHash ` | ` Uint8Array ` | Event ContractHash |
144
- | ` name ` | ` string ` | Event name |
145
- | ` data ` | ` Record<string,CLValue> ` | Event Data |
139
+ | Property | Type | Description |
140
+ | --- | --- | --- |
141
+ | ` contractHash ` | ` Uint8Array ` | Event ContractHash |
142
+ | ` contractPackageHash ` | ` Uint8Array ` | Event ContractHash |
143
+ | ` name ` | ` string ` | Event name |
144
+ | ` data ` | ` Record<string,CLValue> ` | Event Data |
146
145
147
146
### ` ParseResult `
148
147
@@ -170,6 +169,4 @@ Schemas represent a map of event name and its Schema.
170
169
171
170
To run unit tests for the library, make sure you are in the root of the library:
172
171
173
- ``
174
- npm run test
175
- ``
172
+ ` npm run test `
0 commit comments