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

Commit

Permalink
Merge pull request #826 from EOSIO/additional_types_endpoints
Browse files Browse the repository at this point in the history
Additional types for JsonRPC endpoints
  • Loading branch information
Brad Hart authored Feb 10, 2021
2 parents 6067080 + 64353e0 commit 8065061
Show file tree
Hide file tree
Showing 20 changed files with 2,120 additions and 200 deletions.
8 changes: 4 additions & 4 deletions .github/eosjs-ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
### Current Version: v0.2.8
### Current Version: v0.2.9
### Test:
#### docker build --tag eosjs-ci:test ./.github/eosjs-ci
#### docker run --publish 8888:8888 eosjs-ci:test
### Deploy:
#### docker build --tag eosio/eosjs-ci:v0.2.8 ./.github/eosjs-ci
#### docker push eosio/eosjs-ci:v0.2.8
#### docker build --tag eosio/eosjs-ci:v0.2.9 ./.github/eosjs-ci
#### docker push eosio/eosjs-ci:v0.2.9

FROM ubuntu:18.04
ENTRYPOINT ["nodeos", "--data-dir", "/root/.local/share", "-e", "-p", "eosio", "--replay-blockchain", "--plugin", "eosio::producer_plugin", "--plugin", "eosio::chain_api_plugin", "--plugin", "eosio::http_plugin", "--http-server-address=0.0.0.0:8888", "--access-control-allow-origin=*", "--contracts-console", "--http-validate-host=false", "--verbose-http-errors", "--max-transaction-time=100"]
ENTRYPOINT ["nodeos", "--data-dir", "/root/.local/share", "-e", "-p", "eosio", "--replay-blockchain", "--plugin", "eosio::producer_plugin", "--plugin", "eosio::chain_api_plugin", "--plugin", "eosio::trace_api_plugin", "--trace-no-abis", "--plugin", "eosio::db_size_api_plugin", "--plugin", "eosio::http_plugin", "--http-server-address=0.0.0.0:8888", "--access-control-allow-origin=*", "--contracts-console", "--http-validate-host=false", "--enable-account-queries=true", "--verbose-http-errors", "--max-transaction-time=100"]

### base
RUN yes | unminimize \
Expand Down
23 changes: 23 additions & 0 deletions .github/eosjs-ci/scripts/deploy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ if [ -z "$NODEOS_RUNNING" ]; then
--http-validate-host=false \
--plugin eosio::producer_api_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::trace_api_plugin \
--trace-no-abis \
--plugin eosio::db_size_api_plugin \
--plugin eosio::http_plugin \
--http-server-address=0.0.0.0:8888 \
--access-control-allow-origin=* \
--contracts-console \
--enable-account-queries=true \
--max-transaction-time=100000 \
--verbose-http-errors &
fi
Expand All @@ -147,6 +151,15 @@ cleos wallet import --private-key $EXAMPLE_ACCOUNT_PRIVATE_KEY
cleos wallet import --private-key $R1_EXAMPLE_ACCOUNT_PRIVATE_KEY
cleos wallet import --private-key $CFHELLO_PRIVATE_KEY
cleos wallet import --private-key $CFACTOR_PRIVATE_KEY
cleos create account eosio eosio.bpay $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.msig $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.names $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.ram $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.ramfee $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.saving $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.stake $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.vpay $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.rex $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio eosio.token $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio returnvalue $SYSTEM_ACCOUNT_PUBLIC_KEY
cleos create account eosio todo $SYSTEM_ACCOUNT_PUBLIC_KEY
Expand Down Expand Up @@ -189,6 +202,14 @@ sleep 1s
cleos push action eosio setkvparams '[{"max_key_size":1024, "max_value_size":4096, "max_iterators":1024}]' -p eosio@active
cleos push action eosio setpparams '["01110000400100000000"]' -p eosio@active

sleep 1s
setabi eosio $CONTRACTS_DIR/eosio.system/eosio.system.abi
setcode eosio $CONTRACTS_DIR/eosio.system/eosio.system.wasm

