Skip to content

Commit 3b3131a

Browse files
committed
Self contained
1 parent 76905e0 commit 3b3131a

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

explorer/src/lib/parser.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export enum ConditionArgType {
6262
}
6363

6464
interface BundleContext {
65+
selfContained: boolean;
6566
announcementCoinIds: Record<string, Uint8Array>;
6667
announcementPuzzleHashes: Record<string, Uint8Array>;
6768
announcementMessages: Record<string, Uint8Array>;
@@ -80,11 +81,15 @@ interface DeserializedCoinSpend {
8081
conditions: Program[];
8182
}
8283

83-
export function parseSpendBundle(spendBundle: SpendBundle): ParsedSpendBundle {
84+
export function parseSpendBundle(
85+
spendBundle: SpendBundle,
86+
selfContained: boolean,
87+
): ParsedSpendBundle {
8488
const clvm = new Clvm();
8589

8690
const deserializedCoinSpends: DeserializedCoinSpend[] = [];
8791
const announcements: BundleContext = {
92+
selfContained,
8893
announcementCoinIds: {},
8994
announcementPuzzleHashes: {},
9095
announcementMessages: {},
@@ -321,7 +326,10 @@ function parseCondition(
321326
type: ConditionArgType.Copiable,
322327
};
323328

324-
if (!ctx.coinAnnouncementAssertions.has(announcementId)) {
329+
if (
330+
!ctx.coinAnnouncementAssertions.has(announcementId) &&
331+
ctx.selfContained
332+
) {
325333
warning = 'Not asserted';
326334
}
327335
}
@@ -345,7 +353,7 @@ function parseCondition(
345353
value: `0x${toHex(ctx.announcementCoinIds[announcementId])}`,
346354
type: ConditionArgType.CoinId,
347355
};
348-
} else {
356+
} else if (ctx.selfContained) {
349357
warning = 'Announcement does not exist';
350358
}
351359

@@ -384,7 +392,10 @@ function parseCondition(
384392
type: ConditionArgType.Copiable,
385393
};
386394

387-
if (!ctx.puzzleAnnouncementAssertions.has(announcementId)) {
395+
if (
396+
!ctx.puzzleAnnouncementAssertions.has(announcementId) &&
397+
ctx.selfContained
398+
) {
388399
warning = 'Not asserted';
389400
}
390401
}
@@ -408,7 +419,7 @@ function parseCondition(
408419
value: `0x${toHex(ctx.announcementPuzzleHashes[announcementId])}`,
409420
type: ConditionArgType.Copiable,
410421
};
411-
} else {
422+
} else if (ctx.selfContained) {
412423
warning = 'Announcement does not exist';
413424
}
414425

@@ -428,7 +439,10 @@ function parseCondition(
428439
type: ConditionArgType.CoinId,
429440
};
430441

431-
if (!ctx.spentCoinIds.has(toHex(assertConcurrentSpend.coinId))) {
442+
if (
443+
!ctx.spentCoinIds.has(toHex(assertConcurrentSpend.coinId)) &&
444+
ctx.selfContained
445+
) {
432446
warning = 'Coin not spent';
433447
}
434448
}
@@ -443,7 +457,10 @@ function parseCondition(
443457
type: ConditionArgType.Copiable,
444458
};
445459

446-
if (!ctx.spentPuzzleHashes.has(toHex(assertConcurrentPuzzle.puzzleHash))) {
460+
if (
461+
!ctx.spentPuzzleHashes.has(toHex(assertConcurrentPuzzle.puzzleHash)) &&
462+
ctx.selfContained
463+
) {
447464
warning = 'Puzzle not spent';
448465
}
449466
}
@@ -576,7 +593,7 @@ function parseCondition(
576593
type = ConditionType.Assertion;
577594
name = 'ASSERT_EPHEMERAL';
578595

579-
if (!ctx.createdCoinIds.has(toHex(coin.coinId()))) {
596+
if (!ctx.createdCoinIds.has(toHex(coin.coinId())) && ctx.selfContained) {
580597
warning = 'Coin not created ephemerally in this bundle';
581598
}
582599
}

explorer/src/pages/Tools.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import { useLocalStorage } from 'usehooks-ts';
2424
export function Tools() {
2525
const [value, setValue] = useLocalStorage('tools-bundle', '');
2626

27-
const spendBundle = useMemo(() => {
27+
const parsedSpendBundle = useMemo(() => {
2828
if (!value) return null;
2929

3030
try {
31-
return decodeOffer(value);
31+
return parseSpendBundle(decodeOffer(value), true);
3232
} catch {
3333
// Not a valid offer
3434
}
@@ -37,9 +37,12 @@ export function Tools() {
3737
const result = parseJson(JSON.parse(value));
3838

3939
if (result instanceof SpendBundle) {
40-
return result;
40+
return parseSpendBundle(result, true);
4141
} else if (result instanceof CoinSpend) {
42-
return new SpendBundle([result], Signature.infinity());
42+
return parseSpendBundle(
43+
new SpendBundle([result], Signature.infinity()),
44+
false,
45+
);
4346
} else if (result instanceof Coin) {
4447
return null;
4548
}
@@ -50,12 +53,6 @@ export function Tools() {
5053
return null;
5154
}, [value]);
5255

53-
const parsedSpendBundle = useMemo(() => {
54-
if (!spendBundle) return null;
55-
56-
return parseSpendBundle(spendBundle);
57-
}, [spendBundle]);
58-
5956
return (
6057
<Layout>
6158
<Textarea

0 commit comments

Comments
 (0)