Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 25x 25x 25x 25x 165x 165x 165x 1059x 44x 531x 4x | import { Contract } from "@jonloucks/contracts-ts/api/Contract";
import { ContractException } from "@jonloucks/contracts-ts/api/ContractException";
import { Config as ContractsConfig } from "@jonloucks/contracts-ts/api/Contracts";
import { isRatifiedContract } from "@jonloucks/contracts-ts/api/RatifiedContract";
import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
import { Policy } from "./Policy";
import { used } from "../auxiliary/Checks";
export { RequiredType } from "@jonloucks/contracts-ts/api/Types";
export { Policy } from "./Policy";
/**
* Factory method to create Policy instance.
*
* @param config the configuration for the Policy instance
* @returns the Policy implementation
*/
export function create(config?: ContractsConfig): RequiredType<Policy> {
return {
checkContract: compileContractCheck(config)
};
}
// ---- Implementation details below ----
function compileContractCheck<T>(config?: ContractsConfig): (contract: Contract<T>) => void {
const ratified: boolean = config?.ratified ?? true;
if (ratified === false) {
return (c: Contract<T>) => { used(c); };
} else {
return (contract: Contract<T>) => {
if (isRatifiedContract(contract) === false) {
throw new ContractException("Action denied: Only a ratified contract can be used.");
}
};
}
} |