Files
api/packages/api-derive/src/util/approvalFlagToBool.ts
T
Jaco Greeff 2a37b8746d Rename srml to interfaces (#1198)
* Rename srml to interfaces

* newline, package.json
2019-07-26 12:08:17 +02:00

22 lines
753 B
TypeScript

// Copyright 2017-2019 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApprovalFlag } from '@polkadot/types/interfaces/elections';
import BN from 'bn.js';
import { Vec } from '@polkadot/types';
export function approvalFlagToBool (flags: Vec<ApprovalFlag>): boolean[] {
const bools: boolean[] = [];
for (const flag of flags) {
for (const bit of [...Array(flag.bitLength())].map((_, i): number => i)) {
bools.push(!flag.toBn().uand((new BN(1)).shln(bit)).isZero());
}
}
const lastApproval: number = bools.lastIndexOf(true);
return lastApproval >= 0 ? bools.slice(0, lastApproval + 1) : [];
}