导航

[【T00ls公告】] 分享T00ls目前使用的TuBiCoin操作代码,共同完善

#1
TuBiCoin是币安链上发行的代币,前期T00ls为了整合TuBiCoin,通过Python开发了简单交易代码,主要实现了查询TuBiCoin数目、交易TuBiCoin等功能。使用几年功能正常,不过目前似乎在交易功能上有问题了,可能币安对币安链有调整?

有心人士帮忙修改下此代码,完善下代码功能,确保可用性。

T00ls目前使用的TuBiCoin操作代码如下:
from gevent import monkey
from gevent.pywsgi import WSGIServer
monkey.patch_all()

from flask import Flask
from flask import request
from web3 import Web3
import json
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'
   
def showmoney(my_address, contract_address):
    bsc = "https://bsc-dataseed.binance.org/"
    web3 = Web3(Web3.HTTPProvider(bsc))
    abi = json.loads('[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"name","type":"string"},{"name":"symbol","type":"string"},{"name":"decimals","type":"uint8"},{"name":"totalSupply","type":"uint256"},{"name":"feeReceiver","type":"address"},{"name":"tokenOwnerAddress","type":"address"}],"payable":true,"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]')

    contract_address = web3.to_checksum_address(contract_address)
    contract = web3.eth.contract(address=contract_address, abi=abi)
    my_address = web3.to_checksum_address(my_address)
    balanceOf = contract.functions.balanceOf(my_address).call()
    if balanceOf is None:
        return '{"status": "failed", "error": "timeout"}'
    else:
        return '{"status": "success", "TuBiCoin": ' + format(balanceOf) + '}'
        
def transaction(my_address, to_address, contract_address, private_key, send, gas):
    bsc = "https://bsc-dataseed.binance.org/"
    web3 = Web3(Web3.HTTPProvider(bsc))
    #print(web3.isConnected()) #status
    abi = json.loads('[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"name","type":"string"},{"name":"symbol","type":"string"},{"name":"decimals","type":"uint8"},{"name":"totalSupply","type":"uint256"},{"name":"feeReceiver","type":"address"},{"name":"tokenOwnerAddress","type":"address"}],"payable":true,"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]')

    contract_address = web3.to_checksum_address(contract_address)
    contract = web3.eth.contract(address=contract_address, abi=abi)
    #print(contract.functions.name().call()) #name
    #print(contract.functions.symbol().call()) #symbol
    totalSupply = contract.functions.totalSupply().call()
    #print(totalSupply) #totalSupply
    my_address = web3.to_checksum_address(my_address)
    balance = web3.eth.get_balance(my_address)
    humanReadalbe = web3.fromWei(balance, 'ether')
    #print(humanReadalbe) #Mybnb
    balanceOf = contract.functions.balanceOf(my_address).call()
    #print(balanceOf) #MyTUBI
    #amount = web3.toWei(send, 'ether')
    amount = int(send)
    nonce = web3.eth.getTransactionCount(my_address)
    #print(nonce) #nonce
    to_address = web3.to_checksum_address(to_address)
    token_tx = contract.functions.transfer(to_address, amount).buildTransaction({
        'chainId':56, 'gas': 70000,'gasPrice': web3.toWei(gas,'gwei'), 'nonce':nonce
    })
    sign_txn = web3.eth.account.signTransaction(token_tx, private_key=private_key)
    tx_hash = web3.eth.sendRawTransaction(sign_txn.rawTransaction)
   
    if tx_hash is None:
        return '{"status": "failed", "error": "timeout"}'
    else:
        return '{"status": "success", "Transaction": "' + web3.toHex(tx_hash) + '"}'
        
