Skip to content

Commit

Permalink
fix add-all command
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Oct 26, 2023
1 parent d50d306 commit b1c536a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
73 changes: 39 additions & 34 deletions add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` " +
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@flowty/flow-contracts": "file:..",
"@flowtyio/flow-contracts": "file:.."
}
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ program.command("add-all")
.option('-a, --account <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)
Expand Down

0 comments on commit b1c536a

Please sign in to comment.