Skip to content

Commit

Permalink
fix: bump polkadot-js deps (#796)
Browse files Browse the repository at this point in the history
* fix: change registry used in operation from Block -> ApiDecoration<promise>

* fix: bump polkadot-js deps

* fix: add import @polkadot/api-augment; to entry

* fix: update imports for Codecs

* comment

* bump apps-config

* add comment

* fix: inline doc comments

* update apps-config
  • Loading branch information
TarikGul committed Dec 21, 2021
1 parent 1059c1a commit c79d126
Show file tree
Hide file tree
Showing 12 changed files with 455 additions and 321 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"test:test-release": "yarn start:test-release"
},
"dependencies": {
"@polkadot/api": "^6.12.1",
"@polkadot/apps-config": "0.98.2-124",
"@polkadot/util-crypto": "^8.1.2",
"@polkadot/api": "^7.0.1",
"@polkadot/apps-config": "0.98.2-164",
"@polkadot/util-crypto": "^8.2.2",
"@polkadot/x-rxjs": "^6.11.1",
"@substrate/calc": "^0.2.6",
"argparse": "^2.0.1",
Expand All @@ -75,14 +75,14 @@
"tsc-watch": "^4.4.0"
},
"resolutions": {
"@polkadot/api": "6.12.1",
"@polkadot/keyring": "8.1.2",
"@polkadot/networks": "8.1.2",
"@polkadot/types": "6.12.1",
"@polkadot/types-known": "6.12.1",
"@polkadot/util": "8.1.2",
"@polkadot/util-crypto": "8.1.2",
"@polkadot/wasm-crypto": "4.4.1",
"@polkadot/api": "7.0.1",
"@polkadot/keyring": "8.2.2",
"@polkadot/networks": "8.2.2",
"@polkadot/types": "7.0.1",
"@polkadot/types-known": "7.0.1",
"@polkadot/util": "8.2.2",
"@polkadot/util-crypto": "8.2.2",
"@polkadot/wasm-crypto": "4.5.1",
"bn.js": "4.12.0",
"node-forge": ">=0.10.0",
"node-fetch": ">=2.6.1",
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/blocks/BlocksTraceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export default class BlocksTraceController extends AbstractController<BlocksTrac
): Promise<void> => {
const hash = await this.api.rpc.chain.getFinalizedHead();
const includeActions = actions === 'true';
const historicApi = await this.api.at(hash);

BlocksController.sanitizedSend(
res,
await this.service.operations(hash, includeActions)
await this.service.operations(hash, historicApi, includeActions)
);
};

Expand All @@ -57,10 +58,11 @@ export default class BlocksTraceController extends AbstractController<BlocksTrac
): Promise<void> => {
const hash = await this.getHashForBlock(number);
const includeActions = actions === 'true';
const historicApi = await this.api.at(hash);

BlocksController.sanitizedSend(
res,
await this.service.operations(hash, includeActions)
await this.service.operations(hash, historicApi, includeActions)
);
};
}
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// Introduced via `@polkadot/api v7.0.1`.
import '@polkadot/api-augment';

import { ApiPromise } from '@polkadot/api';
import * as apps from '@polkadot/apps-config/api';
import { WsProvider } from '@polkadot/rpc-provider';
Expand Down
3 changes: 1 addition & 2 deletions src/sanitize/sanitizeNumbers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
Vec,
VecFixed,
} from '@polkadot/types';
import { CodecDate } from '@polkadot/types/codec/Date';
import { UInt } from '@polkadot/types/codec/UInt';
import { CodecDate, UInt } from '@polkadot/types-codec';
import BN from 'bn.js';

