accountNextIndex on nonce = -1 (#2618)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user