Skip to content

Commit

Permalink
Merge pull request #1375 from RunOnFlux/development
Browse files Browse the repository at this point in the history
v5.18.0
  • Loading branch information
TheTrunk authored Jul 23, 2024
2 parents d5bd76c + adc282e commit dc949e7
Show file tree
Hide file tree
Showing 39 changed files with 2,254 additions and 741 deletions.
15 changes: 0 additions & 15 deletions HomeUI/src/services/FluxService.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ export default {
},
});
},
adjustCruxID(zelidauthHeader, cruxid) {
return Api().get(`/flux/adjustcruxid/${cruxid}`, {
headers: {
zelidauth: zelidauthHeader,
},
});
},
adjustKadena(zelidauthHeader, account, chainid) {
return Api().get(`/flux/adjustkadena/${account}/${chainid}`, {
headers: {
Expand Down Expand Up @@ -148,14 +141,6 @@ export default {
};
return Api().post('/flux/adjustblockedrepositories', data, axiosConfig);
},
getCruxID() {
const axiosConfig = {
headers: {
'x-apicache-bypass': true,
},
};
return Api().get('/flux/cruxid', axiosConfig);
},
getKadenaAccount() {
const axiosConfig = {
headers: {
Expand Down
8 changes: 4 additions & 4 deletions HomeUI/src/views/fluxadmin/ManageFlux.vue
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,11 @@ export default {
const chainid = this.kadenaChainIDInput;
const zelidauth = localStorage.getItem('zelidauth');
try {
const cruxIDResponse = await FluxService.adjustKadena(zelidauth, account, chainid);
if (cruxIDResponse.data.status === 'error') {
this.showToast('danger', cruxIDResponse.data.data.message || cruxIDResponse.data.data);
const response = await FluxService.adjustKadena(zelidauth, account, chainid);
if (response.data.status === 'error') {
this.showToast('danger', response.data.data.message || response.data.data);
} else {
this.showToast('success', cruxIDResponse.data.data.message || cruxIDResponse.data.data);
this.showToast('success', response.data.data.message || response.data.data);
}
} catch (error) {
this.showToast('danger', error.message || error);
Expand Down
1 change: 1 addition & 0 deletions ZelBack/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = {
rpcport: 16124,
porttestnet: 26125,
rpcporttestnet: 26124,
zmqport: 16123,
},
minimumFluxBenchAllowedVersion: '4.0.0',
minimumFluxOSAllowedVersion: '5.4.0',
Expand Down
6 changes: 0 additions & 6 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ module.exports = (app) => {
app.get('/flux/pgp', cache('30 seconds'), (req, res) => {
fluxService.getFluxPGPidentity(req, res);
});
app.get('/flux/cruxid', cache('30 seconds'), (req, res) => {
fluxService.getFluxCruxID(req, res);
});
app.get('/flux/kadena', cache('30 seconds'), (req, res) => {
fluxService.getFluxKadena(req, res);
});
Expand Down Expand Up @@ -880,9 +877,6 @@ module.exports = (app) => {
idService.logoutAllUsers(req, res);
});

app.get('/flux/adjustcruxid/:cruxid?', (req, res) => { // note this essentially rebuilds flux use with caution!
fluxService.adjustCruxID(req, res);
});
app.get('/flux/adjustkadena/:account?/:chainid?', (req, res) => { // note this essentially rebuilds flux use with caution!
fluxService.adjustKadenaAccount(req, res);
});
Expand Down
64 changes: 40 additions & 24 deletions ZelBack/src/services/benchmarkService.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
const benchmarkrpc = require('daemonrpc');
const path = require('node:path');
const fs = require('node:fs/promises');

const config = require('config');
const path = require('path');
const fs = require('fs');
const userconfig = require('../../../config/userconfig');
const log = require('../lib/log');

const serviceHelper = require('./serviceHelper');
const messageHelper = require('./messageHelper');
const verificationHelper = require('./verificationHelper');
const generalService = require('./generalService');
const upnpService = require('./upnpService');
const log = require('../lib/log');
const fluxRpc = require('./utils/fluxRpc');

const isTestnet = userconfig.initial.testnet;
let response = messageHelper.createErrorMessage();

const rpcport = isTestnet === true ? config.benchmark.rpcporttestnet : config.benchmark.rpcport;
let benchdClient = null;

const homeDirPath = path.join(__dirname, '../../../../');
const newBenchmarkPath = path.join(homeDirPath, '.fluxbenchmark');
async function buildBenchdClient() {
const homeDirPath = path.join(__dirname, '../../../../');
const fluxbenchdPath = path.join(homeDirPath, '.fluxbenchmark');

let response = messageHelper.createErrorMessage();
const exists = await fs.stat(fluxbenchdPath).catch(() => false);

const prefix = exists ? 'flux' : 'zel';

const username = `${prefix}benchuser`;
const password = `${prefix}benchpassword`;

const { initial: { testnet: isTestnet } } = userconfig;
const portId = isTestnet ? 'rpcporttestnet' : 'rpcport';
const rpcPort = config.benchmark[portId];

const client = new fluxRpc.FluxRpc(`http://127.0.0.1:${rpcPort}`, {
auth: { username, password }, timeout: 10_000, mode: 'fluxbenchd',
});

benchdClient = client;
return client;
}

/**
* To execute a remote procedure call (RPC).
Expand All @@ -26,23 +47,14 @@ let response = messageHelper.createErrorMessage();
* @returns {object} Message.
*/
async function executeCall(rpc, params) {
let callResponse;
const rpcparameters = params || [];
try {
let rpcuser = 'zelbenchuser';
let rpcpassword = 'zelbenchpassword';
if (fs.existsSync(newBenchmarkPath)) {
rpcuser = 'fluxbenchuser';
rpcpassword = 'fluxbenchpassword';
}

const client = new benchmarkrpc.Client({
port: rpcport,
user: rpcuser,
pass: rpcpassword,
timeout: 60000,
});
const data = await client[rpc](...rpcparameters);
if (!benchdClient) await buildBenchdClient();

let callResponse;

try {
const data = await benchdClient.run(rpc, { params: rpcparameters });
const successResponse = messageHelper.createDataMessage(data);
callResponse = successResponse;
} catch (error) {
Expand Down Expand Up @@ -252,6 +264,10 @@ async function executeUpnpBench() {
}
}

if (require.main === module) {
getInfo().then((res) => console.log(res));
}

module.exports = {
// == Export for testing purposes ==
executeCall,
Expand Down
4 changes: 3 additions & 1 deletion ZelBack/src/services/daemonService/daemonServiceMiscRpcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const daemonServiceUtils = require('./daemonServiceUtils');
const daemonServiceBlockchainRpcs = require('./daemonServiceBlockchainRpcs');
const log = require('../../lib/log');

const isTestnet = userconfig.initial.testnet;
const userconfig = require('../../../../config/userconfig');

const { initial: { isTestnet } } = userconfig;

let currentDaemonHeight = 0;
let currentDaemonHeader = isTestnet === true ? 377006 : 1136836;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const serviceHelper = require('../serviceHelper');
const messageHelper = require('../messageHelper');
const daemonServiceUtils = require('./daemonServiceUtils');
const verificationHelper = require('../verificationHelper');
const client = require('../utils/daemonrpcClient').default;

let response = messageHelper.createErrorMessage();

Expand All @@ -21,7 +20,7 @@ async function createRawTransaction(req, res) {
addresses = addresses || req.query.addresses;
let { locktime } = req.params;
locktime = locktime || req.query.locktime || 0;
const blockcount = await client.getBlockCount().catch((error) => {
const blockcount = await daemonServiceUtils.getFluxdClient().getBlockCount().catch((error) => {
response = messageHelper.createErrorMessage(error.message, error.name, error.code);
});
if (!blockcount) {
Expand Down Expand Up @@ -64,7 +63,7 @@ async function createRawTransactionPost(req, res) {
let { addresses } = processedBody;
let { locktime } = processedBody;
locktime = locktime || 0;
const blockcount = await client.getBlockCount().catch((error) => {
const blockcount = await daemonServiceUtils.getFluxdClient().getBlockCount().catch((error) => {
response = messageHelper.createErrorMessage(error.message, error.name, error.code);
});
if (!blockcount) {
Expand Down
Loading

0 comments on commit dc949e7

Please sign in to comment.