From d4e3be925fef7ed729b477729ab82e9a3e7f1a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20S=C3=A1nchez=20Garc=C3=ADa?= Date: Mon, 1 Jul 2024 19:44:29 +0200 Subject: [PATCH] update referenda tooling --- src/utils/monitoring.ts | 2 +- src/utils/referenda.ts | 15 ++++----------- src/utils/transactions.ts | 10 +++------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/utils/monitoring.ts b/src/utils/monitoring.ts index 42ff50f..5d2990e 100644 --- a/src/utils/monitoring.ts +++ b/src/utils/monitoring.ts @@ -183,7 +183,7 @@ export const getAccountIdentity = async ( : [null, null]; identityCache[account] = { lastUpdate: Date.now(), - identity: identity && ("info" in identity ? identity : identity[0]), + identity: identity[0], superOf: superOfIdentity && ("info" in superOfIdentity ? superOfIdentity : superOfIdentity[0]), }; diff --git a/src/utils/referenda.ts b/src/utils/referenda.ts index daea4b9..8545273 100644 --- a/src/utils/referenda.ts +++ b/src/utils/referenda.ts @@ -69,7 +69,7 @@ export function isConvictionTally( ); } -function curveDelay(curve: PalletReferendaCurve, input: BN, div: BN): BN { +export function curveDelay(curve: PalletReferendaCurve, input: BN, div: BN): BN { // if divisor is zero, we return the max if (div.isZero()) { return BN_BILLION; @@ -181,12 +181,8 @@ function parseImage( } const [proposer, balance] = status.isUnrequested - ? "deposit" in status.asUnrequested - ? status.asUnrequested["deposit"] - : status.asUnrequested.ticket - : ("deposit" in status.asRequested - ? status.asRequested["deposit"] - : status.asRequested.maybeTicket + ? status.asUnrequested.ticket + : (status.asRequested.maybeTicket ).unwrapOrDefault(); let proposal: Call | undefined; @@ -202,10 +198,7 @@ function parseImage( } async function getImageProposal(api: ApiPromise | ApiDecoration<"promise">, hash: string) { - const optStatus = - "requestStatusFor" in api.query.preimage - ? await api.query.preimage["requestStatusFor"](hash) - : await api.query.preimage.statusFor(hash); + const optStatus = await api.query.preimage.requestStatusFor(hash); const status = optStatus.unwrapOr(null) as PalletPreimageRequestStatus; if (!status) { return null; diff --git a/src/utils/transactions.ts b/src/utils/transactions.ts index 4523c80..e132da1 100644 --- a/src/utils/transactions.ts +++ b/src/utils/transactions.ts @@ -158,23 +158,19 @@ export async function callInterpreter( subCalls: subCallsData, }; } - const imageStatusFn = - "requestStatusFor" in api.query.preimage - ? api.query.preimage["requestStatusFor"] - : api.query.preimage.statusFor; const callData = nested.inlined ? call.args[nested.argumentPosition] - : await imageStatusFn(call.args[nested.argumentPosition].toHex()).then((optStatus) => { + : await api.query.preimage.requestStatusFor(call.args[nested.argumentPosition].toHex()).then((optStatus) => { if (optStatus.isNone) { return null; } const status = optStatus.unwrap(); const len = status.isRequested - ? status.asRequested.len.unwrapOr(0) + ? status.asRequested.maybeLen.unwrapOr(0) : status.asUnrequested.len || 0; return api.query.preimage .preimageFor([call.args[nested.argumentPosition].toHex(), len]) - .then((preimage: Option) => preimage.unwrap().toHex()); + .then((preimage) => preimage.unwrap().toHex()); }); if (callData) { const subCall = await api.registry.createType("Call", callData);