Bugfix/number of elements fix (#389)

* number of elements fix

* number of elements fix part 2
This commit is contained in:
Rad 2021-09-14 10:50:44 +12:00 committed by GitHub
parent 76de057a0c
commit 308fb29a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -35,7 +35,6 @@ programCommand('upload')
.option('-n, --number <number>', 'Number of images to upload')
.action(async (files: string[], options, cmd) => {
const {number, keypair, env, cacheName} = cmd.opts();
const parsedNumber = parseInt(number);
const pngFileCount = files.filter(it => {
return it.endsWith(EXTENSION_PNG);
@ -44,18 +43,23 @@ programCommand('upload')
return it.endsWith(EXTENSION_JSON);
}).length;
const parsedNumber = parseInt(number);
const elemCount = parsedNumber ? parsedNumber : pngFileCount;
if (pngFileCount !== jsonFileCount) {
throw new Error(`number of png files (${pngFileCount}) is different than the number of json files (${jsonFileCount})`);
}
if (parsedNumber < pngFileCount) {
throw new Error(`max number (${parsedNumber})cannot be smaller than the number of elements in the source folder (${pngFileCount})`);
if (elemCount < pngFileCount) {
throw new Error(`max number (${elemCount})cannot be smaller than the number of elements in the source folder (${pngFileCount})`);
}
log.info(`Beginning the upload for ${elemCount} (png+json) pairs`)
const startMs = Date.now();
log.info("started at: " + startMs.toString())
for (; ;) {
const successful = await upload(files, cacheName, env, keypair, parsedNumber);
const successful = await upload(files, cacheName, env, keypair, elemCount);
if (successful) {
break;
} else {

View File

@ -148,6 +148,6 @@ export async function loadAnchorProgram(walletKeyPair: Keypair, env: string) {
const idl = await anchor.Program.fetchIdl(CANDY_MACHINE_PROGRAM_ID, provider);
const program = new anchor.Program(idl, CANDY_MACHINE_PROGRAM_ID, provider);
log.info("program id from anchor", program.programId.toBase58());
log.debug("program id from anchor", program.programId.toBase58());
return program;
}