Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 69 additions & 22 deletions .github/workflows/test_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ on:
jobs:
test:
name: Run Insight API tests
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: Enable NPM cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand All @@ -36,21 +36,70 @@ jobs:
- name: Run tests
run: npm run test

functional:
name: Run Insight API functional tests
runs-on: ubuntu-24.04
timeout-minutes: 15
env:
DASH_VERSION: 24.0.0
DASH_SHA256: 1ffce395e035fb2ee617c92e6eeaab139ca3d10db6f83d4e816136b726512c5e
DASHCORE_NODE_REF: 2027c2d72d3f080591457d137e1780dafc95f304
steps:
- uses: actions/checkout@v4

- uses: actions/checkout@v4
with:
repository: dashpay/dashcore-node
ref: ${{ env.DASHCORE_NODE_REF }}
path: dashcore-node

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Enable NPM cache
uses: actions/cache@v4
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install NPM dependencies
run: |
npm ci
npm ci --prefix dashcore-node
echo "DASHCORE_NODE_PATH=$PWD/dashcore-node" >> "$GITHUB_ENV"

- name: Download Dash Core
run: |
curl -fsSL -o dashcore.tar.gz "https://github.com/dashpay/dash/releases/download/v${DASH_VERSION}/dashcore-${DASH_VERSION}-x86_64-linux-gnu.tar.gz"
echo "${DASH_SHA256} dashcore.tar.gz" | sha256sum -c -
tar xzf dashcore.tar.gz
echo "DASHD_PATH=$PWD/dashcore-${DASH_VERSION}/bin/dashd" >> "$GITHUB_ENV"

- name: Run functional tests
run: npm run test:functional

release-npm:
name: Release NPM package
runs-on: ubuntu-20.04
needs: test
runs-on: ubuntu-24.04
needs: [test, functional]
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Check package version matches tag
uses: geritol/match-tag-to-package-version@0.1.0
env:
TAG_PREFIX: refs/tags/v

- name: Enable NPM cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand All @@ -61,7 +110,7 @@ jobs:
run: npm ci

- name: Set release tag
uses: actions/github-script@v3
uses: actions/github-script@v7
id: tag
with:
result-encoding: string
Expand All @@ -71,53 +120,51 @@ jobs:
return (tag.includes('dev') ? `${major}.${minor}-dev` : 'latest');

- name: Publish NPM package
uses: JS-DevTools/npm-publish@v1
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
tag: ${{ steps.tag.outputs.result }}

release-docker:
name: Release Docker image
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
needs: release-npm
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
with:
version: v0.7.0
install: true
driver-opts: image=moby/buildkit:buildx-stable-1

- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set suffix to Docker tags
uses: actions/github-script@v3
uses: actions/github-script@v7
id: suffix
with:
result-encoding: string
script: "return (context.payload.release.tag_name.includes('-dev') ? '-dev' : '');"

- name: Set Docker tags and labels
id: docker_meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: dashpay/insight-api
tags: |
Expand All @@ -131,7 +178,7 @@ jobs:

- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
context: docker
file: docker/Dockerfile
Expand Down
44 changes: 22 additions & 22 deletions lib/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,21 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
// them all back together to get the binary size of the block.
// FIXME: This code might still read the whole block. Fixing that
// would require changes in dashcore-node.
var header = dashcore.BlockHeader.fromBufferReader(br);
var info = {};
var txlength = br.readVarintNum();
info.transactions = [dashcore.Transaction().fromBufferReader(br)];
var header;
var txlength;
try {
header = dashcore.BlockHeader.fromBufferReader(br);
txlength = br.readVarintNum();
} catch (parseErr) {
return next(new Error('Failed to parse block ' + hash + ': ' + parseErr.message));
}
// The coinbase only feeds poolInfo, so a payload the library cannot read must not hide the block.
var poolInfo = {};
try {
poolInfo = self.getPoolInfo({transactions: [dashcore.Transaction().fromBufferReader(br)]});
} catch (parseErr) {
self.node.log.warn('Failed to parse the coinbase of block ' + hash + ': ' + parseErr.message);
}

self.node.services.dashd.getBlockHeader(hash, function(err, blockHeader) {
if (err) {
Expand All @@ -270,7 +281,7 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
hash: hash,
time: header.time,
txlength: txlength,
poolInfo: self.getPoolInfo(info)
poolInfo: poolInfo
};

var confirmations = self.node.services.dashd.height - height + 1;
Expand Down Expand Up @@ -390,24 +401,11 @@ BlockController.prototype.formatTimestamp = function(date) {
* Previous blockHeader is used to determine block reward
*/
BlockController.prototype.getPreviousBlock = function(prevHash, cb) {
var self = this;
//On genesis block, the previousHash will be null.
if(prevHash===null) cb(null,null);
else {
self.node.getBlock(prevHash, function (err, block) {
if ((err && err.code === -5) || (err && err.code === -8)) {
return self.common.handleErrors(null, block);
} else if (err) {
return self.common.handleErrors(err, block);
}
self.node.services.dashd.getBlockHeader(prevHash, function (err, info) {
if (err) {
return self.common.handleErrors(err, info);
}
cb(null, info); // return blockHeader
});
});
if (prevHash === null) {
return cb(null, null);
}
this.node.services.dashd.getBlockHeader(prevHash, cb);
};

BlockController.prototype.getBlockReward = function(prevHash, cb) {
Expand All @@ -418,7 +416,9 @@ BlockController.prototype.getBlockReward = function(prevHash, cb) {

// block reward is based on the previous block diff / height
self.getPreviousBlock(prevHash, function(err, info) {
if(err) cb(err, null);
if (err) {
return cb(err, null);
}
//if we seek for prevHash of genesis, previousBlock return an info being null.
if(info===null){
//Genesis reward is 50.
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ InsightAPI.prototype.transactionEventHandler = function(txBuffer) {
}
catch(error) {
console.log(`${error}\nbad txBuffer: ${txBuffer.toString('hex')}`);
return;
}
var result = this.txController.transformInvTransaction(tx);

Expand All @@ -325,6 +326,7 @@ InsightAPI.prototype.transactionLockEventHandler = function(txBuffer) {
}
catch(error) {
console.log(`${error}\nbad txBuffer: ${txBuffer.toString('hex')}`);
return;
}
var result = this.txController.transformInvTransaction(tx, true);

Expand Down
38 changes: 29 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dashevo/insight-api",
"description": "A Dash blockchain REST and WebSocket API Service",
"version": "4.0.8",
"version": "4.0.9",
"repository": "git://github.com/dashevo/insight-api.git",
"contributors": [
{
Expand Down Expand Up @@ -56,11 +56,12 @@
"node": ">=6"
},
"scripts": {
"test": "NODE_ENV=test mocha -R spec --recursive"
"test": "NODE_ENV=test mocha -R spec --recursive --exclude \"test/functional/**\"",
"test:functional": "NODE_ENV=test mocha -R spec --exit test/functional"
},
"main": "lib/index.js",
"dependencies": {
"@dashevo/dashcore-lib": "^0.22.0",
"@dashevo/dashcore-lib": "^0.26.1",
"async": "^2.6.2",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
Expand Down
Loading
Loading