Skip to content

Commit

Permalink
update referenda tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-sangar committed Jul 1, 2024
1 parent 08f69e9 commit d4e3be9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/utils/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
};
Expand Down
15 changes: 4 additions & 11 deletions src/utils/referenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions src/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PalletPreimageRequestStatus>) => preimage.unwrap().toHex());
.then((preimage) => preimage.unwrap().toHex());
});
if (callData) {
const subCall = await api.registry.createType("Call", callData);
Expand Down

0 comments on commit d4e3be9

Please sign in to comment.