Esempio n. 1
0
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    if (!size || data[size - 1]) {
        return 0;
    }

    struct json *j1 = json_from_string((const char *)data);
    if (j1->type == JSON_STRING) {
        json_destroy(j1);
        return 0;
    }

    free(json_to_string(j1, JSSF_SORT | JSSF_PRETTY));

    struct jsonrpc_msg *msg;
    char *error = jsonrpc_msg_from_json(j1, &msg); /* Frees 'j1'. */
    if (error) {
        free(error);
        return 0;
    }

    struct json *j2 = jsonrpc_msg_to_json(msg); /* Frees 'msg'. */
    if (j2->type == JSON_STRING) {
        json_destroy(j2);
        return 0;
    }

    free(json_to_string(j2, JSSF_SORT | JSSF_PRETTY));
    json_destroy(j2);

    return 0;
}
Esempio n. 2
0
CRpcHelper::mini_booklist CRpcHelper::GetMiniBookList()
{
    mini_booklist result;
#if 1
    Json::Value args;
    args.append( MAX_CONF );
    args.append( true );

    Json::Value jv = json_from_string( m_rpc->Send( "listreceivedbyaddress", args ) );
    for( Json::ValueIterator it = jv.begin(); it != jv.end(); ++it )
    {
        const Json::Value& rv = *it;
        bool ok = result.insert( std::make_pair( rv["address"].asString(), rv["account"].asString() ) ).second;
        assert( ok );

    }
#else
    str_unique_list labels = GetLabelList();
    for( str_unique_list::const_iterator it_label = labels.begin(); it_label != labels.end(); ++it_label )
    {
        str_unique_list label_addr_list = GetAddrList_FromLabel( *it_label );
        for( str_unique_list::const_iterator it_addr = label_addr_list.begin(); it_addr != label_addr_list.end(); ++it_addr )
        {
            bool ok = result.insert( std::make_pair( *it_addr, *it_label ) ).second;
            assert( ok );
        }
    }
#endif
    return result;
}
Esempio n. 3
0
CRpcHelper::str_unique_list CRpcHelper::GetAddressList()
{
    str_unique_list result;

#if 1
    Json::Value args;
    args.append( MAX_CONF );
    args.append( true );

    Json::Value jv = json_from_string( m_rpc->Send( "listreceivedbyaddress", args ) );
    for( Json::ValueIterator it = jv.begin(); it != jv.end(); ++it )
    {
        const Json::Value& rv = *it;
        bool ok = result.insert( rv["address"].asString() ).second;
        assert( ok );
    }
#else
    str_unique_list labels = GetLabelList();
    for( str_unique_list::const_iterator l_it = labels.begin(); l_it != labels.end(); ++l_it )
    {
        str_unique_list label_addr_list = GetAddrList_FromLabel( *l_it );
        for( str_unique_list::const_iterator a_it = label_addr_list.begin(); a_it != label_addr_list.end(); ++a_it )
        {
            bool ok = result.insert( *a_it ).second;
            assert( ok );
        }
    }
#endif
    return result;
}
Esempio n. 4
0
CRpcHelper::unspent_info CRpcHelper::GetUnspentData_FromRecvAddr( const address_str& addr )
{
    // assert( !IsMulSigAddr(addr) ); // not support mulsig address

    Json::Value keys;
    keys.append( addr );

    Json::Value args;
    args.append( 1 );
    args.append( MAX_CONF );
    args.append( keys );
    const Json::Value jv = json_from_string( m_rpc->Send( "listunspent", args ) );

    unspent_info result;
    for( Json::Value::const_iterator it = jv.begin(); it != jv.end(); ++it )
    {
        const Json::Value& rv = *it;
        if( rv["address"] == addr )
        {
            unspent_info::unspent_txlist::value_type nv;
            nv.txid = txid_str( rv["txid"].asString() );
            nv.vout = rv["vout"].asInt();

            result.txlist.push_back( nv );
            result.total += rv["amount"].asDouble();
        }
    }
    return result;
}
Esempio n. 5
0
Json::Value CRpcHelper::DecodeRawTransactionJson( const txdata_str& txdata )
{
    Json::Value args;
    args.append( txdata );
    std::string ret = m_rpc->Send( "decoderawtransaction", args );
    return json_from_string( ret );
}
Esempio n. 6
0
CRpcHelper::pubkey_str CRpcHelper::GetPubKey( const address_str& recvaddr )
{
    Json::Value param;
    param.append( recvaddr );
    Json::Value ret = json_from_string( m_rpc->Send( "validateaddress", param ) );
    return pubkey_str( ret["pubkey"].asString() );
}
Esempio n. 7
0
CRpcHelper::txdata_str CRpcHelper::SignRawTransaction( const txdata_str& txdata )
{
    Json::Value args;
    args.append( txdata );
    Json::Value jv = json_from_string( m_rpc->Send( "signrawtransaction", args ) );
	// assert( jv["complete"].asBool() ); // don't check it.
    return txdata_str( jv["hex"].asString() );
}
Esempio n. 8
0
static struct json *
parse_json(const char *s)
{
    struct json *json = json_from_string(s);
    if (json->type == JSON_STRING) {
        ovs_fatal(0, "\"%s\": %s", s, json->u.string);
    }
    return json;
}
Esempio n. 9
0
CRpcHelper::full_booklist CRpcHelper::GetFullBookList()
{
    full_booklist result;
    Json::Value ret = json_from_string( m_rpc->Send( "listaddressgroupings" ) );

    std::stack<Json::Value> stk;
    stk.push( ret );
    while( stk.size() )
    {
        const Json::Value rv = stk.top();
        stk.pop();
        if( rv.isArray() || rv.isObject() )
        {
            if( rv.size() > 0 )
            {
                if( rv[UINT( 0 )].isString() && rv.size() >= 2 )
                {
                    assert( rv[1].isDouble() );
                    addr_ext_info nv;
                    address_str addr = address_str( rv[UINT( 0 )].asString() );
                    nv.balance = rv[1].asDouble();
                    if( rv.size() >= 3 )
                    {
                        nv.label = label_str( rv[2].asString() );
                    }
                    bool ok = result.insert( std::make_pair( addr, nv ) ).second;
                    assert( ok );
                }
                else
                {
                    for( Json::Value::const_iterator it = rv.begin(); it != rv.end(); ++it )
                    {
                        stk.push( *it );
                    }
                }
            }
        }
        else
        {
            assert( 0 );
        }
    }

    mini_booklist minis = GetMiniBookList();
    for( mini_booklist::const_iterator it = minis.begin(); it != minis.end(); ++it )
    {
        addr_ext_info ar;
        ar.label = it->second;
        ar.balance = 0;
        result.insert( std::make_pair( it->first, ar ) ).second;

    }

    return result;
}
Esempio n. 10
0
CRpcHelper::str_unique_list CRpcHelper::GetAddrList_FromLabel( const label_str& label )
{
    str_unique_list result;

    Json::Value args;
    args.append( label );
    const Json::Value jv = json_from_string( m_rpc->Send( "getaddressesbyaccount", args ) );

    for( Json::Value::const_iterator it = jv.begin(); it != jv.end(); ++it )
    {
        bool ok = result.insert( ( *it ).asString() ).second;
        assert( ok );
    }
    return result;
}
Esempio n. 11
0
CRpcHelper::str_unique_list CRpcHelper::GetLabelList()
{
    str_unique_list result;

    Json::Value args;
    args.append( MAX_CONF );
    const Json::Value labels = json_from_string( m_rpc->Send( "listaccounts", args ) );

    for( Json::Value::const_iterator it = labels.begin(); it != labels.end(); ++it )
    {
        bool ok = result.insert( it.key().asString() ).second;
        assert( ok );
    }
    return result;
}
Esempio n. 12
0
std::pair<CRpcHelper::address_str, double> CRpcHelper::gettxout( const txid_str& txid, int n )
{
    std::pair<CRpcHelper::address_str, double> result;
    Json::Value args;
    args.append( txid );
    args.append( n );
    Json::Value jsv = json_from_string( m_rpc->Send( "gettxout", args ) );
    if( jsv.size() )
    {
        result.second = jsv["value"].asDouble();
        jsv = jsv["scriptPubKey"]["addresses"];
        if( jsv.size() )
        {
            result.first = address_str( jsv[UINT(0)].asString() );
			return result;
        }
    }
	throw std::runtime_error( "not coin in local database or was spend.");
}
Esempio n. 13
0
static void test_json (const char *name, const char *s)
{
	json_t *root;
	char   *txt;

	printf ("Test: %s\n", name);

	txt = strdup (s);
	root = json_from_string (txt, NULL);
	if (!root) {
		fprintf (stderr, "Parse failed\n");
		return;
	}

	json_print (root);
	printf ("\n");

	json_free (root);
	free (txt);
}
Esempio n. 14
0
int test_lines(void)
{
	json_t *root;
	json_t *a;
	json_t *i;
	char *str = strdup ("{ \"lines\" : [\"word1\", \"word2\"] }");

	root = json_from_string (str, NULL);

	a = json_get_array (root, "lines", NULL);

	for (i = json_get_first(a); i; i = i->next) {
		printf ("w = %s\n", i->val.str);
	}

	json_free (root);
	free (str);

	return 0;
}
Esempio n. 15
0
int test_basic (void)
{
	json_t      *root;
	json_t      *o;
	json_t      *i;
	char        *str;
	const char  *s;
	int          n;
	double       d;
	int          boolval;

	str = "  {\"l1\" : 1111, "
		" \"l2\" : {\"l3\": {\"l4\": \"s2\", \"l5\": 2222 } }, "
		" \"l6\" : [1,2,3,4,5], "
		" \"l7\" : { \"l8\" : \"Hello World\" }, "
		" \"float\": 273.93,"
		" \"b1\": trUe,"
		" \"nil\": nulL,"
		" \"b2\": false} \n\t";
	str = strdup (str);

	root = json_from_string (str, NULL);
	assert (root);

	n = json_get_int (root, "l1", NULL);
	assert (n == 1111);

	d = json_get_double (root, "float", NULL);
	assert (d == 273.93);

	i = json_get_array (root, "l6", NULL);
	assert (i->type == JSON_TYPE_ARRAY);

	i = json_get_first (i);
	for (n = 0; i; n++, i = i->next) {
		int data[] = {1,2,3,4,5};
		assert (i->type == JSON_TYPE_INT);
		assert (i->val.num == data[n]);
	}

	o = json_get (root, "nil", NULL);
	assert (o->type == JSON_TYPE_NULL);

	o = json_get (root, "b1", NULL);
	assert (o->type == JSON_TYPE_TRUE);

	o = json_get (root, "b2", NULL);
	assert (o->type == JSON_TYPE_FALSE);
	
	boolval = json_get_bool (root, "b1", NULL);
	assert (boolval == 1);

	boolval = json_get_bool (root, "b2", NULL);
	assert (boolval == 0);

	boolval = json_get_bool (root, "nonexisting", NULL);
	assert (boolval == -1);

	o = json_get_object (root, "l7", NULL);
	assert (o);
	if (o) {
		s = json_get_string (o, "l8", NULL);
		printf ("str = %s\n", s);
	}

	printf ("\n");

	json_print (root);
	printf ("\n");

	json_free (root);
	free (str);
	return 0;
}