From b1c536a076ae2ddb47041228c2e76ab236bb4915 Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Thu, 26 Oct 2023 08:10:23 -0700 Subject: [PATCH] fix add-all command --- add.js | 73 +++++++++++++++++++++++--------------------- example/package.json | 1 - index.js | 4 +-- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/add.js b/add.js index ba62930..e0042b0 100644 --- a/add.js +++ b/add.js @@ -3,39 +3,10 @@ const {getImports} = require("./dependency-tree"); const specialContractsHandlers = { "FungibleToken": (contract, userConfig, account) => { - console.log("FungibleToken requires some special setup. The account `emulator-ft` " + - "will be created and the contract will be deployed to it on the emulator. \nGoing forward, any deployments to the " + - "flow emulator will require the --update flag to work correctly.") - - const name = "FungibleToken" - - const serverPK = userConfig.accounts[account].key - const ftAccount = { - address: "ee82856bf20e2aa6", // this is the FungibleToken address on the flow emulator - key: serverPK - } - const emulatorAcct = "emulator-ft" - - // ensure emulator-ft is an account - userConfig.accounts[emulatorAcct] = ftAccount - if (!userConfig.deployments) { - userConfig.deployments = {} - } - - // ensure that emulator-ft is a deployment account - if (!userConfig.deployments.emulator) { - userConfig.deployments.emulator = {} - } - - if (!userConfig.deployments.emulator[emulatorAcct]) { - userConfig.deployments.emulator[emulatorAcct] = [] - } - - userConfig.contracts[name] = contract - - if (!userConfig.deployments.emulator[emulatorAcct].includes(name)) { - userConfig.deployments.emulator[emulatorAcct].push(name) - } + return handleFungibleTokenAccountContract(contract, userConfig, account, "FungibleToken") + }, + "FungibleTokenMetadataViews": (contract, userConfig, account) => { + return handleFungibleTokenAccountContract(contract, userConfig, account, "FungibleTokenMetadataViews") }, "FlowToken": (contract, userConfig, account) => { console.log("FlowToken requires some special setup. The account `emulator-flowtoken` " + @@ -46,7 +17,7 @@ const specialContractsHandlers = { const serverPK = userConfig.accounts[account].key const ftAccount = { - address: "e5a8b7f23e8b548f", // this is the FungibleToken address on the flow emulator + address: "0ae53cb6e3f42a79", // this is the FungibleToken address on the flow emulator key: serverPK } const emulatorAcct = "emulator-flowtoken" @@ -166,6 +137,40 @@ const addAll = (path, account) => { }) } +const handleFungibleTokenAccountContract = (contract, userConfig, account, contractName) => { + console.log(`FungibleToken requires some special setup. The account "emulator-ft"\n + will be created and the contract will be deployed to it on the emulator. \nGoing forward, any deployments to the\n + flow emulator will require the --update flag to work correctly.`) + + const serverPK = userConfig.accounts[account].key + const ftAccount = { + address: "ee82856bf20e2aa6", // this is the FungibleToken address on the flow emulator + key: serverPK + } + const emulatorAcct = "emulator-ft" + + // ensure emulator-ft is an account + userConfig.accounts[emulatorAcct] = ftAccount + if (!userConfig.deployments) { + userConfig.deployments = {} + } + + // ensure that emulator-ft is a deployment account + if (!userConfig.deployments.emulator) { + userConfig.deployments.emulator = {} + } + + if (!userConfig.deployments.emulator[emulatorAcct]) { + userConfig.deployments.emulator[emulatorAcct] = [] + } + + userConfig.contracts[contractName] = contract + + if (!userConfig.deployments.emulator[emulatorAcct].includes(contractName)) { + userConfig.deployments.emulator[emulatorAcct].push(contractName) + } +} + module.exports = { add, addAll diff --git a/example/package.json b/example/package.json index e668636..2528764 100644 --- a/example/package.json +++ b/example/package.json @@ -9,7 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "@flowty/flow-contracts": "file:..", "@flowtyio/flow-contracts": "file:.." } } diff --git a/index.js b/index.js index b9cad47..2e1494b 100755 --- a/index.js +++ b/index.js @@ -33,8 +33,8 @@ program.command("add-all") .option('-a, --account ', 'Account to be used for signing', 'emulator-account') .action(({config, account}) => { if(!config) { - options.config = getDefaultConfigPath() - console.log("no config specified, using default config: ", options.config) + config = getDefaultConfigPath() + console.log("no config specified, using default config: ", config) } addAll(config, account)