Skip to content

Commit

Permalink
chore: more work
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jun 29, 2024
1 parent ce231ee commit f83ec20
Show file tree
Hide file tree
Showing 59 changed files with 303 additions and 422 deletions.
224 changes: 80 additions & 144 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"configure": "yarn exec ./scripts/configure.sh",
"clean:data": "yarn run dashmate group reset --verbose --group=local --hard",
"clean": "yarn run clean:data && yarn run build",
"dashmate": "yarn workspace dashmate run dashmate",
"dashmate": "./packages/dashmate/bin/run.js",
"release": "yarn exec ./scripts/release/release.sh",
"bench": "yarn workspace @dashevo/bench-suite bench"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/dash-spv/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const DashUtil = require('@dashevo/dash-util');
const utils = require('../lib/utils');

module.exports = {
Expand All @@ -7,7 +6,7 @@ module.exports = {
return utils.normalizeHeader({
version: 1,
previousblockhash: '0000000000000000000000000000000000000000000000000000000000000000',
merkleroot: DashUtil.nullHash.toString('hex'),
merkleroot: '0000000000000000000000000000000000000000000000000000000000000000',
time: 1504510163,
bits: '1fffffff',
nonce: 2307,
Expand Down
4 changes: 1 addition & 3 deletions packages/dash-spv/lib/merkleproofs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const DashUtil = require('@dashevo/dash-util');

const merkleproofs = {
/**
* validates an array of tx hashes or Transaction instances
Expand All @@ -11,7 +9,7 @@ const merkleproofs = {
validateTxProofs: (merkleBlock, transactions) => {
let txToFilter = transactions.slice();
if (typeof transactions[0] === 'string') {
txToFilter = txToFilter.map((tx) => DashUtil.toHash(tx).toString('hex'));
txToFilter = txToFilter.map((tx) => Buffer.from(tx, 'hex').reverse().toString('hex'));
}
return merkleBlock.validMerkleTree
&& txToFilter.filter((tx) => merkleBlock.hasTransaction(tx)).length === transactions.length;
Expand Down
25 changes: 19 additions & 6 deletions packages/dash-spv/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint no-underscore-dangle: ["error", { "allow": ["_getHash"] }] */
/* eslint-disable no-bitwise */
const DashUtil = require('@dashevo/dash-util');
const dashcore = require('@dashevo/dashcore-lib');

module.exports = {

getCorrectedHash(reversedHashObj) {
const clone = Buffer.alloc(32);
reversedHashObj.copy(clone);
Expand All @@ -26,7 +24,7 @@ module.exports = {

return new dashcore.BlockHeader({
version: el.version,
prevHash: DashUtil.toHash(el.previousblockhash || el.prevHash),
prevHash: Buffer.from(el.previousblockhash || el.prevHash, 'hex').reverse(),
merkleRoot: (el.merkleroot || el.merkleRoot),
time: el.time,
bits: parseInt(el.bits, 16),
Expand All @@ -39,8 +37,23 @@ module.exports = {
target: header.bits,
};
},
expandTarget(bits) {
if (bits > 0xffffffff) {
throw new Error('"bits" may not be larger than 4 bytes');
}

const exponent = bits >>> 24;
if (exponent <= 3) throw new Error('target exponent must be > 3');
if (exponent > 32) throw new Error('target exponent must be < 32');

const mantissa = bits & 0x007fffff;
const target = Buffer.alloc(32).fill(0);
target.writeUInt32BE(mantissa << 8, 32 - exponent);

return target;
},
validProofOfWork(header) {
const target = DashUtil.expandTarget(header.bits);
const target = this.expandTarget(header.bits);
const hash = header._getHash().reverse();
return hash.compare(target) === -1;
},
Expand All @@ -50,8 +63,8 @@ module.exports = {
do {
header = new dashcore.BlockHeader({
version: 2,
prevHash: prev ? prev._getHash() : DashUtil.nullHash,
merkleRoot: DashUtil.nullHash,
prevHash: prev ? prev._getHash() : Buffer.alloc(32),
merkleRoot: Buffer.alloc(32),
time: prev ? (prev.time + 1) : Math.floor(Date.now() / 1000),
bits,
nonce: i += 1,
Expand Down
1 change: 0 additions & 1 deletion packages/dash-spv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"license": "MIT",
"dependencies": {
"@dashevo/dark-gravity-wave": "^1.1.1",
"@dashevo/dash-util": "^2.0.3",
"@dashevo/dashcore-lib": "~0.21.1",
"levelup": "^4.4.0",
"memdown": "^5.1.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/dashmate/bin/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
async function main() {
const { execute } = await import('@oclif/core');
await execute({ dir: '/Users/ivanshumkov/Projects/dashpay/platform/packages/dashmate/', development: true });
}
#!/usr/bin/env node

await main();
import { run } from '../dist/index.js';

await run();
2 changes: 1 addition & 1 deletion packages/dashmate/configs/defaults/getBaseConfigFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const { version } = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_DIR, 'pack
* @param {HomeDir} homeDir
* @returns {getBaseConfig}
*/
export default function getBaseConfigFactory(homeDir) {
export default function getBaseConfigFactory({ homeDir }) {
const prereleaseTag = semver.prerelease(version) === null ? '' : `-${semver.prerelease(version)[0]}`;
const dockerImageVersion = `${semver.major(version)}.${semver.minor(version)}${prereleaseTag}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { merge: lodashMerge } = lodash;
* @param {getBaseConfig} getBaseConfig
* @returns {getLocalConfig}
*/
export default function getLocalConfigFactory(getBaseConfig) {
export default function getLocalConfigFactory({ getBaseConfig }) {
/**
* @typedef {function} getLocalConfig
* @returns {Config}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { merge: lodashMerge } = lodash;
* @param {getBaseConfig} getBaseConfig
* @returns {getMainnetConfig}
*/
export default function getMainnetConfigFactory(homeDir, getBaseConfig) {
export default function getMainnetConfigFactory({ homeDir, getBaseConfig }) {
/**
* @typedef {function} getMainnetConfig
* @returns {Config}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { merge: lodashMerge } = lodash;
* @param {getBaseConfig} getBaseConfig
* @returns {getTestnetConfig}
*/
export default function getTestnetConfigFactory(homeDir, getBaseConfig) {
export default function getTestnetConfigFactory({ homeDir, getBaseConfig }) {
/**
* @typedef {function} getTestnetConfig
* @returns {Config}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
* @param {DefaultConfigs} defaultConfigs
* @returns {getConfigFileMigrations}
*/
export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs) {
export default function getConfigFileMigrationsFactory({ homeDir, defaultConfigs }) {
/**
* @typedef {function} getConfigFileMigrations
* @returns {Object}
Expand Down
21 changes: 13 additions & 8 deletions packages/dashmate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test:unit": "mocha --recursive test/unit",
"test:e2e": "mocha --recursive test/e2e",
"helper": "node scripts/helper.js",
"build": "./scripts/build.js",
"dashmate": "node ./dist/bin/run.js"
"build": "rm -rf dist && ./scripts/build.js",
"dashmate": "node ./bin/run.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -67,8 +67,7 @@
"@dashevo/masternode-reward-shares-contract": "workspace:*",
"@dashevo/wallet-lib": "workspace:*",
"@dashevo/withdrawals-contract": "workspace:*",
"@oclif/core": "3.27.0",
"@oclif/plugin-help": "6.0.5",
"@oclif/core": "^4.0.7",
"ajv": "^8.6.0",
"ajv-formats": "^2.1.1",
"awilix": "^4.2.6",
Expand Down Expand Up @@ -99,12 +98,17 @@
"table": "^6.8.1",
"wrap-ansi": "^7.0.0"
},
"optionalDependencies": {
"typescript": "^5"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/eslint-parser": "^7.23.3",
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"dirty-chai": "^2.0.1",
"ejs": "^3.1.6",
"esbuild": "^0.21.5",
"esbuild-plugin-fileloc": "^0.0.6",
"eslint": "^8.53.0",
Expand Down Expand Up @@ -134,15 +138,16 @@
"additionalHelpFlags": [
"-h"
],
"commands": "src/commands",
"commands": {
"strategy": "explicit",
"target": "./dist/index.js",
"identifier": "COMMANDS"
},
"bin": "dashmate",
"macos": {
"identifier": "org.dash.dashmate",
"sign": "'Developer ID Installer: The Dash Foundation, Inc.'"
},
"plugins": [
"@oclif/plugin-help"
],
"topics": {
"config": {
"description": "Manage configs"
Expand Down
8 changes: 5 additions & 3 deletions packages/dashmate/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import * as esbuild from 'esbuild';
import fileloc from 'esbuild-plugin-fileloc';

await esbuild.build({
entryPoints: ['./bin/run.js', './src/commands/index.js'],
entryPoints: ['./src/index.js', 'src/help.js'],
bundle: true,
outdir: './dist',
platform: 'node',
target: 'node20',
format: 'esm',
inject: ['./scripts/build/shim.js'],
plugins: [fileloc.filelocPlugin()],
// external: ['ejs'],
treeShaking: true,
loader: {
'.node': 'file',
// '.proto': 'file',
'.node': 'copy',
},
mainFields: ['main'],
});
7 changes: 3 additions & 4 deletions packages/dashmate/src/commands/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ export default class ConfigCommand extends ConfigBaseCommand {
* @param {Config} config
* @return {Promise<void>}
*/
async runWithDependencies(
args,
{
async runWithDependencies({
flags: {
format,
},
config,
) {
}) {
let configOptions;
if (format === OUTPUT_FORMATS.JSON) {
configOptions = JSON.stringify(config.getOptions(), null, 2);
Expand Down
34 changes: 0 additions & 34 deletions packages/dashmate/src/commands/index.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/dashmate/src/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default class SetupCommand extends BaseCommand {
* @param {DefaultConfigs} defaultConfigs
* @return {Promise<void>}
*/
async runWithDependencies(
{
async runWithDependencies({
args: {
preset,
},
{
flags: {
'node-count': nodeCount,
'debug-logs': debugLogs,
'miner-interval': minerInterval,
Expand All @@ -59,7 +59,7 @@ export default class SetupCommand extends BaseCommand {
setupRegularPresetTask,
dockerCompose,
defaultConfigs,
) {
}) {
if (nodeCount !== null && (nodeCount < 3)) {
throw new Error('node-count flag should be not less than 3');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class ConfigFileJsonRepository {
* @param {migrateConfigFile} migrateConfigFile
* @param {HomeDir} homeDir
*/
constructor(migrateConfigFile, homeDir) {
constructor({ migrateConfigFile, homeDir }) {
this.migrateConfigFile = migrateConfigFile;
this.ajv = new Ajv();
this.configFilePath = homeDir.joinPath('config.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PACKAGE_ROOT_DIR } from '../../constants.js';
* @param {HomeDir} homeDir
* @return {createConfigFile}
*/
export default function createConfigFileFactory(defaultConfigs, homeDir) {
export default function createConfigFileFactory({ defaultConfigs, homeDir }) {
/**
* @typedef {function} createConfigFile
* @returns {ConfigFile}
Expand Down
2 changes: 1 addition & 1 deletion packages/dashmate/src/config/generateEnvsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DASHMATE_HELPER_DOCKER_IMAGE } from '../constants.js';
* @param {getConfigProfiles} getConfigProfiles
* @return {generateEnvs}
*/
export default function generateEnvsFactory(configFile, homeDir, getConfigProfiles) {
export default function generateEnvsFactory({ configFile, homeDir, getConfigProfiles }) {
/**
* @typedef {function} generateEnvs
* @param {Config} config
Expand Down
3 changes: 2 additions & 1 deletion packages/dashmate/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const HPMN_COLLATERAL_AMOUNT = 4000;
// number of blocks to wait before core DKG exchange session
export const MIN_BLOCKS_BEFORE_DKG = 6;

export const PACKAGE_ROOT_DIR = path.join(__dirname, '..');
// export const PACKAGE_ROOT_DIR = path.join(__dirname, '..');
export const PACKAGE_ROOT_DIR = path.join(url.fileURLToPath(import.meta.url), '../..');
export const TEMPLATES_DIR = path.join(PACKAGE_ROOT_DIR, 'templates');

const { version } = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_DIR, 'package.json'), 'utf8'));
Expand Down
6 changes: 2 additions & 4 deletions packages/dashmate/src/core/startCoreFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import CoreService from './CoreService.js';
/**
* @param {createRpcClient} createRpcClient
* @param {waitForCoreStart} waitForCoreStart
* @param {waitForCoreSync} waitForCoreSync
* @param {DockerCompose} dockerCompose
* @param {getConnectionHost} getConnectionHost
* @param {ensureFileMountExists} ensureFileMountExists
* @return {startCore}
*/
export default function startCoreFactory(
export default function startCoreFactory({
createRpcClient,
waitForCoreStart,
waitForCoreSync,
dockerCompose,
getConnectionHost,
ensureFileMountExists,
) {
}) {
/**
* @typedef startCore
* @param {Config} config
Expand Down
Loading

0 comments on commit f83ec20

Please sign in to comment.