Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getBytes = block => {
const blockVersionBuffer = intToBuffer(
block.version,
SIZE_INT32,
LITTLE_ENDIAN,
);
const timestampBuffer = intToBuffer(
block.timestamp,
SIZE_INT32,
LITTLE_ENDIAN,
);
const previousBlockBuffer = block.previousBlockId
? intToBuffer(block.previousBlockId, SIZE_INT64, BIG_ENDIAN)
: Buffer.alloc(SIZE_INT64);
const numTransactionsBuffer = intToBuffer(
block.numberOfTransactions,
SIZE_INT32,
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
const getBytes = block => {
const blockVersionBuffer = intToBuffer(
block.version,
SIZE_INT32,
LITTLE_ENDIAN,
);
const timestampBuffer = intToBuffer(
block.timestamp,
SIZE_INT32,
LITTLE_ENDIAN,
);
const previousBlockBuffer = block.previousBlockId
? intToBuffer(block.previousBlockId, SIZE_INT64, BIG_ENDIAN)
: Buffer.alloc(SIZE_INT64);
const numTransactionsBuffer = intToBuffer(
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const rewardBuffer = intToBuffer(
block.reward.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const payloadLengthBuffer = intToBuffer(
block.payloadLength,
SIZE_INT32,
LITTLE_ENDIAN,
);
const payloadHashBuffer = hexToBuffer(block.payloadHash);
const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);
const blockSignatureBuffer = block.blockSignature
block.timestamp,
SIZE_INT32,
LITTLE_ENDIAN,
);
const previousBlockBuffer = block.previousBlockId
? intToBuffer(block.previousBlockId, SIZE_INT64, BIG_ENDIAN)
: Buffer.alloc(SIZE_INT64);
const numTransactionsBuffer = intToBuffer(
block.numberOfTransactions,
SIZE_INT32,
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const rewardBuffer = intToBuffer(
block.reward.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const rewardBuffer = intToBuffer(
block.reward.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const payloadLengthBuffer = intToBuffer(
block.payloadLength,
SIZE_INT32,
LITTLE_ENDIAN,
);
const payloadHashBuffer = hexToBuffer(block.payloadHash);
const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);
const blockSignatureBuffer = block.blockSignature
? hexToBuffer(block.blockSignature)
: Buffer.alloc(0);
return Buffer.concat([
blockVersionBuffer,
timestampBuffer,
LITTLE_ENDIAN,
);
const numTransactionsBuffer = intToBuffer(
block.numberOfTransactions,
SIZE_INT32,
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const rewardBuffer = intToBuffer(
block.reward.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const payloadLengthBuffer = intToBuffer(
block.payloadLength,
SIZE_INT32,
LITTLE_ENDIAN,
);
const heightBuffer = intToBuffer(block.height, SIZE_INT32, LITTLE_ENDIAN);
const maxHeightPreviouslyForgedBuffer = intToBuffer(
block.maxHeightPreviouslyForged,
SIZE_INT32,
LITTLE_ENDIAN,
);
const maxHeightPrevotedBuffer = intToBuffer(
block.maxHeightPrevoted,
SIZE_INT32,
LITTLE_ENDIAN,
);
const numTransactionsBuffer = intToBuffer(
block.numberOfTransactions,
SIZE_INT32,
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
LITTLE_ENDIAN,
);
const totalAmountBuffer = intToBuffer(
block.totalAmount.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const totalFeeBuffer = intToBuffer(
block.totalFee.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const rewardBuffer = intToBuffer(
block.reward.toString(),
SIZE_INT64,
LITTLE_ENDIAN,
);
const payloadLengthBuffer = intToBuffer(
block.payloadLength,
SIZE_INT32,
LITTLE_ENDIAN,
);
const payloadHashBuffer = hexToBuffer(block.payloadHash);
const generatorPublicKeyBuffer = hexToBuffer(block.generatorPublicKey);
const blockSignatureBuffer = block.blockSignature
const assetToBytes = tx => {
const { mandatoryKeys, optionalKeys, numberOfSignatures } = tx.asset;
const mandatoryKeysBuffer = Buffer.from(mandatoryKeys.join(''), 'utf8');
const optionalKeysBuffer = Buffer.from(optionalKeys.join(''), 'utf8');
const assetBuffer = Buffer.concat([
intToBuffer(mandatoryKeys.length, 1),
mandatoryKeysBuffer,
intToBuffer(optionalKeys.length, 1),
optionalKeysBuffer,
intToBuffer(numberOfSignatures, 1),
]);
return assetBuffer;
};