@substrate/api-sidecar
Version:
REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.
53 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PalletsOnGoingReferendaService = void 0;
const AbstractService_1 = require("../AbstractService");
class PalletsOnGoingReferendaService extends AbstractService_1.AbstractService {
/**
* Fetch all on-going referenda that have track: root (0) and whitelisted (1), along
* with their associated information.
*
* @param hash `BlockHash` to make call at
*/
async derivePalletOnGoingReferenda(hash) {
const { api } = this;
const [historicApi, { number }] = await Promise.all([api.at(hash), api.rpc.chain.getHeader(hash)]);
const referenda = [];
if (historicApi.query.referenda) {
const referendaEntries = await historicApi.query.referenda.referendumInfoFor.entries();
for (const referendum of referendaEntries) {
const referendumInfo = referendum[1];
if (referendumInfo.isSome) {
const refUnwrapped = referendumInfo.unwrap();
const refId = referendum[0].toHuman();
if (refUnwrapped.type == 'Ongoing' &&
(refUnwrapped.asOngoing.track.toHuman() == '0' || refUnwrapped.asOngoing.track.toHuman() == '1')) {
const decisionDeposit = refUnwrapped.asOngoing.decisionDeposit.isSome
? refUnwrapped.asOngoing.decisionDeposit.unwrap()
: null;
const enactment = refUnwrapped.asOngoing.enactment;
const submitted = refUnwrapped.asOngoing.submitted;
const deciding = refUnwrapped.asOngoing.deciding.isSome ? refUnwrapped.asOngoing.deciding.unwrap() : null;
const refInfo = { id: refId[0], decisionDeposit, enactment, submitted, deciding };
referenda.push(refInfo);
}
}
}
}
else {
throw new Error(`The runtime does not include the module 'api.query.referenda' at this block height: ${number
.unwrap()
.toString(10)}`);
}
const at = {
hash,
height: number.unwrap().toString(10),
};
return {
at,
referenda,
};
}
}
exports.PalletsOnGoingReferendaService = PalletsOnGoingReferendaService;
//# sourceMappingURL=PalletsOnGoingReferendaService.js.map