chore: Convert to a node style

This commit is contained in:
BluJ
2023-03-01 14:16:18 -07:00
parent 04f185f208
commit d4e0cdfd92
783 changed files with 11054 additions and 135393 deletions

View File

@@ -0,0 +1,554 @@
describe("Properties Matcher", () => {
test("matches", () => {
});
});
// import * as PM from "./propertiesMatcher";
// import { expect } from "https://deno.land/x/expect@v0.2.9/mod";
// import * as matches from "ts-matches";
// import { configSpec as bitcoinPropertiesConfig } from "./test/output";
// const randWithSeed = (seed = 1) => {
// return function random() {
// const x = Math.sin(seed++) * 10000;
// return x - Math.floor(x);
// };
// };
// const bitcoinProperties = bitcoinPropertiesConfig.build();
// type BitcoinProperties = typeof bitcoinProperties;
// const anyValue: unknown = "";
// const _testBoolean: boolean = anyValue as PM.GuardAll<
// BitcoinProperties["rpc"]["spec"]["enable"]
// >;
// // @ts-expect-error Boolean can't be a string
// const _testBooleanBad: string = anyValue as PM.GuardAll<
// BitcoinProperties["rpc"]["spec"]["enable"]
// >;
// const _testString: string = anyValue as PM.GuardAll<
// BitcoinProperties["rpc"]["spec"]["username"]
// >;
// // @ts-expect-error string can't be a boolean
// const _testStringBad: boolean = anyValue as PM.GuardAll<
// BitcoinProperties["rpc"]["spec"]["username"]
// >;
// const _testNumber: number = anyValue as PM.GuardAll<
// BitcoinProperties["advanced"]["spec"]["dbcache"]
// >;
// // @ts-expect-error Number can't be string
// const _testNumberBad: string = anyValue as PM.GuardAll<
// BitcoinProperties["advanced"]["spec"]["dbcache"]
// >;
// const _testObject: {
// enable: boolean;
// avoidpartialspends: boolean;
// discardfee: number;
// } = anyValue as PM.GuardAll<BitcoinProperties["wallet"]>;
// // @ts-expect-error Boolean can't be object
// const _testObjectBad: boolean = anyValue as PM.GuardAll<
// BitcoinProperties["wallet"]
// >;
// const _testObjectNested: { test: { a: boolean } } = anyValue as PM.GuardAll<{
// readonly type: "object";
// readonly spec: {
// readonly test: {
// readonly type: "object";
// readonly spec: {
// readonly a: {
// readonly type: "boolean";
// };
// };
// };
// };
// }>;
// const _testList: readonly string[] = anyValue as PM.GuardAll<{
// type: "list";
// subtype: "string";
// default: [];
// }>;
// // @ts-expect-error number[] can't be string[]
// const _testListBad: readonly number[] = anyValue as PM.GuardAll<{
// type: "list";
// subtype: "string";
// default: [];
// }>;
// const _testPointer: string | null = anyValue as PM.GuardAll<{
// type: "pointer";
// }>;
// const testUnionValue = anyValue as PM.GuardAll<{
// type: "union";
// tag: {
// id: "mode";
// name: "Pruning Mode";
// warning: null;
// description: '- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n';
// "variant-names": {
// disabled: "Disabled";
// automatic: "Automatic";
// manual: "Manual";
// };
// };
// variants: {
// disabled: Record<string, never>;
// automatic: {
// size: {
// type: "number";
// nullable: false;
// name: "Max Chain Size";
// description: "Limit of blockchain size on disk.";
// warning: "Increasing this value will require re-syncing your node.";
// default: 550;
// range: "[550,1000000)";
// integral: true;
// units: "MiB";
// placeholder: null;
// };
// };
// manual: {
// size: {
// type: "number";
// nullable: false;
// name: "Failsafe Chain Size";
// description: "Prune blockchain if size expands beyond this.";
// default: 65536;
// range: "[550,1000000)";
// integral: true;
// units: "MiB";
// };
// };
// };
// default: "disabled";
// }>;
// const _testUnion:
// | { mode: "disabled" }
// | { mode: "automatic"; size: number }
// | {
// mode: "manual";
// size: number;
// } = testUnionValue;
// //@ts-expect-error Bad mode name
// const _testUnionBadUnion:
// | { mode: "disabled" }
// | { mode: "bad"; size: number }
// | {
// mode: "manual";
// size: number;
// } = testUnionValue;
// const _testAll: PM.TypeFromProps<BitcoinProperties> = anyValue as {
// rpc: {
// enable: boolean;
// username: string;
// password: string;
// advanced: {
// auth: string[];
// serialversion: "non-segwit" | "segwit";
// servertimeout: number;
// threads: number;
// workqueue: number;
// };
// };
// "zmq-enabled": boolean;
// txindex: boolean;
// wallet: {
// enable: boolean;
// avoidpartialspends: boolean;
// discardfee: number;
// };
// advanced: {
// mempool: {
// mempoolfullrbf: boolean;
// persistmempool: boolean;
// maxmempool: number;
// mempoolexpiry: number;
// };
// peers: {
// listen: boolean;
// onlyconnect: boolean;
// onlyonion: boolean;
// addnode: readonly { hostname: string; port: number }[];
// };
// dbcache: number;
// pruning:
// | { mode: "disabled" }
// | { mode: "automatic"; size: number }
// | {
// mode: "manual";
// size: number;
// };
// blockfilters: {
// blockfilterindex: boolean;
// peerblockfilters: boolean;
// };
// bloomfilters: {
// peerbloomfilters: boolean;
// };
// };
// };
// const { test } = Deno;
// {
// test("matchNumberWithRange (1,4)", () => {
// const checker = PM.matchNumberWithRange("(1,4)");
// expect(checker.test(0)).toBe(false);
// expect(checker.test(1)).toBe(false);
// expect(checker.test(2)).toBe(true);
// expect(checker.test(3)).toBe(true);
// expect(checker.test(4)).toBe(false);
// expect(checker.test(5)).toBe(false);
// });
// test("matchNumberWithRange [1,4]", () => {
// const checker = PM.matchNumberWithRange("[1,4]");
// expect(checker.test(0)).toBe(false);
// expect(checker.test(1)).toBe(true);
// expect(checker.test(2)).toBe(true);
// expect(checker.test(3)).toBe(true);
// expect(checker.test(4)).toBe(true);
// expect(checker.test(5)).toBe(false);
// });
// test("matchNumberWithRange [1,*)", () => {
// const checker = PM.matchNumberWithRange("[1,*)");
// expect(checker.test(0)).toBe(false);
// expect(checker.test(1)).toBe(true);
// expect(checker.test(2)).toBe(true);
// expect(checker.test(3)).toBe(true);
// expect(checker.test(4)).toBe(true);
// expect(checker.test(5)).toBe(true);
// });
// test("matchNumberWithRange (*,4]", () => {
// const checker = PM.matchNumberWithRange("(*,4]");
// expect(checker.test(0)).toBe(true);
// expect(checker.test(1)).toBe(true);
// expect(checker.test(2)).toBe(true);
// expect(checker.test(3)).toBe(true);
// expect(checker.test(4)).toBe(true);
// expect(checker.test(5)).toBe(false);
// });
// }
// {
// test("Generate 1", () => {
// const random = randWithSeed(1);
// const options = { random };
// const generated = PM.generateDefault(
// { charset: "a-z,B-X,2-5", len: 100 },
// options
// );
// expect(generated.length).toBe(100);
// expect(generated).toBe(
// "WwwgjGRkvDaGQSLeKTtlOmdDbXoCBkOn3dxUvkKkrlOFd4FbKuvIosvfPTQhbWCTQakqnwpoHmPnbgyK5CGtSQyGhxEGLjS3oKko"
// );
// });
// test("Generate Tests", () => {
// const random = randWithSeed(2);
// const options = { random };
// expect(PM.generateDefault({ charset: "0-1", len: 100 }, options)).toBe(
// "0000110010000000000011110000010010000011101111001000000000000000100001101000010000001000010000010110"
// );
// expect(PM.generateDefault({ charset: "a-z", len: 100 }, options)).toBe(
// "qipnycbqmqdtflrhnckgrhftrqnvxbhyyfehpvficljseasxwdyleacmjqemmpnuotkwzlsqdumuaaksxykchljgdoslrfubhepr"
// );
// expect(
// PM.generateDefault({ charset: "a,b,c,d,f,g", len: 100 }, options)
// ).toBe(
// "bagbafcgaaddcabdfadccaadfbddffdcfccfbafbddbbfcdggfcgaffdbcgcagcfbdbfaagbfgfccdbfdfbdagcfdcabbdffaffc"
// );
// });
// }
// {
// test("Specs Union", () => {
// const checker = PM.guardAll(bitcoinProperties.advanced.spec.pruning);
// console.log("Checker = ", matches.Parser.parserAsString(checker.parser));
// checker.unsafeCast({ mode: "automatic", size: 1234 });
// });
// test("A default that is invalid according to the tests", () => {
// const checker = PM.typeFromProps({
// pubkey_whitelist: {
// name: "Pubkey Whitelist (hex)",
// description:
// "A list of pubkeys that are permitted to publish through your relay. A minimum, you need to enter your own Nostr hex (not npub) pubkey. Go to https://damus.io/key/ to convert from npub to hex.",
// type: "list",
// range: "[1,*)",
// subtype: "string",
// spec: {
// masked: false,
// placeholder: "hex (not npub) pubkey",
// pattern: "[0-9a-fA-F]{3}",
// "pattern-description":
// "Must be a valid 64-digit hexadecimal value (ie a Nostr hex pubkey, not an npub). Go to https://damus.io/key/ to convert npub to hex.",
// },
// default: [] as string[], // [] as string []
// warning: null,
// },
// } as const);
// checker.unsafeCast({
// pubkey_whitelist: ["aaa"],
// });
// });
// test("Bad list", () => {
// const props = {
// addWatchtowers: {
// type: "list",
// name: "Add Watchtowers",
// description: "Add URIs of Watchtowers to connect to.",
// warning: null,
// range: "[0,*)",
// subtype: "string",
// spec: {
// pattern: null,
// "pattern-description": null,
// masked: false,
// placeholder: "pubkey@host",
// },
// nullable: true,
// default: Array<string>(), // [] as string []
// },
// } as const;
// type test = PM.GuardList<(typeof props)["addWatchtowers"]>;
// function isType<A>(_a: A) {}
// isType<test>([""]);
// isType<ArrayLike<string>>([""] as test);
// const checker = PM.typeFromProps(props);
// checker.unsafeCast({
// addWatchtowers: ["aaa"],
// });
// expect(() => checker.unsafeCast({ addWatchtowers: 123 })).toThrow();
// });
// test("Full spec", () => {
// const checker = PM.typeFromProps(bitcoinProperties);
// checker.unsafeCast({
// rpc: {
// enable: true,
// username: "asdf",
// password: "asdf",
// advanced: {
// auth: ["test:34$aa"],
// serialversion: "non-segwit",
// servertimeout: 12,
// threads: 12,
// workqueue: 12,
// },
// },
// "zmq-enabled": false,
// txindex: false,
// wallet: {
// enable: true,
// avoidpartialspends: false,
// discardfee: 0,
// },
// advanced: {
// mempool: {
// mempoolfullrbf: false,
// persistmempool: false,
// maxmempool: 3012,
// mempoolexpiry: 321,
// },
// peers: {
// listen: false,
// onlyconnect: false,
// onlyonion: false,
// addnode: [{ hostname: "google.com", port: 231 }],
// },
// dbcache: 123,
// pruning: { mode: "automatic", size: 1234 },
// blockfilters: {
// blockfilterindex: false,
// peerblockfilters: false,
// },
// bloomfilters: {
// peerbloomfilters: false,
// },
// },
// });
// expect(() =>
// checker.unsafeCast({
// rpc: {
// enable: true,
// username: "asdf",
// password: "asdf",
// advanced: {
// auth: ["test:34$aa"],
// serialversion: "non-segwit",
// servertimeout: 12,
// threads: 12,
// workqueue: 12,
// },
// },
// "zmq-enabled": false,
// txindex: false,
// wallet: {
// enable: true,
// avoidpartialspends: false,
// discardfee: 0,
// },
// advanced: {
// mempool: {
// mempoolfullrbf: false,
// persistmempool: false,
// maxmempool: 3012,
// mempoolexpiry: 321,
// },
// peers: {
// listen: false,
// onlyconnect: false,
// onlyonion: false,
// addnode: [{ hostname: "google", port: 231 }],
// },
// dbcache: 123,
// pruning: { mode: "automatic", size: 1234 },
// blockfilters: {
// blockfilterindex: false,
// peerblockfilters: false,
// },
// bloomfilters: {
// peerbloomfilters: false,
// },
// },
// })
// ).toThrow();
// expect(() =>
// checker.unsafeCast({
// rpc: {
// enable: true,
// username: "asdf",
// password: "asdf",
// advanced: {
// auth: ["test34$aa"],
// serialversion: "non-segwit",
// servertimeout: 12,
// threads: 12,
// workqueue: 12,
// },
// },
// "zmq-enabled": false,
// txindex: false,
// wallet: {
// enable: true,
// avoidpartialspends: false,
// discardfee: 0,
// },
// advanced: {
// mempool: {
// mempoolfullrbf: false,
// persistmempool: false,
// maxmempool: 3012,
// mempoolexpiry: 321,
// },
// peers: {
// listen: false,
// onlyconnect: false,
// onlyonion: false,
// addnode: [{ hostname: "google.com", port: 231 }],
// },
// dbcache: 123,
// pruning: { mode: "automatic", size: 1234 },
// blockfilters: {
// blockfilterindex: false,
// peerblockfilters: false,
// },
// bloomfilters: {
// peerbloomfilters: false,
// },
// },
// })
// ).toThrow();
// expect(() =>
// checker.unsafeCast({
// rpc: {
// enable: true,
// username: "asdf",
// password: "asdf",
// advanced: {
// auth: ["test:34$aa"],
// serialversion: "non-segwit",
// servertimeout: 12,
// threads: 12,
// workqueue: 12,
// },
// },
// "zmq-enabled": false,
// txindex: false,
// wallet: {
// enable: true,
// avoidpartialspends: false,
// discardfee: 0,
// },
// advanced: {
// mempool: {
// mempoolfullrbf: false,
// persistmempool: false,
// maxmempool: 3012,
// mempoolexpiry: 321,
// },
// peers: {
// listen: false,
// onlyconnect: false,
// onlyonion: false,
// addnode: [{ hostname: "google.com", port: 231 }],
// },
// dbcache: 123,
// pruning: { mode: "automatic", size: "1234" },
// blockfilters: {
// blockfilterindex: false,
// peerblockfilters: false,
// },
// bloomfilters: {
// peerbloomfilters: false,
// },
// },
// })
// ).toThrow();
// checker.unsafeCast({
// rpc: {
// enable: true,
// username: "asdf",
// password: "asdf",
// advanced: {
// auth: ["test:34$aa"],
// serialversion: "non-segwit",
// servertimeout: 12,
// threads: 12,
// workqueue: 12,
// },
// },
// "zmq-enabled": false,
// txindex: false,
// wallet: {
// enable: true,
// avoidpartialspends: false,
// discardfee: 0,
// },
// advanced: {
// mempool: {
// mempoolfullrbf: false,
// persistmempool: false,
// maxmempool: 3012,
// mempoolexpiry: 321,
// },
// peers: {
// listen: false,
// onlyconnect: false,
// onlyonion: false,
// addnode: [{ hostname: "google.com", port: 231 }],
// },
// dbcache: 123,
// pruning: { mode: "automatic", size: 1234 },
// blockfilters: {
// blockfilterindex: false,
// peerblockfilters: false,
// },
// bloomfilters: {
// peerbloomfilters: false,
// },
// },
// });
// });
// }

