Skip to content

Commit 8af876e

Browse files
feat: Add create pure and kill pure transaction for version > 0.9.30 (#276)
* feat(metadata): add v0.9.35 Metadata * feat(txwrapper-substrate): add createPure transaction * feat(txwrapper-substrate): add killPure transaction
1 parent 963b543 commit 8af876e

8 files changed

Lines changed: 199 additions & 0 deletions

File tree

packages/txwrapper-dev/src/constants/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { kusamaV9160MetadataHex } from '../metadata/kusama/kusamaV9160MetadataHex';
22
import { kusamaV9320MetadataHex } from '../metadata/kusama/kusamaV9320MetadataHex';
33
import { polkadotV9122MetadataHex } from '../metadata/polkadot/polkadotV9122MetadataHex';
4+
import { polkadotV9350MetadataHex } from '../metadata/polkadot/polkadotV9350MetadataHex';
45
import { metadataRpc } from '../metadata/static/staticV3-1-1';
56
import { metadataRpcV29 } from '../metadata/static/staticV4-3-1';
67
import { getRegistryKusama, getRegistryPolkadot } from '../registries';
@@ -91,6 +92,14 @@ export const KUSAMA_9320_TEST_OPTIONS = {
9192
registry: getRegistryKusama(9320, kusamaV9320MetadataHex),
9293
};
9394

95+
/**
96+
* Test options for runtime v9350 Polkadot
97+
*/
98+
export const POLKADOT_9350_TEST_OPTIONS = {
99+
metadataRpc: polkadotV9350MetadataHex,
100+
registry: getRegistryPolkadot(9350, polkadotV9350MetadataHex),
101+
};
102+
94103
/**
95104
* Dummy arguments for all methods we're testing.
96105
*/

packages/txwrapper-dev/src/metadata/polkadot/polkadotV9350MetadataHex.ts

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
itHasCorrectBaseTxInfo,
3+
POLKADOT_9350_TEST_OPTIONS,
4+
TEST_BASE_TX_INFO,
5+
} from '@substrate/txwrapper-dev';
6+
7+
import { TEST_METHOD_ARGS } from '../../test-helpers';
8+
import { createPure } from './createPure';
9+
10+
describe('proxy::createPure', () => {
11+
it('should work', () => {
12+
const unsigned = createPure(
13+
TEST_METHOD_ARGS.proxy.createPure,
14+
TEST_BASE_TX_INFO,
15+
POLKADOT_9350_TEST_OPTIONS
16+
);
17+
18+
itHasCorrectBaseTxInfo(unsigned);
19+
20+
expect(unsigned.method).toBe('0x1d04001e0000000100');
21+
});
22+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
Args,
3+
BaseTxInfo,
4+
defineMethod,
5+
OptionsWithMeta,
6+
UnsignedTransaction,
7+
} from '@substrate/txwrapper-core';
8+
9+
interface ProxyCreatePureArgs extends Args {
10+
/**
11+
* The type of the proxy that the sender will be registered as over the
12+
* new account. This will almost always be the most permissive `ProxyType` possible to
13+
* allow for maximum flexibility. (`ProxyType` variants vary by runtime.)
14+
*/
15+
proxyType: string;
16+
/**
17+
* The announcement period (measured in number of blocks) required of the initial proxy.
18+
* Will generally be zero.
19+
*/
20+
delay: number;
21+
/**
22+
* A positive, non-zero disambiguation index, in case this is called multiple times in the same
23+
* transaction (e.g. with `utility::batch`). Unless you're using `batch` you probably just
24+
* want to use `0`.
25+
*/
26+
index: number;
27+
}
28+
29+
/**
30+
* Spawn a fresh new account that is guaranteed to be otherwise inaccessible, and
31+
* initialize it with a proxy of `proxy_type` for `origin` sender.
32+
*
33+
* NOTE: Was named anonymous before v9300
34+
*
35+
* Requires a `Signed` origin
36+
*
37+
* Fails with `Duplicate` if this has already been called in this transaction, from the
38+
* same sender, with the same parameters.
39+
*
40+
* Fails if there are insufficient funds to pay for deposit.
41+
*
42+
* @param args - Arguments specific to this method.
43+
* @param info - Information required to construct the transaction.
44+
* @param options - Registry and metadata used for constructing the method.
45+
*/
46+
export function createPure(
47+
args: ProxyCreatePureArgs,
48+
info: BaseTxInfo,
49+
options: OptionsWithMeta
50+
): UnsignedTransaction {
51+
return defineMethod(
52+
{
53+
method: {
54+
args,
55+
name: 'createPure',
56+
pallet: 'proxy',
57+
},
58+
...info,
59+
},
60+
options
61+
);
62+
}

packages/txwrapper-substrate/src/methods/proxy/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export * from './addProxy';
22
export * from './announce';
33
export * from './anonymous';
4+
export * from './createPure';
45
export * from './killAnonymous';
6+
export * from './killPure';
57
export * from './proxy';
68
export * from './proxyAnnounced';
79
export * from './rejectAnnouncement';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
itHasCorrectBaseTxInfo,
3+
POLKADOT_9350_TEST_OPTIONS,
4+
TEST_BASE_TX_INFO,
5+
} from '@substrate/txwrapper-dev';
6+
7+
import { TEST_METHOD_ARGS } from '../../test-helpers';
8+
import { killPure } from './killPure';
9+
10+
describe('proxy::killPure', () => {
11+
it('should work', () => {
12+
const unsigned = killPure(
13+
TEST_METHOD_ARGS.proxy.killPure,
14+
TEST_BASE_TX_INFO,
15+
POLKADOT_9350_TEST_OPTIONS
16+
);
17+
18+
itHasCorrectBaseTxInfo(unsigned);
19+
20+
expect(unsigned.method).toBe(
21+
'0x1d05008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4800000002093d0000'
22+
);
23+
});
24+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {
2+
Args,
3+
BaseTxInfo,
4+
defineMethod,
5+
OptionsWithMeta,
6+
UnsignedTransaction,
7+
} from '@substrate/txwrapper-core';
8+
9+
interface ProxyKillPureArgs extends Args {
10+
/**
11+
* The account that originally called `createPure` to create this account.
12+
*/
13+
spawner: string;
14+
/**
15+
* The proxy type originally passed to `createPure`.
16+
*/
17+
proxyType: string;
18+
/**
19+
* The disambiguation index originally passed to `createPure`. Probably `0`
20+
*/
21+
index: number;
22+
/**
23+
* The height of the chain when the call to `createPure` was processed.
24+
*/
25+
height: number;
26+
/**
27+
* The extrinsic index in which the call to `createPure` was processed.
28+
*/
29+
extIndex: number;
30+
}
31+
32+
/**
33+
* Removes a previously spawned pure proxy.
34+
*
35+
* NOTE: Was named killAnonymous before v9300
36+
*
37+
* WARNING: **All access to this account will be lost.** Any funds held in it will be
38+
* inaccessible.
39+
*
40+
* Requires a `Signed` origin, and the sender account must have been created by a call to
41+
* `anonymous` with corresponding parameters.
42+
*
43+
* Fails with `NoPermission` in case the caller is not a previously created anonymous
44+
* account whose `anonymous` call has corresponding parameters.
45+
*
46+
* @param args Arguments specific to this method.
47+
* @param info Information required to construct the transaction.
48+
* @param options Registry and metadata used for constructing the method.
49+
* @returns
50+
*/
51+
export function killPure(
52+
args: ProxyKillPureArgs,
53+
info: BaseTxInfo,
54+
options: OptionsWithMeta
55+
): UnsignedTransaction {
56+
return defineMethod(
57+
{
58+
method: {
59+
args,
60+
name: 'killPure',
61+
pallet: 'proxy',
62+
},
63+
...info,
64+
},
65+
options
66+
);
67+
}

packages/txwrapper-substrate/src/test-helpers/TEST_METHOD_ARGS.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,25 @@ export const TEST_METHOD_ARGS = {
8282
delay: 30,
8383
index: 1,
8484
},
85+
createPure: {
86+
proxyType: 'Any',
87+
delay: 30,
88+
index: 1,
89+
},
8590
killAnonymous: {
8691
spawner: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3',
8792
proxyType: 'Any',
8893
index: 0,
8994
height: 1000000,
9095
extIndex: 0,
9196
},
97+
killPure: {
98+
spawner: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3',
99+
proxyType: 'Any',
100+
index: 0,
101+
height: 1000000,
102+
extIndex: 0,
103+
},
92104
},
93105
session: {
94106
setKeys: {

0 commit comments

Comments
 (0)