Esempio n. 1
0
bool coind_validate_address(YAAMP_COIND *coind)
{
    if(!coind->wallet[0]) return false;

    char params[YAAMP_SMALLBUFSIZE];
    sprintf(params, "[\"%s\"]", coind->wallet);

    json_value *json = rpc_call(&coind->rpc, "validateaddress", params);
    if(!json) return false;

    json_value *json_result = json_get_object(json, "result");
    if(!json_result)
    {
        json_value_free(json);
        return false;
    }

    bool isvalid = json_get_bool(json_result, "isvalid");
    if(!isvalid) stratumlog("%s wallet %s is not valid.\n", coind->name, coind->wallet);

    bool ismine = json_get_bool(json_result, "ismine");
    if(!ismine) stratumlog("%s wallet %s is not mine.\n", coind->name, coind->wallet);

    const char *p = json_get_string(json_result, "pubkey");
    if(p) strcpy(coind->pubkey, p);

    json_value_free(json);
    base58_decode(coind->wallet, coind->script_pubkey);

    return isvalid && ismine;
}
Esempio n. 2
0
gboolean
json_api_get_bool (JsonNode *parent, const gchar *mapping)
{
	JsonNode	*node;
	const gchar	*field;

	if (!node || !mapping)
		return FALSE;

	node = json_api_get_node (parent, mapping);
	field = strrchr (mapping, '/');
	if (!field)
		field = mapping;
	else
		field++;

	return json_get_bool (node, field);
}
Esempio n. 3
0
void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *json_result)
{
	char eheight[64];
	ser_number(templ->height, eheight);

	char etime[64];
	ser_number(time(NULL), etime);

	char entime[64];
	memset(entime, 0, 64);

	if(coind->pos)
		ser_string_be(templ->ntime, entime, 1);

	char eversion1[64] = "01000000";

	if(coind->txmessage)
		strcpy(eversion1, "02000000");

	char script1[4*1024];
	sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);

	char script2[4*1024] = "7961616d702e636f6d00";		// yaamp.com
	if(!coind->pos && !coind->isaux && templ->auxs_size)
		coinbase_aux(templ, script2);

	int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;

	sprintf(templ->coinb1,
		"%s%s010000000000000000000000000000000000000000000000000000000000000000ffffffff%02x%s",		// 8+8+74+2 -> height
		eversion1, entime, script_len, script1);

	sprintf(templ->coinb2, "%s00000000", script2);
	json_int_t available = templ->value;

	if(strcmp(coind->symbol, "DRK") == 0 || strcmp(coind->symbol, "DASH") == 0 || strcmp(coind->symbol, "BOD") == 0)
//	if(strcmp(coind->symbol, "DRK") == 0)
	{
		char charity_payee[1024] = "";
		strcpy(charity_payee, json_get_string(json_result, "payee"));

		json_int_t charity_amount = json_get_int(json_result, "payee_amount");
		bool charity_payments = json_get_bool(json_result, "masternode_payments");
		bool charity_enforce = json_get_bool(json_result, "enforce_masternode_payments");

		if(charity_payments && charity_enforce)
		{
			strcat(templ->coinb2, "02");
			available -= charity_amount;

			char script_payee[1024];
			base58_decode(charity_payee, script_payee);

			job_pack_tx(coind, templ->coinb2, charity_amount, script_payee);
		}
		else
			strcat(templ->coinb2, "01");
	}

	else
		strcat(templ->coinb2, "01");

	job_pack_tx(coind, templ->coinb2, available, NULL);
	strcat(templ->coinb2, "00000000");				// locktime

	coind->reward = (double)available/100000000*coind->reward_mul;
//	debuglog("coinbase %f\n", coind->reward);

//	debuglog("new job: %x, %s, %s, %s\n", coind->templ->id, coind->templ->version, coind->templ->nbits, coind->templ->ntime);
//	debuglog("coinb1 %s\n", templ->coinb1);
//	debuglog("coinb2 %s\n", templ->coinb2);
}
Esempio n. 4
0
static void
ttrss_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags)
{
	if (result->data && result->httpstatus == 200) {
		JsonParser	*parser = json_parser_new ();

		if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
			JsonArray	*array = json_node_get_array (json_get_node (json_parser_get_root (parser), "content"));
			GList		*elements = json_array_get_elements (array);
			GList		*iter = elements;
			GList		*items = NULL;

			/*
			   We expect to get something like this
			   
			   [{"id":118,
			     "unread":true,
			     "marked":false,
			     "updated":1287927675,
			     "is_updated":false,
			     "title":"IBM Says New ...",
			     "link":"http:\/\/rss.slashdot.org\/~r\/Slashdot\/slashdot\/~3\/ALuhNKO3NV4\/story01.htm",
			     "feed_id":"5",
			     "content":"coondoggie writes ..."
			    },
			    {"id":117,
			     "unread":true,
			     "marked":false,
			     "updated":1287923814,
                           [...]
                         */
                         
			while (iter) {
				JsonNode *node = (JsonNode *)iter->data;
				itemPtr item = item_new ();
				gchar *id;
				const gchar *content; 
				gchar *xhtml;

				id = g_strdup_printf ("%" G_GINT64_FORMAT, json_get_int (node, "id"));
				item_set_id (item, id);
				g_free (id);
				item_set_title (item, json_get_string (node, "title"));
				item_set_source (item, json_get_string (node, "link"));

				content = json_get_string (node, "content");
				xhtml = xhtml_extract_from_string (content, NULL);
				item_set_description (item, xhtml);
				xmlFree (xhtml);

				item->time = json_get_int (node, "updated");
				
				if (json_get_bool (node, "unread")) {
					item->readStatus = FALSE;
				}
				else {
					item->readStatus = TRUE;
				}
				if (json_get_bool (node, "marked"))
					item->flagStatus = TRUE;
					
				items = g_list_append (items, (gpointer)item);
				
				iter = g_list_next (iter);
			}

			g_list_free (elements);

			/* merge against feed cache */
			if (items) {
				itemSetPtr itemSet = node_get_itemset (subscription->node);
				gint newCount = itemset_merge_items (itemSet, items, TRUE /* feed valid */, FALSE /* markAsRead */);
				itemlist_merge_itemset (itemSet);
				itemset_free (itemSet);

				feedlist_node_was_updated (subscription->node, newCount);
			}

			subscription->node->available = TRUE;
		} else {
			subscription->node->available = FALSE;

			g_string_append (((feedPtr)subscription->node->data)->parseErrors, _("Could not parse JSON returned by TinyTinyRSS API!"));
		}

		g_object_unref (parser);
	} else {
		subscription->node->available = FALSE;
	}
}
Esempio n. 5
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;
}