View File

@@ -0,0 +1,320 @@
import * as matches from "ts-matches";
import { ConfigSpec, ValueSpec as ValueSpecAny } from "../types/config-types";
type TypeBoolean = "boolean";
type TypeString = "string";
type TypeNumber = "number";
type TypeObject = "object";
type TypeList = "list";
type TypeEnum = "enum";
type TypePointer = "pointer";
type TypeUnion = "union";
// prettier-ignore
// deno-fmt-ignore
type GuardDefaultNullable<A, Type> =
A extends { readonly default: unknown} ? Type :
A extends { readonly nullable: true} ? Type :
A extends {readonly nullable: false} ? Type | null | undefined :
Type
// prettier-ignore
// deno-fmt-ignore
type GuardNumber<A> =
A extends {readonly type:TypeNumber} ? GuardDefaultNullable<A, number> :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardString<A> =
A extends {readonly type:TypeString} ? GuardDefaultNullable<A, string> :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardBoolean<A> =
A extends {readonly type:TypeBoolean} ? GuardDefaultNullable<A, boolean> :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardObject<A> =
A extends {readonly type: TypeObject, readonly spec: infer B} ? (
B extends Record<string, unknown> ? {readonly [K in keyof B & string]: _<GuardAll<B[K]>>} :
{_error: "Invalid Spec"}
) :
unknown
// prettier-ignore
// deno-fmt-ignore
export type GuardList<A> =
A extends {readonly type:TypeList, readonly subtype: infer B, spec?: {spec?: infer C }} ? ReadonlyArray<GuardAll<Omit<A, "type" | "spec"> & ({type: B, spec: C})>> :
// deno-lint-ignore ban-types
A extends {readonly type:TypeList, readonly subtype: infer B, spec?: {}} ? ReadonlyArray<GuardAll<Omit<A, "type" > & ({type: B})>> :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardPointer<A> =
A extends {readonly type:TypePointer} ? (string | null) :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardEnum<A> =
A extends {readonly type:TypeEnum, readonly values: ArrayLike<infer B>} ? GuardDefaultNullable<A, B> :
unknown
// prettier-ignore
// deno-fmt-ignore
type GuardUnion<A> =
A extends {readonly type:TypeUnion, readonly tag: {id: infer Id & string}, variants: infer Variants & Record<string, unknown>} ? {[K in keyof Variants]: {[keyType in Id & string]: K}&TypeFromProps<Variants[K]>}[keyof Variants] :
unknown
type _<T> = T;
export type GuardAll<A> = GuardNumber<A> &
GuardString<A> &
GuardBoolean<A> &
GuardObject<A> &
GuardList<A> &
GuardPointer<A> &
GuardUnion<A> &
GuardEnum<A>;
// prettier-ignore
// deno-fmt-ignore
export type TypeFromProps<A> =
A extends Record<string, unknown> ? {readonly [K in keyof A & string]: _<GuardAll<A[K]>>} :
unknown;
const isType = matches.shape({ type: matches.string });
const recordString = matches.dictionary([matches.string, matches.unknown]);
const matchDefault = matches.shape({ default: matches.unknown });
const matchNullable = matches.shape({ nullable: matches.literal(true) });
const matchPattern = matches.shape({ pattern: matches.string });
const rangeRegex = /(\[|\()(\*|(\d|\.)+),(\*|(\d|\.)+)(\]|\))/;
const matchRange = matches.shape({ range: matches.regex(rangeRegex) });
const matchIntegral = matches.shape({ integral: matches.literal(true) });
const matchSpec = matches.shape({ spec: recordString });
const matchSubType = matches.shape({ subtype: matches.string });
const matchUnion = matches.shape({
tag: matches.shape({ id: matches.string }),
variants: recordString,
});
const matchValues = matches.shape({
values: matches.arrayOf(matches.string),
});
function charRange(value = "") {
const split = value
.split("-")
.filter(Boolean)
.map((x) => x.charCodeAt(0));
if (split.length < 1) return null;
if (split.length === 1) return [split[0], split[0]];
return [split[0], split[1]];
}
/**
* @param generate.charset Pattern like "a-z" or "a-z,1-5"
* @param generate.len Length to make random variable
* @param param1
* @returns
*/
export function generateDefault(
generate: { charset: string; len: number },
{ random = () => Math.random() } = {}
) {
const validCharSets: number[][] = generate.charset
.split(",")
.map(charRange)
.filter(Array.isArray);
if (validCharSets.length === 0) {
throw new Error("Expecing that we have a valid charset");
}
const max = validCharSets.reduce(
(acc, x) => x.reduce((x, y) => Math.max(x, y), acc),
0
);
let i = 0;
const answer: string[] = Array(generate.len);
while (i < generate.len) {
const nextValue = Math.round(random() * max);
const inRange = validCharSets.reduce(
(acc, [lower, upper]) =>
acc || (nextValue >= lower && nextValue <= upper),
false
);
if (!inRange) continue;
answer[i] = String.fromCharCode(nextValue);
i++;
}
return answer.join("");
}
function withPattern<A>(value: unknown) {
if (matchPattern.test(value)) return matches.regex(RegExp(value.pattern));
return matches.string;
}
export function matchNumberWithRange(range: string) {
const matched = rangeRegex.exec(range);
if (!matched) return matches.number;
const [, left, leftValue, , rightValue, , right] = matched;
return matches.number
.validate(
leftValue === "*"
? (_) => true
: left === "["
? (x) => x >= Number(leftValue)
: (x) => x > Number(leftValue),
leftValue === "*"
? "any"
: left === "["
? `greaterThanOrEqualTo${leftValue}`
: `greaterThan${leftValue}`
)
.validate(
rightValue === "*"
? (_) => true
: right === "]"
? (x) => x <= Number(rightValue)
: (x) => x < Number(rightValue),
rightValue === "*"
? "any"
: right === "]"
? `lessThanOrEqualTo${rightValue}`
: `lessThan${rightValue}`
);
}
function withIntegral(parser: matches.Parser<unknown, number>, value: unknown) {
if (matchIntegral.test(value)) {
return parser.validate(Number.isInteger, "isIntegral");
}
return parser;
}
function withRange(value: unknown) {
if (matchRange.test(value)) {
return matchNumberWithRange(value.range);
}
return matches.number;
}
const isGenerator = matches.shape({
charset: matches.string,
len: matches.number,
}).test;
function defaultNullable<A>(
parser: matches.Parser<unknown, A>,
value: unknown
) {
if (matchDefault.test(value)) {
if (isGenerator(value.default)) {
return parser.defaultTo(
parser.unsafeCast(generateDefault(value.default))
);
}
return parser.defaultTo(value.default);
}
if (matchNullable.test(value)) return parser.optional();
return parser;
}
/**
* ConfigSpec: Tells the UI how to ask for information, verification, and will send the service a config in a shape via the spec.
* ValueSpecAny: This is any of the values in a config spec.
*
* Use this when we want to convert a value spec any into a parser for what a config will look like
* @param value
* @returns
*/
export function guardAll<A extends ValueSpecAny>(
value: A
): matches.Parser<unknown, GuardAll<A>> {
if (!isType.test(value)) {
// deno-lint-ignore no-explicit-any
return matches.unknown as any;
}
switch (value.type) {
case "boolean":
// deno-lint-ignore no-explicit-any
return defaultNullable(matches.boolean, value) as any;
case "string":
// deno-lint-ignore no-explicit-any
return defaultNullable(withPattern(value), value) as any;
case "number":
return defaultNullable(
withIntegral(withRange(value), value),
value
// deno-lint-ignore no-explicit-any
) as any;
case "object":
if (matchSpec.test(value)) {
// deno-lint-ignore no-explicit-any
return defaultNullable(typeFromProps(value.spec), value) as any;
}
// deno-lint-ignore no-explicit-any
return matches.unknown as any;
case "list": {
const spec = (matchSpec.test(value) && value.spec) || {};
const rangeValidate =
(matchRange.test(value) && matchNumberWithRange(value.range).test) ||
(() => true);
const subtype = matchSubType.unsafeCast(value).subtype;
return defaultNullable(
matches
// deno-lint-ignore no-explicit-any
.arrayOf(guardAll({ type: subtype, ...spec } as any))
.validate((x) => rangeValidate(x.length), "valid length"),
value
// deno-lint-ignore no-explicit-any
) as any;
}
case "enum":
if (matchValues.test(value)) {
return defaultNullable(
matches.literals(value.values[0], ...value.values),
value
// deno-lint-ignore no-explicit-any
) as any;
}
// deno-lint-ignore no-explicit-any
return matches.unknown as any;
case "union":
if (matchUnion.test(value)) {
return matches.some(
...Object.entries(value.variants).map(([variant, spec]) =>
matches
.shape({ [value.tag.id]: matches.literal(variant) })
.concat(typeFromProps(spec))
) // deno-lint-ignore no-explicit-any
) as any;
}
// deno-lint-ignore no-explicit-any
return matches.unknown as any;
}
// deno-lint-ignore no-explicit-any
return matches.unknown as any;
}
/**
* ConfigSpec: Tells the UI how to ask for information, verification, and will send the service a config in a shape via the spec.
* ValueSpecAny: This is any of the values in a config spec.
*
* Use this when we want to convert a config spec into a parser for what a config will look like
* @param valueDictionary
* @returns
*/
export function typeFromProps<A extends ConfigSpec>(
valueDictionary: A
): matches.Parser<unknown, TypeFromProps<A>> {
// deno-lint-ignore no-explicit-any
if (!recordString.test(valueDictionary)) return matches.unknown as any;
return matches.shape(
Object.fromEntries(
Object.entries(valueDictionary).map(([key, value]) => [
key,
guardAll(value),
])
)
// deno-lint-ignore no-explicit-any
) as any;
}

