diff --git a/CHANGELOG.md b/CHANGELOG.md index a1316e3..986c83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.0.5 +*2023-12-15* + +### Small improvements. +### Added latest release check in the CLI mode. + + # 1.0.0 *2023-08-24* diff --git a/PocketTRC20/CLI.py b/PocketTRC20/CLI.py new file mode 100644 index 0000000..07b2109 --- /dev/null +++ b/PocketTRC20/CLI.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- + +import sys, time, requests, json +from .config import VERSION +from progress.bar import IncrementalBar + + +class Scan(): + def __init__(self): + self.bar = IncrementalBar('Scanning transaction', max=7, suffix='%(percent)d%%') + + def banner(self): + banner = ''' + $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ +$ $ +$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ +$ ____ ___ ____ _ _______ _____ $ +$ | _ \ / _ \ / ___| |/ / ____|_ _| $ +$ | |_) | | | | | | ' /| _| | | $ +$ | __/| |_| | |___| . \| |___ | | $ +$ |_| \___/ \____|_|\_\_____| |_| $ +$ _____ ____ ____ ____ ___ $ +$ |_ _| _ \ / ___|___ \ / _ \ $ +$ | | | |_) | | __) | | | | $ +$ | | | _ <| |___ / __/| |_| | $ +$ |_| |_| \_|\____|_____|\___/ $ +$ $ + $ $ + $ (..) $ + $$$$$$$$ $$$$$$$$ + $$$$$$$$$$$$$$$$$$ + \033[1;34mby Lao\033[0m + ''' + print(banner + ' \033[34mv' + VERSION + '\033[0m') + + def check_latest_release(self): + headers = {'Accept': 'application/vnd.github+json'} + check_latest_release = requests.get('https://api.github.com/repos/codelao/PocketTRC20/releases/latest', headers=headers) + if check_latest_release.status_code == 200: + latest_release = json.loads(check_latest_release.text) + if not latest_release['tag_name'] == 'v'+VERSION: + return latest_release['tag_name'] + + def hash_scanner(self, hash): + if not self.check_latest_release() == None: + print('\033[32mNew PocketTRC20 release found!\033[0m\nInstalled release: v'+VERSION+'\nLatest: '+self.check_latest_release()+'\n\nVisit \033[96mhttps://github.com/codelao/PocketTRC20/releases/latest\033[0m.\n') + if not len(hash) == 64: + print('\033[31m! Incorrect hash entered\033[0m') + sys.exit(1) + else: + link = 'https://apilist.tronscan.org/api/transaction-info?hash=' + hash + headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'} + get_link = requests.get(link, headers=headers).text + time.sleep(0.1) + self.bar.next() + self.check_hash = json.loads(get_link) + time.sleep(0.1) + self.bar.next() + if self.check_hash == {} or self.check_hash == {"message":"some parameters are missing"} or self.check_hash == {"riskTransaction":False}: + time.sleep(0.1) + self.bar.finish() + print('\033[31m! Unable to get details of this transaction\033[0m') + sys.exit(1) + else: + token_check = self.check_hash["contractType"] + time.sleep(0.1) + self.bar.next() + if token_check == 31: + status = self.check_hash["contractRet"] + time.sleep(0.1) + self.bar.next() + if status == 'SUCCESS': + from_address = self.check_hash["tokenTransferInfo"]["from_address"] + time.sleep(0.1) + self.bar.next() + to_address = self.check_hash["tokenTransferInfo"]["to_address"] + time.sleep(0.1) + self.bar.next() + amount = self.check_hash["tokenTransferInfo"]["amount_str"] + time.sleep(0.1) + self.bar.next() + time.sleep(0.1) + self.bar.finish() + print( + '\033[32mTransaction details:\033[0m' + + '\nStatus: ' + status + + '\nFrom: ' + from_address + + '\nTo: ' + to_address + + '\nAmount: ' + str(amount)[0:-6] + ' USDT' + ) + sys.exit(0) + else: + time.sleep(0.1) + self.bar.finish() + print( + '\033[32mTransaction details:\033[0m' + + '\nStatus: ' + status + + '\nAmount: 0 USDT' + ) + sys.exit(0) + elif token_check == 1: + status = self.check_hash["contractRet"] + time.sleep(0.1) + self.bar.next() + if status == 'SUCCESS': + from_address = self.check_hash["contractData"]["owner_address"] + time.sleep(0.1) + self.bar.next() + to_address = self.check_hash["contractData"]["to_address"] + time.sleep(0.1) + self.bar.next() + amount = self.check_hash["contractData"]["amount"] + time.sleep(0.1) + self.bar.next() + time.sleep(0.1) + self.bar.finish() + print( + '\033[32mTransaction details:\033[0m' + + '\nStatus: ' + status + + '\nFrom: ' + from_address + + '\nTo: ' + to_address + + '\nAmount: ' + str(amount)[0:-6] + ' TRX' + ) + sys.exit(0) + else: + time.sleep(0.1) + self.bar.finish() + print( + '\033[32mTransaction details:\033[0m' + + '\nStatus: ' + status + + '\nAmount: 0 TRX' + ) + sys.exit(0) + else: + time.sleep(0.1) + self.bar.finish() + print('\033[31m! Unable to get details of this transaction\033[0m') + sys.exit(1) diff --git a/PocketTRC20/__init__.py b/PocketTRC20/__init__.py index 2a8dc7a..8b578b2 100644 --- a/PocketTRC20/__init__.py +++ b/PocketTRC20/__init__.py @@ -18,7 +18,3 @@ #$$$$$$$$$$$$$$$$$ from .scanner import transaction, status, amount - - -NAME = 'PocketTRC20' -VERSION = '1.2.5' diff --git a/PocketTRC20/__main__.py b/PocketTRC20/__main__.py index 2a79f0c..2770482 100644 --- a/PocketTRC20/__main__.py +++ b/PocketTRC20/__main__.py @@ -17,24 +17,38 @@ #$$$$$$$ $$$$$$$$ #$$$$$$$$$$$$$$$$$ -import sys -import colorama -from .console import Scan +import sys, colorama, requests +from .CLI import Scan +def checkConnection(): + try: + requests.get('https://google.com', timeout=1) + return True + except: + return False + def entry_point(): colorama.init() if '--hash' in sys.argv: if len(sys.argv) == 3: - hash = sys.argv[2] - Scan().banner() - Scan().hash_scanner(hash) + if checkConnection() == True: + hash = sys.argv[2] + Scan().banner() + Scan().hash_scanner(hash) + else: + print('\033[31m! Check your internet connection\033[0m') + sys.exit(1) else: print('\033[31m! Hash wasn\'t entered\033[0m') + sys.exit(1) elif '--info' in sys.argv: if len(sys.argv) == 2: print('PocketTRC20\nby Lao\nLicensed under MIT\n\nOptions:\n--hash TRANSACTION_HASH scan transaction\n--info you\'re here') + sys.exit(0) else: print('\033[31m! Unknown value: \033[0m' + sys.argv[2]) + sys.exit(1) else: print('\033[31m! Incorrect option\033[0m') + sys.exit(1) diff --git a/PocketTRC20/config.py b/PocketTRC20/config.py index de1bc4c..42c9c83 100644 --- a/PocketTRC20/config.py +++ b/PocketTRC20/config.py @@ -1,21 +1,2 @@ - #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -# $ -#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -# ____ ___ ____ _ _______ _____ $ -# | _ \ / _ \ / ___| |/ / ____|_ _| $ -# | |_) | | | | | | ' /| _| | | $ -# | __/| |_| | |___| . \| |___ | | $ -# |_| \___/ \____|_|\_\_____| |_| $ -# _____ ____ ____ ____ ___ $ -# |_ _| _ \ / ___|___ \ / _ \ $ -# | | | |_) | | __) | | | | $ -# | | | _ <| |___ / __/| |_| | $ -# |_| |_| \_|\____|_____|\___/ $ -# $ - # $ - # (..) $ - #$$$$$$$ $$$$$$$$ - #$$$$$$$$$$$$$$$$$ - NAME = 'PocketTRC20' -VERSION = '1.0.0' +VERSION = '1.0.5' diff --git a/PocketTRC20/console.py b/PocketTRC20/console.py deleted file mode 100644 index 1dfb984..0000000 --- a/PocketTRC20/console.py +++ /dev/null @@ -1,143 +0,0 @@ -# -*- coding: utf-8 -*- - -import time -import requests -import urllib.request -import json -import sys -from .config import VERSION -from progress.bar import IncrementalBar - - -class Scan(): - def __init__(self): - self.bar = IncrementalBar('Scanning transaction', max=7, suffix='%(percent)d%%') - - def banner(self): - art = ''' - $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -$ $ -$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -$ ____ ___ ____ _ _______ _____ $ -$ | _ \ / _ \ / ___| |/ / ____|_ _| $ -$ | |_) | | | | | | ' /| _| | | $ -$ | __/| |_| | |___| . \| |___ | | $ -$ |_| \___/ \____|_|\_\_____| |_| $ -$ _____ ____ ____ ____ ___ $ -$ |_ _| _ \ / ___|___ \ / _ \ $ -$ | | | |_) | | __) | | | | $ -$ | | | _ <| |___ / __/| |_| | $ -$ |_| |_| \_|\____|_____|\___/ $ -$ $ - $ $ - $ (..) $ - $$$$$$$$ $$$$$$$$ - $$$$$$$$$$$$$$$$$$ - \033[1;34mby Lao\033[0m - ''' - print(art + ' \033[34mv' + VERSION + '\033[0m') - - def check_intConnection(self): - try: - urllib.request.urlopen('https://google.com', timeout=1) - return True - except: - return False - - def hash_scanner(self, hash): - if self.check_intConnection() == True: - if not len(hash) == 64: - print('\033[31m! Incorrect hash entered\033[0m') - sys.exit(1) - else: - link = 'https://apilist.tronscan.org/api/transaction-info?hash=' + hash - headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'} - get_link = requests.get(link, headers=headers).text - time.sleep(0.1) - self.bar.next() - self.check_hash = json.loads(get_link) - time.sleep(0.1) - self.bar.next() - if self.check_hash == {} or self.check_hash == {"message":"some parameters are missing"} or self.check_hash == {"riskTransaction":False}: - time.sleep(0.1) - self.bar.finish() - print('\033[31m! Unable to get details of this transaction\033[0m') - sys.exit(1) - else: - token_check = self.check_hash["contractType"] - time.sleep(0.1) - self.bar.next() - if token_check == 31: - status = self.check_hash["contractRet"] - time.sleep(0.1) - self.bar.next() - if status == 'SUCCESS': - from_address = self.check_hash["tokenTransferInfo"]["from_address"] - time.sleep(0.1) - self.bar.next() - to_address = self.check_hash["tokenTransferInfo"]["to_address"] - time.sleep(0.1) - self.bar.next() - amount = self.check_hash["tokenTransferInfo"]["amount_str"] - time.sleep(0.1) - self.bar.next() - time.sleep(0.1) - self.bar.finish() - print( - '\033[32mTransaction details:\033[0m' + - '\nStatus: ' + status + - '\nFrom: ' + from_address + - '\nTo: ' + to_address + - '\nAmount: ' + str(amount)[0:-6] + ' USDT' - ) - sys.exit(0) - else: - time.sleep(0.1) - self.bar.finish() - print( - '\033[32mTransaction details:\033[0m' + - '\nStatus: ' + status + - '\nAmount: 0 USDT' - ) - sys.exit(0) - elif token_check == 1: - status = self.check_hash["contractRet"] - time.sleep(0.1) - self.bar.next() - if status == 'SUCCESS': - from_address = self.check_hash["contractData"]["owner_address"] - time.sleep(0.1) - self.bar.next() - to_address = self.check_hash["contractData"]["to_address"] - time.sleep(0.1) - self.bar.next() - amount = self.check_hash["contractData"]["amount"] - time.sleep(0.1) - self.bar.next() - time.sleep(0.1) - self.bar.finish() - print( - '\033[32mTransaction details:\033[0m' + - '\nStatus: ' + status + - '\nFrom: ' + from_address + - '\nTo: ' + to_address + - '\nAmount: ' + str(amount)[0:-6] + ' TRX' - ) - sys.exit(0) - else: - time.sleep(0.1) - self.bar.finish() - print( - '\033[32mTransaction details:\033[0m' + - '\nStatus: ' + status + - '\nAmount: 0 TRX' - ) - sys.exit(0) - else: - time.sleep(0.1) - self.bar.finish() - print('\033[31m! Unable to get details of this transaction\033[0m') - sys.exit(1) - else: - print('\033[31m! Check your internet connection\033[0m') - sys.exit(1) diff --git a/PocketTRC20/scanner.py b/PocketTRC20/scanner.py index 5b1bd6d..bd672ff 100644 --- a/PocketTRC20/scanner.py +++ b/PocketTRC20/scanner.py @@ -1,10 +1,10 @@ import requests import json -from .console import Scan +from .__main__ import checkConnection def transaction(hash): - if Scan().check_intConnection() == True: + if checkConnection() == True: if not len(hash) == 64: raise ValueError('Incorrect hash entered.') else: diff --git a/README.md b/README.md index cacfd6c..0046625 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - [Welcome to PocketTRC20's wiki!](https://github.com/codelao/PocketTRC20/wiki#welcome-to-pockettrc20s-wiki) - [Description](https://github.com/codelao/PocketTRC20/wiki#description) - [Getting started](https://github.com/codelao/PocketTRC20/wiki/Getting-started) - - [Using PocketTRC20 as a console program](https://github.com/codelao/PocketTRC20/wiki/Getting-started#using-pockettrc20-as-a-console-program) + - [Using PocketTRC20 as a CLI app](https://github.com/codelao/PocketTRC20/wiki/Getting-started#using-pockettrc20-as-a-cli-app) - [Using PocketTRC20 as a Python module](https://github.com/codelao/PocketTRC20/wiki/Getting-started#using-pockettrc20-as-a-python-module) - [Installation](https://github.com/codelao/PocketTRC20/wiki/Installation) - [Install via pip](https://github.com/codelao/PocketTRC20/wiki/Installation#install-via-pip)