Fix dispatchQueue preimage retrieval in derives (#5356)

This commit is contained in:
Jaco
2022-11-28 12:06:06 +02:00
committed by GitHub
parent 2da085afb8
commit fde69670f1
20 changed files with 183 additions and 170 deletions
@@ -84,7 +84,7 @@ function getDemocracyImages (api: DeriveApi, hashes: (Hash | Uint8Array | string
);
}
function getImages (api: DeriveApi, bounded: FrameSupportPreimagesBounded[]): Observable<(DeriveProposalImage | undefined)[]> {
function getImages (api: DeriveApi, bounded: (FrameSupportPreimagesBounded | Uint8Array | string)[]): Observable<(DeriveProposalImage | undefined)[]> {
const hashes = bounded.map((b) => getImageHashBounded(b));
return api.query.preimage.statusFor.multi(hashes).pipe(
@@ -123,7 +123,7 @@ export function preimages (instanceId: string, api: DeriveApi): (hashes: (Hash |
? isFunction(api.query.democracy.preimages)
? getDemocracyImages(api, hashes as string[])
: isFunction(api.query.preimage.preimageFor)
? getImages(api, hashes as FrameSupportPreimagesBounded[])
? getImages(api, hashes)
: of([])
: of([])
);
+9 -3
View File
@@ -7,7 +7,7 @@ import type { Option } from '@polkadot/types-codec';
import type { HexString } from '@polkadot/util/types';
import type { DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes, DeriveReferendumVoteState } from '../types';
import { BN, bnSqrt, objectSpread } from '@polkadot/util';
import { BN, bnSqrt, isHex, isString, isU8a, objectSpread, stringToHex, u8aToHex } from '@polkadot/util';
interface ApproxState {
votedAye: BN;
@@ -141,7 +141,7 @@ export function getStatus (info: Option<PalletDemocracyReferendumInfo | Referend
: null;
}
export function getImageHashBounded (hash: Hash | FrameSupportPreimagesBounded): HexString {
export function getImageHashBounded (hash: Uint8Array | string | Hash | FrameSupportPreimagesBounded): HexString {
return (hash as FrameSupportPreimagesBounded).isLegacy
? (hash as FrameSupportPreimagesBounded).asLegacy.hash_.toHex()
: (hash as FrameSupportPreimagesBounded).isLookup
@@ -149,7 +149,13 @@ export function getImageHashBounded (hash: Hash | FrameSupportPreimagesBounded):
// for inline, use the actual Bytes hash
: (hash as FrameSupportPreimagesBounded).isInline
? (hash as FrameSupportPreimagesBounded).asInline.hash.toHex()
: hash.toHex();
: isString(hash)
? isHex(hash)
? hash
: stringToHex(hash)
: isU8a(hash)
? u8aToHex(hash)
: hash.toHex();
}
export function getImageHash (status: PalletDemocracyReferendumStatus | ReferendumInfoTo239): HexString {