Exemplo n.º 1
0
static struct trace *add_trace(const struct trace *t)
{
	struct trace *trace = malloc(sizeof(*trace));
	*trace = *t;
	thash_add(&htable, trace);
	return trace;
}
Exemplo n.º 2
0
/* gateway-txs file contains the transactions we've already injected. */
static int read_gateway_txs(struct thash *thash)
{
	struct protocol_double_sha *sha;
	struct stat st;
	int fd, i, num;

	fd = open("gateway-txs", O_RDWR);
	if (fd < 0)
		err(1, "Opening gateway file");

	if (!get_lock(fd))
		err(1, "Locking gateway file");

	if (fstat(fd, &st) == -1)
		err(1, "Statting gateway file");

	if (st.st_size % sizeof(*sha))
		errx(1, "Gateway file invalid size %llu",
		     (long long)st.st_size);

	num = st.st_size / sizeof(*sha);
	sha = tal_arr(NULL, struct protocol_double_sha, num);

	if (read(fd, sha, st.st_size) != st.st_size)
		err(1, "Reading gateway file");

	for (i = 0; i < num; i++)
		thash_add(thash, sha + i);

	return fd;
}