Skip to content

Commit

Permalink
Renamed ExecutionResultV2 'effect' field to 'effects'. Changes type o…
Browse files Browse the repository at this point in the history
…f 'effects' to a newly introduced type 'TransformV2'. Fixed interface 'Effect' to include 'operations' field
  • Loading branch information
Jakub Zajkowski committed Aug 28, 2024
1 parent 1124678 commit b7c60c3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 9 deletions.
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

0 comments on commit b7c60c3

Please sign in to comment.