Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Merge 97f7e16 into 5c94931
Browse files Browse the repository at this point in the history
  • Loading branch information
garatortiz authored Mar 22, 2018
2 parents 5c94931 + 97f7e16 commit 9f192e7
Show file tree
Hide file tree
Showing 44 changed files with 284 additions and 284 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function (cfg_public) {
rpc: '******************************',
signer: '0x****************************', // with 0x prefix
signerPrivateKey: '******************************', // without 0x prefix
confirmation_page_url: '******************************',
confirmationPageUrl: '******************************',
};
};
```
Expand Down Expand Up @@ -157,9 +157,9 @@ module.exports = function (cfg_public) {
rpc: '*** PROBABLY INFURA ***',
signer: '*** SIGNER ADDRESS, 0x... ***', // with 0x prefix
signerPrivateKey: '*** SIGNER PRIVATE KEY ***', // without 0x prefix
confirmation_page_url: '*** URL FOR CONFIRMATION PAGE, e.g. https://yourserver.com/confirm ***', // used only for postcard
confirmationPageUrl: '*** URL FOR CONFIRMATION PAGE, e.g. https://yourserver.com/confirm ***', // used only for postcard
// it is recommended to install and use redis for keeping session keys
session_store: {
sessionStore: {
"type": "redis",
"params": { *** REDIS CONNECTION PARAMETERS *** }
},
Expand Down
6 changes: 3 additions & 3 deletions utils/deploy_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var confirm = function (next) {
logger.log('(3) Confirmation');
logger.log('\n==============================');
logger.log('* This will deploy contract from ' + config.source_file + ' to network', config.network);
logger.log('* Contract output will be saved to ' + config.contract_output);
logger.log('* Contract output will be saved to ' + config.contractOutput);
logger.log('* Contract owner is ' + (config.owner === '$TEST' ? 'TEST ' : '') + owner);
logger.log('* Gas estimation: ' + egas + ' => ~' + gprice*egas/1e18 + ' ETH');
logger.log('* Will set gas = ' + ugas + ' => ~' + gprice*ugas/1e18 + ' ETH');
Expand Down Expand Up @@ -170,8 +170,8 @@ confirm(function () {
bytecode: bytecode,
abi: abi_def,
};
logger.log('(5) Saving contract output to ' + config.contract_output);
fs.writeFileSync(config.contract_output, JSON.stringify(file_output, null, 4));
logger.log('(5) Saving contract output to ' + config.contractOutput);
fs.writeFileSync(config.contractOutput, JSON.stringify(file_output, null, 4));

logger.log('\nDONE');
return process.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion utils/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var logger = console;

var config = require('./utils-config')();

var cout = require(config.contract_output);
var cout = require(config.contractOutput);
var web3 = new Web3(config.network);
var cconf = cout[config.contract_name];
var contract = web3.eth.contract(cconf.abi).at(cconf.address);
Expand Down
2 changes: 1 addition & 1 deletion utils/utils-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var utils_config = {
source_file: path.join(__dirname, '../blockchain/contracts/ProofOfPhysicalAddress.sol'),
contract_name: 'ProofOfPhysicalAddress',
network: network,
contract_output: path.join(__dirname, '../web-dapp/src/contract-output.json'),
contractOutput: path.join(__dirname, '../web-dapp/src/contract-output.json'),
};

module.exports = function () {
Expand Down
6 changes: 3 additions & 3 deletions web-dapp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const express = require('express');
const path = require('path');
const body_parser = require('body-parser');
const bodyParser = require('body-parser');
const helmet = require('helmet');

const app = express();
Expand All @@ -14,8 +14,8 @@ app.use('/', express.static(path.join(__dirname, 'build')));
app.use('/confirm', express.static(path.join(__dirname, 'build')));

// api
app.use(body_parser.urlencoded({ extended: true }));
app.use(body_parser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

const routes = require('./routes')({});
app.use('/api', routes);
Expand Down
60 changes: 30 additions & 30 deletions web-dapp/controllers/notifyRegTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const config = require('../server-config');
const db = require('../server-lib/session_store');
const post_api = require('../server-lib/post_api');
const postApi = require('../server-lib/post_api');
const logger = require('../server-lib/logger');
const {validate, normalize} = require('../server-lib/validations');
const {createResponseObject} = require('../server-lib/utils');
Expand All @@ -24,62 +24,62 @@ const validateData = (opts, prelog = '') => {
logger.log(`${prelog} validation error on wallet: body.wallet, error: ${validate.wallet(body.wallet).msg}`);
return createResponseObject(false, validate.wallet(body.wallet).msg);
}
// tx_id
if (!validate.string(body.tx_id).ok) {
logger.log(`${prelog} validation error on tx_id: body.tx_id, error: ${validate.string(body.tx_id).msg}`);
return createResponseObject(false, validate.string(body.tx_id).msg);
// txId
if (!validate.string(body.txId).ok) {
logger.log(`${prelog} validation error on txId: body.txId, error: ${validate.string(body.txId).msg}`);
return createResponseObject(false, validate.string(body.txId).msg);
}
// session_key
if (!validate.string(body.session_key).ok) {
logger.log(`${prelog} validation error on session_key: body.session_key, error: ${validate.string(body.session_key).msg}`);
return createResponseObject(false, validate.string(body.session_key).msg);
// sessionKey
if (!validate.string(body.sessionKey).ok) {
logger.log(`${prelog} validation error on sessionKey: body.sessionKey, error: ${validate.string(body.sessionKey).msg}`);
return createResponseObject(false, validate.string(body.sessionKey).msg);
}
return createResponseObject(true, '');
};

const normalizeData = (body) => {
const wallet = body.wallet;
const tx_id = normalize.string(body.tx_id);
const session_key = normalize.string(body.session_key);
return {wallet, tx_id, session_key};
const txId = normalize.string(body.txId);
const sessionKey = normalize.string(body.sessionKey);
return {wallet, txId, sessionKey};
};

const getTxInfo = (opts, prelog = '') => {
const {session_key, wallet} = opts;
logger.log(`${prelog} fetching info by session_key: ${session_key}`);
const {sessionKey, wallet} = opts;
logger.log(`${prelog} fetching info by sessionKey: ${sessionKey}`);

return db.get(session_key)
.then(info => (validateTxInfo({info, session_key, wallet})));
return db.get(sessionKey)
.then(info => (validateTxInfo({info, sessionKey, wallet})));
};

const getTxBlockNumber = (opts, prelog = '') => {
const {tx_id, wallet, contractAddress, waitInterval, waitMaxTime, startedAt} = opts;
const {txId, wallet, contractAddress, waitInterval, waitMaxTime, startedAt} = opts;


logger.log(`${prelog} fetching tx_details from blockchain by tx_id: ${tx_id}`);
return getTransaction(tx_id)
logger.log(`${prelog} fetching tx_details from blockchain by txId: ${txId}`);
return getTransaction(txId)
.then((result) => {
const {error, txDetails} = result;
return validateTxDetails(error, txDetails, contractAddress, wallet);
})
.then(txDetails => {
logger.log(`${prelog} got block number for tx_id: ${tx_id}, tx_bn: ${txDetails.blockNumber}`);
logger.log(`${prelog} got block number for txId: ${txId}, txBn: ${txDetails.blockNumber}`);
return txDetails.blockNumber;
})
.then((blockNumber) => {
logger.log(`${prelog} checking tx receipt for status`);
return getTxReceipt(tx_id);
return getTxReceipt(txId);
})
.then((result) => {
const {error, txReceipt} = result;
return validateTxReceipt(tx_id, error, txReceipt);
return validateTxReceipt(txId, error, txReceipt);
})
.catch((error) => {
if (error.fatal || new Date() - startedAt > waitMaxTime) {
throw new Error(error);
}
logger.error(`${prelog} ${error.msg}`);
logger.log(`${prelog} check tx_id: ${tx_id} again in: ${waitInterval}ms`);
logger.log(`${prelog} check txId: ${txId} again in: ${waitInterval}ms`);
return new Promise((resolve) => {
setTimeout(() => {
resolve(getTxBlockNumber(opts));
Expand Down Expand Up @@ -107,10 +107,10 @@ const getAddressByBN = (opts, prelog = '') => {
};

const createPostCard = (opts, prelog) => {
const {wallet, tx_id, address, confirmationCodePlain} = opts;
const {wallet, txId, address, confirmationCodePlain} = opts;

return new Promise((resolve, reject) => {
post_api.create_postcard(wallet, address, tx_id, confirmationCodePlain, function (err, result) {
postApi.create_postcard(wallet, address, txId, confirmationCodePlain, function (err, result) {
if (err) {
logger.error(`${prelog} error returned by create_postcard: ${err}`);
return reject(createResponseObject(false, 'error while sending postcard'));
Expand All @@ -121,10 +121,10 @@ const createPostCard = (opts, prelog) => {
};

const removeUsedSessionKey = (opts, prelog) => {
const {session_key, postcard} = opts;
const {sessionKey, postcard} = opts;

logger.log(`${prelog} removing used session_key from memory: ${session_key}`);
return db.unset(session_key)
logger.log(`${prelog} removing used sessionKey from memory: ${sessionKey}`);
return db.unset(sessionKey)
.then(() => {
return {
ok: true,
Expand All @@ -135,8 +135,8 @@ const removeUsedSessionKey = (opts, prelog) => {
};
})
.catch(err => {
logger.error(`${prelog} error removing used session_key: ${err}`);
throw new Error(createResponseObject(false, 'error removing used session_key'));
logger.error(`${prelog} error removing used sessionKey: ${err}`);
throw new Error(createResponseObject(false, 'error removing used sessionKey'));
});
};

Expand Down
4 changes: 2 additions & 2 deletions web-dapp/controllers/prepareRegTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ const setSessionKey = (wallet, confirmationCodePlain) => {
return db.set(sessionKey, {wallet, date: new Date(), confirmationCodePlain})
.then(() => sessionKey)
.catch(err => {
const log = `error setting session_key: ${err}`;
const msg = 'error setting session_key';
const log = `error setting sessionKey: ${err}`;
const msg = 'error setting sessionKey';
throw {ok: false, log, msg};
});
};
Expand Down
2 changes: 1 addition & 1 deletion web-dapp/postcard/front.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{{code}}
</div>
<div class="text">
Open <a href="{{confirmation_page_url}}" class="link">{{confirmation_page_url}}</a>
Open <a href="{{confirmation_page_url}}" class="link">{{confirmationPageUrl}}</a>
in your browser and<br> enter confirmation code above (case insensitive).
</div>
</body>
Expand Down
10 changes: 5 additions & 5 deletions web-dapp/routes/_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const logger = require('../logger'); // eslint-disable-line no-unused-vars
const express = require('express');
const post_api = require('../server-lib/post_api');
const postApi = require('../server-lib/post_api');

const MIN_SEARCH_LEN = 2;

Expand All @@ -16,14 +16,14 @@ module.exports = function (opts) {
if (!name || typeof name !== 'string') return res.json([]);
name = name.toLowerCase();
if (name.length < MIN_SEARCH_LEN) return res.json([]);
var countries = post_api.lists.countries.filter((c) => {
var countries = postApi.lists.countries.filter((c) => {
return (c.name.toLowerCase().indexOf(name) >= 0 || c.short_name.toLowerCase().indexOf(name) >= 0);
});
res.json(countries);
});

router.post('/lists/allCountries', function (req, res) {
res.json(post_api.lists.countries);
res.json(postApi.lists.countries);
});

router.post('/lists/states', function (req, res) {
Expand All @@ -37,7 +37,7 @@ module.exports = function (opts) {
name = name.toLowerCase();
if (name.length < MIN_SEARCH_LEN) return res.json([]);

var states = post_api.lists.states.US.filter((s) => {
var states = postApi.lists.states.US.filter((s) => {
return (s.name.toLowerCase().indexOf(name) >= 0 || s.short_name.toLowerCase().indexOf(name) >= 0);
});

Expand All @@ -50,7 +50,7 @@ module.exports = function (opts) {
cname = cname.toLowerCase();
if (cname !== 'united states') return res.json([]);

res.json(post_api.lists.states.US);
res.json(postApi.lists.states.US);
});

return router;
Expand Down
6 changes: 3 additions & 3 deletions web-dapp/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const express = require('express');
const fs = require('fs');
const logger = require('../server-lib/logger');
const req_id = require('../server-lib/req_id');
const log_request = require('../server-lib/log_request');
const reqId = require('../server-lib/req_id');
const logRequest = require('../server-lib/log_request');

module.exports = (opts) => {
const router = express.Router();
Expand All @@ -14,7 +14,7 @@ module.exports = (opts) => {

logger.log('Found ' + files.length + ' route(s): ' + JSON.stringify(files));
for (let f of files) {
router.use('/', req_id, log_request, require('./' + f)(opts));
router.use('/', reqId, logRequest, require('./' + f)(opts));
}

return router;
Expand Down
30 changes: 15 additions & 15 deletions web-dapp/routes/notify_reg_tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
const logger = require('../server-lib/logger');
const express = require('express');
const config = require('../server-config');
const send_response = require('../server-lib/send_response');
const sendResponse = require('../server-lib/send_response');
const notifyRegTxController = require('../controllers/notifyRegTx');

// eslint-disable-next-line no-unused-vars
module.exports = (opts) => {
const router = express.Router();
router.post('/notifyRegTx', function(req, res) {
const log_prfx = req.log_prfx;
const prelog = `[notifyRegTx] (${log_prfx})`;
const logPrfx = req.logPrfx;
const prelog = `[notifyRegTx] (${logPrfx})`;

const body = req.body;
const isValidData = notifyRegTxController.validateData({body}, prelog);
if (!isValidData.ok) return send_response(res, { ok: false, err: isValidData.err });
if (!isValidData.ok) return sendResponse(res, { ok: false, err: isValidData.err });

const {wallet, tx_id, session_key} = notifyRegTxController.normalizeData(body);
const {wallet, txId, sessionKey} = notifyRegTxController.normalizeData(body);

let confirmationCodePlain;
return notifyRegTxController.getTxInfo({ session_key, wallet }, prelog)
return notifyRegTxController.getTxInfo({ sessionKey, wallet }, prelog)
.then(info => {
confirmationCodePlain = info.confirmationCodePlain;
const contractAddress = config.cconf.address;
const waitMaxTime = config.block_wait_max_time_ms;
const waitInterval = config.block_wait_interval_ms;
const waitMaxTime = config.blockWaitMaxTimeMs;
const waitInterval = config.blockWaitIntervalMs;
const startedAt = new Date();
return notifyRegTxController.getTxBlockNumber({tx_id, wallet, contractAddress, waitMaxTime, waitInterval, startedAt}, prelog);
return notifyRegTxController.getTxBlockNumber({txId, wallet, contractAddress, waitMaxTime, waitInterval, startedAt}, prelog);
})
.then(tx_bn => {
return notifyRegTxController.getAddressByBN({wallet, tx_bn}, prelog);
.then(txBn => {
return notifyRegTxController.getAddressByBN({wallet, txBn}, prelog);
})
.then(address => {
return notifyRegTxController.createPostCard({wallet, tx_id, address, confirmationCodePlain}, prelog);
return notifyRegTxController.createPostCard({wallet, txId, address, confirmationCodePlain}, prelog);
})
.then(postcard => {
logger.log(`${prelog} postcard: ${JSON.stringify(postcard)}`);
return notifyRegTxController.removeUsedSessionKey({session_key, postcard}, prelog);
return notifyRegTxController.removeUsedSessionKey({sessionKey, postcard}, prelog);
})
.then(result => {
return send_response(res, {ok: result.ok, result: result.result});
return sendResponse(res, {ok: result.ok, result: result.result});
})
.catch(error => {
logger.error(`${prelog} ${error.msg}`);
return send_response(res, { ok: false, err: error.msg });
return sendResponse(res, { ok: false, err: error.msg });
});
});

Expand Down
2 changes: 1 addition & 1 deletion web-dapp/routes/prepare_con_tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const prepareConTx = require('../controllers/prepareConTx');
module.exports = (opts) => {
var router = express.Router();
router.post('/prepareConTx', function(req, res) {
const prelog = `[prepareConTx] (${req.log_prfx})`;
const prelog = `[prepareConTx] (${req.logPrfx})`;
let params;
let wallet;

Expand Down
Loading

0 comments on commit 9f192e7

Please sign in to comment.