Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f739337df122
Choose a base ref
...
head repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: caf75a8b8d4c
Choose a head ref
  • 5 commits
  • 10 files changed
  • 1 contributor

Commits on Aug 8, 2014

  1. json_add_tx: separate JSON printing of a TX into its own file.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 8, 2014
    Copy the full SHA
    97d1853 View commit details
  2. gettransaction: new JSON command.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 8, 2014
    Copy the full SHA
    2df86f2 View commit details
  3. getinfo, dev-listtodo: beef up output.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 8, 2014
    Copy the full SHA
    4cb6d34 View commit details
  4. Fix case where we get stuck in sync.

    Chasing bug #22, but this just reveals more problems.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 8, 2014
    Copy the full SHA
    9fff8cc View commit details
  5. protocol: fix horizon time.

    It was out by a factor of 10; I wondered why it was 120 hours on
    the test network.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 8, 2014
    Copy the full SHA
    caf75a8 View commit details
Showing with 253 additions and 127 deletions.
  1. +1 −1 Makefile.in
  2. +15 −4 getinfo.c
  3. +64 −0 gettransaction.c
  4. +114 −0 json_add_tx.c
  5. +14 −0 json_add_tx.h
  6. +1 −1 jsonrpc.c
  7. +1 −0 jsonrpc.h
  8. +7 −116 listtransactions.c
  9. +1 −1 protocol.h
  10. +35 −4 todo.c
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
# blackbox-check: run the blackbox tests
# update-mocks: regenerate the mocks for the unit tests.

