|
1 | | -import { isRunestone } from './src/artifact'; |
| 1 | +import { isRunestone as isRunestoneArtifact } from './src/artifact'; |
2 | 2 | import { MAX_DIVISIBILITY } from './src/constants'; |
3 | 3 | import { Etching } from './src/etching'; |
| 4 | +import { Flaw as FlawEnum } from './src/flaw'; |
4 | 5 | import { RuneEtchingSpec } from './src/indexer'; |
5 | 6 | import { u128, u32, u64, u8 } from './src/integer'; |
6 | 7 | import { None, Option, Some } from './src/monads'; |
@@ -56,15 +57,52 @@ export type RunestoneSpec = { |
56 | 57 | }[]; |
57 | 58 | }; |
58 | 59 |
|
| 60 | +export type Flaw = |
| 61 | + | 'edict_output' |
| 62 | + | 'edict_rune_id' |
| 63 | + | 'invalid_script' |
| 64 | + | 'opcode' |
| 65 | + | 'supply_overflow' |
| 66 | + | 'trailing_integers' |
| 67 | + | 'truncated_field' |
| 68 | + | 'unrecognized_even_tag' |
| 69 | + | 'unrecognized_flag' |
| 70 | + | 'varint'; |
| 71 | + |
59 | 72 | export type Cenotaph = { |
60 | | - flaws: string[]; |
| 73 | + flaws: Flaw[]; |
61 | 74 | etching?: string; |
62 | 75 | mint?: { |
63 | 76 | block: bigint; |
64 | 77 | tx: number; |
65 | 78 | }; |
66 | 79 | }; |
67 | 80 |
|
| 81 | +function getFlawString(flaw: FlawEnum): Flaw { |
| 82 | + switch (flaw) { |
| 83 | + case FlawEnum.EDICT_OUTPUT: |
| 84 | + return 'edict_output'; |
| 85 | + case FlawEnum.EDICT_RUNE_ID: |
| 86 | + return 'edict_rune_id'; |
| 87 | + case FlawEnum.INVALID_SCRIPT: |
| 88 | + return 'invalid_script'; |
| 89 | + case FlawEnum.OPCODE: |
| 90 | + return 'opcode'; |
| 91 | + case FlawEnum.SUPPLY_OVERFLOW: |
| 92 | + return 'supply_overflow'; |
| 93 | + case FlawEnum.TRAILING_INTEGERS: |
| 94 | + return 'trailing_integers'; |
| 95 | + case FlawEnum.TRUNCATED_FIELD: |
| 96 | + return 'truncated_field'; |
| 97 | + case FlawEnum.UNRECOGNIZED_EVEN_TAG: |
| 98 | + return 'unrecognized_even_tag'; |
| 99 | + case FlawEnum.UNRECOGNIZED_FLAG: |
| 100 | + return 'unrecognized_flag'; |
| 101 | + case FlawEnum.VARINT: |
| 102 | + return 'varint'; |
| 103 | + } |
| 104 | +} |
| 105 | + |
68 | 106 | // Helper functions to ensure numbers fit the desired type correctly |
69 | 107 | const u8Strict = (n: number) => { |
70 | 108 | const bigN = BigInt(n); |
@@ -195,14 +233,18 @@ export function encodeRunestone(runestone: RunestoneSpec): { |
195 | 233 | }; |
196 | 234 | } |
197 | 235 |
|
| 236 | +export function isRunestone(artifact: RunestoneSpec | Cenotaph): artifact is RunestoneSpec { |
| 237 | + return !('flaws' in artifact); |
| 238 | +} |
| 239 | + |
198 | 240 | export function tryDecodeRunestone(tx: RunestoneTx): RunestoneSpec | Cenotaph | null { |
199 | 241 | const optionArtifact = Runestone.decipher(tx); |
200 | 242 | if (optionArtifact.isNone()) { |
201 | 243 | return null; |
202 | 244 | } |
203 | 245 |
|
204 | 246 | const artifact = optionArtifact.unwrap(); |
205 | | - if (isRunestone(artifact)) { |
| 247 | + if (isRunestoneArtifact(artifact)) { |
206 | 248 | const runestone = artifact; |
207 | 249 |
|
208 | 250 | const etching = () => runestone.etching.unwrap(); |
@@ -286,7 +328,7 @@ export function tryDecodeRunestone(tx: RunestoneTx): RunestoneSpec | Cenotaph | |
286 | 328 | } else { |
287 | 329 | const cenotaph = artifact; |
288 | 330 | return { |
289 | | - flaws: [], |
| 331 | + flaws: cenotaph.flaws.map(getFlawString), |
290 | 332 | ...(cenotaph.etching.isSome() ? { etching: cenotaph.etching.unwrap().toString() } : {}), |
291 | 333 | ...(cenotaph.mint.isSome() |
292 | 334 | ? { mint: { block: cenotaph.mint.unwrap().block, tx: Number(cenotaph.mint.unwrap().tx) } } |
|
0 commit comments