コード例 #1
0
ファイル: tx.c プロジェクト: throckmortonsign/lightning
static void pull_input(const tal_t *ctx, const u8 **cursor, size_t *max,
		       struct bitcoin_tx_input *input)
{
	pull_sha256_double(cursor, max, &input->txid);
	input->index = pull_le32(cursor, max);
	input->script_length = pull_length(cursor, max);
	input->script = tal_arr(ctx, u8, input->script_length);
	pull(cursor, max, input->script, input->script_length);
	input->sequence_number = pull_le32(cursor, max);
}
コード例 #2
0
ファイル: netaddr.c プロジェクト: braydonf/lightning
bool netaddr_from_blob(const void *linear, size_t len, struct netaddr *a)
{
	const u8 *p = linear;

	a->type = pull_le32(&p, &len);
	a->protocol = pull_le32(&p, &len);
	a->addrlen = pull_le32(&p, &len);
	if (a->addrlen > sizeof(a->saddr))
		return false;
	pull(&p, &len, &a->saddr, a->addrlen);
	return p != NULL && len == 0;
}
コード例 #3
0
ファイル: tx.c プロジェクト: throckmortonsign/lightning
struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx,
				   const u8 **cursor, size_t *max)
{
	struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
	size_t i;
	u8 flag = 0;

	tx->version = pull_le32(cursor, max);
	tx->input_count = pull_length(cursor, max);
	/* BIP 144 marker is 0 (impossible to have tx with 0 inputs) */
	if (tx->input_count == 0) {
		pull(cursor, max, &flag, 1);
		if (flag != SEGREGATED_WITNESS_FLAG)
			return tal_free(tx);
		tx->input_count = pull_length(cursor, max);
	}

	tx->input = tal_arr(tx, struct bitcoin_tx_input, tx->input_count);
	for (i = 0; i < tx->input_count; i++)
		pull_input(tx, cursor, max, tx->input + i);

	tx->output_count = pull_length(cursor, max);
	tx->output = tal_arr(tx, struct bitcoin_tx_output, tx->output_count);
	for (i = 0; i < tx->output_count; i++)
		pull_output(tx, cursor, max, tx->output + i);

	if (flag & SEGREGATED_WITNESS_FLAG) {
		for (i = 0; i < tx->input_count; i++)
			pull_witness(tx->input, i, cursor, max);
	} else {
		for (i = 0; i < tx->input_count; i++)
			tx->input[i].witness = NULL;
	}
	tx->lock_time = pull_le32(cursor, max);

	/* If we ran short, fail. */
	if (!*cursor)
		tx = tal_free(tx);
	return tx;
}