* Sign scriptPubKey using signature made with creator. * Signatures are returned in scriptSigRet (or returns false if scriptPubKey can't be signed), * unless whichTypeRet is TX_SCRIPTHASH, in which case scriptSigRet is the redemption script. * Returns false if scriptPubKey could not be completely satisfied. */
| 66 | * Returns false if scriptPubKey could not be completely satisfied. |
| 67 | */ |
| 68 | static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptPubKey, |
| 69 | std::vector<valtype>& ret, txnouttype& whichTypeRet, SigVersion sigversion) |
| 70 | { |
| 71 | CScript scriptRet; |
| 72 | uint160 h160; |
| 73 | ret.clear(); |
| 74 | |
| 75 | vector<valtype> vSolutions; |
| 76 | if (!Solver(scriptPubKey, whichTypeRet, vSolutions)) |
| 77 | return false; |
| 78 | |
| 79 | CKeyID keyID; |
| 80 | switch (whichTypeRet) |
| 81 | { |
| 82 | case TX_NONSTANDARD: |
| 83 | case TX_NULL_DATA: |
| 84 | case TX_WITNESS_UNKNOWN: |
| 85 | return false; |
| 86 | case TX_PUBKEY: |
| 87 | keyID = CPubKey(vSolutions[0]).GetID(); |
| 88 | return Sign1(keyID, creator, scriptPubKey, ret, sigversion); |
| 89 | case TX_PUBKEYHASH: |
| 90 | keyID = CKeyID(uint160(vSolutions[0])); |
| 91 | if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion)) |
| 92 | return false; |
| 93 | else |
| 94 | { |
| 95 | CPubKey vch; |
| 96 | creator.KeyStore().GetPubKey(keyID, vch); |
| 97 | ret.push_back(ToByteVector(vch)); |
| 98 | } |
| 99 | return true; |
| 100 | case TX_SCRIPTHASH: |
| 101 | if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) { |
| 102 | ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end())); |
| 103 | return true; |
| 104 | } |
| 105 | return false; |
| 106 | |
| 107 | case TX_MULTISIG: |
| 108 | ret.push_back(valtype()); // workaround CHECKMULTISIG bug |
| 109 | return (SignN(vSolutions, creator, scriptPubKey, ret, sigversion)); |
| 110 | |
| 111 | case TX_WITNESS_V0_KEYHASH: |
| 112 | ret.push_back(vSolutions[0]); |
| 113 | return true; |
| 114 | |
| 115 | case TX_WITNESS_V0_SCRIPTHASH: |
| 116 | CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin()); |
| 117 | if (creator.KeyStore().GetCScript(h160, scriptRet)) { |
| 118 | ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end())); |
| 119 | return true; |
| 120 | } |
| 121 | return false; |
| 122 | |
| 123 | default: |
| 124 | return false; |
| 125 | } |
no test coverage detected