예제 #1
0
static void json_add_inputs(struct json_result *response, const union protocol_tx *tx)
{
	unsigned int i;

	json_array_start(response, "vin");
	for (i = 0; i < num_inputs(tx); i++)
		json_add_input(response, NULL, tx_input(tx, i));
	json_array_end(response);
}
예제 #2
0
static void add_skipped(struct log_info *info)
{
	if (info->num_skipped) {
		json_array_start(info->response, NULL);
		json_add_string(info->response, "type", "SKIPPED");
		json_add_num(info->response, "num_skipped", info->num_skipped);
		json_array_end(info->response);
		info->num_skipped = 0;
	}
}
예제 #3
0
static void json_help(struct command *cmd,
		      const char *buffer, const jsmntok_t *params)
{
	unsigned int i;
	struct json_result *response = new_json_result(cmd);

	json_array_start(response, NULL);
	for (i = 0; i < ARRAY_SIZE(cmdlist); i++) {
		json_add_object(response,
				"command", JSMN_STRING,
				cmdlist[i]->name,
				"description", JSMN_STRING,
				cmdlist[i]->description,
				NULL);
	}
	json_array_end(response);
	command_success(cmd, response);
}
예제 #4
0
static void json_add_outputs(struct json_result *response,
			     struct state *state, const union protocol_tx *tx)
{
	unsigned int i;
	struct protocol_gateway_payment *outputs;

	outputs = get_from_gateway_outputs(&tx->from_gateway);

	json_array_start(response, "vout");
	for (i = 0; i < num_outputs(tx); i++) {
		json_object_start(response, NULL);
		json_add_num(response, "send_amount",
			 le32_to_cpu(outputs[i].send_amount));
		json_add_address(response, "output_addr", state->test_net,
				 &outputs[i].output_addr);
		json_object_end(response);
	}
	json_array_end(response);
}
예제 #5
0
static void log_to_json(unsigned int skipped,
			struct timerel diff,
			enum log_level level,
			const char *prefix,
			const char *log,
			struct log_info *info)
{
	info->num_skipped += skipped;

	if (level < info->level) {
		info->num_skipped++;
		return;
	}

	add_skipped(info);

	json_array_start(info->response, NULL);
	json_add_string(info->response, "type",
			level == LOG_BROKEN ? "BROKEN"
			: level == LOG_UNUSUAL ? "UNUSUAL"
			: level == LOG_INFORM ? "INFO"
			: level == LOG_DBG ? "DEBUG"
			: level == LOG_IO ? "IO"
			: "UNKNOWN");
	json_add_time(info->response, "time", diff.ts);
	json_add_string(info->response, "source", prefix);
	if (level == LOG_IO) {
		if (log[0])
			json_add_string(info->response, "direction", "IN");
		else
			json_add_string(info->response, "direction", "OUT");

		json_add_hex(info->response, "data", log+1, tal_count(log)-1);
	} else
		json_add_string(info->response, "log", log);

	json_array_end(info->response);
}
예제 #6
0
static char *ask_process(const tal_t *ctx,
			 const char *name,
			 const char *arg1,
			 const char *arg2,
			 const char *arg3,
			 const char *arg4,
			 const char *arg5)
{
	struct json_result *response = new_json_result(ctx);

	if (streq(name, "bitcoind")) {
		assert(streq(arg1, "-testnet"));
		if (streq(arg2, "listtransactions")) {
			unsigned int i, num, skip;

			assert(streq(arg3, "gateway"));
			num = atoi(arg4 ? arg4 : "10");
			assert(num);
			skip = atoi(arg5 ? arg5 : "0");

			json_array_start(response, NULL);
			/* Like bitcoind, list oldest first. */
			for (i = skip; i < skip+num; i++) {
				unsigned int confs;

				if (i >= ARRAY_SIZE(listtxs_response))
					break;
				/* We only show one the first time. */
				if (i > sleeps)
					break;
				/* First one is 16 confs, then 4, 1, then 0,
				 * plus one each time you ask. */
				confs = (1 << ((ARRAY_SIZE(listtxs_response)
						- i) * 2)) + sleeps;

				result_append_fmt(response, listtxs_response[i],
						  confs);
			}
			json_array_end(response);
			assert(!response->indent);
			return response->s;
		} else if (streq(arg2, "getrawtransaction")) {
			unsigned int i;

			/* We only do verbose mode */
			assert(streq(arg4, "1"));
			assert(arg5 == NULL);

			/* Search through responses for this txid */
			for (i = 0; i < ARRAY_SIZE(getrawtxs_response); i++) {
				const char *p;
				p = strstr(getrawtxs_response[i],
					   "    \"txid\" : \"");
				if (strstarts(p + strlen("    \"txid\" : \""),
					      arg3))
					return tal_strdup(ctx,
							  getrawtxs_response[i]);
			}
		} else if (streq(arg2, "getinfo")) {
			return tal_strdup(ctx, getinfo_response);
		} else if (streq(arg2, "sendtoaddress")) {
			if (mark_off_payment(arg3,
					     amount_in_satoshis(arg4,
								strlen(arg4))))
				return tal_strdup(ctx, "some-new-bitcoin-txid");
		}
	} else if (streq(name, "pettycoin-tx")) {
		assert(streq(arg1, "--no-fee"));
		assert(streq(arg2, "from-gateway"));
		assert(streq(arg3, "FAKE-gateway-privkey"));

		if (mark_off_payment(arg4, atol(arg5)))
			return tal_fmt(ctx, "raw-transaction-%s", arg4);
	} else if (streq(name, "pettycoin-query")) {
		assert(streq(arg1, "sendrawtransaction"));
		assert(strstarts(arg2, "raw-transaction-"));
		assert(arg3 == NULL);
		assert(arg4 == NULL);
		assert(arg5 == NULL);
		return tal_fmt(ctx, "txid for %s", arg2);
	}

	printf("ask_process: name=%s arg1=%s arg2=%s arg3=%s arg4=%s arg5=%s",
	       name, arg1, arg2, arg3, arg4, arg5);
	return NULL;
}