import {
Expand Down
10 changes: 6 additions & 4 deletions src/sanitize/sanitizeNumbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
Set as CodecSet,
Struct,
} from '@polkadot/types';
import { AbstractArray } from '@polkadot/types/codec/AbstractArray';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import { Json } from '@polkadot/types/codec/Json';
import { CodecMap } from '@polkadot/types/codec/Map';
import {
AbstractArray,
AbstractInt,
CodecMap,
Json,
} from '@polkadot/types-codec';
import { isObject, stringCamelCase } from '@polkadot/util';
import BN from 'bn.js';
import { InternalServerError } from 'http-errors';
Expand Down
10 changes: 5 additions & 5 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { AugmentedConst } from '@polkadot/api/types';
import { PromiseRpcResult } from '@polkadot/api/types/rpc';
import { PromiseRpcResult } from '@polkadot/api-base/types/rpc';
import { GenericExtrinsic, u128 } from '@polkadot/types';
import { GenericCall } from '@polkadot/types/generic';
import { BlockHash, Hash, SignedBlock } from '@polkadot/types/interfaces';
Expand Down Expand Up @@ -360,14 +360,14 @@ describe('BlocksService', () => {
expect(() =>
blocksService['parseGenericCall'](
{} as unknown as GenericCall,
mockBlock789629.registry
mockHistoricApi.registry
)
).toThrow());

it('parses a simple balances.transfer', () => {
expect(
JSON.stringify(
blocksService['parseGenericCall'](transfer, mockBlock789629.registry)
blocksService['parseGenericCall'](transfer, mockHistoricApi.registry)
)
).toBe(JSON.stringify(transferOutput));
});
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('BlocksService', () => {

expect(
JSON.stringify(
blocksService['parseGenericCall'](batch4, mockBlock789629.registry)
blocksService['parseGenericCall'](batch4, mockHistoricApi.registry)
)
).toBe(
JSON.stringify({
Expand Down Expand Up @@ -461,7 +461,7 @@ describe('BlocksService', () => {

expect(
JSON.stringify(
blocksService['parseGenericCall'](batch, mockBlock789629.registry)
blocksService['parseGenericCall'](batch, mockHistoricApi.registry)
)
).toEqual(
JSON.stringify({
Expand Down
14 changes: 5 additions & 9 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { extractAuthor } from '@polkadot/api-derive/type/util';
import { Compact, GenericCall, Struct, Vec } from '@polkadot/types';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import {
AccountId32,
Block,
Expand All @@ -15,6 +14,7 @@ import {
Header,
} from '@polkadot/types/interfaces';
import { AnyJson, Codec, Registry } from '@polkadot/types/types';
import { AbstractInt } from '@polkadot/types-codec';
import { u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { CalcFee } from '@substrate/calc';
Expand Down Expand Up @@ -126,6 +126,7 @@ export class BlocksService extends AbstractService {
const nonSanitizedExtrinsics = this.extractExtrinsics(
block,
events,
historicApi.registry,
extrinsicDocs
);

Expand Down Expand Up @@ -353,21 +354,16 @@ export class BlocksService extends AbstractService {
*
* @param block Block
* @param events events fetched by `fetchEvents`
* @param regsitry The corresponding blocks runtime registry
* @param extrinsicDocs To include the extrinsic docs or not
*/
private extractExtrinsics(
block: Block,
events: Vec<EventRecord> | string,
registry: Registry,
extrinsicDocs: boolean
) {
const defaultSuccess = typeof events === 'string' ? events : false;
// Note, if events is a string then there was an issue getting them from the node.
// In this case we try and create the calls with the registry on `block`.
// The block from `api.derive.chain.getBlock` has the most recent registry,
// which could cause issues with historical querries.
// On the other hand, we know `events` will have the correctly dated query
// since it is a storage query.
const registry =
typeof events === 'string' ? block.registry : events.registry;

return block.extrinsics.map((extrinsic) => {
const { method, nonce, signature, signer, isSigned, tip, era } =
Expand Down
27 changes: 13 additions & 14 deletions src/services/blocks/BlocksTraceService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ApiDecoration } from '@polkadot/api/types';

import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { kusamRegistryV2025 } from '../../test-helpers/registries';
import {
blockHash789629,
defaultMockApi,
mockBlock789629,
} from '../test-helpers/mock';
import { blockHash789629, defaultMockApi } from '../test-helpers/mock';
import { keyNames } from '../test-helpers/mock/data/getKeyNames';
import operationsResponse from '../test-helpers/responses/blocks/operations.json';
import tracesResponse from '../test-helpers/responses/blocks/traces.json';
Expand All @@ -16,29 +14,26 @@ import { Trace } from './trace';
* for testing and then reassign it back to the original after this test suite is done.
*/
const tempGetKeyNames = Trace['getKeyNames'].bind(Trace);

/**
* Save the refference to the mockBlock789629's registry so we can reassign it back once
* the tests are over.
* HistoricApi used in order to create the correct types per the blocks runtime.
*/
const tempMockBlock789629Registry = mockBlock789629.registry;
const mockHistoricApi = {
registry: kusamRegistryV2025,
} as unknown as ApiDecoration<'promise'>;

/**
* BlocksTraceService mock
*/
const blocksTraceService = new BlocksTraceService(defaultMockApi);

beforeAll(() => {
// Override registry so we correctly create kusama types.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(mockBlock789629 as any).registry = kusamRegistryV2025;
Trace['getKeyNames'] = () => keyNames;
});

afterAll(() => {
// Clean up our test specific overrides
Trace['getKeyNames'] = tempGetKeyNames;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(mockBlock789629 as any).registry = tempMockBlock789629Registry;
});

describe('BlocksTraceService', () => {
Expand All @@ -54,7 +49,11 @@ describe('BlocksTraceService', () => {
it('works when ApiPromise works (without `actions`)', async () => {
expect(
sanitizeNumbers(
await blocksTraceService.operations(blockHash789629, false)
await blocksTraceService.operations(
blockHash789629,
mockHistoricApi,
false
)
)
).toMatchObject(operationsResponse);
});
Expand Down
5 changes: 4 additions & 1 deletion src/services/blocks/BlocksTraceService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiDecoration } from '@polkadot/api/types';
import { BlockHash } from '@polkadot/types/interfaces';
import { BlockTrace as PdJsBlockTrace } from '@polkadot/types/interfaces';
import { InternalServerError } from 'http-errors';
Expand Down Expand Up @@ -74,10 +75,12 @@ export class BlocksTraceService extends AbstractService {
* Get the balance changing operations induced by a block.
*
* @param hash `BlockHash` to get balance transfer operations at.
* @param historicApi ApiDecoration used to retrieve the correct registry
* @param includeActions whether or not to include `actions` field in the response.
*/
async operations(
hash: BlockHash,
historicApi: ApiDecoration<'promise'>,
includeActions: boolean
): Promise<BlocksTraceOperations> {
const [{ block }, traceResponse] = await Promise.all([
Expand All @@ -93,7 +96,7 @@ export class BlocksTraceService extends AbstractService {
const trace = new Trace(
this.api,
BlocksTraceService.formatBlockTrace(traceResponse.asBlockTrace),
block.registry
historicApi.registry
);

const { operations, actions } = trace.actionsAndOps();
Expand Down
2 changes: 1 addition & 1 deletion src/services/paras/ParasService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { Option, Tuple, Vec } from '@polkadot/types';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import { BlockNumber, Hash } from '@polkadot/types/interfaces';
import { Codec } from '@polkadot/types/types';
import { AbstractInt } from '@polkadot/types-codec';
import BN from 'bn.js';

import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
Expand Down
2 changes: 1 addition & 1 deletion src/types/responses/Paras.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Option } from '@polkadot/types/codec';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import {
AccountId,
BalanceOf,
FundInfo,
ParaId,
ParaLifecycle,
} from '@polkadot/types/interfaces';
import { AbstractInt } from '@polkadot/types-codec/abstract';
import BN from 'bn.js';

import { IOption } from '../util';
Expand Down
Loading

0 comments on commit c79d126

Please sign in to comment.