* 1.4.2

* Actual version bump

* Rework api.tx decoratation (with tests)
This commit is contained in:
Jaco Greeff
2020-02-27 11:16:23 +01:00
committed by GitHub
parent e199a9b11a
commit d531dd374f
20 changed files with 97 additions and 75 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
"keywords": [
@@ -27,9 +27,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/api": "1.5.0-beta.5",
"@polkadot/rpc-core": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/api": "1.4.2",
"@polkadot/rpc-core": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"bn.js": "^5.1.1",
"rxjs": "^6.5.4"
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
"keywords": [
@@ -28,10 +28,10 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/api": "1.5.0-beta.5",
"@polkadot/rpc-core": "1.5.0-beta.5",
"@polkadot/rpc-provider": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/api": "1.4.2",
"@polkadot/rpc-core": "1.4.2",
"@polkadot/rpc-provider": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"bn.js": "^5.1.1",
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
"main": "index.js",
"keywords": [
@@ -27,12 +27,12 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/api-derive": "1.5.0-beta.5",
"@polkadot/api-derive": "1.4.2",
"@polkadot/keyring": "^2.5.1",
"@polkadot/metadata": "1.5.0-beta.5",
"@polkadot/rpc-core": "1.5.0-beta.5",
"@polkadot/rpc-provider": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/metadata": "1.4.2",
"@polkadot/rpc-core": "1.4.2",
"@polkadot/rpc-provider": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"bn.js": "^5.1.1",
+2 -2
View File
@@ -8,7 +8,7 @@ import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collectiv
import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
import { Vote } from '@polkadot/types/interfaces/elections';
import { Signature } from '@polkadot/types/interfaces/extrinsics';
import { Extrinsic, Signature } from '@polkadot/types/interfaces/extrinsics';
import { IdentityFields, IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity';
import { Heartbeat } from '@polkadot/types/interfaces/imOnline';
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment } from '@polkadot/types/interfaces/runtime';
@@ -1624,7 +1624,7 @@ declare module '@polkadot/api/types/submittable' {
}
export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
(extrinsic: Uint8Array | string): SubmittableExtrinsic<ApiType>;
(extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;
[index: string]: SubmittableModuleExtrinsics<ApiType>;
}
}
+9 -3
View File
@@ -48,7 +48,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
protected _derive?: ReturnType<Decorate<ApiType>['decorateDerive']>;
protected _extrinsics: SubmittableExtrinsics<ApiType> = {} as SubmittableExtrinsics<ApiType>;
protected _extrinsics?: SubmittableExtrinsics<ApiType>;
protected _extrinsicType: number = EXTRINSIC_DEFAULT_VERSION;
@@ -160,13 +160,19 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
public injectMetadata (metadata: Metadata, fromEmpty?: boolean): void {
const decoratedMeta = new DecoratedMeta(this.registry, metadata);
if (fromEmpty || !this._extrinsics) {
this._extrinsics = this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod);
this._rx.tx = this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod);
} else {
augmentObject('tx', this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod), this._extrinsics, false);
augmentObject('', this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod), this._rx.tx, false);
}
// this API
augmentObject('tx', this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod), this._extrinsics, fromEmpty);
augmentObject('query', this.decorateStorage(decoratedMeta.query, this.decorateMethod), this._query, fromEmpty);
augmentObject('consts', decoratedMeta.consts, this._consts, fromEmpty);
// rx
augmentObject('', this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod), this._rx.tx, fromEmpty);
augmentObject('', this.decorateStorage(decoratedMeta.query, this.rxDecorateMethod), this._rx.query, fromEmpty);
augmentObject('', decoratedMeta.consts, this._rx.consts, fromEmpty);
}
+29 -16
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiOptions } from '../types';
import { ApiOptions, SubmittableExtrinsic } from '../types';
import createPair from '@polkadot/keyring/pair';
import testKeyring from '@polkadot/keyring/testing';
@@ -13,6 +13,8 @@ import { hexToU8a } from '@polkadot/util';
import { SingleAccountSigner } from '../../test/util';
import ApiPromise from './Api';
const TRANSFER_SIG = '0x62bfcd07a9f50ba32ed9e2c41ca11267ac62a24c95949e25efdccc4989d48573f84754dbbaa1d0937ceb888ad8a2cf71daced1545a839d9d6cceac33a5771401';
describe('ApiPromise', (): void => {
const registry = new TypeRegistry();
const keyring = testKeyring({ type: 'ed25519' });
@@ -25,6 +27,23 @@ describe('ApiPromise', (): void => {
);
let provider: Mock;
async function createTransfer (): Promise<{ api: ApiPromise; transfer: SubmittableExtrinsic<'promise'> }> {
provider.subscriptions.state_subscribeStorage.lastValue = {
changes: [
[
'0x26aa394eea5630e07c48ae0c9558cef79c2f82b23e5fd031fb54c292794b4cc4d560eb8d00e57357cf76492334e43bb2ecaa9f28df6a8c4426d7b6090f7ad3c9',
'0x00'
]
]
};
const signer = new SingleAccountSigner(registry, aliceEd);
const api = await ApiPromise.create({ provider, registry, signer });
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321_564_789_876_512_345n);
return { api, transfer: await transfer.signAsync(aliceEd.address, {}) };
}
beforeEach((): void => {
jest.setTimeout(3000000);
provider = new Mock(registry);
@@ -110,24 +129,18 @@ describe('ApiPromise', (): void => {
describe('decorator.signAsync', (): void => {
it('signs a transfer using an external signer', async (): Promise<void> => {
provider.subscriptions.state_subscribeStorage.lastValue = {
changes: [
[
'0x26aa394eea5630e07c48ae0c9558cef79c2f82b23e5fd031fb54c292794b4cc4d560eb8d00e57357cf76492334e43bb2ecaa9f28df6a8c4426d7b6090f7ad3c9',
'0x00'
]
]
};
const { transfer } = await createTransfer();
const signer = new SingleAccountSigner(registry, aliceEd);
const api = await ApiPromise.create({ provider, registry, signer });
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321_564_789_876_512_345n);
expect(transfer.signature.toHex()).toEqual(TRANSFER_SIG);
});
});
await transfer.signAsync(aliceEd.address, {});
describe('api.tx(...)', (): void => {
it('allows construction from existing extrinsic', async (): Promise<void> => {
const { api, transfer } = await createTransfer();
expect(transfer.signature.toHex()).toEqual(
'0x62bfcd07a9f50ba32ed9e2c41ca11267ac62a24c95949e25efdccc4989d48573f84754dbbaa1d0937ceb888ad8a2cf71daced1545a839d9d6cceac33a5771401'
);
expect(api.tx(transfer.toHex()).signature.toHex()).toEqual(TRANSFER_SIG);
expect(api.tx(transfer).signature.toHex()).toEqual(TRANSFER_SIG);
});
});
});
+4 -4
View File
@@ -3,7 +3,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Address, Call, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { Address, Call, Extrinsic, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { Callback, Codec, Constructor, IKeyringPair, Registry, SignatureOptions, ISubmittableResult } from '@polkadot/types/types';
import { ApiInterfaceRx, ApiTypes, SignerResult } from '../types';
import { AddressOrPair, SignerOptions, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultResult, SubmittableResultSubscription, SubmittableThis } from './types';
@@ -31,12 +31,12 @@ const DEFAULT_MORTAL_LENGTH = 5 * ONE_MINUTE;
export default function createClass <ApiType extends ApiTypes> ({ api, apiType, decorateMethod }: SubmittableOptions<ApiType>): Constructor<SubmittableExtrinsic<ApiType>> {
// an instance of the base extrinsic for us to extend
const Extrinsic = api.registry.createClass('Extrinsic');
const ExtrinsicBase = api.registry.createClass('Extrinsic');
return class Submittable extends Extrinsic implements SubmittableExtrinsic<ApiType> {
return class Submittable extends ExtrinsicBase implements SubmittableExtrinsic<ApiType> {
readonly #ignoreStatusCb: boolean;
constructor (registry: Registry, extrinsic: Call | Uint8Array | string) {
constructor (registry: Registry, extrinsic: Call | Extrinsic | Uint8Array | string) {
super(registry, extrinsic, { version: api.extrinsicType });
this.#ignoreStatusCb = apiType === 'rxjs';
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Call } from '@polkadot/types/interfaces';
import { Call, Extrinsic } from '@polkadot/types/interfaces';
import { Constructor } from '@polkadot/types/types';
import { ApiInterfaceRx, ApiTypes } from '../types';
import { SubmittableExtrinsic } from './types';
@@ -15,7 +15,7 @@ type Creator<ApiType extends ApiTypes> = (extrinsic: Call | Uint8Array | string)
let Submittable: Constructor<SubmittableExtrinsic<any>>;
export default function createSubmittable<ApiType extends ApiTypes> (apiType: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['decorateMethod']): Creator<ApiType> {
return (extrinsic: Call | Uint8Array | string): SubmittableExtrinsic<ApiType> => {
return (extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType> => {
// This is not great, but basically what we do here is to only require the
// class right at the point it is actually needed - delaying initialization
if (!Submittable) {
+3 -3
View File
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, Address, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions, Signer, ISubmittableResult } from '@polkadot/types/types';
import { AccountId, Address, Extrinsic, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsicEra, IKeyringPair, SignatureOptions, Signer, ISubmittableResult } from '@polkadot/types/types';
import { ApiTypes } from '../types';
import { Observable } from 'rxjs';
@@ -43,7 +43,7 @@ export interface SignerOptions {
export type AddressOrPair = IKeyringPair | string | AccountId | Address;
export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends IExtrinsic {
export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends Extrinsic {
paymentInfo (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittablePaymentResult<ApiType>;
send(): SubmittableResultResult<ApiType>;
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/jsonrpc",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Method definitions for the Polkadot RPC layer",
"main": "index.js",
"publishConfig": {
@@ -27,7 +27,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/jsonrpc#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1"
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/metadata",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Helpers to extract information from runtime metadata",
"main": "index.js",
"publishConfig": {
@@ -27,7 +27,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"bn.js": "^5.1.1"
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-core",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -27,10 +27,10 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/jsonrpc": "1.5.0-beta.5",
"@polkadot/metadata": "1.5.0-beta.5",
"@polkadot/rpc-provider": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/jsonrpc": "1.4.2",
"@polkadot/metadata": "1.4.2",
"@polkadot/rpc-provider": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.4"
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
@@ -27,9 +27,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/jsonrpc": "1.5.0-beta.5",
"@polkadot/metadata": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/jsonrpc": "1.4.2",
"@polkadot/metadata": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"bn.js": "^5.1.1",
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Type generation scripts",
"main": "index.js",
"bin": {
@@ -36,11 +36,11 @@
"@babel/core": "^7.8.3",
"@babel/register": "^7.8.3",
"@babel/runtime": "^7.8.4",
"@polkadot/api": "1.5.0-beta.5",
"@polkadot/jsonrpc": "1.5.0-beta.5",
"@polkadot/metadata": "1.5.0-beta.5",
"@polkadot/rpc-provider": "1.5.0-beta.5",
"@polkadot/types": "1.5.0-beta.5",
"@polkadot/api": "1.4.2",
"@polkadot/jsonrpc": "1.4.2",
"@polkadot/metadata": "1.4.2",
"@polkadot/rpc-provider": "1.4.2",
"@polkadot/types": "1.4.2",
"@polkadot/util": "^2.5.1",
"websocket": "^1.0.31",
"yargs": "^15.1.0"
+2 -3
View File
@@ -34,9 +34,8 @@ function generateModule (registry: Registry, allDefs: object, { calls, name }: M
return [];
}
setImports(allDefs, imports, ['SubmittableExtrinsic']);
setImports(allDefs, imports, ['Call', 'Extrinsic', 'SubmittableExtrinsic']);
// NOTE Not removing this concat yet, first see the fallout
return [indent(4)(`${stringCamelCase(name.toString())}: {`)]
.concat(isStrict ? '' : indent(6)('[index: string]: SubmittableExtrinsicFunction<ApiType>;'))
.concat(allCalls.map(({ args, documentation, name }): string => {
@@ -87,7 +86,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
const interfaceEnd = `\n${indent(2)('}')}\n\n`;
const submittableExtrinsicsInterface = indent(2)('export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {')
.concat('\n')
.concat(indent(4)('(extrinsic: Uint8Array | string): SubmittableExtrinsic<ApiType>;\n'))
.concat(indent(4)('(extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;\n'))
.concat(isStrict ? '' : indent(4)('[index: string]: SubmittableModuleExtrinsics<ApiType>;\n'))
.concat(indent(2)('}\n'));
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types",
"version": "1.5.0-beta.5",
"version": "1.4.2",
"description": "Implementation of the Parity codec",
"main": "index.js",
"keywords": [
@@ -27,7 +27,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@polkadot/metadata": "1.5.0-beta.5",
"@polkadot/metadata": "1.4.2",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"@types/bn.js": "^4.11.6",