Esempio n. 1
0
/* We do the same hex-reversing crud as txids. */
bool bitcoin_blkid_from_hex(const char *hexstr, size_t hexstr_len,
			    struct bitcoin_blkid *blockid)
{
	struct bitcoin_txid fake_txid;
	if (!bitcoin_txid_from_hex(hexstr, hexstr_len, &fake_txid))
		return false;
	blockid->shad = fake_txid.shad;
	return true;
}
Esempio n. 2
0
static void parse_anchor_input(const char *spec, struct input *in)
{
	const char *slash;
	char *end;
	long l;
	bool testnet;

	slash = strchr(spec, '/');
	if (!slash)
		errx(1, "Expected / in <txid>/<num>/<satoshis>/<hexscript>/<privkey>");

	if (!bitcoin_txid_from_hex(spec, slash - spec, &in->in.txid))
		errx(1, "Expected 256-bit hex txid before /");

	in->in.index = l = strtol(slash + 1, &end, 10);
	if (end == slash + 1 || *end != '/' || (int64_t)in->in.index != (int64_t)l)
		errx(1, "Expected <outputnum> after /");

	slash = end;
	in->in.input_amount = l = strtol(slash + 1, &end, 10);
	if (end == slash + 1 || *end != '/' || (int64_t)in->in.input_amount != (int64_t)l)
		errx(1, "Expected <satoshis> after second /");

	slash = end;
	end = (char *)slash + 1 + strcspn(slash + 1, "/");
	in->in.script_length = hex_data_size(end - (slash + 1));
	in->in.script = tal_arr(in, u8, in->in.script_length);
	if (!hex_decode(slash + 1, end - (slash + 1),
			in->in.script, in->in.script_length))
		errx(1, "Expected hex string after third /");

	if (*end != '/')
		errx(1, "Expected / after hexscript");

	if (!key_from_base58(end+1, strlen(end + 1), &testnet,
			     &in->privkey, &in->pubkey))
		errx(1, "Invalid private key '%s'", end+1);
	if (!testnet)
		errx(1, "Private key '%s' not on testnet!", end+1);
}