Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,195 changes: 337 additions & 858 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
"ts-results": "^3.3.0"
},
"peerDependencies": {
"casper-js-sdk": "^2.12.0"
"casper-js-sdk": "^5.0.11-beta2"
},
"devDependencies": {
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"casper-js-sdk": "^2.12.0",
"casper-js-sdk": "^5.0.11-beta2",
"copy-webpack-plugin": "^11.0.0",
"crypto-browserify": "^3.12.0",
"eslint": "^8.34.0",
Expand Down
35 changes: 0 additions & 35 deletions src/casper/types.ts

This file was deleted.

227 changes: 0 additions & 227 deletions src/casper/utils.ts

This file was deleted.

53 changes: 21 additions & 32 deletions src/event.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { CLValue, decodeBase16, matchByteParserByCLType } from 'casper-js-sdk';
import { WithRemainder } from './casper/types';
import {CLTypeString, CLValue, CLValueParser, Conversions, Hash, IResultWithBytes} from 'casper-js-sdk';

Check failure on line 1 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `CLTypeString,·CLValue,·CLValueParser,·Conversions,·Hash,·IResultWithBytes` with `⏎··CLTypeString,⏎··CLValue,⏎··CLValueParser,⏎··Conversions,⏎··Hash,⏎··IResultWithBytes,⏎`

Check failure on line 1 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `CLTypeString,·CLValue,·CLValueParser,·Conversions,·Hash,·IResultWithBytes` with `⏎··CLTypeString,⏎··CLValue,⏎··CLValueParser,⏎··Conversions,⏎··Hash,⏎··IResultWithBytes,⏎`

Check failure on line 1 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `CLTypeString,·CLValue,·CLValueParser,·Conversions,·Hash,·IResultWithBytes` with `⏎··CLTypeString,⏎··CLValue,⏎··CLValueParser,⏎··Conversions,⏎··Hash,⏎··IResultWithBytes,⏎`

import {
parseBytesWithRemainder,
parseCLValueFromBytesWithRemainder,
} from './casper/utils';
import { Schema, Schemas } from './schema';
import {Schema, Schemas} from './schema';

Check failure on line 3 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `Schema,·Schemas` with `·Schema,·Schemas·`

Check failure on line 3 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `Schema,·Schemas` with `·Schema,·Schemas·`

Check failure on line 3 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `Schema,·Schemas` with `·Schema,·Schemas·`

const EVENT_PREFIX = 'event_';

export interface Event {
name: string;
contractHash: Uint8Array | null;
contractPackageHash: Uint8Array | null;
contractHash: Hash | null;
contractPackageHash: Hash | null;
eventId: number;
data: Record<string, CLValue>;
}

export function parseEventNameWithRemainder(
rawEvent: Uint8Array,
): WithRemainder<string> {
const eventNameWithRemainder = parseBytesWithRemainder(rawEvent);
): IResultWithBytes<string> {
const eventNameWithRemainder = CLValueParser.fromBytesByType(rawEvent, CLTypeString);

Check failure on line 18 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `rawEvent,·CLTypeString` with `⏎····rawEvent,⏎····CLTypeString,⏎··`

Check failure on line 18 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `rawEvent,·CLTypeString` with `⏎····rawEvent,⏎····CLTypeString,⏎··`

Check failure on line 18 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `rawEvent,·CLTypeString` with `⏎····rawEvent,⏎····CLTypeString,⏎··`

const eventNameWithPrefix = new TextDecoder().decode(
eventNameWithRemainder.data,
);
const eventNameWithPrefix = eventNameWithRemainder.result.toString();

if (!eventNameWithPrefix.startsWith(EVENT_PREFIX)) {
throw new Error('no event_ prefix for event');
Expand All @@ -32,8 +26,8 @@
const eventName = eventNameWithPrefix.replace('event_', '');

return {
data: eventName,
remainder: eventNameWithRemainder.remainder,
result: eventName,
bytes: eventNameWithRemainder.bytes,
};
}

Expand All @@ -44,28 +38,28 @@
name: string;
data: Record<string, CLValue>;
} {
const event = decodeBase16(rawEvent);
const event = Conversions.decodeBase16(rawEvent);

const clValueWithRemainder = parseCLValueFromBytesWithRemainder(event);
const clValueWithRemainder = CLValueParser.fromBytesWithType(event);

if (clValueWithRemainder.data.bytes.length < 4) {
if (clValueWithRemainder.result.bytes().length < 4) {
throw new Error('invalid event bytes');
}

const eventNameWithRemainder = parseEventNameWithRemainder(
clValueWithRemainder.data.bytes.subarray(4),
clValueWithRemainder.result.bytes().subarray(4),
);

const eventSchema = schemas[eventNameWithRemainder.data];
const eventSchema = schemas[eventNameWithRemainder.result];
if (!eventSchema) {
throw new Error('event name not in schema');
}

return {
name: eventNameWithRemainder.data,
name: eventNameWithRemainder.result,
data: parseEventDataFromBytes(

Check failure on line 60 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `⏎······eventSchema,⏎······eventNameWithRemainder.bytes,⏎····` with `eventSchema,·eventNameWithRemainder.bytes`

Check failure on line 60 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `⏎······eventSchema,⏎······eventNameWithRemainder.bytes,⏎····` with `eventSchema,·eventNameWithRemainder.bytes`

Check failure on line 60 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `⏎······eventSchema,⏎······eventNameWithRemainder.bytes,⏎····` with `eventSchema,·eventNameWithRemainder.bytes`
eventSchema,
eventNameWithRemainder.remainder,
eventNameWithRemainder.bytes,
),
};
}
Expand All @@ -79,19 +73,14 @@
let remainder = rawBytes;

for (const item of schema) {
const parser = matchByteParserByCLType(item.value).unwrap();

const clValueWithRemainder = parser.fromBytesWithRemainder(
remainder,
item.value,
);
const clValueWithRemainder = CLValueParser.fromBytesByType(remainder, item.value);

Check failure on line 76 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Replace `remainder,·item.value` with `⏎······remainder,⏎······item.value,⏎····`

Check failure on line 76 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `remainder,·item.value` with `⏎······remainder,⏎······item.value,⏎····`

Check failure on line 76 in src/event.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `remainder,·item.value` with `⏎······remainder,⏎······item.value,⏎····`

if (!clValueWithRemainder.remainder) {
if (!clValueWithRemainder.bytes) {
throw new Error('remainder is empty');
}

result[item.property] = clValueWithRemainder.result.unwrap();
remainder = clValueWithRemainder.remainder;
result[item.property] = clValueWithRemainder.result;
remainder = clValueWithRemainder.bytes;
}

return result;
Expand Down
5 changes: 0 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@ export {
parseEventDataFromBytes,
parseEventNameWithRemainder,
} from './event';
export { ExecutionResult } from './casper/types';
export {
parseBytesWithRemainder,
parseCLValueFromBytesWithRemainder,
} from './casper/utils';
Loading
Loading