Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function failActionResponse(request, h, err) {
if (process.env.NODE_ENV === 'production') {
// In prod, log a limited error message and throw the default Bad Request error.
console.error('ValidationError:', err.message);
throw Boom.badGateway(`Invalid response data`);
}
// During development, log and respond with the full error.
console.error('ResponseError:', err);
const error = Boom.badGateway(`Invalid response data`);
error.reformat();
error.output.payload.details = err.details;
throw error;
}
async function failActionResponse(request, h, err) {
if (process.env.NODE_ENV === 'production') {
// In prod, log a limited error message and throw the default Bad Request error.
console.error('ValidationError:', err.message);
throw Boom.badGateway(`Invalid response data`);
}
// During development, log and respond with the full error.
console.error('ResponseError:', err);
const error = Boom.badGateway(`Invalid response data`);
error.reformat();
error.output.payload.details = err.details;
throw error;
}
async function getByAddress( request, h ) {
const { address } = request.params;
let result
try {
result = await promiseFromEvent({ action: "getTokenByAddress", payload: address });
} catch (e) {
Boom.badGateway( e )
}
return result
}
async function getPool(request, h) {
let result;
try {
let data = await plasma({action: "getPool", payload: {}});
result = data.transactions.map(tx => Transaction.getJson(tx));
} catch (e) {
return Boom.badGateway(e)
}
return result;
}
async function proof(request, h) {
const {tokenId, blockNumber} = request.query;
let result;
try {
let data = await plasma({action: "getProof", payload: {tokenId, blockNumber}});
result = {hash: ethUtil.addHexPrefix(data.hash.toString('hex'))};
} catch (e) {
return Boom.badGateway(e)
}
return result
}
async function getLastTransaction( request, h ) {
const { tokenId } = request.params;
let result
try {
result = await promiseFromEvent({ action: "getLastTransactionByTokenId", payload: tokenId });
} catch (e) {
Boom.badGateway( e )
}
return result
}
internals.tryParseBuffer = function (buffer, next) {
if (buffer.length === 0) {
return next(null, null);
}
let payload;
try {
payload = Bourne.parse(buffer.toString());
}
catch (err) {
return next(Boom.badGateway(err.message, { payload: buffer }));
}
return next(null, payload);
};
async function last(request, h) {
let result;
try {
let block = await plasma({action: "getLastBlock", payload: {}});
result = Block.getJson(block)
} catch (e) {
return Boom.badGateway(e)
}
return result
}
async function get( request, h ) {
const { tokenId } = request.params;
let result
try {
result = await promiseFromEvent({ action: "getToken", payload: tokenId });
} catch (e) {
Boom.badGateway( e )
}
return result
}
async function getCandidates(request, h) {
let result;
try {
result = await plasma({action: "getCandidates", payload: {}});
} catch (e) {
return Boom.badGateway(e)
}
return result;
}