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

Function debugTemplate

packages/cashscript/src/debugging.ts:36–64  ·  view source on GitHub ↗
(template: WalletTemplate, artifacts: Artifact[])

Source from the content-addressed store, hash-verified

34
35// debugs the template, optionally logging the execution data
36export const debugTemplate = (template: WalletTemplate, artifacts: Artifact[]): DebugResults => {
37 // If a contract has the same name, but a different bytecode, then it is considered a name collision
38 const hasArtifactNameCollision = artifacts.some(
39 (artifact) => (
40 artifacts.some((other) => other.contractName === artifact.contractName && other.bytecode !== artifact.bytecode)
41 ),
42 );
43
44 if (hasArtifactNameCollision) {
45 throw new Error('There are multiple artifacts with the same contractName. Please make sure that all artifacts have unique names.');
46 }
47
48 const results: DebugResults = {};
49 const unlockingScriptIds = Object.keys(template.scripts).filter((key) => 'unlocks' in template.scripts[key]);
50
51 for (const unlockingScriptId of unlockingScriptIds) {
52 const scenarioIds = (template.scripts[unlockingScriptId] as WalletTemplateScriptUnlocking).passes ?? [];
53
54 const matchingArtifact = artifacts.find((artifact) => unlockingScriptId.startsWith(artifact.contractName));
55
56 for (const scenarioId of scenarioIds) {
57 results[`${unlockingScriptId}.${scenarioId}`] = debugSingleScenario(template, matchingArtifact, unlockingScriptId, scenarioId);
58 }
59 }
60
61 verifyFullTransaction(template);
62
63 return results;
64};
65
66const debugSingleScenario = (
67 template: WalletTemplate, artifact: Artifact | undefined, unlockingScriptId: string, scenarioId: string,

Callers 1

debugLibauthTemplateFunction · 0.85

Calls 2

debugSingleScenarioFunction · 0.85
verifyFullTransactionFunction · 0.85

Tested by

no test coverage detected