mkdir like-nodewatch
cd like-nodewatch
npm init #全部適当
npm install express axios
touch app.js
app.js
const express = require('express');
const axios = require('axios');
const app = express();
const port = 3030;
const apiNode = 'http://localhost:3000'
app.get('/api/symbol/height', async (req, res) => {
try {
const response = await axios.get(`${apiNode}/chain/info`);
const data = response.data;
const height = parseInt(data.height, 10);
const finalizedHeight = parseInt(data.latestFinalizedBlock.height, 10);
res.json({
finalizedHeight,
height
});
} catch (error) {
console.error('Error fetching chain info:', error);
res.status(500).send('Error fetching chain info');
}
});
app.get('/api/symbol/nodes/peer', async (req, res) => {
try {
const chRes = await axios.get(`${apiNode}/chain/info`);
const chData = chRes.data;
const height = parseInt(chData.height, 10);
const finalizedHeight = parseInt(chData.latestFinalizedBlock.height, 10);
const niRes = await axios.get(`${apiNode}/node/info`);
const niData = niRes.data;
const mainPublicKey = niData.publicKey;
const nodePublicKey = niData.nodePublicKey;
const name = niData.friendlyName;
const roles = niData.roles;
const endpoint = `http://${niData.host}:3000`;
const npRes = await axios.get(`${apiNode}/network/properties`);
const npData = npRes.data;
const currencyMosaicId = npData.chain.currencyMosaicId
.replace(/'/g, '')
.replace(/^0x/, '');
const aiRes = await axios.get(`${apiNode}/accounts/${mainPublicKey}`);
const aiData = aiRes.data;
const mosaic = aiData.account.mosaics.find(m => m.id === currencyMosaicId);
let balance = 0;
if (mosaic) {
const amountAsBigInt = BigInt(mosaic.amount);
balance = Number(amountAsBigInt) / 1000000;
}
res.json([{
balance,
endpoint,
finalizedHeight,
height,
mainPublicKey,
name,
nodePublicKey,
roles
}]);
} catch (error) {
console.error('Error fetching chain info:', error);
res.status(500).send('Error fetching chain info');
}
});
app.get('/api/symbol/nodes/api', async (req, res) => {
try {
res.json([])
}
catch (error) {
console.error('Error fetching chain info:', error);
res.status(500).send('Error fetching chain info');
}
})
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
nohup node app.js &
最後にshoestringのconfigファイル
mainnet.ini
[services]
nodewatch = http://localhost:3030
これでいけるような気がするけど環境がないので一切試してない!