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
+12 -12
View File
@@ -20,25 +20,25 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "9.9.2",
"version": "9.9.3",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.20.1",
"@polkadot/api": "9.9.2",
"@polkadot/api-augment": "9.9.2",
"@polkadot/api-base": "9.9.2",
"@polkadot/rpc-core": "9.9.2",
"@polkadot/types": "9.9.2",
"@polkadot/types-codec": "9.9.2",
"@polkadot/api": "9.9.3",
"@polkadot/api-augment": "9.9.3",
"@polkadot/api-base": "9.9.3",
"@polkadot/rpc-core": "9.9.3",
"@polkadot/types": "9.9.3",
"@polkadot/types-codec": "9.9.3",
"@polkadot/util": "^10.1.14",
"@polkadot/util-crypto": "^10.1.14",
"rxjs": "^7.5.7"
},
"devDependencies": {
"@polkadot/api": "9.9.2",
"@polkadot/api-augment": "9.9.2",
"@polkadot/rpc-augment": "9.9.2",
"@polkadot/rpc-provider": "9.9.2",
"@polkadot/types-support": "9.9.2"
"@polkadot/api": "9.9.3",
"@polkadot/api-augment": "9.9.3",
"@polkadot/rpc-augment": "9.9.3",
"@polkadot/rpc-provider": "9.9.3",
"@polkadot/types-support": "9.9.3"
}
}
@@ -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 {