Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add proxy methods to txwrapper-{substrate, polkadot} (#21)
General clean up
- Loading branch information
Showing
24 changed files
with
745 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import { balances, utility } from '@substrate/txwrapper-substrate/src/methods'; | ||
import { | ||
balances, | ||
proxy, | ||
utility, | ||
} from '@substrate/txwrapper-substrate/src/methods'; | ||
|
||
// Export methods of pallets included in the Polkadot/ Kusama/ Westend runtimes. | ||
// Note: in the future this may also include methods defined within this package | ||
// that do not exist in Substrate. | ||
export const methods = { | ||
balances, | ||
utility, | ||
proxy, | ||
}; | ||
|
||
// Rexport all of txwrapper-core so users have access to utilities, construct functions, | ||
// decode function, and types. | ||
export * from '@substrate/txwrapper-core'; | ||
|
||
// SS58 is not exported at the top level since most txwrapper-core users don't need it, | ||
// so we have to reach in and grab it | ||
export { PolkadotSS58Format } from '@substrate/txwrapper-core/src/polkadot'; | ||
// getRegistry{Polkadot, Westend, Kusama} | ||
|
||
// exports getRegistry{Polkadot, Westend, Kusama} | ||
export * from './getRegistry'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Name exports to create namespaces that map to pallets | ||
export * as balances from './balances'; | ||
export * as proxy from './proxy'; | ||
export * as utility from './utility'; |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/proxy/addProxy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
POLKADOT_25_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-core/src/test-helpers'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { addProxy } from './addProxy'; | ||
|
||
describe('proxy::addProxy', () => { | ||
it('should work', () => { | ||
const unsigned = addProxy( | ||
TEST_METHOD_ARGS.proxy.addProxy, | ||
TEST_BASE_TX_INFO, | ||
POLKADOT_25_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x1d018eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480039300000' | ||
); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/txwrapper-substrate/src/methods/proxy/addProxy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
export interface ProxyAddProxy extends Args { | ||
/** | ||
* The account that the `caller` would like to make a proxy. | ||
*/ | ||
delegate: string; | ||
/** | ||
* The permissions for this proxy account. See the chain's runtime for the `call` filters. | ||
*/ | ||
proxyType: string; | ||
/** | ||
* The number of blocks that an announcement must be in place for before the corresponding call | ||
* may be dispatched. If zero, then no announcement is needed. | ||
*/ | ||
delay: number | string; | ||
} | ||
|
||
/** | ||
* Register a proxy account for the sender that is able to make calls on its behalf. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function addProxy( | ||
args: ProxyAddProxy, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'addProxy', | ||
pallet: 'proxy', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/proxy/announce.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
POLKADOT_25_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-core/src/test-helpers'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { announce } from './announce'; | ||
|
||
describe('proxy::announce', () => { | ||
it('should work', () => { | ||
const unsigned = announce( | ||
TEST_METHOD_ARGS.proxy.announce, | ||
TEST_BASE_TX_INFO, | ||
POLKADOT_25_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x1d068eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48474235772ae94433aee7d1befac0bfcc35fd0b5dfcf0cfc14bba7d5bbe35b778' | ||
); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/txwrapper-substrate/src/methods/proxy/announce.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
interface ProxyAnnounceArgs extends Args { | ||
/** | ||
* The account that the proxy will make a call on behalf of. | ||
*/ | ||
real: string; | ||
/** | ||
* The hash of the call to be made by the `real` account. | ||
*/ | ||
callHash: string; | ||
} | ||
|
||
/** | ||
* Publish the hash of a proxy-call that will be made in the future. | ||
* | ||
* This must be called `ProxyDefinition.delay` blocks before the corresponding | ||
* `proxy` is attempted if the delay associated with the proxy relationship is | ||
* greater than zero. When a `ProxyDefinition.delay` is 0 `announce` is not neccesary | ||
* and `proxy` can be called at any time. | ||
* | ||
* No more than `MaxPending` announcements may be made at any one time. On Kusama and Polkadot | ||
* `MaxPending` is set to 32. | ||
* | ||
* This will take a deposit of `AnnouncementDepositFactor` as well as | ||
* `AnnouncementDepositBase` if there are no other pending announcements. | ||
* | ||
* The dispatch origin for this call must be _Signed_ and a proxy of `real`. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function announce( | ||
args: ProxyAnnounceArgs, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'announce', | ||
pallet: 'proxy', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './addProxy'; | ||
export * from './announce'; | ||
export * from './proxy'; | ||
export * from './proxyAnnounced'; | ||
export * from './rejectAnnouncement'; | ||
export * from './removeProxies'; | ||
export * from './removeProxy'; |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/proxy/proxy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
POLKADOT_25_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-core/src/test-helpers'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { proxy } from './proxy'; | ||
|
||
describe('proxy::proxy', () => { | ||
it('should work', () => { | ||
const unsigned = proxy( | ||
TEST_METHOD_ARGS.proxy.proxy, | ||
TEST_BASE_TX_INFO, | ||
POLKADOT_25_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x1d008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480100050030672121' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
export interface ProxyProxy extends Args { | ||
/** | ||
* Dispatch the given `call` from an account that the sender is authorized for | ||
* through, `add_proxy`. | ||
*/ | ||
real: string; | ||
/** | ||
* Specify the exact proxy type to be used and checked for this call. | ||
*/ | ||
forceProxyType: string; | ||
/** | ||
* The call to be made by the `real` account. | ||
* To take advantage of txwrapper methods, this could be UnsignedTransaction.method. | ||
*/ | ||
call: { callIndex?: string; args?: string } | string; | ||
} | ||
|
||
/** | ||
* Dispatch the given `call` from an account for which the sender is authorized. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function proxy( | ||
args: ProxyProxy, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'proxy', | ||
pallet: 'proxy', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/proxy/proxyAnnounced.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
POLKADOT_25_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-core/src/test-helpers'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { proxyAnnounced } from './proxyAnnounced'; | ||
|
||
describe('proxy::proxyAnnounced', () => { | ||
it('should work', () => { | ||
const unsigned = proxyAnnounced( | ||
TEST_METHOD_ARGS.proxy.proxyAnnounced, | ||
TEST_BASE_TX_INFO, | ||
POLKADOT_25_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x1d09d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480100050030672121' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.