참고 : https://tron.network/wallet?lng=kor
https://github.com/TronWatch/TronLink/blob/master/packages/backgroundScript/services/WalletService/Account.js
to, from에서 조회한 내역을 MongoDB에 넣어보자
const TronWeb = require('../../dist/TronWeb.node.js');
const fullNode = 'https://api.shasta.trongrid.io'; const solidityNode = 'https://api.shasta.trongrid.io'; const eventServer = 'https://api.shasta.trongrid.io'; const privateKey = 'abc';
const app = async() => { const tronWeb = new TronWeb( fullNode, solidityNode, eventServer, privateKey ); tronWeb.setDefaultBlock('latest');
const nodes = await tronWeb.isConnected(); const connected = !Object.entries(nodes).map(([name, connected]) => { if (!connected) console.error(`Error: ${name} is not connected`); return connected; }).includes(false);
const transactions = [];
let hasMoreTransactions = true; let offset = 0;
while(hasMoreTransactions) { const newTransactions = (await tronWeb.trx.getTransactionsRelated("TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih", 'all', 90, offset)) .map(transaction => { transaction.offset = offset; return transaction; });
if(!newTransactions.length) hasMoreTransactions = false; else offset += 90;
transactions.push(...newTransactions); } console.log("transactions: ", transactions);
}; app();
|
데이터가 블록으로 넘어오는듯,, 블록을 한번 도 조회 해야 되는데
이더처럼 json형태로 to. from. 컨트렉종류, 금액 이렇게 넘어와야 되는데
트론은 token에 대한 개발이 아직 진행중인걸로 보임
테스트넷에 대한 지원도 좀 짜증날 정도로 지원을 안해주고 있음.
async updateTransactions() { if(this.updatingTransactions) return; this.updatingTransactions = true; const transactions = await this.getTransactions(); const filteredTransactions = transactions .filter(( { txID }) => ( !Object.keys(this.transactions).includes(txID) && !this.ignoredTransactions.includes(txID) )); const mappedTransactions = TransactionMapper.mapAll(filteredTransactions) .filter(( { type }) => SUPPORTED_CONTRACTS.includes(type)); const newTransactions = []; const manuallyCached = []; for (const transaction of mappedTransactions) { if(transaction.timestamp) { transaction.cached = true; newTransactions.push(transaction); continue; }const txData = await NodeService.tronWeb.trx .getTransactionInfo(transaction.txID); if(!txData.id) { logger.warn(`Transaction $ { transaction.txID }has not been cached, skipping`); continue; }// if(!txData.id) { // logger.warn(`Transaction ${ transaction.txID }has not been cached`); // // StorageService.addPendingTransaction(address, transaction.txID); // transaction.cached = false; // // this.transactions[ transaction.txID ]= transaction; // continue; // }// logger.info(`Transaction ${ transaction.txID }has been cached`, transaction); transaction.cached = true; transaction.timestamp = txData.blockTimeStamp; transaction.receipt = txData.receipt || false; transaction.result = txData.contractResult || false; newTransactions.push(transaction); manuallyCached.push(transaction.txID); }const sortedTransactions = [ ...Object.values(this.transactions), ...newTransactions ].sort((a, b) => b.timestamp - a.timestamp); this.transactions = sortedTransactions .slice(0, 100) .reduce((transactions, transaction) => { transactions[ transaction.txID ]= transaction; return transactions; }, {}); manuallyCached.forEach(txID => { if(txID in this.transactions) return; // Transaction is now too old for TronLink (100+) this.ignoredTransactions.push(txID); }); this.updatingTransactions = false; this.save(); } |