Skip to content

Check Validators Balance #7

Check Validators Balance

Check Validators Balance #7

name: Check Validators Balance
on:
workflow_dispatch:
inputs:
process_type:
description: 'Select process type'
required: true
default: 'check_balance'
type: choice
options:
- check_balance
jobs:
check-balance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install axios
- name: Check Validators
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = require('path');
const axios = require('axios');
async function checkBalance(btcAddress) {
try {
console.log(`Checking balance for BTC address: ${btcAddress}`);
const response = await axios.get(`https://mempool.space/signet/api/address/${btcAddress}`);
const balanceInBTC = response.data.chain_stats.funded_txo_sum / 100000000;
console.log(`Current balance: ${balanceInBTC} BTC`);
return {
balance: balanceInBTC,
hasEnough: balanceInBTC >= 1
};
} catch (error) {
console.error(`Error checking balance: ${error.message}`);
throw error;
}
}
// Get the correct validators directory path
const validatorsDir = path.join(process.cwd(), 'fiamma-testnet-1/bitvm2-staker-validators');
console.log('Looking for validators in:', validatorsDir);
if (!fs.existsSync(validatorsDir)) {
console.error('Validators directory not found!');
core.setFailed('Validators directory not found');
return;
}
// Read all validator files
const files = fs.readdirSync(validatorsDir);
console.log(`Found ${files.length} files in validators directory`);
for (const file of files) {
if (!file.endsWith('.json')) continue;
const filePath = path.join(validatorsDir, file);
console.log(`\nProcessing file: ${file}`);
try {
const content = fs.readFileSync(filePath, 'utf8');
console.log('File content:', content);
let validatorData;
try {
validatorData = JSON.parse(content);
} catch (error) {
console.error(`Invalid JSON in ${file}:`, error.message);
continue;
}
if (!validatorData.btc_address) {
console.log(`No BTC address found in ${file}`);
continue;
}
console.log(`Found BTC address: ${validatorData.btc_address}`);
const result = await checkBalance(validatorData.btc_address);
if (!result.hasEnough) {
console.log(`❌ Insufficient balance for ${validatorData.btc_address}: ${result.balance} BTC`);
} else {
console.log(`✅ Sufficient balance for ${validatorData.btc_address}: ${result.balance} BTC`);
}
} catch (error) {
console.error(`Error processing ${file}:`, error.message);
}
}