View File

@@ -0,0 +1,326 @@
{
"rpc": {
"type": "object",
"name": "RPC Settings",
"description": "RPC configuration options.",
"spec": {
"enable": {
"type": "boolean",
"name": "Enable",
"description": "Allow remote RPC requests.",
"default": true
},
"username": {
"type": "string",
"nullable": false,
"name": "Username",
"description": "The username for connecting to Bitcoin over RPC.",
"default": "bitcoin",
"masked": true,
"pattern": "^[a-zA-Z0-9_]+$",
"pattern-description": "Must be alphanumeric (can contain underscore)."
},
"password": {
"type": "string",
"nullable": false,
"name": "RPC Password",
"description": "The password for connecting to Bitcoin over RPC.",
"default": {
"charset": "a-z,2-7",
"len": 20
},
"pattern": "^[^\\n\"]*$",
"pattern-description": "Must not contain newline or quote characters.",
"copyable": true,
"masked": true
},
"advanced": {
"type": "object",
"name": "Advanced",
"description": "Advanced RPC Settings",
"spec": {
"auth": {
"name": "Authorization",
"description": "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.",
"type": "list",
"subtype": "string",
"default": [],
"spec": {
"pattern": "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$",
"pattern-description": "Each item must be of the form \"<USERNAME>:<SALT>$<HASH>\".",
"masked": false
},
"range": "[0,*)"
},
"serialversion": {
"name": "Serialization Version",
"description": "Return raw transaction or block hex with Segwit or non-SegWit serialization.",
"type": "enum",
"values": ["non-segwit", "segwit"],
"value-names": {},
"default": "segwit"
},
"servertimeout": {
"name": "Rpc Server Timeout",
"description": "Number of seconds after which an uncompleted RPC call will time out.",
"type": "number",
"nullable": false,
"range": "[5,300]",
"integral": true,
"units": "seconds",
"default": 30
},
"threads": {
"name": "Threads",
"description": "Set the number of threads for handling RPC calls. You may wish to increase this if you are making lots of calls via an integration.",
"type": "number",
"nullable": false,
"default": 16,
"range": "[1,64]",
"integral": true
},
"workqueue": {
"name": "Work Queue",
"description": "Set the depth of the work queue to service RPC calls. Determines how long the backlog of RPC requests can get before it just rejects new ones.",
"type": "number",
"nullable": false,
"default": 128,
"range": "[8,256]",
"integral": true,
"units": "requests"
}
}
}
}
},
"zmq-enabled": {
"type": "boolean",
"name": "ZeroMQ Enabled",
"description": "Enable the ZeroMQ interface",
"default": true
},
"txindex": {
"type": "boolean",
"name": "Transaction Index",
"description": "Enable the Transaction Index (txindex)",
"default": true
},
"wallet": {
"type": "object",
"name": "Wallet",
"description": "Wallet Settings",
"spec": {
"enable": {
"name": "Enable Wallet",
"description": "Load the wallet and enable wallet RPC calls.",
"type": "boolean",
"default": true
},
"avoidpartialspends": {
"name": "Avoid Partial Spends",
"description": "Group outputs by address, selecting all or none, instead of selecting on a per-output basis. This improves privacy at the expense of higher transaction fees.",
"type": "boolean",
"default": true
},
"discardfee": {
"name": "Discard Change Tolerance",
"description": "The fee rate (in BTC/kB) that indicates your tolerance for discarding change by adding it to the fee.",
"type": "number",
"nullable": false,
"default": 0.0001,
"range": "[0,.01]",
"integral": false,
"units": "BTC/kB"
}
}
},
"advanced": {
"type": "object",
"name": "Advanced",
"description": "Advanced Settings",
"spec": {
"mempool": {
"type": "object",
"name": "Mempool",
"description": "Mempool Settings",
"spec": {
"mempoolfullrbf": {
"name": "Enable Full RBF",
"description": "Policy for your node to use for relaying and mining unconfirmed transactions. For details, see https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-24.0.md#notice-of-new-option-for-transaction-replacement-policies",
"type": "boolean",
"default": false
},
"persistmempool": {
"type": "boolean",
"name": "Persist Mempool",
"description": "Save the mempool on shutdown and load on restart.",
"default": true
},
"maxmempool": {
"type": "number",
"nullable": false,
"name": "Max Mempool Size",
"description": "Keep the transaction memory pool below <n> megabytes.",
"range": "[1,*)",
"integral": true,
"units": "MiB",
"default": 300
},
"mempoolexpiry": {
"type": "number",
"nullable": false,
"name": "Mempool Expiration",
"description": "Do not keep transactions in the mempool longer than <n> hours.",
"range": "[1,*)",
"integral": true,
"units": "Hr",
"default": 336
}
}
},
"peers": {
"type": "object",
"name": "Peers",
"description": "Peer Connection Settings",
"spec": {
"listen": {
"type": "boolean",
"name": "Make Public",
"description": "Allow other nodes to find your server on the network.",
"default": true
},
"onlyconnect": {
"type": "boolean",
"name": "Disable Peer Discovery",
"description": "Only connect to specified peers.",
"default": false
},
"onlyonion": {
"type": "boolean",
"name": "Disable Clearnet",
"description": "Only connect to peers over Tor.",
"default": false
},
"addnode": {
"name": "Add Nodes",
"description": "Add addresses of nodes to connect to.",
"type": "list",
"subtype": "object",
"range": "[0,*)",
"default": [],
"spec": {
"unique-by": null,
"spec": {
"hostname": {
"type": "string",
"nullable": false,
"name": "Hostname",
"description": "Domain or IP address of bitcoin peer",
"pattern": "(^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)|((^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)|(^[a-z2-7]{16}\\.onion$)|(^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$))",
"pattern-description": "Must be either a domain name, or an IPv4 or IPv6 address. Do not include protocol scheme (eg 'http://') or port.",
"masked": false
},
"port": {
"type": "number",
"nullable": true,
"name": "Port",
"description": "Port that peer is listening on for inbound p2p connections",
"range": "[0,65535]",
"integral": true
}
}
}
}
}
},
"dbcache": {
"type": "number",
"nullable": true,
"name": "Database Cache",
"description": "How much RAM to allocate for caching the TXO set. Higher values improve syncing performance, but increase your chance of using up all your system's memory or corrupting your database in the event of an ungraceful shutdown. Set this high but comfortably below your system's total RAM during IBD, then turn down to 450 (or leave blank) once the sync completes.",
"warning": "WARNING: Increasing this value results in a higher chance of ungraceful shutdowns, which can leave your node unusable if it happens during the initial block download. Use this setting with caution. Be sure to set this back to the default (450 or leave blank) once your node is synced. DO NOT press the STOP button if your dbcache is large. Instead, set this number back to the default, hit save, and wait for bitcoind to restart on its own.",
"range": "(0,*)",
"integral": true,
"units": "MiB"
},
"pruning": {
"type": "union",
"name": "Pruning Settings",
"description": "Blockchain Pruning Options\nReduce the blockchain size on disk\n",
"warning": "If you set pruning to Manual and your disk is smaller than the total size of the blockchain, you MUST have something running that prunes these blocks or you may overfill your disk!\nDisabling pruning will convert your node into a full archival node. This requires a resync of the entire blockchain, a process that may take several days. Make sure you have enough free disk space or you may fill up your disk.\n",
"tag": {
"id": "mode",
"name": "Pruning Mode",
"description": "- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the \"pruneblockchain\" RPC\n",
"variant-names": {
"disabled": "Disabled",
"automatic": "Automatic",
"manual": "Manual"
}
},
"variants": {
"disabled": {},
"automatic": {
"size": {
"type": "number",
"nullable": false,
"name": "Max Chain Size",
"description": "Limit of blockchain size on disk.",
"warning": "Increasing this value will require re-syncing your node.",
"default": 550,
"range": "[550,1000000)",
"integral": true,
"units": "MiB"
}
},
"manual": {
"size": {
"type": "number",
"nullable": false,
"name": "Failsafe Chain Size",
"description": "Prune blockchain if size expands beyond this.",
"default": 65536,
"range": "[550,1000000)",
"integral": true,
"units": "MiB"
}
}
},
"default": "disabled"
},
"blockfilters": {
"type": "object",
"name": "Block Filters",
"description": "Settings for storing and serving compact block filters",
"spec": {
"blockfilterindex": {
"type": "boolean",
"name": "Compute Compact Block Filters (BIP158)",
"description": "Generate Compact Block Filters during initial sync (IBD) to enable 'getblockfilter' RPC. This is useful if dependent services need block filters to efficiently scan for addresses/transactions etc.",
"default": true
},
"peerblockfilters": {
"type": "boolean",
"name": "Serve Compact Block Filters to Peers (BIP157)",
"description": "Serve Compact Block Filters as a peer service to other nodes on the network. This is useful if you wish to connect an SPV client to your node to make it efficient to scan transactions without having to download all block data. 'Compute Compact Block Filters (BIP158)' is required.",
"default": false
}
}
},
"bloomfilters": {
"type": "object",
"name": "Bloom Filters (BIP37)",
"description": "Setting for serving Bloom Filters",
"spec": {
"peerbloomfilters": {
"type": "boolean",
"name": "Serve Bloom Filters to Peers",
"description": "Peers have the option of setting filters on each connection they make after the version handshake has completed. Bloom filters are for clients implementing SPV (Simplified Payment Verification) that want to check that block headers connect together correctly, without needing to verify the full blockchain. The client must trust that the transactions in the chain are in fact valid. It is highly recommended AGAINST using for anything except Bisq integration.",
"warning": "This is ONLY for use with Bisq integration, please use Block Filters for all other applications.",
"default": false
}
}
}
}
}
}