sleep 1s
setabi eosio.msig $CONTRACTS_DIR/eosio.msig/eosio.msig.abi
setcode eosio.msig $CONTRACTS_DIR/eosio.msig/eosio.msig.wasm

sleep 1s
setabi cfhello $CONTRACTS_DIR/cfhello/cfhello.abi
setcode cfhello $CONTRACTS_DIR/cfhello/cfhello.wasm
Expand Down Expand Up @@ -216,6 +237,8 @@ cleos push action todo upsert '["bf581bee-9f2c-447b-94ad-78e4984b6f51", "todo",
cleos push action todo upsert '["b7b0d09d-a82b-44d9-b067-3bae2d02917e", "todo", "Start Blockchain", false]' -p todo@active
cleos push action todo upsert '["ac8acfe7-cd4e-4d22-8400-218b697a4517", "todo", "Deploy Hello World Contract", false]' -p todo@active

cleos push action eosio init '[0, "4,SYS"]' -p eosio@active

echo "All done initializing the blockchain"

if [[ -z $NODEOS_RUNNING ]]; then
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Test Node
run: |
yarn test-node
- name: Test Types
run: |
yarn test-types
- name: Build
run: |
yarn build-web
Expand All @@ -73,7 +76,7 @@ jobs:
git push origin ${GITHUB_REF#refs/*/}
services:
nodeos:
image: eosio/eosjs-ci:v0.2.8
image: eosio/eosjs-ci:v0.2.9

ports:
- 8888:8888
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Test Node
run: |
yarn test-node
- name: Test Types
run: |
yarn test-types
- name: Build
run: |
yarn build-web
Expand All @@ -58,7 +61,7 @@ jobs:

services:
nodeos:
image: eosio/eosjs-ci:v0.2.8
image: eosio/eosjs-ci:v0.2.9

ports:
- 8888:8888
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Test Node
run: |
yarn test-node
- name: Test Types
run: |
yarn test-types
- name: Build
run: |
yarn build-web
Expand All @@ -57,7 +60,7 @@ jobs:

services:
nodeos:
image: eosio/eosjs-ci:v0.2.8
image: eosio/eosjs-ci:v0.2.9

ports:
- 8888:8888
Expand Down Expand Up @@ -98,6 +101,9 @@ jobs:
- name: Test Node
run: |
yarn test-node
- name: Test Types
run: |
yarn test-types
- name: Build
run: |
yarn build-web
Expand All @@ -117,7 +123,7 @@ jobs:

services:
nodeos:
image: eosio/eosjs-ci:v0.2.8
image: eosio/eosjs-ci:v0.2.9

ports:
- 8888:8888
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
"test": "jest src/tests/*eosjs*",
"test-node": "jest src/tests/*node*",
"test-all": "yarn test && yarn test-node && yarn cypress",
"test-types": "jest src/tests/type-checks.test.ts",
"test-all": "yarn test && yarn test-node && yarn test-types && yarn cypress",
"build": "rimraf dist && tsc -p ./tsconfig.json && node scripts/copy-ripe-md.js",
"build-web": "webpack --config webpack.prod.js && webpack --config webpack.debug.js",
"build-production": "yarn build && yarn build-web && yarn test-all",
Expand All @@ -36,17 +37,19 @@
"@types/elliptic": "^6.4.12",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.25",
"@types/node-fetch": "^2.5.8",
"@types/pako": "^1.0.1",
"clean-webpack-plugin": "^3.0.0",
"cypress": "^6.4.0",
"eosjs-ecc": "^4.0.7",
"eslint": "^6.8.0",
"jest": "^26.6.3",
"jest-extended": "^0.11.5",
"jest-fetch-mock": "^3.0.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.1",
"ts-loader": "^8.0.16",
"typescript": "^3.9.8",
"ts-loader": "^8.0.17",
"typescript": "^3.9.9",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
Expand All @@ -55,6 +58,9 @@
"setupFiles": [
"./src/tests/setupJest.js"
],
"setupFilesAfterEnv": [
"jest-extended"
],
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down
6 changes: 3 additions & 3 deletions src/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PrivateKey {
}

/** Export private key as `elliptic`-format private key */
public toElliptic() {
public toElliptic(): EC.KeyPair {
return this.ec.keyFromPrivate(this.key.data);
}

Expand Down Expand Up @@ -67,10 +67,10 @@ export class PrivateKey {
}
let tries = 0;
let signature: Signature;
const isCanonical = (sigData: Uint8Array) =>
const isCanonical = (sigData: Uint8Array): boolean =>
!(sigData[1] & 0x80) && !(sigData[1] === 0 && !(sigData[2] & 0x80))
&& !(sigData[33] & 0x80) && !(sigData[33] === 0 && !(sigData[34] & 0x80));
const constructSignature = (options: EC.SignOptions) => {
const constructSignature = (options: EC.SignOptions): Signature => {
const ellipticPrivateKey = this.toElliptic();
const ellipticSignature = ellipticPrivateKey.sign(data, options);
return Signature.fromElliptic(ellipticSignature, this.getType(), this.ec);
Expand Down
22 changes: 11 additions & 11 deletions src/eosjs-api-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

/** Arguments to `getRequiredKeys` */
export interface AuthorityProviderArgs {
Expand Down Expand Up @@ -73,11 +72,6 @@ export interface SignatureProvider {
sign: (args: SignatureProviderArgs) => Promise<PushTransactionArgs>;
}

export interface Extension {
type: number;
data: string;
}

export interface Transaction {
expiration?: string;
ref_block_num?: number;
Expand All @@ -88,7 +82,7 @@ export interface Transaction {
context_free_actions?: Action[];
context_free_data?: Uint8Array[];
actions: Action[];
transaction_extensions?: Extension[];
transaction_extensions?: [number, string][];
}

/** Optional transact configuration object */
Expand All @@ -102,6 +96,12 @@ export interface TransactConfig {
expireSeconds?: number;
}

export interface TransactionHeader {
expiration: string;
ref_block_num: number;
ref_block_prefix: number;
}

export interface AccountDelta {
account: string;
delta: number;
Expand All @@ -117,7 +117,7 @@ export interface ActionReceipt {
act_digest: string;
global_sequence: number;
recv_sequence: number;
auth_sequence: AuthSequence[];
auth_sequence: [ string, number ][];
code_sequence: number;
abi_sequence: number;
}
Expand All @@ -140,10 +140,10 @@ export interface ActionTrace {
account_disk_deltas: AccountDelta[];
except: any;
error_code: number|null;
return_value: any;
return_value_hex?: string;
return_value?: any;
return_value_hex_data?: string;
return_value_data?: any;
inline_traces: ActionTrace[];
inline_traces?: ActionTrace[];
}

export interface TransactionReceiptHeader {
Expand Down
19 changes: 9 additions & 10 deletions src/eosjs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
GetBlockResult
} from './eosjs-rpc-interfaces';
import * as ser from './eosjs-serialize';
import { RpcError } from './eosjs-rpcerror';

const transactionAbi = require('../src/transaction.abi.json');

Expand Down Expand Up @@ -390,7 +389,7 @@ export class Api {
signatures,
compression: 0,
serializedTransaction
});
}) as any;

const returnBuffer = new ser.SerialBuffer({
textEncoder: this.textEncoder,
Expand Down Expand Up @@ -436,7 +435,7 @@ export class Api {
blocksBehind: number | undefined,
useLastIrreversible: boolean | undefined,
expireSeconds: number
) {
): Promise<Transaction> {
if (!info) {
info = await this.rpc.get_info();
}
Expand All @@ -447,7 +446,7 @@ export class Api {

const taposBlockNumber: number = info.head_block_num - blocksBehind;

const refBlock: GetBlockHeaderStateResult | GetBlockResult =
const refBlock: GetBlockHeaderStateResult | GetBlockResult | GetBlockInfoResult =
taposBlockNumber <= info.last_irreversible_block_num
? await this.tryGetBlockInfo(taposBlockNumber)
: await this.tryGetBlockHeaderState(taposBlockNumber);
Expand All @@ -456,11 +455,11 @@ export class Api {
}

// eventually break out into TransactionValidator class
private hasRequiredTaposFields({ expiration, ref_block_num, ref_block_prefix }: any): boolean {
private hasRequiredTaposFields({ expiration, ref_block_num, ref_block_prefix }: Transaction): boolean {
return !!(expiration && typeof(ref_block_num) === 'number' && typeof(ref_block_prefix) === 'number');
}

private async tryGetBlockHeaderState(taposBlockNumber: number): Promise<GetBlockHeaderStateResult | GetBlockResult>
private async tryGetBlockHeaderState(taposBlockNumber: number): Promise<GetBlockHeaderStateResult | GetBlockResult | GetBlockInfoResult>
{
try {
return await this.rpc.get_block_header_state(taposBlockNumber);
Expand Down Expand Up @@ -502,7 +501,7 @@ export class Api {
return new ActionBuilder(this, accountName);
}

public buildTransaction(cb?: (tx: TransactionBuilder) => void) {
public buildTransaction(cb?: (tx: TransactionBuilder) => void): TransactionBuilder|void {
const tx = new TransactionBuilder(this);
if (cb) {
return cb(tx);
Expand All @@ -514,7 +513,7 @@ export class Api {
export class TransactionBuilder {
private api: Api;
private actions: ActionBuilder[] = [];
private contextFreeGroups: any[] = [];
private contextFreeGroups: ContextFreeGroupCallback[] = [];
constructor(api: Api) {
this.api = api;
}
Expand All @@ -525,7 +524,7 @@ export class TransactionBuilder {
return actionBuilder;
}

public associateContextFree(contextFreeGroup: ContextFreeGroupCallback) {
public associateContextFree(contextFreeGroup: ContextFreeGroupCallback): TransactionBuilder {
this.contextFreeGroups.push(contextFreeGroup);
return this;
}
Expand Down Expand Up @@ -571,7 +570,7 @@ export class ActionBuilder {
this.accountName = accountName;
}

public as(actorName: string | ser.Authorization[] = []) {
public as(actorName: string | ser.Authorization[] = []): ActionSerializerType {
let authorization: ser.Authorization[] = [];
if (actorName && typeof actorName === 'string') {
authorization = [{ actor: actorName, permission: 'active'}];
Expand Down
8 changes: 4 additions & 4 deletions src/eosjs-ecc-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {KeyType} from './eosjs-numeric';
import {ec as EC} from 'elliptic';

export const ecc = {
initialize: () => console.error('Method deprecated'),
unsafeRandomKey: () => console.error('Method deprecated'),
initialize: (): void => console.error('Method deprecated'),
unsafeRandomKey: (): void => console.error('Method deprecated'),
randomKey: (
cpuEntropyBits?: number, options: { secureEnv?: boolean, ecOptions?: EC.GenKeyPairOptions } = {}
): Promise<string> => {
Expand All @@ -17,7 +17,7 @@ export const ecc = {
const { privateKey } = generateKeyPair(KeyType.k1, options);
return Promise.resolve(privateKey.toLegacyString());
},
seedPrivate: () => console.error('Method deprecated'),
seedPrivate: (): void => console.error('Method deprecated'),
privateToPublic: (key: string, pubkey_prefix?: string): string => {
if (pubkey_prefix !== undefined) {
console.warn('Argument `pubkey_prefix` is deprecated, ' +
Expand Down Expand Up @@ -54,7 +54,7 @@ export const ecc = {
const signature = privKey.sign(data, true, encoding);
return signature.toString();
},
signHash: (dataSha256: string|Buffer, privateKey: string|PrivateKey, encoding: BufferEncoding = 'hex') => {
signHash: (dataSha256: string|Buffer, privateKey: string|PrivateKey, encoding: BufferEncoding = 'hex'): string => {
const privKey = typeof privateKey === 'string' ? PrivateKey.fromString(privateKey) : privateKey;
const signature = privKey.sign(dataSha256, false, encoding);
return signature.toString();
Expand Down
Loading

0 comments on commit 8065061

Please sign in to comment.