UNPKG

@leda-mint-io/candymachine-client-sdk

Version:

Metaplex Candy Machine Client SDK

66 lines (65 loc) 3.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateV2 = void 0; const web3_js_1 = require("@safecoin/web3.js"); const cache_1 = require("./cache"); /** * * Update a given candy machine with the new settings passed and cache. * At the end of the update, the updated cache can be downloaded. * @newSettings The new settings to update the candy machine with. * @candyMachinePubkey The public key of the candy machine to update. * @publicKey The public key of the authority of the candy machine * @treasuryWallet The public key of the treasury wallet * @anchorProgram The program that is used to update the candy machine. * @cache The cache to update the candy machine with. * @newAuthority (Optional) The new authority of the candy machine. */ function updateV2({ newSettings, candyMachinePubkey, publicKey, treasuryWallet, anchorProgram, cache, newAuthority, }) { return __awaiter(this, void 0, void 0, function* () { try { const cacheContent = JSON.parse(cache); const env = cacheContent.env; const cacheName = cacheContent.cacheName; const tx = yield anchorProgram.methods .updateCandyMachine(newSettings) .accounts({ candyMachine: new web3_js_1.PublicKey(candyMachinePubkey), authority: publicKey, wallet: treasuryWallet, }) .signers([]) .rpc(); cacheContent.startDate = newSettings.goLiveDate; console.log("update_candy_machine finished", tx); if (newAuthority) { const tx = yield anchorProgram.methods .updateAuthority(new web3_js_1.PublicKey(newAuthority)) .accounts({ candyMachine: new web3_js_1.PublicKey(candyMachinePubkey), authority: publicKey, wallet: treasuryWallet, }) .rpc(); cacheContent.authority = new web3_js_1.PublicKey(newAuthority).toBase58(); console.log(` - updated authority: ${cacheContent.authority}`); console.log("update_authority finished", tx); } (0, cache_1.saveCache)(cacheName, env, cacheContent); } catch (err) { console.error(err); throw new Error(); } }); } exports.updateV2 = updateV2;