def gettransaction(transaction_hash,contract_address):
    bsc = "https://bsc-dataseed.binance.org/"
    web3 = Web3(Web3.HTTPProvider(bsc))
    abi = json.loads('[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"name","type":"string"},{"name":"symbol","type":"string"},{"name":"decimals","type":"uint8"},{"name":"totalSupply","type":"uint256"},{"name":"feeReceiver","type":"address"},{"name":"tokenOwnerAddress","type":"address"}],"payable":true,"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]')

    contract_address = web3.to_checksum_address(contract_address)
    contract = web3.eth.contract(address=contract_address, abi=abi)
   
    transaction = web3.eth.get_transaction(transaction_hash)
   
    from_address = transaction['from']
    input=contract.decode_function_input(transaction.input)
    to_address = format(input[1]['to'])
    value = format(input[1]['value'])
   
    if from_address is None or value is None:
        return '{"status": "failed", "error": "timeout"}'
    else:
        return '{"status": "success", "from_address": "' + from_address + '", "to_address": "' + to_address + '", "value": "' + value + '"}'
        
@app.route('/showTuBiCoin', methods=['POST'])
def showTuBiCoin():
    contract_address='0x713ac71a6ad1021416f12c4a9e17bdf489de6d7e'
    if request.method == 'POST':
        if request.form['address'] is not None:
            return showmoney(request.form['address'],contract_address)
        else:
            return "{'status': 'failed', 'error': 'erroraddress'}"
        
@app.route('/getTxnDetail', methods=['POST'])
def getTxnDetail():
    contract_address='0x713ac71a6ad1021416f12c4a9e17bdf489de6d7e'
    if request.method == 'POST':
        if request.form['transaction_hash'] is not None:
            return gettransaction(request.form['transaction_hash'],contract_address)
        else:
            return "{'status': 'failed', 'error': 'erroraddress'}"
        
@app.route('/transactionTuBiCoin', methods=['POST'])
def transactionTuBiCoin():
    contract_address='0x713ac71a6ad1021416f12c4a9e17bdf489de6d7e'
    my_address='0x729968a431aC46D8455971DdB86c356a480B9AE6'
    private_key='Idontknow'
    gas=5
    if request.method == 'POST':
        send=request.form['tubi']
        to_address=request.form['address']
        if to_address == contract_address:
            return "{'status': 'failed', 'error': 'erroraddress'}"
        if (send is not None) and (to_address is not None):
            return transaction(my_address, to_address, contract_address, private_key, send, gas)
        else:
            return "{'status': 'failed', 'error': 'erroraddress'}"
        

http_server = WSGIServer(('0.0.0.0', int(5000)), app)
http_server.serve_forever()
2025-06-24
#2
管理大哥,TuBiCoin忘记怎么注册的了。 还能找回吗?
圈子不同别硬容,凡事自己去经历!
2025-06-24
#3
回复 2# mtjbyddzqfwdyy



    你的助记词或者私钥没丢的话,那找回的问题不大
2025-06-24
#4
from gevent import monkey
from gevent.pywsgi import WSGIServer
monkey.patch_all()

from flask import Flask, request, jsonify
from web3 import Web3
import json
import logging
import time

