Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed ExecutionResultV2 'effect' field to 'effects'. Changes type o… #452

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casper-js-sdk",
"version": "3.0.0-rc04",
"version": "3.0.0-rc05",
"license": "Apache 2.0",
"description": "SDK to interact with the Casper blockchain",
"homepage": "https://github.com/casper-ecosystem/casper-js-sdk#README.md",
Expand Down
34 changes: 34 additions & 0 deletions src/services/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { Operation, OpKind } from './types';

chai.use(chaiAsPromised);

describe('CasperServiceByJsonRPC', () => {
it('should deserialize operations', async () => {
let operationRaw = '{"key":"key","kind":"Read"}';
let operation: Operation = JSON.parse(operationRaw);
let expected: Operation = { key: 'key', kind: OpKind.Read };
expect(operation).to.deep.eq(expected);

operationRaw = '{"key":"key2","kind":"Write"}';
operation = JSON.parse(operationRaw);
expected = { key: 'key2', kind: OpKind.Write };
expect(operation).to.deep.eq(expected);

operationRaw = '{"key":"key3","kind":"Add"}';
operation = JSON.parse(operationRaw);
expected = { key: 'key3', kind: OpKind.Add };
expect(operation).to.deep.eq(expected);

operationRaw = '{"key":"key4","kind":"NoOp"}';
operation = JSON.parse(operationRaw);
expected = { key: 'key4', kind: OpKind.NoOp };
expect(operation).to.deep.eq(expected);

operationRaw = '{"key":"key5","kind":"Prune"}';
operation = JSON.parse(operationRaw);
expected = { key: 'key5', kind: OpKind.Prune };
expect(operation).to.deep.eq(expected);
});
});
84 changes: 75 additions & 9 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,97 @@ export type AddKey = {
key: string;
name: string;
};
export type ISeigniorageAllocation =
| {
Validator: {
validator_public_key: string;
amount: string;
};
}
| {
Delegator: {
delegator_public_key: string;
validator_public_key: string;
amount: string;
};
};

export interface EraInfo {
seigniorage_allocations: ISeigniorageAllocation[];
}
export type TransformValue =
| 'Identity'
| 'WriteContractWasm'
| 'WriteContract'
| 'WriteContractPackage'
| {
WriteCLValue: WriteCLValue;
}
| { WriteAccount: string }
| 'WriteContractWasm'
| 'WriteContract'
| 'WriteContractPackage'
| { WriteDeployInfo: WriteDeployInfo }
| { WriteEraInfo: EraInfo }
| { WriteTransfer: WriteTransfer }
| { WriteBid: any } //TODO fill this definition
| { WriteWithdraw: any[] } //TODO fill this definition
| { AddInt32: number }
| { AddUInt64: number }
| { AddUInt128: string }
| { AddUInt256: string }
| { AddUInt512: string }
| { AddKeys: AddKey[] };

interface Transform {
| { AddKeys: AddKey[] }
| { Failure: string }
| { WriteUnbonding: any[] } //TODO fill this definition
| 'WriteAddressableEntity'
| { Prune: string }
| { WriteBidKind: any }; //TODO fill this definition

export interface Transform {
key: string;
transform: TransformValue;
}

interface Effect {
export interface TransformV2 {
key: string;
kind: TransformKindV2;
}

export type TransformKindV2 =
| 'Identity'
| { Write: any }
| { AddInt32: number }
| { AddUInt64: number }
| { AddUInt128: string }
| { AddUInt256: string }
| { AddUInt512: string }
| { AddKeys: NamedKey[] }
| { Prune: string }
| {
Failure:
| 'Deprecated'
| { Serialization: string }
| { TypeMismatch: { expected: string; found: string } };
};

export enum OpKind {
Read = 'Read',
Write = 'Write',
Add = 'Add',
NoOp = 'NoOp',
Prune = 'Prune'
}

export interface Operation {
key: string;
kind: OpKind;
}

export interface Effect {
operations: Operation[];
transforms: Transform[];
}

/** Result interface for an execution result body */
interface ExecutionResultBody {
export interface ExecutionResultBody {
cost: number;
error_message?: string | null;
transfers: string[];
Expand All @@ -200,7 +266,7 @@ export interface ExecutionResultV2 {
cost: string;
payment: { source: string }[];
transfers: any[];
effect: Effect;
effects: TransformV2[];
}

export type ExecutionResult =
Expand Down
Loading