Skip to content

Commit

Permalink
Add specific types for value and gas limit (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Jul 13, 2022
1 parent 22f2967 commit 28fa0eb
Show file tree
Hide file tree
Showing 29 changed files with 142 additions and 117 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/CI-CD-gear-js-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ jobs:
file-url: https://unpkg.com/@gear-js/api@latest/package.json
static-checking: localIsNew

- name: Install dependencies and build @gear-js/api
working-directory: api
run: npm ci

- name: Publish
if: steps.check.outputs.changed == 'true'
working-directory: api
working-directory: api/lib
run: |
export token=$(printenv $(printenv GITHUB_ACTOR))
npm ci
npm config set //registry.npmjs.org/:_authToken=$token
npm publish
env:
Expand Down
18 changes: 9 additions & 9 deletions api/.npmignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.vscode/
node_modules/
src/
examples/
test/
using-examples/
**/tsconfig*
.prettierrc
.tslint.json
.env
babel.*
jest.*
rollup.*

.eslintrc.cjs
.gitignore
babel.config.json
jest.config.js
package-lock.json
examples/
rollup.config.js
tsconfig*
13 changes: 13 additions & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 0.23.3

_07/12/2022_

https://github.com/gear-tech/gear-js/pull/822

### Changes

- Add specific types for gas limit and value
- Update build process

---

## 0.23.2

_07/12/2022_
Expand Down
4 changes: 2 additions & 2 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 11 additions & 14 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@gear-js/api",
"version": "0.23.2",
"version": "0.23.3",
"description": "A JavaScript library that provides functionality to connect GEAR Component APIs.",
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"main": "cjs/index.js",
"module": "index.js",
"types": "index.d.ts",
"type": "module",
"author": "Gear Technologies",
"bugs": {
Expand All @@ -29,15 +29,15 @@
"prepare": "npm run build"
},
"exports": {
"./cjs/package.json": "./lib/cjs/package.json",
"./cjs/*": "./lib/cjs/*.js",
"./cjs/package.json": "./cjs/package.json",
"./cjs/*": "./cjs/*.js",
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/index.d.ts"
"import": "./index.js",
"require": "./cjs/index.js",
"types": "./index.d.ts"
},
"./types": {
"import": "./lib/types/index.d.ts"
"import": "./types/index.d.ts"
}
},
"license": "GPL-3.0",
Expand Down Expand Up @@ -67,8 +67,5 @@
"rollup-plugin-typescript2": "0.31.2",
"ts-jest": "28.0.4",
"typescript": "4.7.3"
},
"files": [
"lib"
]
}
}
18 changes: 14 additions & 4 deletions api/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { writeFileSync } from 'fs';
import { writeFileSync, cpSync } from 'fs';

function writeCjsPackageJson() {
function writePackageJson() {
return {
name: 'write-cjs-package-json',
name: 'write-package-json',
closeBundle() {
writeFileSync('./lib/cjs/package.json', JSON.stringify({ type: 'commonjs' }));
cpSync('./package.json', 'lib/package.json');
},
};
}
function cpReadme() {
return {
name: 'cp-readme',
closeBundle() {
cpSync('./README.md', 'lib/README.md');
},
};
}
Expand Down Expand Up @@ -51,7 +60,8 @@ export default [
json(),
nodeResolve({ preferBuiltins: true, resolveOnly: (module) => !module.includes('polkadot') }),
commonjs(),
writeCjsPackageJson(),
writePackageJson(),
cpReadme(),
],
},
];
7 changes: 4 additions & 3 deletions api/src/Balance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ISystemAccountInfo } from './types/interfaces';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { Balance } from '@polkadot/types/interfaces';
import { BN } from '@polkadot/util';

import { GearTransaction } from './Transaction';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { ISystemAccountInfo } from './types';
import { GearApi } from './GearApi';

export class GearBalance extends GearTransaction {
Expand Down
7 changes: 4 additions & 3 deletions api/src/Blocks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GearApi } from './GearApi';
import { GetBlockError } from './errors';
import { AnyTuple, AnyNumber } from '@polkadot/types/types';
import { u64, Compact, GenericExtrinsic, Vec } from '@polkadot/types';
import { SignedBlock, BlockNumber, BlockHash } from '@polkadot/types/interfaces';
import { FrameSystemEventRecord } from '@polkadot/types/lookup';
import { AnyTuple, AnyNumber } from '@polkadot/types/types';
import { isHex, isU8a } from '@polkadot/util';

import { CreateType } from './create-type';
import { GetBlockError } from './errors';
import { GearApi } from './GearApi';
export class GearBlock {
protected api: GearApi;
constructor(api: GearApi) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/Claim.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ISubmittableResult } from '@polkadot/types/types';

import { GearTransaction } from './Transaction';
import { ClaimValueError } from './errors';
import { Hex } from './types';
import { GearTransaction } from './Transaction';

