delet TRON wallet type

This commit is contained in:
NW 2025-01-02 16:19:39 +00:00
parent c9bcb09221
commit 22f76c64a6
3 changed files with 17 additions and 94 deletions

View File

@ -30,9 +30,6 @@ export default class AdminWalletsHandler {
[
{ text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' },
{ text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' }
],
[
{ text: 'TRON (TRX)', callback_data: 'wallet_type_TRON' }
]
]
}
@ -81,7 +78,6 @@ export default class AdminWalletsHandler {
const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null,
wallet.wallet_type.startsWith('TRON') ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null,
null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -138,7 +134,6 @@ export default class AdminWalletsHandler {
const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null,
wallet.wallet_type.startsWith('TRON') ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null,
null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -212,7 +207,6 @@ export default class AdminWalletsHandler {
const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null,
wallet.wallet_type.startsWith('TRON') ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null,
null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -272,9 +266,6 @@ export default class AdminWalletsHandler {
[
{ text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' },
{ text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' }
],
[
{ text: 'TRON (TRX)', callback_data: 'wallet_type_TRON' }
]
]
}

View File

@ -32,7 +32,6 @@ export default class UserWalletsHandler {
const walletUtilsInstance = new WalletUtils(
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
cryptoWallets.find(w => w.wallet_type === 'ETH')?.address,
user.id,
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -46,7 +45,6 @@ export default class UserWalletsHandler {
const baseType = this.getBaseWalletType(type);
const wallet = cryptoWallets.find(w =>
w.wallet_type === baseType ||
(type.includes('TRC-20') && w.wallet_type === 'TRON') ||
(type.includes('ERC-20') && w.wallet_type === 'ETH')
);
@ -187,7 +185,7 @@ export default class UserWalletsHandler {
await bot.sendMessage(chatId, 'Error loading transaction history. Please try again.');
}
}
static async handleRefreshBalance(callbackQuery) {
const chatId = callbackQuery.message.chat.id;
const messageId = callbackQuery.message.message_id;
@ -231,7 +229,6 @@ export default class UserWalletsHandler {
const cryptoOptions = [
['BTC', 'ETH', 'LTC'],
['USDT TRC-20', 'USDD TRC-20'],
['USDT ERC-20', 'USDC ERC-20']
];
@ -276,7 +273,7 @@ export default class UserWalletsHandler {
const mnemonic = await WalletGenerator.generateMnemonic();
const wallets = await WalletGenerator.generateWallets(mnemonic);
// Get the base wallet type (ETH for ERC-20, TRON for TRC-20)
// Get the base wallet type (ETH for ERC-20)
const baseType = this.getBaseWalletType(walletType);
// Get existing wallet of this type
@ -392,7 +389,6 @@ export default class UserWalletsHandler {
const walletUtilsInstance = new WalletUtils(
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
cryptoWallets.find(w => w.wallet_type === 'TRON')?.address,
cryptoWallets.find(w => w.wallet_type === 'ETH')?.address,
user.id,
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -402,11 +398,9 @@ export default class UserWalletsHandler {
for (const [type, balance] of Object.entries(balances)) {
if (cryptoWallets.some(w => w.wallet_type === type.split(' ')[0] ||
(type.includes('TRC-20') && w.wallet_type === 'TRON') ||
(type.includes('ERC-20') && w.wallet_type === 'ETH'))) {
const wallet = cryptoWallets.find(w =>
w.wallet_type === type.split(' ')[0] ||
(type.includes('TRC-20') && w.wallet_type === 'TRON') ||
(type.includes('ERC-20') && w.wallet_type === 'ETH')
);
message += `🔐 *${type}*\n`;
@ -547,7 +541,6 @@ export default class UserWalletsHandler {
const walletUtilsInstance = new WalletUtils(
groupedWallets['BTC']?.[0]?.address,
groupedWallets['LTC']?.[0]?.address,
groupedWallets['TRON']?.[0]?.address,
groupedWallets['ETH']?.[0]?.address,
user.id,
Date.now() - 30 * 24 * 60 * 60 * 1000
@ -587,10 +580,6 @@ export default class UserWalletsHandler {
balance = balances.ETH.amount;
usdValue = balances.ETH.usdValue;
break;
case 'TRON':
balance = balances['USDT TRC-20'].amount + balances['USDD TRC-20'].amount;
usdValue = balances['USDT TRC-20'].usdValue + balances['USDD TRC-20'].usdValue;
break;
}
typeTotal += balance;
@ -675,13 +664,11 @@ export default class UserWalletsHandler {
// Helper methods
static getBaseWalletType(walletType) {
if (walletType.includes('TRC-20')) return 'TRON';
if (walletType.includes('ERC-20')) return 'ETH';
return walletType;
}
static getWalletAddress(wallets, walletType) {
if (walletType.includes('TRC-20')) return wallets.TRON.address;
if (walletType.includes('ERC-20')) return wallets.ETH.address;
if (walletType === 'BTC') return wallets.BTC.address;
if (walletType === 'LTC') return wallets.LTC.address;
@ -690,7 +677,6 @@ export default class UserWalletsHandler {
}
static getNetworkName(walletType) {
if (walletType.includes('TRC-20')) return 'Tron Network (TRC-20)';
if (walletType.includes('ERC-20')) return 'Ethereum Network (ERC-20)';
if (walletType === 'BTC') return 'Bitcoin Network';
if (walletType === 'LTC') return 'Litecoin Network';

View File

@ -4,14 +4,13 @@ import { publicToAddress } from 'ethereumjs-util';
import * as bitcoin from 'bitcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
import { ECPairFactory } from 'ecpair';
import CryptoJS from 'crypto-js';
const ECPair = ECPairFactory(ecc);
export default class WalletGenerator {
static async generateMnemonic() {
try {
return bip39.generateMnemonic(128); // 12 words for maximum security
return bip39.generateMnemonic(128); // 12 слов
} catch (error) {
console.error('Error generating mnemonic:', error);
throw new Error('Failed to generate mnemonic');
@ -26,8 +25,8 @@ export default class WalletGenerator {
// Generate BTC wallet (BIP84 - Native SegWit)
const btcNode = hdkey.derive("m/84'/0'/0'/0/0");
const btcKeyPair = ECPair.fromPrivateKey(btcNode.privateKey);
const btcAddress = bitcoin.payments.p2wpkh({
pubkey: btcKeyPair.publicKey
const btcAddress = bitcoin.payments.p2wpkh({
pubkey: btcKeyPair.publicKey,
}).address;
// Generate ETH wallet (BIP44)
@ -44,84 +43,31 @@ export default class WalletGenerator {
bech32: 'ltc',
bip32: {
public: 0x019da462,
private: 0x019d9cfe
private: 0x019d9cfe,
},
pubKeyHash: 0x30,
scriptHash: 0x32,
wif: 0xb0
}
wif: 0xb0,
},
}).address;
// Generate TRON address (BIP44)
const tronNode = hdkey.derive("m/44'/195'/0'/0/0");
const tronAddress = this.generateTronAddress(tronNode.publicKey);
return {
BTC: {
address: btcAddress,
path: "m/84'/0'/0'/0/0"
BTC: {
address: btcAddress,
path: "m/84'/0'/0'/0/0",
},
ETH: {
address: ethAddress,
path: "m/44'/60'/0'/0/0"
ETH: {
address: ethAddress,
path: "m/44'/60'/0'/0/0",
},
LTC: {
address: ltcAddress,
path: "m/84'/2'/0'/0/0"
LTC: {
address: ltcAddress,
path: "m/84'/2'/0'/0/0",
},
TRON: {
address: tronAddress,
path: "m/44'/195'/0'/0/0"
}
};
} catch (error) {
console.error('Error in generateWallets:', error);
throw new Error('Failed to generate cryptocurrency wallets: ' + error.message);
}
}
static generateTronAddress(publicKey) {
try {
const addressPrefix = '41'; // TRON mainnet prefix
const pubKeyHash = CryptoJS.SHA256(
CryptoJS.lib.WordArray.create(publicKey)
).toString();
const address = addressPrefix + pubKeyHash.substring(0, 40);
return this.base58Encode(Buffer.from(address, 'hex'));
} catch (error) {
console.error('Error generating TRON address:', error);
throw new Error('Failed to generate TRON address: ' + error.message);
}
}
static base58Encode(buffer) {
try {
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
let digits = [0];
for (let i = 0; i < buffer.length; i++) {
let carry = buffer[i];
for (let j = 0; j < digits.length; j++) {
carry += digits[j] << 8;
digits[j] = carry % 58;
carry = (carry / 58) | 0;
}
while (carry > 0) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
}
// Add leading zeros
for (let i = 0; buffer[i] === 0 && i < buffer.length - 1; i++) {
digits.push(0);
}
return digits.reverse().map(digit => ALPHABET[digit]).join('');
} catch (error) {
console.error('Error in base58Encode:', error);
throw new Error('Failed to encode address: ' + error.message);
}
}
}