UNPKG

leap-node

Version:

[![codecov](https://codecov.io/gh/leapdao/leap-node/branch/master/graph/badge.svg)](https://codecov.io/gh/leapdao/leap-node) [![Docker Repository on Quay](https://quay.io/repository/leapdao/leap-node/status "Docker Repository on Quay")](https://quay.io/re

32 lines (26 loc) 817 B
/* eslint-disable no-prototype-builtins */ function flagValue(bridgeState, flagHeights, flag) { const targetHeight = flagHeights[flag] || 0; return bridgeState.blockHeight >= targetHeight; } module.exports = (flags = []) => (bridgeState, flagHeights = {}) => { const proxy = new Proxy(flagHeights, { get(target, key) { if (key === 'toJSON') { return () => flags.reduce((flagValues, flag) => { flagValues[flag] = flagValue(bridgeState, target, flag); return flagValues; }, {}); } if (!flags.includes(key)) { throw new Error(`Unknown feature flag ${key}`); } return flagValue(bridgeState, target, key); }, set(_, key) { throw new Error(`Flags are read-only: ${key}`); }, }); return proxy; };