Skip to content

Commit

Permalink
Merge pull request #463 from EYBlockchain/daveroga/add-optimist-endpo…
Browse files Browse the repository at this point in the history
…int-contract-address

daveroga/Add contract-address endpoint in optimist
  • Loading branch information
Ilyas Ridhuan authored Feb 7, 2022
2 parents 34aec0e + c4ac253 commit 5f7acd5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
15 changes: 14 additions & 1 deletion cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion nightfall-optimist/src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
25 changes: 25 additions & 0 deletions nightfall-optimist/src/routes/contract-address.mjs
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion nightfall-optimist/src/routes/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit 5f7acd5

Please sign in to comment.