Пример #1
0
bool blkdb_init(struct blkdb *db, const unsigned char *netmagic,
		const bu256_t *genesis_block)
{
	memset(db, 0, sizeof(*db));

	db->fd = -1;

	bu256_copy(&db->block0, genesis_block);

	memcpy(db->netmagic, netmagic, sizeof(db->netmagic));
	db->blocks = bp_hashtab_new_ext(bu256_hash, bu256_equal_,
					NULL, (bp_freefunc) bi_free);

	return true;
}
Пример #2
0
int main (int argc, char *argv[])
{
	LOG_INIT(LOG_ALL);
	LOG_GMT_ZONE;

	LOG_BEGIN;

	settings = bp_hashtab_new_ext(czstr_hash, czstr_equal,
				      free, free);

	if (!preload_settings()){
		LOG_END_RC(1);
		//return 1;
	}
	chain_set();
	LOG("chain-set");
	RAND_bytes((unsigned char *)&instance_nonce, sizeof(instance_nonce));

	unsigned int arg;
	for (arg = 1; arg < argc; arg++) {
		const char *argstr = argv[arg];
		if (!do_setting(argstr)){
			LOG_END_RC(1);
			//return 1;
		}
	}
	LOG("arguments processed");

	/*
	 * properly capture TERM and other signals
	 */
	signal(SIGHUP, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGINT, term_signal);
	signal(SIGTERM, term_signal);

	LOG("signals set");

	init_daemon(&global_nci);
	run_daemon(&global_nci);

	fprintf(plog, "daemon exiting\n");

	shutdown_daemon(&global_nci);
	LOG_END_RC(0);
	//return 0;
}
Пример #3
0
static void runtest(bool is_valid, const char *basefn)
{
	char *fn = test_filename(basefn);
	json_t *tests = read_json(fn);
	assert(json_is_array(tests));

	struct bp_hashtab *input_map = bp_hashtab_new_ext(
		input_hash, input_equal,
		free, input_value_free);

	comments = parr_new(8, free);

	unsigned int idx;
	for (idx = 0; idx < json_array_size(tests); idx++) {
		json_t *test = json_array_get(tests, idx);

		if (!json_is_array(json_array_get(test, 0))) {
			const char *cmt =
				json_string_value(json_array_get(test, 0));
			if (cmt)
				parr_add(comments, strdup(cmt));
			continue;			/* comments */
		}

		assert(json_is_array(test));
		assert(json_array_size(test) == 3);
		assert(json_is_string(json_array_get(test, 1)));
		assert(json_is_boolean(json_array_get(test, 2)));

		json_t *inputs = json_array_get(test, 0);
		assert(json_is_array(inputs));

		bp_hashtab_clear(input_map);

		unsigned int i;
		for (i = 0; i < json_array_size(inputs); i++) {
			json_t *input = json_array_get(inputs, i);
			assert(json_is_array(input));

			const char *prev_hashstr =
				json_string_value(json_array_get(input, 0));
			int prev_n =
				json_integer_value(json_array_get(input, 1));
			const char *prev_pubkey_enc =
				json_string_value(json_array_get(input, 2));

			assert(prev_hashstr != NULL);
			assert(json_is_integer(json_array_get(input, 1)));
			assert(prev_pubkey_enc != NULL);

			struct bp_outpt *outpt;
			outpt = malloc(sizeof(*outpt));
			hex_bu256(&outpt->hash, prev_hashstr);
			outpt->n = prev_n;

			cstring *script = parse_script_str(prev_pubkey_enc);
			assert(script != NULL);

			bp_hashtab_put(input_map, outpt, script);
		}

		const char *tx_hexser =
			json_string_value(json_array_get(test, 1));
		assert(tx_hexser != NULL);

		bool enforce_p2sh = json_is_true(json_array_get(test, 2));

		cstring *tx_ser = hex2str(tx_hexser);
		assert(tx_ser != NULL);

		test_tx_valid(is_valid, input_map, tx_ser, enforce_p2sh);

		cstr_free(tx_ser, true);

		if (comments->len > 0) {
			parr_free(comments, true);
			comments = parr_new(8, free);
		}
	}

	parr_free(comments, true);
	comments = NULL;

	bp_hashtab_unref(input_map);
	json_decref(tests);
	free(fn);
}
Пример #4
0
static void init_orphans(void)
{
	orphans = bp_hashtab_new_ext(bu256_hash, bu256_equal_,
				     (bp_freefunc) bu256_free, (bp_freefunc) buffer_free);
}