MCPcopy Create free account
hub / github.com/CashScript/cashscript / createProgram

Function createProgram

packages/cashscript/src/debugging.ts:206–234  ·  view source on GitHub ↗
(template: WalletTemplate, unlockingScriptId: string, scenarioId: string)

Source from the content-addressed store, hash-verified

204
205// internal util. instantiates the virtual machine and compiles the template into a program
206const createProgram = (template: WalletTemplate, unlockingScriptId: string, scenarioId: string): CreateProgramResult => {
207 const configuration = walletTemplateToCompilerConfiguration(template);
208 const vm = createVirtualMachine(template.supported[0] as VmTarget);
209 const compiler = createCompiler(configuration);
210
211 if (!template.scripts[unlockingScriptId]) {
212 throw new Error(`No unlock script found in template for ID ${unlockingScriptId}`);
213 }
214
215 if (!template.scenarios?.[scenarioId]) {
216 throw new Error(`No scenario found in template for ID ${scenarioId}`);
217 }
218
219 const scenarioGeneration = compiler.generateScenario({
220 debug: true,
221 unlockingScriptId,
222 scenarioId,
223 });
224
225 if (typeof scenarioGeneration === 'string') {
226 throw new FailedTransactionError(scenarioGeneration, getBitauthUri(template));
227 }
228
229 if (typeof scenarioGeneration.scenario === 'string') {
230 throw new FailedTransactionError(scenarioGeneration.scenario, getBitauthUri(template));
231 }
232
233 return { vm, program: scenarioGeneration.scenario.program };
234};
235
236const logConsoleLogStatement = (
237 log: LogEntry,

Callers 2

debugSingleScenarioFunction · 0.85
verifyFullTransactionFunction · 0.85

Calls 2

createVirtualMachineFunction · 0.85
getBitauthUriFunction · 0.85

Tested by

no test coverage detected