import time
import os

import pymysql
import requests
import json
import hashlib
import logging
from osTools import *
# 设置日志格式
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

DIR = os.path.dirname(os.path.abspath(__file__))
IS_DEV = os.path.isfile(os.path.join(DIR, '.debug'))
# 定义base url

SQL_URL = "http://localhost:8888"

def post_(url, data):
    headers = {'Content-type': 'application/json'}
    url = SQL_URL + url
    r = requests.post(url, json=data, headers=headers).text
    return r

def findHash(id, hash):
    urlI = '/pending/findByChainIdAndHash'
    data = {}
    data['chainId'] = id
    data['hash'] = hash
    r = post_(urlI, data)
    return r

def addPending(id, params):
    urlI = '/pending/appendOrUpdate'
    data = params
    data['chainId'] = id
    r = post_(urlI, data)
    return r

def addChain(params):
    exp = {
        "id": 1,
        "chain": "Ethereum",
        "tokenSymbol": "ETH",
        "networkName": "Ethereum Network",
        "http": "https://mainnet.infura.io/v3",
        "explorer": "https://etherscan.io"
    }
    urlI = '/chain/append'
    data = params
    r = post_(urlI, data)
    return r


def test():
    r = requests.post('http://localhost:8888/hello').text
    return r



print(speedTest(test, ))


