Changeset View
Changeset View
Standalone View
Standalone View
src/script/descriptor.cpp
Show First 20 Lines • Show All 1,170 Lines • ▼ Show 20 Lines | std::unique_ptr<PubkeyProvider> InferPubkey(const CPubKey &pubkey, | ||||
} | } | ||||
return key_provider; | return key_provider; | ||||
} | } | ||||
std::unique_ptr<DescriptorImpl> InferScript(const CScript &script, | std::unique_ptr<DescriptorImpl> InferScript(const CScript &script, | ||||
ParseScriptContext ctx, | ParseScriptContext ctx, | ||||
const SigningProvider &provider) { | const SigningProvider &provider) { | ||||
std::vector<std::vector<uint8_t>> data; | std::vector<std::vector<uint8_t>> data; | ||||
txnouttype txntype = Solver(script, data); | TxoutType txntype = Solver(script, data); | ||||
if (txntype == TX_PUBKEY) { | if (txntype == TxoutType::PUBKEY) { | ||||
CPubKey pubkey(data[0].begin(), data[0].end()); | CPubKey pubkey(data[0].begin(), data[0].end()); | ||||
if (pubkey.IsValid()) { | if (pubkey.IsValid()) { | ||||
return std::make_unique<PKDescriptor>( | return std::make_unique<PKDescriptor>( | ||||
InferPubkey(pubkey, ctx, provider)); | InferPubkey(pubkey, ctx, provider)); | ||||
} | } | ||||
} | } | ||||
if (txntype == TX_PUBKEYHASH) { | if (txntype == TxoutType::PUBKEYHASH) { | ||||
uint160 hash(data[0]); | uint160 hash(data[0]); | ||||
CKeyID keyid(hash); | CKeyID keyid(hash); | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (provider.GetPubKey(keyid, pubkey)) { | if (provider.GetPubKey(keyid, pubkey)) { | ||||
return std::make_unique<PKHDescriptor>( | return std::make_unique<PKHDescriptor>( | ||||
InferPubkey(pubkey, ctx, provider)); | InferPubkey(pubkey, ctx, provider)); | ||||
} | } | ||||
} | } | ||||
if (txntype == TX_MULTISIG) { | if (txntype == TxoutType::MULTISIG) { | ||||
std::vector<std::unique_ptr<PubkeyProvider>> providers; | std::vector<std::unique_ptr<PubkeyProvider>> providers; | ||||
for (size_t i = 1; i + 1 < data.size(); ++i) { | for (size_t i = 1; i + 1 < data.size(); ++i) { | ||||
CPubKey pubkey(data[i].begin(), data[i].end()); | CPubKey pubkey(data[i].begin(), data[i].end()); | ||||
providers.push_back(InferPubkey(pubkey, ctx, provider)); | providers.push_back(InferPubkey(pubkey, ctx, provider)); | ||||
} | } | ||||
return std::make_unique<MultisigDescriptor>((int)data[0][0], | return std::make_unique<MultisigDescriptor>((int)data[0][0], | ||||
std::move(providers)); | std::move(providers)); | ||||
} | } | ||||
if (txntype == TX_SCRIPTHASH && ctx == ParseScriptContext::TOP) { | if (txntype == TxoutType::SCRIPTHASH && ctx == ParseScriptContext::TOP) { | ||||
uint160 hash(data[0]); | uint160 hash(data[0]); | ||||
CScriptID scriptid(hash); | CScriptID scriptid(hash); | ||||
CScript subscript; | CScript subscript; | ||||
if (provider.GetCScript(scriptid, subscript)) { | if (provider.GetCScript(scriptid, subscript)) { | ||||
auto sub = | auto sub = | ||||
InferScript(subscript, ParseScriptContext::P2SH, provider); | InferScript(subscript, ParseScriptContext::P2SH, provider); | ||||
if (sub) { | if (sub) { | ||||
return std::make_unique<SHDescriptor>(std::move(sub)); | return std::make_unique<SHDescriptor>(std::move(sub)); | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |