bool bp_txout_match(const struct bp_txout *txout, const struct bp_keyset *ks) { if (!txout || !txout->scriptPubKey || !ks) return false; bool rc = false; struct bscript_addr addrs; if (!bsp_addr_parse(&addrs, txout->scriptPubKey->str, txout->scriptPubKey->len)) return false; struct const_buffer *buf; clist *tmp = addrs.pub; while (tmp) { buf = tmp->data; tmp = tmp->next; if (bpks_lookup(ks, buf->p, buf->len, false)) { rc = true; goto out; } } tmp = addrs.pubhash; while (tmp) { buf = tmp->data; tmp = tmp->next; if (bpks_lookup(ks, buf->p, buf->len, true)) { rc = true; goto out; } } out: clist_free_ext(addrs.pub, buffer_free); clist_free_ext(addrs.pubhash, buffer_free); return rc; }
static void test_shuffle(void) { clist *l = NULL; l = clist_append(l, strdup("one")); l = clist_append(l, strdup("two")); l = clist_append(l, strdup("three")); clist_shuffle(l); // TODO: improve test clist_free_ext(l, free); }
void peerman_free(struct peer_manager *peers) { if (!peers) return; bp_hashtab_unref(peers->map_addr); clist_free_ext(peers->addrlist, peer_ent_free); memset(peers, 0, sizeof(*peers)); free(peers); }
static void test_txout(const struct bitc_txout *txout) { struct const_buffer buf = { txout->scriptPubKey->str, txout->scriptPubKey->len }; struct bscript_parser bsp; struct bscript_op op; clist *ops = NULL; /* * parse script */ bsp_start(&bsp, &buf); while (bsp_getop(&op, &bsp)) { struct bscript_op *op_p; op_p = memdup(&op, sizeof(op)); ops = clist_append(ops, op_p); } assert(!bsp.error); /* * build script */ clist *tmp = ops; cstring *s = cstr_new_sz(256); while (tmp) { struct bscript_op *op_p; op_p = tmp->data; tmp = tmp->next; if (is_bsp_pushdata(op_p->op)) { bsp_push_data(s, op_p->data.p, op_p->data.len); } else { bsp_push_op(s, op_p->op); } } clist_free_ext(ops, free); /* byte-compare original and newly created scripts */ assert(cstr_equal(s, txout->scriptPubKey)); cstr_free(s, true); }