accountNextIndex on nonce = -1 (#2618)

This commit is contained in:
Jaco Greeff
2020-09-17 14:54:06 +02:00
committed by GitHub
parent 6c00a5a408
commit 4596e434dd
3 changed files with 11 additions and 2 deletions
+1
View File
@@ -6,6 +6,7 @@ Upgrade priority: High. Metadata v12 is the next major version containing struct
Changes:
- When passing `{ nonce: -1 }` to `signAndSend` the API will use `system.accountNextIndex` to determine the nonce
- Ensure that upgrades override old registry types (non-specified in current)
- Support for Metadata v12 with fixed indices
- Cleanups for WebSocket class detection and creation
+9 -1
View File
@@ -24,6 +24,12 @@ function latestNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
);
}
function nextNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
return api.rpc.system?.accountNextIndex
? api.rpc.system.accountNextIndex(address)
: latestNonce(api, address);
}
function signingHeader (api: ApiInterfaceRx): Observable<Header> {
return combineLatest([
api.rpc.chain.getHeader(),
@@ -47,7 +53,9 @@ export function signingInfo (_instanceId: string, api: ApiInterfaceRx): (address
// retrieve nonce if none was specified
isUndefined(nonce)
? latestNonce(api, address)
: of(api.registry.createType('Index', nonce)),
: nonce === -1
? nextNonce(api, address)
: of(api.registry.createType('Index', nonce)),
// if no era (create) or era > 0 (mortal), do block retrieval
(isUndefined(era) || (isNumber(era) && era > 0))
? signingHeader(api)
+1 -1
View File
@@ -240,7 +240,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
}
// NOTE here we actually override nonce if it was specified (backwards compat for
// the previous signature - don't let userspace break, but allow then time to upgrade)
// the previous signature - don't let user space break, but allow then time to upgrade)
#optionsOrNonce = (optionsOrNonce: Partial<SignerOptions> = {}): Partial<SignerOptions> => {
return isBn(optionsOrNonce) || isNumber(optionsOrNonce)
? { nonce: optionsOrNonce }