get out all console log
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
fce59c4463
commit
618553a205
33
index.js
33
index.js
@ -224,7 +224,6 @@ async function initBitcoinMonitoring() {
|
||||
|
||||
// Clear processed transactions to start fresh
|
||||
processedTransactions.clear();
|
||||
console.log('Starting Bitcoin monitoring with fresh transaction history');
|
||||
|
||||
// Create a completely new Socket instance
|
||||
btcSocket = new Socket();
|
||||
@ -237,8 +236,7 @@ async function initBitcoinMonitoring() {
|
||||
try {
|
||||
// Check if we've already processed this transaction
|
||||
if (processedTransactions.has(tx.hash)) {
|
||||
console.log(`Duplicate transaction detected: ${tx.hash}`);
|
||||
return;
|
||||
return; // Skip silently
|
||||
}
|
||||
|
||||
// Add to processed transactions
|
||||
@ -252,9 +250,6 @@ async function initBitcoinMonitoring() {
|
||||
return; // Skip this transaction if it's below the minimum amount
|
||||
}
|
||||
|
||||
// Log for debugging
|
||||
console.log(`Processing BTC transaction: ${txData.hash} - ${txData.amount} BTC`);
|
||||
|
||||
// Create Discord embed
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('🟠 New Bitcoin Transaction')
|
||||
@ -263,6 +258,7 @@ async function initBitcoinMonitoring() {
|
||||
{ name: '🔗 Transaction Hash', value: `\`${txData.hash}\``, inline: false },
|
||||
{ name: '💰 Amount', value: `${txData.amount} BTC`, inline: true },
|
||||
{ name: '📊 Size', value: `${txData.size} bytes`, inline: true },
|
||||
{ name: '💸 Fee', value: txData.fee !== 'Unknown' ? `${(txData.fee / 100000000).toFixed(8)} BTC` : 'Unknown', inline: true },
|
||||
{ name: '⚡ Fee Rate', value: `${txData.feeRate} sat/byte`, inline: true }
|
||||
)
|
||||
.setTimestamp()
|
||||
@ -299,7 +295,6 @@ async function initBitcoinMonitoring() {
|
||||
// Register the transaction handler
|
||||
btcSocket.onTransaction(transactionHandler);
|
||||
|
||||
console.log('Bitcoin monitoring initialized successfully');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Bitcoin monitoring:', error);
|
||||
@ -319,17 +314,32 @@ async function processBitcoinTransaction(tx, blockexplorer) {
|
||||
.filter(output => output.addr)
|
||||
.map(output => output.addr);
|
||||
|
||||
// Calculate total transaction value
|
||||
const totalValue = tx.out.reduce((sum, output) => sum + (output.value || 0), 0) / 100000000;
|
||||
// Calculate total input value
|
||||
const totalInputValue = tx.inputs.reduce((sum, input) => {
|
||||
return sum + (input.prev_out ? (input.prev_out.value || 0) : 0);
|
||||
}, 0);
|
||||
|
||||
// Calculate total output value
|
||||
const totalOutputValue = tx.out.reduce((sum, output) => sum + (output.value || 0), 0);
|
||||
|
||||
// Calculate fee rate (if available)
|
||||
const feeRate = tx.fee && tx.size ? Math.round(tx.fee / tx.size) : 'Unknown';
|
||||
// Calculate fee in satoshis
|
||||
const feeSatoshis = totalInputValue - totalOutputValue;
|
||||
|
||||
// Calculate fee rate (sat/byte)
|
||||
let feeRate = 'Unknown';
|
||||
if (tx.size && feeSatoshis > 0) {
|
||||
feeRate = Math.round(feeSatoshis / tx.size);
|
||||
}
|
||||
|
||||
// Convert total output value to BTC (since this represents the transaction amount)
|
||||
const totalValue = totalOutputValue / 100000000;
|
||||
|
||||
return {
|
||||
hash: tx.hash,
|
||||
amount: totalValue.toFixed(8),
|
||||
size: tx.size || 'Unknown',
|
||||
feeRate: feeRate,
|
||||
fee: feeSatoshis > 0 ? feeSatoshis : 'Unknown',
|
||||
inputAddresses: inputAddresses,
|
||||
outputAddresses: outputAddresses,
|
||||
timestamp: new Date()
|
||||
@ -368,7 +378,6 @@ function stopBitcoinMonitoring() {
|
||||
|
||||
// Clear processed transactions to prevent duplicate detection issues
|
||||
processedTransactions.clear();
|
||||
console.log(`Bitcoin monitoring stopped, WebSocket closed, and cleared ${processedTransactions.size} processed transactions`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user