PRIVATE_KEY = 'Idontknow'  # 发送者私钥
SENDER_ADDRESS = '0x729968a431aC46D8455971DdB86c356a480B9AE6'  # 发送者地址
CONTRACT_ADDRESS = '0x713ac71a6ad1021416f12c4a9e17bdf489de6d7e'  # TuBiCoin合约
BSC_RPC_URLS = [
    # 官方节点
    "https://bsc-dataseed1.binance.org/",
    "https://bsc-dataseed2.binance.org/",
    "https://bsc-dataseed3.binance.org/",
    "https://bsc-dataseed4.binance.org/",
    "https://bsc-dataseed1.defibit.io/",
    "https://bsc-dataseed2.defibit.io/",
    "https://bsc-dataseed3.defibit.io/",
    "https://bsc-dataseed4.defibit.io/",
    "https://bsc-dataseed1.ninicoin.io/",
    "https://bsc-dataseed2.ninicoin.io/",
    "https://bsc-dataseed3.ninicoin.io/",
    "https://bsc-dataseed4.ninicoin.io/",
    # 社区/第三方节点
    "https://bsc.nodereal.io",
    "https://rpc-bsc.bnb48.club",
    "https://bscrpc.com",
    "https://bsc.rpcgator.com",
    "https://binance.nodereal.io",
    "https://bsc-mainnet.public.blastapi.io",
    "https://bsc.meowrpc.com",
    "https://1rpc.io/bnb",
    "https://bscapi.terminet.io/rpc",
    "https://bsc.publicnode.com",
    "https://bsc-mainnet.core.chainstack.com"
]
DEFAULT_GAS_PRICE_GWEI = 15
MIN_GAS_PRICE_GWEI = 10
GAS_LIMIT_BUFFER = 1.2
REQUEST_TIMEOUT = 30
MAX_RPC_RETRY = 3
# ERC20 Token ABI
TOKEN_ABI = [
    {"constant": True, "inputs": [], "name": "name", "outputs": [{"name": "", "type": "string"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"constant": True, "inputs": [], "name": "symbol", "outputs": [{"name": "", "type": "string"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"constant": True, "inputs": [], "name": "decimals", "outputs": [{"name": "", "type": "uint8"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"constant": True, "inputs": [], "name": "totalSupply", "outputs": [{"name": "", "type": "uint256"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"constant": True, "inputs": [{"name": "owner", "type": "address"}], "name": "balanceOf", "outputs": [{"name": "", "type": "uint256"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"constant": False, "inputs": [{"name": "to", "type": "address"}, {"name": "value", "type": "uint256"}], "name": "transfer", "outputs": [{"name": "", "type": "bool"}], "payable": False, "stateMutability": "nonpayable", "type": "function"},
    {"constant": False, "inputs": [{"name": "spender", "type": "address"}, {"name": "value", "type": "uint256"}], "name": "approve", "outputs": [{"name": "", "type": "bool"}], "payable": False, "stateMutability": "nonpayable", "type": "function"},
    {"constant": True, "inputs": [{"name": "owner", "type": "address"}, {"name": "spender", "type": "address"}], "name": "allowance", "outputs": [{"name": "", "type": "uint256"}], "payable": False, "stateMutability": "view", "type": "function"},
    {"anonymous": False, "inputs": [{"indexed": True, "name": "from", "type": "address"}, {"indexed": True, "name": "to", "type": "address"}, {"indexed": False, "name": "value", "type": "uint256"}], "name": "Transfer", "type": "event"},
    {"anonymous": False, "inputs": [{"indexed": True, "name": "owner", "type": "address"}, {"indexed": True, "name": "spender", "type": "address"}, {"indexed": False, "name": "value", "type": "uint256"}], "name": "Approval", "type": "event"}
]

# 日志配置
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("tubicoin")

app = Flask(__name__)

def get_web3_connection():
    # 获取可用的Web3连接,自动轮询多个RPC节点,带重试。
    last_error = None
    for attempt in range(MAX_RPC_RETRY):
        for rpc_url in BSC_RPC_URLS:
            try:
                web3 = Web3(Web3.HTTPProvider(rpc_url, request_kwargs={'timeout': REQUEST_TIMEOUT}))
                if web3.is_connected():
                    logger.info(f"Connected to BSC via {rpc_url}")
                    return web3
            except Exception as e:
                logger.warning(f"Failed to connect to {rpc_url}: {e}")
                last_error = e
        time.sleep(1)
    raise Exception(f"无法连接到BSC网络: {last_error}")

def get_gas_price(web3):
    # 获取当前gas价格,自动加缓冲,保证最低gas。
    try:
        gas_price = web3.eth.gas_price
        gas_price_gwei = web3.from_wei(gas_price, 'gwei')
        min_gas_price = max(float(gas_price_gwei) * 1.1, MIN_GAS_PRICE_GWEI)
        return web3.to_wei(min_gas_price, 'gwei')
    except Exception as e:
        logger.warning(f"Failed to get gas price: {e}")
        return web3.to_wei(DEFAULT_GAS_PRICE_GWEI, 'gwei')

def estimate_gas_limit(web3, contract, from_address, to_address, amount):
    #估算gas限制,失败时返回默认值。
    try:
        gas_estimate = contract.functions.transfer(to_address, amount).estimate_gas({'from': from_address})
        return int(gas_estimate * GAS_LIMIT_BUFFER)
    except Exception as e:
        logger.warning(f"Failed to estimate gas: {e}")
        return 100000

@app.route('/')
def hello_world():
    return jsonify({
        "status": "success",
        "message": "TuBiCoin API Server",
        "endpoints": {
            "showTuBiCoin": "POST /showTuBiCoin",
            "transactionTuBiCoin": "POST /transactionTuBiCoin",
            "getTxnDetail": "POST /getTxnDetail"
        }
    })

def showmoney(my_address, contract_address):
    # 查询TuBiCoin余额
    try:
        web3 = get_web3_connection()
        contract_address = web3.to_checksum_address(contract_address)
        contract = web3.eth.contract(address=contract_address, abi=TOKEN_ABI)
        my_address = web3.to_checksum_address(my_address)
        balance = contract.functions.balanceOf(my_address).call()
        decimals = contract.functions.decimals().call()
        human_balance = balance / (10 ** decimals)
        return jsonify({
            "status": "success",
            "address": my_address,
            "balance_raw": str(balance),
            "balance_human": str(human_balance),
            "decimals": decimals
        })
    except Exception as e:
        logger.error(f"Error in showmoney: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

def transaction(my_address, to_address, contract_address, private_key, send, gas_price_gwei=None):
    # 执行TuBiCoin转账
    try:
        web3 = get_web3_connection()
        contract_address = web3.to_checksum_address(contract_address)
        contract = web3.eth.contract(address=contract_address, abi=TOKEN_ABI)
        my_address = web3.to_checksum_address(my_address)
        to_address = web3.to_checksum_address(to_address)
        # 检查余额
        balance = contract.functions.balanceOf(my_address).call()
        amount = int(send)
        if balance < amount:
            return jsonify({"status": "failed", "error": f"余额不足。当前余额: {balance}, 需要: {amount}"}), 400
        nonce = web3.eth.get_transaction_count(my_address)
        if gas_price_gwei:
            gas_price = web3.to_wei(gas_price_gwei, 'gwei')
        else:
            gas_price = get_gas_price(web3)
        gas_limit = estimate_gas_limit(web3, contract, my_address, to_address, amount)
        token_tx = contract.functions.transfer(to_address, amount).build_transaction({
            'chainId': 56,
            'gas': gas_limit,
            'gasPrice': gas_price,
            'nonce': nonce
        })
        signed_txn = web3.eth.account.sign_transaction(token_tx, private_key=private_key)
        tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
        return jsonify({
            "status": "success",
            "transaction_hash": web3.to_hex(tx_hash),
            "from": my_address,
            "to": to_address,
            "amount": str(amount),
            "gas_price_gwei": web3.from_wei(gas_price, 'gwei'),
            "gas_limit": gas_limit
        })
    except Exception as e:
        logger.error(f"Error in transaction: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

def gettransaction(transaction_hash, contract_address):
    # 获取交易详情
    try:
        web3 = get_web3_connection()
        contract_address = web3.to_checksum_address(contract_address)
        contract = web3.eth.contract(address=contract_address, abi=TOKEN_ABI)
        tx = web3.eth.get_transaction(transaction_hash)
        if not tx:
            return jsonify({"status": "failed", "error": "交易不存在"}), 404
        try:
            decoded_input = contract.decode_function_input(tx.input)
            function_name = decoded_input[0]
            function_params = decoded_input[1]
            if function_name.fn_name == 'transfer':
                to_address = function_params['to']
                value = function_params['value']
                decimals = contract.functions.decimals().call()
                human_value = value / (10 ** decimals)
                return jsonify({
                    "status": "success",
                    "transaction_hash": transaction_hash,
                    "from_address": tx['from'],
                    "to_address": to_address,
                    "value_raw": str(value),
                    "value_human": str(human_value),
                    "block_number": tx['blockNumber'],
                    "gas_used": tx['gas'],
                    "gas_price": str(tx['gasPrice'])
                })
            else:
                return jsonify({"status": "failed", "error": f"不支持的函数: {function_name}"}), 400
        except Exception as e:
            return jsonify({"status": "failed", "error": f"无法解析交易数据: {str(e)}"}), 400
    except Exception as e:
        logger.error(f"Error in gettransaction: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

@app.route('/showTuBiCoin', methods=['POST'])
def showTuBiCoin():
    # 查询TuBiCoin余额API
    try:
        if request.method == 'POST':
            address = request.form.get('address')
            if not address:
                return jsonify({"status": "failed", "error": "缺少address参数"}), 400
            return showmoney(address, CONTRACT_ADDRESS)
        else:
            return jsonify({"status": "failed", "error": "只支持POST方法"}), 405
    except Exception as e:
        logger.error(f"Error in showTuBiCoin endpoint: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

@app.route('/getTxnDetail', methods=['POST'])
def getTxnDetail():
    # 获取交易详情API
    try:
        if request.method == 'POST':
            transaction_hash = request.form.get('transaction_hash')
            if not transaction_hash:
                return jsonify({"status": "failed", "error": "缺少transaction_hash参数"}), 400
            return gettransaction(transaction_hash, CONTRACT_ADDRESS)
        else:
            return jsonify({"status": "failed", "error": "只支持POST方法"}), 405
    except Exception as e:
        logger.error(f"Error in getTxnDetail endpoint: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

@app.route('/transactionTuBiCoin', methods=['POST'])
def transactionTuBiCoin():
    # TuBiCoin转账API
    try:
        if request.method == 'POST':
            send = request.form.get('tubi')
            to_address = request.form.get('address')
            gas_price_gwei = request.form.get('gas_price', DEFAULT_GAS_PRICE_GWEI)
            if not send or not to_address:
                return jsonify({"status": "failed", "error": "缺少tubi或address参数"}), 400
            if to_address == CONTRACT_ADDRESS:
                return jsonify({"status": "failed", "error": "不能转账到合约地址"}), 400
            try:
                gas_price_gwei = float(gas_price_gwei)
            except ValueError:
                gas_price_gwei = DEFAULT_GAS_PRICE_GWEI
            return transaction(SENDER_ADDRESS, to_address, CONTRACT_ADDRESS, PRIVATE_KEY, send, gas_price_gwei)
        else:
            return jsonify({"status": "failed", "error": "只支持POST方法"}), 405
    except Exception as e:
        logger.error(f"Error in transactionTuBiCoin endpoint: {e}")
        return jsonify({"status": "failed", "error": str(e)}), 500

@app.route('/health', methods=['GET'])
def health_check():
    # 健康检查API
    try:
        web3 = get_web3_connection()
        return jsonify({
            "status": "success",
            "message": "服务正常运行",
            "bsc_connected": web3.is_connected(),
            "latest_block": web3.eth.block_number
        })
    except Exception as e:
        return jsonify({"status": "failed", "error": str(e)}), 500

if __name__ == '__main__':
    logger.info("启动TuBiCoin API服务器...")
    http_server = WSGIServer(('0.0.0.0', 5000), app)
    http_server.serve_forever()
附rust版本代码

评分记录

2025-06-25
#5
感谢 @adysec ,此功能已经修复。
T00.ls:https://t00.ls/t00ls
T00ls官方Telegram公开频道:https://t.me/T00lsCom
T00ls官方Telegram群:https://t.me/T00lsTB
T00ls官方Twitter:https://twitter.com/T00lsCom
2025-06-25
#6
回复 2# mtjbyddzqfwdyy



你好像没兑换TuBiCoin,不行就重新注册一个更换下地址啊
2025-06-26
#7
没领到,还能再发两个吗?
2025-06-28
#8
又没人炒 也不上交易所 没啥用