From 45eca00e56e077576b8df48ba83b8136c3c6daf8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 3 Sep 2018 23:40:00 -1100 Subject: [PATCH] Simple dapp --- src/cc/dapps/oraclefeed.cpp | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/cc/dapps/oraclefeed.cpp diff --git a/src/cc/dapps/oraclefeed.cpp b/src/cc/dapps/oraclefeed.cpp new file mode 100644 index 000000000..ba5e5deb7 --- /dev/null +++ b/src/cc/dapps/oraclefeed.cpp @@ -0,0 +1,47 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include +#include +#include +#include "../../komodo_cJSON.c" +#include "../../komodo_bitcoind.h" + +#define issue_curl(url,cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)(url),0,0,(char *)(cmdstr)) + +cJSON *url_json(char *url) +{ + char *jsonstr; cJSON *json = 0; + if ( (jsonstr= issue_curl(url)) != 0 ) + { + printf("(%s) -> (%s)\n",url,jsonstr); + json = cJSON_Parse(jsonstr); + free(jsonstr); + } + return(json); +} + +int32_t main(int32_t argc,char **argv) +{ + cJSON *pjson,*bpi,*usd; + printf("Powered by CoinDesk (%s)\n","https://www.coindesk.com/price/"); + if ( (pjson= url_json("http://api.coindesk.com/v1/bpi/currentprice.json","")) != 0 ) + { + if ( (bpi= jobj(pjson,"bpi")) != 0 && (usd= jobj(bpi,"USD")) != 0 ) + printf("BTC/USD %.4f\n",jdouble(usd,"rate_float")); + json_close(pjson); + } + return(0); +}