bool extract(payment_address& address, const script_type& script)
		{
			// Cast a data_chunk to a short_hash and set the address
			auto set_hash_data =
				[&address](uint8_t version, const data_chunk& raw_hash)
			{
				short_hash hash_data;
				BITCOIN_ASSERT(raw_hash.size() == hash_data.size());
				std::copy(raw_hash.begin(), raw_hash.end(), hash_data.begin());
				address.set(version, hash_data);
			};
			const operation_stack& ops = script.operations();
			payment_type pay_type = script.type();
			switch (pay_type)
			{
			case payment_type::pubkey:
				BITCOIN_ASSERT(ops.size() == 2);
				set_public_key(address, ops[0].data);
				return true;

			case payment_type::pubkey_hash:
				BITCOIN_ASSERT(ops.size() == 5);
				set_hash_data(payment_address::pubkey_version, ops[2].data);
				return true;

			case payment_type::script_hash:
				BITCOIN_ASSERT(ops.size() == 3);
				set_hash_data(payment_address::script_version, ops[1].data);
				return true;

			case payment_type::multisig:
				// Unimplemented...
				return false;

			case payment_type::pubkey_hash_sig:
				BITCOIN_ASSERT(ops.size() == 2);
				set_public_key(address, ops[1].data);
				return true;

			case payment_type::script_code_sig:
				// Should have at least 1 sig and the script code.
				BITCOIN_ASSERT(ops.size() > 1);
				set_script_hash(address,
					bitcoin_short_hash(ops.back().data));
				return true;

			default:
				return false;
			}
			// Should never happen!
			return false;
		}
		void set_public_key(payment_address& address, const data_chunk& public_key)
		{
			address.set(payment_address::pubkey_version,
				bitcoin_short_hash(public_key));
		}
		void set_script(payment_address& address, const script_type& eval_script)
		{
			address.set(payment_address::script_version,
				bitcoin_short_hash(save_script(eval_script)));
		}
示例#4
0
BCW_API uint32_t hd_public_key::fingerprint() const
{
    short_hash md = bitcoin_short_hash(K_);
    return from_little_endian<uint32_t>(md.begin());
}