Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(genesisBlock, config = {}) {
const errors = liskValidator.validate(genesisBlockSchema, genesisBlock);
if (errors.length) {
throw errors;
}
// Don't change the object parameters provided
let appConfig = _.cloneDeep(config);
if (!_.has(appConfig, 'app.label')) {
_.set(
appConfig,
'app.label',
`lisk-${genesisBlock.payloadHash.slice(0, 7)}`,
);
}
if (!_.has(appConfig, 'components.logger.logFileName')) {
async handleRPCGetTransactions(data = {}, peerId) {
await this._addRateLimit(
'getTransactions',
peerId,
DEFAULT_RATE_LIMIT_FREQUENCY,
);
const errors = validator.validate(schemas.getTransactionsRequest, data);
if (errors.length) {
this.logger.warn(
{ err: errors, peerId },
'Received invalid transactions body',
);
await this.channel.invoke('network:applyPenalty', {
peerId,
penalty: 100,
});
throw errors;
}
const { transactionIds } = data;
if (!transactionIds) {
return {
transactions: this.transactionPoolModule.getMergedTransactionList(
async handleEventPostSignatures(data, peerId) {
await this._addRateLimit(
'postSignatures',
peerId,
DEFAULT_RATE_LIMIT_FREQUENCY,
);
const errors = validator.validate(schemas.postSignatureEvent, data);
if (errors.length) {
this.logger.warn({ err: errors }, 'Invalid signatures body');
await this.channel.invoke('network:applyPenalty', {
peerId,
penalty: 100,
});
throw errors;
}
for (const signature of data.signatures) {
const signatureObjectErrors = validator.validate(
schemas.signatureObject,
signature,
);
const validateSchema = ({ block }) => {
const errors = validator.validate(blockSchema, block);
if (errors.length) {
throw errors;
}
};
protected validateAsset(): ReadonlyArray {
const schemaErrors = validator.validate(
secondSignatureAssetFormatSchema,
this.asset,
);
const errors = convertToAssetError(
this.id,
schemaErrors,
) as TransactionError[];
return errors;
}
const objectNormalize = (block, exceptions = {}) => {
Object.keys(block).forEach(key => {
if (block[key] === null || typeof block[key] === 'undefined') {
delete block[key];
}
});
const errors = validator.validate(blockSchema, block);
if (errors.length) {
throw errors;
}
const { transactionsResponses } = validateTransactions(exceptions)(
block.transactions
);
const invalidTransactionResponse = transactionsResponses.find(
transactionResponse => transactionResponse.status !== TransactionStatus.OK
);
if (invalidTransactionResponse) {
throw invalidTransactionResponse.errors;
}
return block;
};
const validateSchema = ({ block }) => {
const errors = validator.validate(baseBlockSchema, block);
if (errors.length) {
throw errors;
}
};
const objectNormalize = (block, exceptions = {}) => {
Object.keys(block).forEach(key => {
if (block[key] === null || typeof block[key] === 'undefined') {
delete block[key];
}
});
const errors = validator.validate(blockSchema, block);
if (errors.length) {
throw errors;
}
const { transactionsResponses } = validateTransactions(exceptions)(
block.transactions
);
const invalidTransactionResponse = transactionsResponses.find(
transactionResponse => transactionResponse.status !== TransactionStatus.OK
);
if (invalidTransactionResponse) {
throw invalidTransactionResponse.errors;
}
return block;
};
async handleRPCGetBlocksFromId(data, peerId) {
const errors = validator.validate(schemas.getBlocksFromIdRequest, data);
if (errors.length) {
const error = `${errors[0].message}`;
this.logger.warn(
{
err: error,
req: data,
},
'getBlocksFromID request validation failed',
);
await this.channel.invoke('network:applyPenalty', {
peerId,
penalty: 100,
});
throw new Error(error);
async handleEventPostSignature(data) {
const errors = validator.validate(schemas.signatureObject, data.signature);
if (errors.length) {
const error = new TransactionError(errors[0].message);
return {
code: 400,
errors: [error],
};
}
try {
await this.transactionPoolModule.getTransactionAndProcessSignature(
data.signature,
);
return {};
} catch (err) {
return {