Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions clients/js/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ program

// Upload metadata command.
type UploadOptions = GlobalOptions & {
thirdParty: boolean;
nonCanonical: boolean;
file?: string;
url?: string;
account?: string;
Expand All @@ -111,7 +111,7 @@ program
)
.description('Upload metadata')
.option(
'--third-party',
'--non-canonical',
'When provided, a non-canonical metadata account will be uploaded using the active keypair as the authority.',
false
)
Expand Down Expand Up @@ -170,9 +170,9 @@ program
client.rpc,
program
);
if (!options.thirdParty && keypair.address !== programAuthority) {
if (!options.nonCanonical && keypair.address !== programAuthority) {
logErrorAndExit(
'You must be the program authority to upload a canonical metadata account. Use `--third-party` option to upload as a third party.'
'You must be the program authority to upload a canonical metadata account. Use `--non-canonical` option to upload as a third party.'
);
}
const { lastTransaction } = await uploadMetadata({
Expand Down Expand Up @@ -211,7 +211,7 @@ program
// Download metadata command.
type DownloadOptions = GlobalOptions & {
output?: string;
thirdParty?: string | true;
nonCanonical?: string | true;
};
program
.command('download')
Expand All @@ -224,18 +224,18 @@ program
)
.option('-o, --output <path>', 'Path to save the IDL file')
.option(
'--third-party [address]',
'--non-canonical [address]',
'When provided, a non-canonical metadata account will be downloaded using the provided address or the active keypair as the authority.',
false
)
.action(async (seed: string, program: Address, _, cmd: Command) => {
const options = cmd.optsWithGlobals() as DownloadOptions;
const client = getClient(options);
const authority =
options.thirdParty === true
options.nonCanonical === true
? (await getKeyPairSigners(options, client.configs))[0].address
: options.thirdParty
? address(options.thirdParty)
: options.nonCanonical
? address(options.nonCanonical)
: undefined;
try {
const content = await downloadMetadata(
Expand Down Expand Up @@ -349,7 +349,7 @@ program
});

type SetImmutableOptions = GlobalOptions & {
thirdParty: boolean;
nonCanonical: boolean;
};
program
.command('set-immutable')
Expand All @@ -363,7 +363,7 @@ program
address
)
.option(
'--third-party',
'--non-canonical',
'When provided, a non-canonical metadata account will be updated using the active keypair as the authority.',
false
)
Expand All @@ -375,9 +375,9 @@ program
client.rpc,
program
);
if (!options.thirdParty && keypair.address !== programAuthority) {
if (!options.nonCanonical && keypair.address !== programAuthority) {
logErrorAndExit(
'You must be the program authority to update a canonical metadata account. Use `--third-party` option to update as a third party.'
'You must be the program authority to update a canonical metadata account. Use `--non-canonical` option to update as a third party.'
);
}
const { metadata, programData } = await getPdaDetails({
Expand Down Expand Up @@ -406,7 +406,7 @@ program
});

type CloseOptions = GlobalOptions & {
thirdParty: boolean;
nonCanonical: boolean;
};
program
.command('close')
Expand All @@ -418,7 +418,7 @@ program
address
)
.option(
'--third-party',
'--non-canonical',
'When provided, a non-canonical metadata account will be closed using the active keypair as the authority.',
false
)
Expand All @@ -430,9 +430,9 @@ program
client.rpc,
program
);
if (!options.thirdParty && keypair.address !== programAuthority) {
if (!options.nonCanonical && keypair.address !== programAuthority) {
logErrorAndExit(
'You must be the program authority to close a canonical metadata account. Use `--third-party` option to close as a third party.'
'You must be the program authority to close a canonical metadata account. Use `--non-canonical` option to close as a third party.'
);
}
const { metadata, programData } = await getPdaDetails({
Expand Down
27 changes: 11 additions & 16 deletions clients/js/src/updateMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getTransferSolInstruction } from '@solana-program/system';
import {
getCreateAccountInstruction,
getTransferSolInstruction,
} from '@solana-program/system';
import {
CompilableTransactionMessage,
generateKeyPairSigner,
Expand All @@ -16,6 +19,7 @@ import {
getSetAuthorityInstruction,
getSetDataInstruction,
getTrimInstruction,
PROGRAM_METADATA_PROGRAM_ADDRESS,
} from './generated';
import {
calculateMaxChunkSize,
Expand Down Expand Up @@ -191,10 +195,12 @@ export function getUpdateMetadataInstructionPlanUsingBuffer(
}

initialMessage.instructions.push(
getTransferSolInstruction({
source: input.payer,
destination: input.buffer.address,
amount: input.bufferRent,
getCreateAccountInstruction({
payer: input.payer,
newAccount: input.buffer,
lamports: input.bufferRent,
space: getAccountSize(input.data.length),
programAddress: PROGRAM_METADATA_PROGRAM_ADDRESS,
}),
getAllocateInstruction({
buffer: input.buffer.address,
Expand All @@ -221,17 +227,6 @@ export function getUpdateMetadataInstructionPlanUsingBuffer(
);
}

if (input.data.length > REALLOC_LIMIT) {
mainPlan.plans.push(
getExtendInstructionPlan({
account: input.buffer.address,
authority: input.authority,
extraLength: input.data.length,
priorityFees: input.priorityFees,
})
);
}

let offset = 0;
const writePlan: InstructionPlan = { kind: 'parallel', plans: [] };
while (offset < input.data.length) {
Expand Down