Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adjusting types to not require data in action from nodeos response #924

Merged
merged 6 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@
"@blockone/eslint-config-blockone": "^4.0.0",
"@types/elliptic": "^6.4.12",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.43",
"@types/node": "^14.14.45",
"@types/node-fetch": "^2.5.10",
"@types/pako": "^1.0.1",
"buffer": "^6.0.3",
"clean-webpack-plugin": "^3.0.0",
"crypto-browserify": "^3.12.0",
"cypress": "^7.2.0",
"cypress": "^7.3.0",
"eosjs-ecc": "^4.0.7",
"eslint": "^7.25.0",
"eslint": "^7.26.0",
"jest": "^26.6.3",
"jest-extended": "^0.11.5",
"jest-fetch-mock": "^3.0.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.5",
"ts-loader": "^9.1.1",
"ts-jest": "^26.5.6",
"ts-loader": "^9.1.2",
"typescript": "^4.2.4",
"webpack": "^5.36.1",
"webpack-cli": "^4.6.0"
"webpack": "^5.37.0",
"webpack-cli": "^4.7.0"
},
"jest": {
"automock": false,
Expand Down
4 changes: 2 additions & 2 deletions src/eosjs-api-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* copyright defined in eosjs/LICENSE.txt
*/

import { Abi, PushTransactionArgs } from './eosjs-rpc-interfaces';
import { Abi, PushTransactionArgs, ProcessedAction } from './eosjs-rpc-interfaces';
import { Anyvar, Authorization, Action, SerializedAction } from './eosjs-serialize';

/** Arguments to `getRequiredKeys` */
Expand Down Expand Up @@ -128,7 +128,7 @@ export interface ActionTrace {
closest_unnotified_ancestor_action_ordinal: number;
receipt: ActionReceipt;
receiver: string;
act: Action;
act: ProcessedAction;
context_free: boolean;
elapsed: number;
console: string;
Expand Down
2 changes: 1 addition & 1 deletion src/eosjs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
PushTransactionArgs,
GetBlockHeaderStateResult,
GetBlockInfoResult,
GetBlockResult
GetBlockResult,
} from './eosjs-rpc-interfaces';
import * as ser from './eosjs-serialize';

Expand Down
37 changes: 34 additions & 3 deletions src/eosjs-rpc-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* copyright defined in eosjs/LICENSE.txt
*/

import { TransactionReceiptHeader, Transaction } from './eosjs-api-interfaces';
import { TransactionReceiptHeader } from './eosjs-api-interfaces';
import { Authorization } from './eosjs-serialize';

/** Structured format for abis */
Expand Down Expand Up @@ -214,14 +214,35 @@ export interface GetBlockInfoResult {
ref_block_prefix: number;
}

/** Returned action from nodeos, data is optional */
export interface ProcessedAction {
account: string;
name: string;
authorization: Authorization[];
data?: any;
hex_data?: string;
}
export interface ProcessedTransaction {
expiration?: string;
ref_block_num?: number;
ref_block_prefix?: number;
max_net_usage_words?: number;
max_cpu_usage_ms?: number;
delay_sec?: number;
context_free_actions?: ProcessedAction[];
context_free_data?: Uint8Array[];
actions: ProcessedAction[];
transaction_extensions?: [number, string][];
}

export interface PackedTransaction {
id: string;
signatures: string[];
compression: number|string;
packed_context_free_data: string;
context_free_data: string[];
packed_trx: string;
transaction: Transaction;
transaction: ProcessedTransaction;
}

export interface PackedTrx {
Expand Down Expand Up @@ -300,6 +321,15 @@ export interface ProtocolFeatureActivationSet {
protocol_features: string[]
}

export interface SecurityGroupInfo {
version: number;
participants: string[];
}

export interface StateExtension {
security_group_info: SecurityGroupInfo
}

/** Return value of `/v1/chain/get_block_header_state` */
export interface GetBlockHeaderStateResult {
id: string;
Expand All @@ -317,6 +347,7 @@ export interface GetBlockHeaderStateResult {
// valid_block_signing_authority: BlockSigningAuthority;
valid_block_signing_authority: any;
confirm_count: number[];
state_extension: [number, StateExtension];
}

/** Subset of `GetBlockHeaderStateResult` used to calculate TAPoS fields in transactions */
Expand Down Expand Up @@ -413,7 +444,7 @@ export interface GetRawAbiResult {
abi: string;
}

export interface DeferredTransaction extends Transaction {
export interface DeferredTransaction extends ProcessedTransaction {
deferred_transaction_generation?: {
sender_trx_id: string;
sender_id: string;
Expand Down
26 changes: 16 additions & 10 deletions src/tests/type-checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
TraceApiGetBlockResult,
DBSizeGetResult,
} from '../eosjs-rpc-interfaces';
import { TransactResult } from '../eosjs-api-interfaces';
import { Transaction, TransactResult } from '../eosjs-api-interfaces';
import 'jest-extended';

const privateKey = '5JuH9fCXmU3xbj8nRmhPZaVrxxXrdPaRmZLW1cznNTmTQR2Kg5Z';
Expand Down Expand Up @@ -336,7 +336,13 @@ describe('Chain API Plugin Endpoints', () => {
weight: 'number',
},
}],
confirm_count: 'number'
confirm_count: 'number',
state_extension: [ 'number', {
security_group_info: {
version: 'number',
participants: 'string',
},
}]
};
verifyType(result, getBlockHeaderStateResult);
});
Expand Down Expand Up @@ -405,7 +411,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
'context_free_data?': 'number',
Expand All @@ -416,7 +422,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
'transaction_extensions?': {
Expand Down Expand Up @@ -677,7 +683,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
'context_free_data?': 'number',
Expand All @@ -688,7 +694,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
'transaction_extensions?': {
Expand Down Expand Up @@ -752,7 +758,7 @@ describe('Chain API Plugin Endpoints', () => {

it('validates return type of get_required_keys', async () => {
const info = await rpc.get_info();
let transaction: any = {
let transaction: Transaction = {
actions: [{
account: 'eosio.token',
name: 'transfer',
Expand Down Expand Up @@ -846,7 +852,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
context_free: 'boolean',
Expand Down Expand Up @@ -962,7 +968,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
context_free: 'boolean',
Expand Down Expand Up @@ -1059,7 +1065,7 @@ describe('Chain API Plugin Endpoints', () => {
actor: 'string',
permission: 'string',
},
data: 'any',
'data?': 'any',
'hex_data?': 'string',
},
context_free: 'boolean',
Expand Down
Loading