PETTYCOIN_OBJS := block.o check_block.o check_tx.o difficulty.o shadouble.o timestamp.o gateways.o hash_tx.o pettycoin.o merkle_txs.o merkle_recurse.o tx_cmp.o genesis.o marshal.o hash_block.o prev_txhashes.o state.o tal_packet.o dns.o netaddr.o peer.o peer_cache.o pseudorand.o welcome.o log.o generating.o blockfile.o pending.o log_helper.o txhash.o signature.o proof.o chain.o features.o todo.o base58.o sync.o create_refs.o shard.o packet_io.o tx.o complain.o block_shard.o recv_block.o input_refs.o peer_wants.o inputhash.o tx_in_hashes.o merkle_hashes.o recv_tx.o reward.o recv_complain.o json.o jsonrpc.o getinfo.o ecode_names.o sendrawtransaction.c pettycoin_dir.o pkt_names.o hex.o listtransactions.o
PETTYCOIN_OBJS := block.o check_block.o check_tx.o difficulty.o shadouble.o timestamp.o gateways.o hash_tx.o pettycoin.o merkle_txs.o merkle_recurse.o tx_cmp.o genesis.o marshal.o hash_block.o prev_txhashes.o state.o tal_packet.o dns.o netaddr.o peer.o peer_cache.o pseudorand.o welcome.o log.o generating.o blockfile.o pending.o log_helper.o txhash.o signature.o proof.o chain.o features.o todo.o base58.o sync.o create_refs.o shard.o packet_io.o tx.o complain.o block_shard.o recv_block.o input_refs.o peer_wants.o inputhash.o tx_in_hashes.o merkle_hashes.o recv_tx.o reward.o recv_complain.o json.o jsonrpc.o getinfo.o ecode_names.o sendrawtransaction.c pettycoin_dir.o pkt_names.o hex.o listtransactions.o json_add_tx.o gettransaction.o
PETTYCOIN_GENERATE_OBJS := pettycoin-generate.o merkle_hashes.o merkle_recurse.o hash_tx.o tx_cmp.o shadouble.o marshal.o minimal_log.o timestamp.o tal_packet.o hex.o
MKGENESIS_OBJS := mkgenesis.o shadouble.o hash_block.o merkle_hashes.o merkle_recurse.o minimal_log.o
SIZES_OBJS := sizes.o
19 changes: 15 additions & 4 deletions getinfo.c
Original file line number Diff line number Diff line change
@@ -17,8 +17,9 @@ static char *json_getinfo(struct json_connection *jcon,
const jsmntok_t *params,
char **response)
{
size_t i;
size_t i, num_todo, num_peer_todo, num_peers;
struct todo_request *todo;
struct peer *peer;

json_object_start(response, NULL);
if (jcon->state->test_net)
@@ -36,10 +37,20 @@ static char *json_getinfo(struct json_connection *jcon,
json_add_block(response, "preferred_chain",
jcon->state->preferred_chain);

i = 0;
num_todo = 0;
list_for_each(&jcon->state->todo, todo, list)
i++;
json_add_num(response, "num_todos", i);
num_todo++;
json_add_num(response, "num_todos", num_todo);

num_peers = num_peer_todo = 0;
list_for_each(&jcon->state->peers, peer, list) {
struct todo_pkt *todo_pkt;
num_peers++;
list_for_each(&peer->todo, todo_pkt, list)
num_peer_todo++;
}
json_add_num(response, "connections", num_peers);
json_add_num(response, "num_peer_todos", num_peer_todo);

json_add_num(response, "num_pending",
num_pending_known(jcon->state)
64 changes: 64 additions & 0 deletions gettransaction.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "block.h"
#include "chain.h"
#include "hex.h"
#include "json_add_tx.h"
#include "jsonrpc.h"
#include "txhash.h"
#include "state.h"
#include <ccan/tal/str/str.h>

static char *json_gettransaction(struct json_connection *jcon,
const jsmntok_t *params,
char **response)
{
struct protocol_double_sha txhash;
const jsmntok_t *txid;
unsigned int confirms;
struct txhash_elem *te;
struct txhash_iter i;
const union protocol_tx *tx;
const struct block *block;

json_get_params(jcon->buffer, params, "txid", &txid, NULL);
if (!txid)
return "Needs 'txid'";

if (!from_hex(jcon->buffer + txid->start, txid->end - txid->start,
&txhash, sizeof(txhash))) {
return tal_fmt(jcon, "txid %.*s not valid",
json_tok_len(txid),
json_tok_contents(jcon->buffer, txid));
}

te = txhash_firstval(&jcon->state->txhash, &txhash, &i);
if (!te)
return tal_fmt(jcon, "Unknown tx %.*s",
json_tok_len(txid),
json_tok_contents(jcon->buffer, txid));

if (te->status == TX_PENDING) {
confirms = 0;
tx = te->u.tx;
block = NULL;
} else {
tx = block_get_tx(te->u.block, te->shardnum, te->txoff);
block = te->u.block;

if (!block_preceeds(block, jcon->state->preferred_chain)) {
/* FIXME: Report conflicts! */
confirms = 0;
} else {
confirms = le32_to_cpu(jcon->state->preferred_chain->hdr->height)
- le32_to_cpu(block->hdr->height);
}
}

json_add_tx(response, NULL, jcon->state, tx, block, confirms);
return NULL;
}

const struct json_command gettransaction_command = {
"gettransaction", json_gettransaction,
"Dump a transaction",
"Takes <txid>"
};
114 changes: 114 additions & 0 deletions json_add_tx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "block.h"
#include "hash_tx.h"
#include "json.h"
#include "json_add_tx.h"
#include "state.h"
#include "tx.h"

static void json_add_input(char **response, const char *fieldname,
const struct protocol_input *inp)
{
json_object_start(response, fieldname);
json_add_double_sha(response, "input", &inp->input);
json_add_num(response, "output", le16_to_cpu(inp->output));
json_object_end(response);
}

static void json_add_inputs(char **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);
}

static void json_add_outputs(char **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);
}

void json_add_tx(char **response, const char *fieldname,
struct state *state,
const union protocol_tx *tx,
const struct block *block,
unsigned int confirms)
{
struct protocol_double_sha sha;

json_object_start(response, fieldname);
hash_tx(tx, &sha);
json_add_double_sha(response, "txid", &sha);
if (block)
json_add_double_sha(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);
}

14 changes: 14 additions & 0 deletions json_add_tx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef PETTYCOIN_JSON_ADD_TX_H
#define PETTYCOIN_JSON_ADD_TX_H

struct state;
union protocol_tx;
struct block;

void json_add_tx(char **response, const char *fieldname,
struct state *state,
const union protocol_tx *tx,
const struct block *block,
unsigned int confirms);

#endif /* PETTYCOIN_JSON_ADD_TX_H */
2 changes: 1 addition & 1 deletion jsonrpc.c
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ static const struct json_command stop_command = {
static const struct json_command *cmdlist[] = {
&help_command, &getinfo_command, &sendrawtransaction_command,
&stop_command, &listtransactions_command, &getblock_command,
&getblockhash_command, &submitblock_command,
&getblockhash_command, &submitblock_command, &gettransaction_command,
/* Developer/debugging options. */
&echo_command, &listtodo_command
};
1 change: 1 addition & 0 deletions jsonrpc.h
Original file line number Diff line number Diff line change
@@ -50,5 +50,6 @@ extern const struct json_command listtransactions_command;
extern const struct json_command getblock_command;
extern const struct json_command getblockhash_command;
extern const struct json_command submitblock_command;
extern const struct json_command gettransaction_command;

#endif /* PETTYCOIN_JSONRPC_H */
Loading