@dashevo/dark-gravity-wave
Advanced tools
Comparing version 1.1.0 to 1.1.1
17
index.js
@@ -55,15 +55,18 @@ /* eslint new-cap: 0 */ | ||
// TODO: write tests | ||
if (allowMinDifficultyBlocks) { | ||
// recent block is more than 2 hours old | ||
// most recent block is more than 2 hours old | ||
if (newHeader.timestamp > blocks[0].timestamp + (2 * 60 * 60)) { | ||
return maxTarget; | ||
} | ||
// recent block is more than 10 minutes old | ||
// most recent block is more than 10 minutes old | ||
if (newHeader.timestamp > blocks[0].timestamp + (powTargetSpacing * 4)) { | ||
let bnNew = blocks[0].target * 10; | ||
if (bnNew > maxTarget) { | ||
bnNew = maxTarget; | ||
let bnNew = new u256(); | ||
bnNew.setCompact(blocks[0].target); | ||
bnNew = bnNew.multiplyWithInteger(10); | ||
const uMaxTarget = new u256(); | ||
uMaxTarget.setCompact(maxTarget); | ||
if (bnNew.getCompact() > uMaxTarget.getCompact()) { | ||
bnNew = uMaxTarget; | ||
} | ||
return bnNew; | ||
return bnNew.getCompact(); | ||
} | ||
@@ -70,0 +73,0 @@ } |
{ | ||
"name": "@dashevo/dark-gravity-wave", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Dark Gravity Wave difficulty retarget algorithm in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ # dark-gravity-wave-js | ||
> Dark Gravity Wave difficulty retarget algorithm in JavaScript | ||
> Dark Gravity Wave difficulty retargeting algorithm in JavaScript | ||
@@ -18,6 +18,6 @@ ## Install | ||
```js | ||
var dgw = require('@dashevo/dark-gravity-wave'); | ||
const dgw = require('@dashevo/dark-gravity-wave'); | ||
dgw.getTarget(lastHeaders); | ||
// -> '1be4c4d3' | ||
dgw.hasValidTarget(header, previousHeaders, 'testnet'); | ||
// -> true or false | ||
``` | ||
@@ -27,19 +27,20 @@ | ||
### getTarget(array) | ||
### hasValidTarget(header, previousHeaders, [network = 'mainnet']) | ||
#### array | ||
#### header | ||
Type: `object` | ||
#### previousHeaders | ||
Type: `array` | ||
Get the difficulty. The array must contain the last 24 blocks. Arrays with length > 24 are allowed however only latest 24 will be considered. | ||
Array objects must contain *timestamp* and *target* properties (where target = the difficulty at which the block has been solved) | ||
#### network | ||
### getTarget(array,blockTime) | ||
Type: `string` (optional, default = 'mainnet') | ||
#### array | ||
Validates the target (bits) property of a block header. The 2nd argument, the array of most recent previous headers, must contain block header objects of the last 24 blocks. Arrays with length > 24 are allowed however only the latest 24 will be considered. | ||
The block header objects must contain *timestamp* and *target* properties (nBits field of the block header) | ||
Type: `array`, `int` (default 150) | ||
Get the difficulty for dark-gravity-wave's other than dash's 150 second block time. | ||
## Contributing | ||
@@ -46,0 +47,0 @@ |
@@ -469,3 +469,3 @@ const { expect } = require('chai'); | ||
it('should have lowest diff with timestamp (10m+1sec)', () => { | ||
it('should have target below max target with timestamp (10m+1sec)', () => { | ||
timestamp = 1438531999 + 601; | ||
@@ -475,6 +475,6 @@ const highTargetBits = 0x207fffff; | ||
const result = dgw.hasValidTarget(header, blocks, 'devnet'); | ||
expect(result).to.equal(true); | ||
expect(result).to.equal(false); | ||
}); | ||
it('should have lowest diff with timestamp (20m)', () => { | ||
it('should have target below max target with timestamp (20m)', () => { | ||
timestamp = 1438531999 + 1200; | ||
@@ -484,3 +484,3 @@ const highTargetBits = 0x207fffff; | ||
const result = dgw.hasValidTarget(header, blocks, 'devnet'); | ||
expect(result).to.equal(true); | ||
expect(result).to.equal(false); | ||
}); | ||
@@ -487,0 +487,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
64807
1003
50
0