Skip to content

Commit

Permalink
Merge pull request #106 from zelcash/development
Browse files Browse the repository at this point in the history
v0.63
  • Loading branch information
TheTrunk authored Jun 30, 2020
2 parents 5b5b525 + 2eb748b commit 0e44f71
Show file tree
Hide file tree
Showing 24 changed files with 859 additions and 206 deletions.
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# ZelFlux - ZelNode Daemon
# Flux - Node Daemon

![ZelNode.gif](ZelFront/src/assets/img/zelnode.gif)
![Flux.png](ZelFront/src/assets/img/flux_banner.png)

[![DeepScan grade](https://deepscan.io/api/teams/6436/projects/8442/branches/100920/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=6436&pid=8442&bid=100920) [![CodeFactor](https://www.codefactor.io/repository/github/zelcash/zelflux/badge)](https://www.codefactor.io/repository/github/zelcash/zelflux)
[![DeepScan grade](https://deepscan.io/api/teams/6436/projects/8442/branches/100920/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=6436&pid=8442&bid=100920) [![CodeFactor](https://www.codefactor.io/repository/github/zelcash/zelflux/badge)](https://www.codefactor.io/repository/github/zelcash/zelflux)[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/zelcash/zelflux.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/zelcash/zelflux/context:javascript)

## API Documentation

[API documentation](https://zelcash.github.io/zelfluxdocs/)

## The gateway to the Zel Network

ZelFlux is the frontend UI to the entire Zel Network, it enables ZelNode operators to manage their ZelNode easily via a simple web interface. ZelFlux enables a ZelNode operator to perform all tasks such as updating and maintenance from a simple web interface, instead of having to remotely login to their ZelNode to manage it.
Flux is the frontend UI to the entire Zel Network, it enables ZelNode operators to manage their ZelNode easily via a simple web interface. Flux enables a ZelNode operator to perform all tasks such as updating and maintenance from a simple web interface, instead of having to remotely login to their ZelNode to manage it.

ZelFlux Requires a reasonably new version of Node.js (npm), MongoDB and Docker. It is a MongoDB, Express.js, Vue.js, Node.js (MEVN) application
Flux Requires a reasonably new version of Node.js (npm), MongoDB and Docker. It is a MongoDB, Express.js, Vue.js, Node.js (MEVN) application

This application communicates locally with the ZelCash Daemon (zelcashd), ZelBench Daemon (benchmarkd) and with other ZelNode Daemons (zelflux).
This application communicates locally with the ZelCash Daemon (zelcashd), ZelBench Daemon (benchmarkd) and with other ZelNode Daemons (Flux).

## Application Overview

### Backend Solution - zelback

- Provide communication with zelcashd
- Providing private API, and public API, ZelNode team API (limited!)
- Listen and handel frontend requests
- Requests signing and authenticity verifying
- Handel communication with other zelnode daemons (zelflux solution)
- Manage ZelNode applications - smart spawning, distributing workload, termination depending of application subscription.
- and more!
- Provide communication with zelcashd
- Providing private API, and public API, ZelNode team API (limited!)
- Listen and handel frontend requests
- Requests signing and authenticity verifying
- Handel communication with other zelnode daemons (Flux solution)
- Manage ZelNode applications - smart spawning, distributing workload, termination depending of application subscription.
- and more!

### Frontend Solution - zelfront

- Display ZelNode status information
- Display Zel Network information
- Display ZelCash status information
- Display ZelCash network information
- Display Specific application information
- Provide API access
- Login into private API part (frontend part)
- Login into ZelNode team API part (frontend part)
- Private: Management of ZelNode
- Private: Management of ZelCash
- Private: Update, status information
- and more!
- Display ZelNode status information
- Display Zel Network information
- Display ZelCash status information
- Display ZelCash network information
- Display Specific application information
- Provide API access
- Login into private API part (frontend part)
- Login into ZelNode team API part (frontend part)
- Private: Management of ZelNode
- Private: Management of ZelCash
- Private: Update, status information
- and more!

This application is open source and distributed under the GNU AGPLv3 licence

## Start ZelFlux
## Start Flux

ZelFlux needs Zelcashd to be ruuning, to setup Zelcashd follow [these instructions.](https://github.com/zelcash/ZelNodeInstallv3)
Flux needs Zelcashd to be ruuning, to setup Zelcashd follow [these instructions.](https://github.com/zelcash/ZelNodeInstallv3)

Setup Mongodb on Ubuntu 16.04 (LTS):

Expand Down Expand Up @@ -144,20 +144,20 @@ Install Docker using snap
snap install docker
```

Clone ZelFlux repo (Ubuntu):
Clone Flux repo (Ubuntu):

```bash
sudo apt-get install git

git clone https://github.com/zelcash/zelflux
git clone https://github.com/zelcash/Flux
```

Clone ZelFlux repo (Redhat/CentOS):
Clone Flux repo (Redhat/CentOS):

```bash
sudo yum install git

git clone https://github.com/zelcash/zelflux
git clone https://github.com/zelcash/Flux
```

Allow Inbound Connections on UFW firewall (ONLY if ufw enabled):
Expand All @@ -167,10 +167,10 @@ sudo ufw allow 16126/tcp
sudo ufw allow 16127/tcp
```

Install ZelFlux dependancies (Ubuntu/CentOS/Redhat):
Install Flux dependancies (Ubuntu/CentOS/Redhat):

```bash
cd zelflux
cd Flux

npm install
```
Expand Down
40 changes: 33 additions & 7 deletions ZelBack/src/services/explorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,19 @@ async function processBlock(blockHeight) {
// normal transactions
if (tx.version < 5 && tx.version > 0) {
let message = '';
let isZelAppMessageValue = 0;

const addresses = [];
tx.senders.forEach((sender) => {
addresses.push(sender.address);
});
tx.vout.forEach((receiver) => {
if (receiver.scriptPubKey.addresses) { // count for messages
addresses.push(receiver.scriptPubKey.addresses[0]);
if (receiver.scriptPubKey.addresses[0] === config.zelapps.address) {
// it is a zelapp message. Get Satoshi amount
isZelAppMessageValue = receiver.valueSat;
}
}
if (receiver.scriptPubKey.asm) {
message = decodeMessage(receiver.scriptPubKey.asm); // TODO adding messages to database so we can then get all messages from blockchain
Expand All @@ -303,13 +309,15 @@ async function processBlock(blockHeight) {
});
}));
// MAY contain ZelApp transaction. Store it.
if (addressesOK.indexOf(config.zelapps.address) > -1 && message.length === 64) { // todo sha256 hash length
const zelappTxRecord = { txid: tx.txid, height: tx.height, zelapphash: message };
zelappsService.checkAndRequestZelApp(message);
if (isZelAppMessageValue > 0 && message.length === 64) {
const zelappTxRecord = {
txid: tx.txid, height: tx.height, zelapphash: message, value: isZelAppMessageValue,
};
await serviceHelper.insertOneToDatabase(database, zelappsHashesCollection, zelappTxRecord).catch((error) => {
db.close();
throw error;
});
zelappsService.checkAndRequestZelApp(message, tx.txid, tx.height, isZelAppMessageValue);
}
}
// tx version 5 are zelnode transactions. Put them into zelnode
Expand Down Expand Up @@ -518,10 +526,28 @@ async function initiateBlockProcessor(restoreDatabase) {
database.collection(zelappsHashesCollection).createIndex({ zelapphash: 1 }, { name: 'query for getting zelapphash' });
}
if (scannedBlockHeight !== 0 && restoreDatabase) {
const databaseRestored = await restoreDatabaseToBlockheightState(scannedBlockHeight);
console.log(`Database restore status: ${databaseRestored}`);
if (!databaseRestored) {
throw new Error('Error restoring database!');
try {
// adjust for initial reorg
if (zelcashHeight < scannedBlockHeight + 100) {
// we are less than 100 blocks from zelcash height. Do deep restoring
scannedBlockHeight = Math.max(scannedBlockHeight - 100, 0);
await restoreDatabaseToBlockheightState(scannedBlockHeight);
const queryHeight = { generalScannedHeight: { $gte: 0 } };
const update = { $set: { generalScannedHeight: scannedBlockHeight } };
const options = { upsert: true };
await serviceHelper.findOneAndUpdateInDatabase(database, scannedHeightCollection, queryHeight, update, options).catch((error) => {
db.close();
throw error;
});
log.info('Database restored OK');
} else {
// we are more than 100 blocks from zelcash. No need for deep restoring
await restoreDatabaseToBlockheightState(scannedBlockHeight);
log.info('Database restored OK');
}
} catch (e) {
log.error('Error restoring database!');
throw e;
}
}
processBlock(scannedBlockHeight + 1);
Expand Down
5 changes: 5 additions & 0 deletions ZelBack/src/services/serviceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const log = require('../lib/log');
const { MongoClient } = mongodb;
const mongoUrl = `mongodb://${config.database.url}:${config.database.port}/`;

function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function createDataMessage(data) {
const successMessage = {
status: 'success',
Expand Down Expand Up @@ -420,4 +424,5 @@ module.exports = {
errUnauthorizedMessage,
axiosGet,
verifyZelID,
delay,
};
Loading

0 comments on commit 0e44f71

Please sign in to comment.