|
1 | | -import { fetchCandyGuard, fetchCandyMachine, findCandyGuardPda } from '@metaplex-foundation/mpl-core-candy-machine' |
| 1 | +import { CandyGuard, fetchCandyGuard, fetchCandyMachine } from '@metaplex-foundation/mpl-core-candy-machine' |
2 | 2 | import { publicKey } from '@metaplex-foundation/umi' |
3 | 3 | import { Args, Flags } from '@oclif/core' |
4 | | -import fs from 'node:fs' |
5 | | -import path from 'node:path' |
| 4 | +import { readCmConfig } from '../../lib/cm/cm-utils.js' |
6 | 5 | import { jsonStringify } from '../../lib/util.js' |
7 | 6 | import { TransactionCommand } from '../../TransactionCommand.js' |
8 | | -import { readCmConfig } from '../../lib/cm/cm-utils.js' |
9 | 7 |
|
10 | 8 | export default class CmFetch extends TransactionCommand<typeof CmFetch> { |
11 | 9 | static override description = `Fetch candy machine and guard data from the blockchain` |
12 | 10 |
|
13 | 11 | static override examples = [ |
14 | 12 | '$ mplx cm fetch', |
15 | 13 | '$ mplx cm fetch <address>', |
| 14 | + '$ mplx cm fetch --items', |
| 15 | + '$ mplx cm fetch <address> --items', |
16 | 16 | ] |
17 | 17 |
|
18 | 18 | static override usage = 'cm fetch [FLAGS] [ARGS]' |
@@ -47,12 +47,33 @@ export default class CmFetch extends TransactionCommand<typeof CmFetch> { |
47 | 47 | this.error('No address provided and no config file found with candy machine address'); |
48 | 48 | } |
49 | 49 |
|
| 50 | + |
| 51 | + let candyGuard: CandyGuard | undefined = undefined; |
| 52 | + let authorityOnlyMinting: boolean = false; |
| 53 | + |
50 | 54 | const { items, ...candyMachine } = await fetchCandyMachine(umi, publicKey(address)); |
51 | | - const candyGuardPda = findCandyGuardPda(umi, { base: candyMachine.publicKey }); |
52 | | - const candyGuard = await fetchCandyGuard(umi, candyGuardPda); |
| 55 | + const mintAuthority = candyMachine.mintAuthority; |
| 56 | + if (mintAuthority === candyMachine.authority) { |
| 57 | + authorityOnlyMinting = true; |
| 58 | + } else { |
| 59 | + this.log(`Checking if mint authority is a Candy Guard...`); |
| 60 | + candyGuard = await fetchCandyGuard(umi, candyMachine.mintAuthority) |
| 61 | + .then(guard => guard) |
| 62 | + .catch(error => { |
| 63 | + this.log(`Failed to fetch candy guard: ${error instanceof Error ? error.message : String(error)}`); |
| 64 | + this.log(`The mint authority address ${candyMachine.mintAuthority} doesn't appear to be a valid candy guard, may be a custom program`); |
| 65 | + return undefined; |
| 66 | + }); |
| 67 | + } |
53 | 68 |
|
54 | 69 | this.log(jsonStringify(candyMachine, 2)); |
55 | | - this.log(jsonStringify(candyGuard, 2)); |
| 70 | + if (candyGuard) { |
| 71 | + this.log(jsonStringify(candyGuard, 2)); |
| 72 | + } else if (authorityOnlyMinting) { |
| 73 | + this.log(`No candy guard - using authority-only minting`); |
| 74 | + } else { |
| 75 | + this.log(`No candy guard found - mint authority may be a custom program`); |
| 76 | + } |
56 | 77 |
|
57 | 78 | if (flags.items) { |
58 | 79 | this.log(jsonStringify(items, 2)); |
|
0 commit comments