Пример #1
0
static void json_add_input(struct json_result *response, const char *fieldname,
			   const struct protocol_input *inp)
{
	json_object_start(response, fieldname);
	json_add_tx_id(response, "input", &inp->input);
	json_add_num(response, "output", le16_to_cpu(inp->output));
	json_object_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_echo(struct command *cmd,
		      const char *buffer, const jsmntok_t *params)
{
	struct json_result *response = new_json_result(cmd);

	json_object_start(response, NULL);
	json_add_num(response, "num", params->size);
	json_add_literal(response, "echo",
			 json_tok_contents(buffer, params),
			 json_tok_len(params));
	json_object_end(response);
	command_success(cmd, response);
}
Пример #4
0
static void json_getlog(struct command *cmd,
			const char *buffer, const jsmntok_t *params)
{
	struct log_info info;
	struct log_record *lr = cmd->dstate->log_record;
	jsmntok_t *level;

	json_get_params(buffer, params, "?level", &level, NULL);

	info.num_skipped = 0;

	if (!level)
		info.level = LOG_INFORM;
	else if (json_tok_streq(buffer, level, "io"))
		info.level = LOG_IO;
	else if (json_tok_streq(buffer, level, "debug"))
		info.level = LOG_DBG;
	else if (json_tok_streq(buffer, level, "info"))
		info.level = LOG_INFORM;
	else if (json_tok_streq(buffer, level, "unusual"))
		info.level = LOG_UNUSUAL;
	else {
		command_fail(cmd, "Invalid level param");
		return;
	}

	info.response = new_json_result(cmd);
	json_object_start(info.response, NULL);
	json_add_time(info.response, "creation_time", log_init_time(lr)->ts);
	json_add_num(info.response, "bytes_used", (unsigned int)log_used(lr));
	json_add_num(info.response, "bytes_max", (unsigned int)log_max_mem(lr));
	json_object_start(info.response, "log");
	log_each_line(lr, log_to_json, &info);
	json_object_end(info.response);
	json_object_end(info.response);
	command_success(cmd, info.response);
}
Пример #5
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);
}
Пример #6
0
void json_add_tx(struct json_result *response, const char *fieldname,
		 struct state *state,
		 const union protocol_tx *tx,
		 const struct block *block,
		 unsigned int confirms)
{
	struct protocol_tx_id sha;

	json_object_start(response, fieldname);
	hash_tx(tx, &sha);
	json_add_tx_id(response, "txid", &sha);
	if (block)
		json_add_block_id(response, "block", &block->sha);
	json_add_num(response, "confirmations", confirms);
	json_add_num(response, "version", tx->hdr.version);
	json_add_num(response, "features", tx->hdr.features);

	switch (tx_type(tx)) {
	case TX_NORMAL:
		json_add_string(response, "type", "TX_NORMAL");
		json_add_pubkey(response, "input_key", &tx->normal.input_key);
		json_add_address(response, "output_addr",
				 state->test_net, &tx->normal.output_addr);
		json_add_num(response, "send_amount",
			     le32_to_cpu(tx->normal.send_amount));
		json_add_num(response, "change_amount",
			     le32_to_cpu(tx->normal.change_amount));
		json_add_signature(response, "signature",
				   &tx->normal.signature);
		json_add_inputs(response, tx);
		goto finish;
	case TX_FROM_GATEWAY:
		json_add_string(response, "type", "TX_FROM_GATEWAY");
		json_add_pubkey(response, "gateway_key",
				&tx->from_gateway.gateway_key);
		json_add_signature(response, "signature",
				   &tx->normal.signature);
		json_add_outputs(response, state, tx);
		goto finish;
	case TX_TO_GATEWAY:
		json_add_string(response, "type", "TX_TO_GATEWAY");
		json_add_pubkey(response, "input_key",
				&tx->to_gateway.input_key);
		json_add_address(response, "output_addr",
				 state->test_net,
				 &tx->to_gateway.to_gateway_addr);
		json_add_num(response, "send_amount",
			     le32_to_cpu(tx->to_gateway.send_amount));
		json_add_num(response, "change_amount",
			     le32_to_cpu(tx->to_gateway.change_amount));
		json_add_signature(response, "signature",
				   &tx->to_gateway.signature);
		json_add_inputs(response, tx);
		goto finish;
	case TX_CLAIM:
		json_add_string(response, "type", "TX_CLAIM");
		json_add_pubkey(response, "input_key", &tx->claim.input_key);
		json_add_num(response, "amount", le32_to_cpu(tx->claim.amount));
		json_add_signature(response, "claim", &tx->claim.signature);
		json_add_input(response, "input", &tx->claim.input);
		goto finish;
	}
	abort();

finish:
	json_object_end(response);
}