Skip to content

Commit 1b4fafc

Browse files
api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 15.8.1
1 parent 0bfd7fe commit 1b4fafc

File tree

16 files changed

+136
-13
lines changed

16 files changed

+136
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

5+
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 15.8.1
56
- phishing 0.25.5
67
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 15.7.2
78
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 15.7.1

api-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

api-base/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

api-contract/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

api-derive/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

api-derive/tx/extrinsicInfo.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
2+
import type { Observable } from 'https://esm.sh/[email protected]';
3+
import type { GenericExtrinsic } from 'https://deno.land/x/polkadot/types/mod.ts';
4+
import type { EventRecord, Hash } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
5+
import type { DeriveApi } from '../types.ts';
6+
7+
import { map } from 'https://esm.sh/[email protected]';
8+
9+
import { memo } from '../util/index.ts';
10+
11+
interface ExtrinsicInfo {
12+
blockHash: Hash | string,
13+
blockNumber: number,
14+
extrinsic: GenericExtrinsic,
15+
events: EventRecord[]
16+
success: boolean
17+
}
18+
19+
interface ExtrinsicsInfo {
20+
blockHash: Hash | string,
21+
blockNumber: number,
22+
extrinsics: {
23+
events: EventRecord[]
24+
extrinsic: GenericExtrinsic,
25+
success: boolean
26+
}[],
27+
}
28+
29+
/**
30+
* @name extrinsicInfo
31+
* @param { Hash } at The block hash to query at.
32+
* @param { Uint8Array | string } transactionHash A transaction hash as U8 array or string.
33+
* @description Retrieves the extrinsic information and its events.
34+
* @example
35+
* ```javascript
36+
* const blockHash = api.registry.createType(
37+
* 'Hash',
38+
* '0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
39+
* );
40+
* const extrinsicInfo = await api.derive.tx.extrinsicInfo(
41+
* blockHash,
42+
* '0xcd96520b05e0c4648ea365f3f063f27c5cdd8be10d41a1c44566428c91f37dcb'
43+
* );
44+
*
45+
* console.log(extrinsicInfo.extrinsic.toHuman());
46+
* ```
47+
*/
48+
export function extrinsicInfo (instanceId: string, api: DeriveApi): (at: Hash, transactionHash: Uint8Array | string) => Observable<ExtrinsicInfo | null> {
49+
return memo(instanceId, (at: Hash, transactionHash: Uint8Array | string): Observable<ExtrinsicInfo | null> => {
50+
return api.derive.tx.events(at).pipe(map(({ block, events }) => {
51+
const index = block.block.extrinsics.findIndex((ext) => ext.hash.toString() === transactionHash);
52+
53+
if (index === -1) {
54+
return null;
55+
}
56+
57+
const extEvents = events.filter(
58+
({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index)
59+
);
60+
61+
return {
62+
blockHash: block.hash.toHex(),
63+
blockNumber: block.block.header.number.toNumber(),
64+
events: extEvents,
65+
extrinsic: block.block.extrinsics[index],
66+
success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
67+
};
68+
}));
69+
});
70+
}
71+
72+
/**
73+
* @name accountExtrinsics
74+
* @description Retrieves information about every extrinsic submitted by an account at a given block.
75+
* @param { Hash } at The block hash to query at.
76+
* @param { Uint8Array | strings } accountId The account identifier to query.
77+
* @example
78+
* ```javascript
79+
const blockHash = api.registry.createType(
80+
'Hash',
81+
'0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
82+
);
83+
const extrinsicsInfo = await api.derive.tx.accountExtrinsics(
84+
blockHash,
85+
'0x21895DdfD4640b4e0aDCa2865b907f2CE6e6B777'
86+
);
87+
88+
console.log(extrinsicsInfo.extrinsics[0]).extrinsic.toHuman();
89+
* ```
90+
*/
91+
export function accountExtrinsics (instanceId: string, api: DeriveApi): (at: Hash, accountId: Uint8Array | string) => Observable<ExtrinsicsInfo> {
92+
return memo(instanceId, (at: Hash, accountId: Uint8Array | string): Observable<ExtrinsicsInfo> => {
93+
return api.derive.tx.events(at).pipe(map(({ block, events }) => {
94+
const indexes: number[] = [];
95+
96+
return {
97+
blockHash: block.hash.toHex(),
98+
blockNumber: block.block.header.number.toNumber(),
99+
extrinsics: block.block.extrinsics.filter((ext, index) => {
100+
if (ext.signer.toString() === accountId) {
101+
indexes.push(index);
102+
103+
return true;
104+
}
105+
106+
return false;
107+
}).map((ext, i) => {
108+
const extEvents = events.filter(
109+
({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(indexes[i])
110+
);
111+
112+
return {
113+
events: extEvents,
114+
extrinsic: ext,
115+
success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
116+
};
117+
})
118+
};
119+
}));
120+
});
121+
}

api-derive/tx/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
export * from './events.ts';
3+
export * from './extrinsicInfo.ts';
34
export * from './signingInfo.ts';

api/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

rpc-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

rpc-core/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

rpc-provider/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-provider', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-provider', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

types-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/types-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

types-codec/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types-codec', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/types-codec', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

types-create/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types-create', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/types-create', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

types-known/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types-known', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/types-known', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

types/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.7.2' };
3+
export const packageInfo = { name: '@polkadot/types', path: new URL(import.meta.url).pathname, type: 'deno', version: '15.8.1' };

0 commit comments

Comments
 (0)