Changeset View
Changeset View
Standalone View
Standalone View
src/script/sign.cpp
Show All 27 Lines | if (!keystore->GetKey(address, key)) { | ||||
return false; | return false; | ||||
} | } | ||||
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount); | uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount); | ||||
if (!key.Sign(hash, vchSig)) { | if (!key.Sign(hash, vchSig)) { | ||||
return false; | return false; | ||||
} | } | ||||
vchSig.push_back((unsigned char)nHashType); | vchSig.push_back(uint8_t(nHashType)); | ||||
return true; | return true; | ||||
} | } | ||||
static bool Sign1(const CKeyID &address, const BaseSignatureCreator &creator, | static bool Sign1(const CKeyID &address, const BaseSignatureCreator &creator, | ||||
const CScript &scriptCode, std::vector<valtype> &ret) { | const CScript &scriptCode, std::vector<valtype> &ret) { | ||||
std::vector<unsigned char> vchSig; | std::vector<unsigned char> vchSig; | ||||
if (!creator.CreateSig(vchSig, address, scriptCode)) { | if (!creator.CreateSig(vchSig, address, scriptCode)) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | if (solved && whichType == TX_SCRIPTHASH) { | ||||
whichType != TX_SCRIPTHASH; | whichType != TX_SCRIPTHASH; | ||||
result.push_back( | result.push_back( | ||||
std::vector<unsigned char>(subscript.begin(), subscript.end())); | std::vector<unsigned char>(subscript.begin(), subscript.end())); | ||||
} | } | ||||
sigdata.scriptSig = PushAll(result); | sigdata.scriptSig = PushAll(result); | ||||
// Test solution | // Test solution | ||||
return solved && VerifyScript(sigdata.scriptSig, fromPubKey, | // Because we have no good way to get nHashType here, we just try with and | ||||
// without enabling it. One of the two must pass. | |||||
// TODO: Remove after the fork. | |||||
return solved && | |||||
(VerifyScript(sigdata.scriptSig, fromPubKey, | |||||
STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker()) || | |||||
VerifyScript(sigdata.scriptSig, fromPubKey, | |||||
STANDARD_SCRIPT_VERIFY_FLAGS | | STANDARD_SCRIPT_VERIFY_FLAGS | | ||||
SCRIPT_ENABLE_SIGHASH_FORKID, | SCRIPT_ENABLE_SIGHASH_FORKID, | ||||
creator.Checker()); | creator.Checker())); | ||||
} | } | ||||
SignatureData DataFromTransaction(const CMutableTransaction &tx, | SignatureData DataFromTransaction(const CMutableTransaction &tx, | ||||
unsigned int nIn) { | unsigned int nIn) { | ||||
SignatureData data; | SignatureData data; | ||||
assert(tx.vin.size() > nIn); | assert(tx.vin.size() > nIn); | ||||
data.scriptSig = tx.vin[nIn].scriptSig; | data.scriptSig = tx.vin[nIn].scriptSig; | ||||
return data; | return data; | ||||
Show All 34 Lines | |||||
static std::vector<valtype> CombineMultisig( | static std::vector<valtype> CombineMultisig( | ||||
const CScript &scriptPubKey, const BaseSignatureChecker &checker, | const CScript &scriptPubKey, const BaseSignatureChecker &checker, | ||||
const std::vector<valtype> &vSolutions, const std::vector<valtype> &sigs1, | const std::vector<valtype> &vSolutions, const std::vector<valtype> &sigs1, | ||||
const std::vector<valtype> &sigs2) { | const std::vector<valtype> &sigs2) { | ||||
// Combine all the signatures we've got: | // Combine all the signatures we've got: | ||||
std::set<valtype> allsigs; | std::set<valtype> allsigs; | ||||
for (const valtype &v : sigs1) { | for (const valtype &v : sigs1) { | ||||
if (!v.empty()) allsigs.insert(v); | if (!v.empty()) { | ||||
allsigs.insert(v); | |||||
} | |||||
} | } | ||||
for (const valtype &v : sigs2) { | for (const valtype &v : sigs2) { | ||||
if (!v.empty()) allsigs.insert(v); | if (!v.empty()) { | ||||
allsigs.insert(v); | |||||
} | |||||
} | } | ||||
// Build a map of pubkey -> signature by matching sigs to pubkeys: | // Build a map of pubkey -> signature by matching sigs to pubkeys: | ||||
assert(vSolutions.size() > 1); | assert(vSolutions.size() > 1); | ||||
unsigned int nSigsRequired = vSolutions.front()[0]; | unsigned int nSigsRequired = vSolutions.front()[0]; | ||||
unsigned int nPubKeys = vSolutions.size() - 2; | unsigned int nPubKeys = vSolutions.size() - 2; | ||||
std::map<valtype, valtype> sigs; | std::map<valtype, valtype> sigs; | ||||
for (const valtype &sig : allsigs) { | for (const valtype &sig : allsigs) { | ||||
for (unsigned int i = 0; i < nPubKeys; i++) { | for (unsigned int i = 0; i < nPubKeys; i++) { | ||||
const valtype &pubkey = vSolutions[i + 1]; | const valtype &pubkey = vSolutions[i + 1]; | ||||
// Already got a sig for this pubkey | // Already got a sig for this pubkey | ||||
if (sigs.count(pubkey)) { | if (sigs.count(pubkey)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (checker.CheckSig(sig, pubkey, scriptPubKey, | // If the transaction is using SIGHASH_FORKID, we ned to set the | ||||
SCRIPT_ENABLE_SIGHASH_FORKID)) { | // apropriate flags. | ||||
// TODO: Remove after the Hard Fork. | |||||
uint32_t flags = STANDARD_SCRIPT_VERIFY_FLAGS; | |||||
if (sig.back() & SIGHASH_FORKID) { | |||||
flags |= SCRIPT_ENABLE_SIGHASH_FORKID; | |||||
} | |||||
if (checker.CheckSig(sig, pubkey, scriptPubKey, flags)) { | |||||
sigs[pubkey] = sig; | sigs[pubkey] = sig; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Now build a merged CScript: | // Now build a merged CScript: | ||||
unsigned int nSigsHave = 0; | unsigned int nSigsHave = 0; | ||||
// pop-one-too-many workaround | // pop-one-too-many workaround | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |