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
38
39
40
41
42
43 |
x2
x2
x2
x2
|
|
import type { Bytes } from '../index.ts';
import { fileURLToPath, resolvePath } from '../deps.ts';
import { Dir, Txt, Bin, Exec, Markdown } from '../context.ts';
import { Fn, Error, Name, Base16, Base64, Pipe, chunked, merged } from '../format.ts';
import { Btc } from './btc.ts';
/** Define a simple Simplicity program. */
export function Simplicity <S extends Simplicity> (...options: Partial<S>[]): S {
const {
name = Error.required("program name") as string,
simcPath = resolvePath(fileURLToPath(import.meta.url), '../simc'),
srcPath = `${name}.simf`,
source = null as (string|string[]),
witPath = `${name}.wit`,
witness = null as Bytes,
program = null,
...rest
} = merged({}, ...options) as S;
const write = Name(`Simf(Init ${name})`, Dir(
Markdown(`README.md`, `# ${name}`, `Generated by @hackbg/fadroma`),
Txt(srcPath, chunked('\n')(source)),
witness && Bin(witPath, witness)));
const build = Name(`Simf(Build ${name})`, Pipe(
(...path: string[]) => Exec(simcPath, resolvePath(...path)),
({ stdout }) => Base64.decode(stdout.split('\n')[1])));
const run = Name(`Simf(Run ${name})`,
(p = program) => Btc().execCli('signrawtransactionwithwallet', Base16.encode(p)));
return { name, srcPath, source, witPath, witness, program,
write, build, run, ...rest as S }
}
export type Simplicity = Partial<Dir> & {
name: string,
srcPath: string,
source: string|string[],
witPath: string,
witness: Bytes,
program: Bytes
simcPath: string,
btcPath: string,
} & {
write: Fn,
build: Fn,
run: Fn,
};
|