Esempio n. 1
0
def handler(x):
    response = Cell()
    try:
        address = x.data.read_address()
        query = query_template % {'address': address.raw}
        result = json.loads(client.execute(query))
        boc = result["data"]["accounts"][0]["data"]
        response = deserialize_boc(boc)
    except:
        pass
    return response
Esempio n. 2
0
def handler(x):
    price = 0
    try:
        response = requests.get(
            'https://api.coindesk.com/v1/bpi/currentprice.json')
        price_data = response.json()
        price = int(x['bpi']['USD']['rate_float'] * 100)
    except:
        pass
    answer = Cell()
    answer.data.put_arbitrary_uint(price, 32)
    return answer
Esempio n. 3
0
def handler(x):
    blockhash = 0
    try:
        height = x.data.read_uint32()
        response = requests.get(
            'https://insight.bitpay.com/api/block-index/%d' % height)
        block_hash = response.json()["blockHash"]
        blockhash = int(block_hash, 16)
    except:
        pass
    answer = Cell()
    answer.data.put_arbitrary_uint(blockhash, 256)
    return blockhash
def handler(x):
    btc_usd_price = 0
    ton_btc_price = 0
    k_crystal_usd_price = 0
    try:
        response = requests.get(
            'https://api.coindesk.com/v1/bpi/currentprice.json')
        price_data = response.json()
        btc_usd_price = int(price_data['bpi']['USD']['rate_float'] * 100)
        response = requests.get(
            'http://exchange-open-api.coineal.com/open/api/get_ticker?symbol=tonbtc'
        )
        price_data = response.json()
        ton_btc_price = price_data["data"]["last"]
        k_crystal_usd_price = int(ton_btc_price * btc_usd_price * 1e3)
    except:
        pass
    answer = Cell()
    answer.data.put_arbitrary_uint(k_crystal_usd_price, 32)
    return answer
Esempio n. 5
0
from server import run_server, Cell, default_network_params
private_key = b'\x00' * 32
oracle_id = 1

handler = lambda x: Cell()
run_server(default_network_params, oracle_id, private_key, handler)