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