Пример #1
0
GPtrArray *bp_block_match(const struct bp_block *block,
			  const struct bp_keyset *ks)
{
	if (!block || !block->vtx || !ks)
		return NULL;

	GPtrArray *arr = g_ptr_array_new_full(block->vtx->len,
				(GDestroyNotify) bbm_free);
	if (!arr)
		return NULL;

	BIGNUM tmp_mask;
	BN_init(&tmp_mask);

	unsigned int n;
	for (n = 0; n < block->vtx->len; n++) {
		struct bp_tx *tx;

		tx = g_ptr_array_index(block->vtx, n);
		if (!bp_tx_match_mask(&tmp_mask, tx, ks))
			goto err_out;

		if (!BN_is_zero(&tmp_mask)) {
			struct bp_block_match *match;

			match = bbm_new();
			match->n = n;
			BN_copy(&match->mask, &tmp_mask);

			g_ptr_array_add(arr, match);
		}
	}

	BN_clear_free(&tmp_mask);
	return arr;

err_out:
	BN_clear_free(&tmp_mask);
	g_ptr_array_free(arr, TRUE);
	return NULL;
}
Пример #2
0
parr *bp_block_match(const struct bp_block *block,
			  const struct bp_keyset *ks)
{
	if (!block || !block->vtx || !ks)
		return NULL;

	parr *arr = parr_new(block->vtx->len, bbm_free);
	if (!arr)
		return NULL;

	BIGNUM tmp_mask;
	BN_init(&tmp_mask);

	unsigned int n;
	for (n = 0; n < block->vtx->len; n++) {
		struct bp_tx *tx;

		tx = parr_idx(block->vtx, n);
		if (!bp_tx_match_mask(&tmp_mask, tx, ks))
			goto err_out;

		if (!BN_is_zero(&tmp_mask)) {
			struct bp_block_match *match;

			match = bbm_new();
			match->n = n;
			BN_copy(&match->mask, &tmp_mask);

			parr_add(arr, match);
		}
	}

	BN_clear_free(&tmp_mask);
	return arr;

err_out:
	BN_clear_free(&tmp_mask);
	parr_free(arr, true);
	return NULL;
}