| 95 | } |
| 96 | |
| 97 | static struct chain_event **chain_events(const tal_t *ctx, |
| 98 | const struct bkpr *bkpr, |
| 99 | const char *buf, |
| 100 | const jsmntok_t *result) |
| 101 | { |
| 102 | struct chain_event **evs; |
| 103 | size_t i; |
| 104 | const jsmntok_t *row, *rows = json_get_member(buf, result, "rows"); |
| 105 | |
| 106 | evs = tal_arr(ctx, struct chain_event *, rows->size); |
| 107 | json_for_each_arr(i, row, rows) { |
| 108 | bool ok = true; |
| 109 | struct chain_event *ev = tal(evs, struct chain_event); |
| 110 | int flag; |
| 111 | |
| 112 | const jsmntok_t *val = row + 1; |
| 113 | assert(row->size == 14); |
| 114 | ok &= json_to_u64(buf, val, &ev->db_id); |
| 115 | val = json_next(val); |
| 116 | ev->acct_name = json_strdup(ev, buf, val); |
| 117 | val = json_next(val); |
| 118 | if (json_tok_is_null(buf, val)) |
| 119 | ev->origin_acct = NULL; |
| 120 | else |
| 121 | ev->origin_acct = json_strdup(ev, buf, val); |
| 122 | val = json_next(val); |
| 123 | ev->tag = json_strdup(ev, buf, val); |
| 124 | val = json_next(val); |
| 125 | ok &= json_to_msat(buf, val, &ev->credit); |
| 126 | val = json_next(val); |
| 127 | ok &= json_to_msat(buf, val, &ev->debit); |
| 128 | val = json_next(val); |
| 129 | ok &= json_to_msat(buf, val, &ev->output_value); |
| 130 | val = json_next(val); |
| 131 | ok &= json_to_u64(buf, val, &ev->timestamp); |
| 132 | val = json_next(val); |
| 133 | ok &= json_to_u32(buf, val, &ev->blockheight); |
| 134 | val = json_next(val); |
| 135 | ok &= json_to_outpoint(buf, val, &ev->outpoint); |
| 136 | /* We may know better! */ |
| 137 | if (ev->blockheight == 0) |
| 138 | ev->blockheight = find_blockheight(bkpr, &ev->outpoint.txid); |
| 139 | val = json_next(val); |
| 140 | if (json_tok_is_null(buf, val)) |
| 141 | ev->spending_txid = NULL; |
| 142 | else { |
| 143 | ev->spending_txid = tal(ev, struct bitcoin_txid); |
| 144 | ok &= json_to_txid(buf, val, ev->spending_txid); |
| 145 | } |
| 146 | val = json_next(val); |
| 147 | if (json_tok_is_null(buf, val)) |
| 148 | ev->payment_id = NULL; |
| 149 | else { |
| 150 | ev->payment_id = tal(ev, struct sha256); |
| 151 | ok &= json_to_sha256(buf, val, ev->payment_id); |
| 152 | } |
| 153 | val = json_next(val); |
| 154 | /* These are 0/1 not true/false */ |
no test coverage detected