diff --git a/cli/lib/nf3.mjs b/cli/lib/nf3.mjs index 3b4df53af..e34895825 100644 --- a/cli/lib/nf3.mjs +++ b/cli/lib/nf3.mjs @@ -239,7 +239,7 @@ class Nf3 { } /** - Returns the address of a Nightfall_3 contract. + Returns the address of a Nightfall_3 contract calling the client. @method @async @param {string} contractName - the name of the smart contract in question. Possible @@ -251,6 +251,19 @@ class Nf3 { return res.data.address; } + /** + Returns the address of a Nightfall_3 contract calling the optimist. + @method + @async + @param {string} contractName - the name of the smart contract in question. Possible + values are 'Shield', 'State', 'Proposers', 'Challengers'. + @returns {Promise} Resolves into the Ethereum address of the contract + */ + async getContractAddressOptimist(contractName) { + const res = await axios.get(`${this.optimistBaseUrl}/contract-address/${contractName}`); + return res.data.address; + } + /** Deposits a Layer 1 token into Layer 2, so that it can be transacted privately. diff --git a/nightfall-optimist/src/app.mjs b/nightfall-optimist/src/app.mjs index d5c9a2146..c5ae626ea 100644 --- a/nightfall-optimist/src/app.mjs +++ b/nightfall-optimist/src/app.mjs @@ -2,7 +2,7 @@ import express from 'express'; import bodyParser from 'body-parser'; import cors from 'cors'; import fileUpload from 'express-fileupload'; -import { proposer, block, challenger, transaction } from './routes/index.mjs'; +import { proposer, block, challenger, transaction, getContractAddress } from './routes/index.mjs'; const app = express(); app.use((req, res, next) => { @@ -24,5 +24,6 @@ app.use('/proposer', proposer); app.use('/block', block); app.use('/challenger', challenger); app.use('/transaction', transaction); +app.use('/contract-address', getContractAddress); export default app; diff --git a/nightfall-optimist/src/routes/contract-address.mjs b/nightfall-optimist/src/routes/contract-address.mjs new file mode 100644 index 000000000..44fb4952e --- /dev/null +++ b/nightfall-optimist/src/routes/contract-address.mjs @@ -0,0 +1,25 @@ +/** +Route for depositing (minting) a crypto commitment. +This code assumes that the Shield contract already has approval to spend +funds on a zkp deposit +*/ +import express from 'express'; +import logger from 'common-files/utils/logger.mjs'; +import { getContractAddress } from 'common-files/utils/contract.mjs'; + +const router = express.Router(); + +router.get('/:contract', async (req, res, next) => { + logger.debug('contract-address endpoint received GET'); + const { contract } = req.params; + try { + const address = await getContractAddress(contract); + logger.debug(`returning address ${address}`); + res.json({ address }); + } catch (err) { + logger.error(err); + next(err); + } +}); + +export default router; diff --git a/nightfall-optimist/src/routes/index.mjs b/nightfall-optimist/src/routes/index.mjs index 1ad9bbf05..b278e1d44 100644 --- a/nightfall-optimist/src/routes/index.mjs +++ b/nightfall-optimist/src/routes/index.mjs @@ -2,5 +2,6 @@ import proposer from './proposer.mjs'; import block from './block.mjs'; import challenger from './challenger.mjs'; import transaction from './transaction.mjs'; +import getContractAddress from './contract-address.mjs'; -export { proposer, block, challenger, transaction }; +export { proposer, block, challenger, transaction, getContractAddress };