/**
* Claim value from mailbox
Expand Down
9 changes: 5 additions & 4 deletions api/src/Code.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GearTransaction } from './Transaction';
import { Hex } from './types';
import { Bytes } from '@polkadot/types';
import { generateCodeHash } from './utils';
import { ISubmittableResult } from '@polkadot/types/types';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { Bytes } from '@polkadot/types';

import { GearTransaction } from './Transaction';
import { generateCodeHash } from './utils';
import { Hex } from './types';
export class GearCode extends GearTransaction {
/**
* Submit code without initialization
Expand Down
33 changes: 17 additions & 16 deletions api/src/Gas.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isHex, isString, isU8a, u8aToHex } from '@polkadot/util';
import { Codec } from '@polkadot/types-codec/types';
import { CreateType } from './create-type';

import { GetGasSpentError } from './errors/program.errors';
import { Hex, PayloadType, Value } from './types';
import { Metadata } from './types/interfaces';
import { Hex, PayloadType } from './types';
import { GearApi } from './GearApi';
import { CreateType } from './create-type';
import { createPayload } from './utils';
import { GetGasSpentError } from './errors/program.errors';
import { GearApi } from './GearApi';
import { GasInfo } from './types';

export class GearGas {
Expand Down Expand Up @@ -66,7 +67,7 @@ export class GearGas {
sourceId: Hex,
code: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
meta?: Metadata,
): Promise<GasInfo>;
Expand Down Expand Up @@ -97,7 +98,7 @@ export class GearGas {
sourceId: Hex,
code: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
typeOfPayload?: string,
): Promise<GasInfo>;
Expand All @@ -116,7 +117,7 @@ export class GearGas {
sourceId: Hex,
code: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo>;
Expand All @@ -125,7 +126,7 @@ export class GearGas {
sourceId: Hex,
code: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo> {
Expand Down Expand Up @@ -171,7 +172,7 @@ export class GearGas {
sourceId: Hex,
destinationId: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
meta?: Metadata,
): Promise<GasInfo>;
Expand Down Expand Up @@ -203,7 +204,7 @@ export class GearGas {
sourceId: Hex,
destinationId: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
typeOfPayload?: string,
): Promise<GasInfo>;
Expand All @@ -222,7 +223,7 @@ export class GearGas {
sourceId: Hex,
destinationId: Hex | Buffer,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo>;
Expand All @@ -231,7 +232,7 @@ export class GearGas {
sourceId: Hex,
destinationId: Hex,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo> {
Expand Down Expand Up @@ -275,7 +276,7 @@ export class GearGas {
messageId: Hex,
exitCode: number,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
meta?: Metadata,
): Promise<GasInfo>;
Expand Down Expand Up @@ -311,7 +312,7 @@ export class GearGas {
messageId: Hex,
exitCode: number,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
typeOfPayload?: string,
): Promise<GasInfo>;
Expand All @@ -332,7 +333,7 @@ export class GearGas {
messageId: Hex,
exitCode: number,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo>;
Expand All @@ -342,7 +343,7 @@ export class GearGas {
messageId: Hex,
exitCode: number,
payload: PayloadType,
value?: number | string,
value?: Value,
allowOtherPanics?: boolean,
metaOrTypeOfPayload?: string | Metadata,
): Promise<GasInfo> {
Expand Down
2 changes: 1 addition & 1 deletion api/src/GearApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
import { Event } from '@polkadot/types/interfaces';

import { GearMessageReply } from './MessageReply';
import { GearApiOptions } from './types/interfaces';
import { gearRpc, gearTypes } from './default';
import { GearProgramState } from './State';
import { GearWaitlist } from './Waitlist';
import { GearClaimValue } from './Claim';
import { GearApiOptions } from './types';
import { GearProgram } from './Program';
import { GearStorage } from './Storage';
import { GearMailbox } from './Mailbox';
Expand Down
7 changes: 4 additions & 3 deletions api/src/Keyring.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair, KeyringPair$Json } from '@polkadot/keyring/types';
import { hexToU8a, isU8a, stringToU8a, isString, u8aToHex } from '@polkadot/util';
import { mnemonicGenerate, mnemonicToMiniSecret, signatureVerify } from '@polkadot/util-crypto';
import { hexToU8a, isU8a, stringToU8a, isString, u8aToHex } from '@polkadot/util';
import { KeyringPair, KeyringPair$Json } from '@polkadot/keyring/types';
import { Keypair } from '@polkadot/util-crypto/types';
import { waitReady } from '@polkadot/wasm-crypto';
import { Keyring } from '@polkadot/api';

import { Hex } from './types';

export class GearKeyring {
Expand Down
8 changes: 4 additions & 4 deletions api/src/Mailbox.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GearApi } from './GearApi';
import { StoredMessage } from './types';
import { MailboxRecord, Hex } from './types';
import { Option } from '@polkadot/types';
import { AccountId32, H256 } from '@polkadot/types/interfaces';
import { UnsubscribePromise } from '@polkadot/api/types';
import { Option } from '@polkadot/types';

import { MailboxRecord, Hex, StoredMessage } from './types';
import { GearClaimValue } from './Claim';
import { GearApi } from './GearApi';

export class GearMailbox {
api: GearApi;
Expand Down
Loading

0 comments on commit 28fa0eb

Please sign in to comment.