View File

@@ -0,0 +1,450 @@
import { configBuilder } from "../../index";
const { Config, Value, List, Variants } = configBuilder;
export const enable = configBuilder.Value.boolean({
name: "Enable",
default: true,
description: "Allow remote RPC requests.",
warning: null,
});
export const username = Value.string({
name: "Username",
default: "bitcoin",
description: "The username for connecting to Bitcoin over RPC.",
warning: null,
nullable: false,
masked: true,
placeholder: null,
pattern: "^[a-zA-Z0-9_]+$",
"pattern-description": "Must be alphanumeric (can contain underscore).",
textarea: null,
});
export const password = Value.string({
name: "RPC Password",
default: {
charset: "a-z,2-7",
len: 20,
},
description: "The password for connecting to Bitcoin over RPC.",
warning: null,
nullable: false,
masked: true,
placeholder: null,
pattern: '^[^\\n"]*$',
"pattern-description": "Must not contain newline or quote characters.",
textarea: null,
});
export const authorizationList = List.string({
name: "Authorization",
range: "[0,*)",
spec: {
masked: null,
placeholder: null,
pattern: "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$",
"pattern-description":
'Each item must be of the form "<USERNAME>:<SALT>$<HASH>".',
textarea: false,
},
default: [],
description:
"Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.",
warning: null,
});
export const auth = Value.list(authorizationList);
export const serialversion = Value.enum({
name: "Serialization Version",
description:
"Return raw transaction or block hex with Segwit or non-SegWit serialization.",
warning: null,
default: "segwit",
values: ["non-segwit", "segwit"],
"value-names": {},
});
export const servertimeout = Value.number({
name: "Rpc Server Timeout",
default: 30,
description:
"Number of seconds after which an uncompleted RPC call will time out.",
warning: null,
nullable: false,
range: "[5,300]",
integral: true,
units: "seconds",
placeholder: null,
});
export const threads = Value.number({
name: "Threads",
default: 16,
description:
"Set the number of threads for handling RPC calls. You may wish to increase this if you are making lots of calls via an integration.",
warning: null,
nullable: false,
range: "[1,64]",
integral: true,
units: null,
placeholder: null,
});
export const workqueue = Value.number({
name: "Work Queue",
default: 128,
description:
"Set the depth of the work queue to service RPC calls. Determines how long the backlog of RPC requests can get before it just rejects new ones.",
warning: null,
nullable: false,
range: "[8,256]",
integral: true,
units: "requests",
placeholder: null,
});
export const advancedSpec = Config.of({
auth: auth,
serialversion: serialversion,
servertimeout: servertimeout,
threads: threads,
workqueue: workqueue,
});
export const advanced = Value.object({
name: "Advanced",
description: "Advanced RPC Settings",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: advancedSpec,
"value-names": {},
});
export const rpcSettingsSpec = Config.of({
enable: enable,
username: username,
password: password,
advanced: advanced,
});
export const rpc = Value.object({
name: "RPC Settings",
description: "RPC configuration options.",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: rpcSettingsSpec,
"value-names": {},
});
export const zmqEnabled = Value.boolean({
name: "ZeroMQ Enabled",
default: true,
description: "Enable the ZeroMQ interface",
warning: null,
});
export const txindex = Value.boolean({
name: "Transaction Index",
default: true,
description: "Enable the Transaction Index (txindex)",
warning: null,
});
export const enable1 = Value.boolean({
name: "Enable Wallet",
default: true,
description: "Load the wallet and enable wallet RPC calls.",
warning: null,
});
export const avoidpartialspends = Value.boolean({
name: "Avoid Partial Spends",
default: true,
description:
"Group outputs by address, selecting all or none, instead of selecting on a per-output basis. This improves privacy at the expense of higher transaction fees.",
warning: null,
});
export const discardfee = Value.number({
name: "Discard Change Tolerance",
default: 0.0001,
description:
"The fee rate (in BTC/kB) that indicates your tolerance for discarding change by adding it to the fee.",
warning: null,
nullable: false,
range: "[0,.01]",
integral: false,
units: "BTC/kB",
placeholder: null,
});
export const walletSpec = Config.of({
enable: enable1,
avoidpartialspends: avoidpartialspends,
discardfee: discardfee,
});
export const wallet = Value.object({
name: "Wallet",
description: "Wallet Settings",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: walletSpec,
"value-names": {},
});
export const mempoolfullrbf = Value.boolean({
name: "Enable Full RBF",
default: false,
description:
"Policy for your node to use for relaying and mining unconfirmed transactions. For details, see https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-24.0.md#notice-of-new-option-for-transaction-replacement-policies",
warning: null,
});
export const persistmempool = Value.boolean({
name: "Persist Mempool",
default: true,
description: "Save the mempool on shutdown and load on restart.",
warning: null,
});
export const maxmempool = Value.number({
name: "Max Mempool Size",
default: 300,
description: "Keep the transaction memory pool below <n> megabytes.",
warning: null,
nullable: false,
range: "[1,*)",
integral: true,
units: "MiB",
placeholder: null,
});
export const mempoolexpiry = Value.number({
name: "Mempool Expiration",
default: 336,
description: "Do not keep transactions in the mempool longer than <n> hours.",
warning: null,
nullable: false,
range: "[1,*)",
integral: true,
units: "Hr",
placeholder: null,
});
export const mempoolSpec = Config.of({
mempoolfullrbf: mempoolfullrbf,
persistmempool: persistmempool,
maxmempool: maxmempool,
mempoolexpiry: mempoolexpiry,
});
export const mempool = Value.object({
name: "Mempool",
description: "Mempool Settings",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: mempoolSpec,
"value-names": {},
});
export const listen = Value.boolean({
name: "Make Public",
default: true,
description: "Allow other nodes to find your server on the network.",
warning: null,
});
export const onlyconnect = Value.boolean({
name: "Disable Peer Discovery",
default: false,
description: "Only connect to specified peers.",
warning: null,
});
export const onlyonion = Value.boolean({
name: "Disable Clearnet",
default: false,
description: "Only connect to peers over Tor.",
warning: null,
});
export const hostname = Value.string({
name: "Hostname",
default: null,
description: "Domain or IP address of bitcoin peer",
warning: null,
nullable: false,
masked: null,
placeholder: null,
pattern:
"(^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)|((^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)|(^[a-z2-7]{16}\\.onion$)|(^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$))",
"pattern-description":
"Must be either a domain name, or an IPv4 or IPv6 address. Do not include protocol scheme (eg 'http://') or port.",
textarea: null,
});
export const port = Value.number({
name: "Port",
default: null,
description: "Port that peer is listening on for inbound p2p connections",
warning: null,
nullable: true,
range: "[0,65535]",
integral: true,
units: null,
placeholder: null,
});
export const addNodesSpec = Config.of({ hostname: hostname, port: port });
export const addNodesList = List.obj({
name: "Add Nodes",
range: "[0,*)",
spec: {
spec: addNodesSpec,
"display-as": null,
"unique-by": null,
},
default: [],
description: "Add addresses of nodes to connect to.",
warning: null,
});
export const addnode = Value.list(addNodesList);
export const peersSpec = Config.of({
listen: listen,
onlyconnect: onlyconnect,
onlyonion: onlyonion,
addnode: addnode,
});
export const peers = Value.object({
name: "Peers",
description: "Peer Connection Settings",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: peersSpec,
"value-names": {},
});
export const dbcache = Value.number({
name: "Database Cache",
default: null,
description:
"How much RAM to allocate for caching the TXO set. Higher values improve syncing performance, but increase your chance of using up all your system's memory or corrupting your database in the event of an ungraceful shutdown. Set this high but comfortably below your system's total RAM during IBD, then turn down to 450 (or leave blank) once the sync completes.",
warning:
"WARNING: Increasing this value results in a higher chance of ungraceful shutdowns, which can leave your node unusable if it happens during the initial block download. Use this setting with caution. Be sure to set this back to the default (450 or leave blank) once your node is synced. DO NOT press the STOP button if your dbcache is large. Instead, set this number back to the default, hit save, and wait for bitcoind to restart on its own.",
nullable: true,
range: "(0,*)",
integral: true,
units: "MiB",
placeholder: null,
});
export const disabled = Config.of({});
export const size = Value.number({
name: "Max Chain Size",
default: 550,
description: "Limit of blockchain size on disk.",
warning: "Increasing this value will require re-syncing your node.",
nullable: false,
range: "[550,1000000)",
integral: true,
units: "MiB",
placeholder: null,
});
export const automatic = Config.of({ size: size });
export const size1 = Value.number({
name: "Failsafe Chain Size",
default: 65536,
description: "Prune blockchain if size expands beyond this.",
warning: null,
nullable: false,
range: "[550,1000000)",
integral: true,
units: "MiB",
placeholder: null,
});
export const manual = Config.of({ size: size1 });
export const pruningSettingsVariants = Variants.of({
disabled: disabled,
automatic: automatic,
manual: manual,
});
export const pruning = Value.union({
name: "Pruning Settings",
description:
"Blockchain Pruning Options\nReduce the blockchain size on disk\n",
warning:
"If you set pruning to Manual and your disk is smaller than the total size of the blockchain, you MUST have something running that prunes these blocks or you may overfill your disk!\nDisabling pruning will convert your node into a full archival node. This requires a resync of the entire blockchain, a process that may take several days. Make sure you have enough free disk space or you may fill up your disk.\n",
default: "disabled",
variants: pruningSettingsVariants,
tag: {
id: "mode",
name: "Pruning Mode",
description:
'- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n',
warning: null,
"variant-names": {
disabled: "Disabled",
automatic: "Automatic",
manual: "Manual",
},
},
"display-as": null,
"unique-by": null,
"variant-names": null,
});
export const blockfilterindex = Value.boolean({
name: "Compute Compact Block Filters (BIP158)",
default: true,
description:
"Generate Compact Block Filters during initial sync (IBD) to enable 'getblockfilter' RPC. This is useful if dependent services need block filters to efficiently scan for addresses/transactions etc.",
warning: null,
});
export const peerblockfilters = Value.boolean({
name: "Serve Compact Block Filters to Peers (BIP157)",
default: false,
description:
"Serve Compact Block Filters as a peer service to other nodes on the network. This is useful if you wish to connect an SPV client to your node to make it efficient to scan transactions without having to download all block data. 'Compute Compact Block Filters (BIP158)' is required.",
warning: null,
});
export const blockFiltersSpec = Config.of({
blockfilterindex: blockfilterindex,
peerblockfilters: peerblockfilters,
});
export const blockfilters = Value.object({
name: "Block Filters",
description: "Settings for storing and serving compact block filters",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: blockFiltersSpec,
"value-names": {},
});
export const peerbloomfilters = Value.boolean({
name: "Serve Bloom Filters to Peers",
default: false,
description:
"Peers have the option of setting filters on each connection they make after the version handshake has completed. Bloom filters are for clients implementing SPV (Simplified Payment Verification) that want to check that block headers connect together correctly, without needing to verify the full blockchain. The client must trust that the transactions in the chain are in fact valid. It is highly recommended AGAINST using for anything except Bisq integration.",
warning:
"This is ONLY for use with Bisq integration, please use Block Filters for all other applications.",
});
export const bloomFiltersBip37Spec = Config.of({
peerbloomfilters: peerbloomfilters,
});
export const bloomfilters = Value.object({
name: "Bloom Filters (BIP37)",
description: "Setting for serving Bloom Filters",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: bloomFiltersBip37Spec,
"value-names": {},
});
export const advancedSpec1 = Config.of({
mempool: mempool,
peers: peers,
dbcache: dbcache,
pruning: pruning,
blockfilters: blockfilters,
bloomfilters: bloomfilters,
});
export const advanced1 = Value.object({
name: "Advanced",
description: "Advanced Settings",
warning: null,
default: null,
"display-as": null,
"unique-by": null,
spec: advancedSpec1,
"value-names": {},
});
export const configSpec = configBuilder.Config.of({
rpc: rpc,
"zmq-enabled": zmqEnabled,
txindex: txindex,
wallet: wallet,
advanced: advanced1,
});
export const matchConfigSpec = configSpec.validator();
export type ConfigSpec = typeof matchConfigSpec._TYPE;