bool script::op_hash160() { if (stack_.size() < 1) return false; data_chunk data = pop_stack(); short_hash hash = generate_ripemd_hash(data); data_chunk raw_hash(hash.begin(), hash.end()); stack_.push_back(raw_hash); return true; }
bool extract(payment_address& address, const script& scr) { // Cast a data_chunk to a short_hash and set the address auto set_hash_data = [&address](payment_type pay_type, 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(pay_type, hash_data); }; const operation_stack& ops = scr.operations(); payment_type pay_type = scr.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(pay_type, ops[2].data); return true; case payment_type::script_hash: BITCOIN_ASSERT(ops.size() == 3); set_hash_data(pay_type, 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, generate_ripemd_hash(ops.back().data)); return true; default: return false; } // Should never happen! return false; }
bool set_script(payment_address& address, const script& eval_script) { return address.set(payment_type::script_hash, generate_ripemd_hash(save_script(eval_script))); }
bool set_public_key(payment_address& address, const data_chunk& public_key) { return address.set(payment_type::pubkey_hash, generate_ripemd_hash(public_key)); }