mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Remove segwit related code
This commit is contained in:
parent
21eca6481f
commit
16bd20e57c
@ -1156,62 +1156,6 @@ PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo)
|
||||
|
||||
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
|
||||
{
|
||||
if (sigversion == SIGVERSION_WITNESS_V0) {
|
||||
uint256 hashPrevouts;
|
||||
uint256 hashSequence;
|
||||
uint256 hashOutputs;
|
||||
|
||||
if (!(nHashType & SIGHASH_ANYONECANPAY)) {
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
for (unsigned int n = 0; n < txTo.vin.size(); n++) {
|
||||
ss << txTo.vin[n].prevout;
|
||||
}
|
||||
hashPrevouts = ss.GetHash(); // TODO: cache this value for all signatures in a transaction
|
||||
}
|
||||
|
||||
if (!(nHashType & SIGHASH_ANYONECANPAY) && (nHashType & 0x1f) != SIGHASH_SINGLE && (nHashType & 0x1f) != SIGHASH_NONE) {
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
for (unsigned int n = 0; n < txTo.vin.size(); n++) {
|
||||
ss << txTo.vin[n].nSequence;
|
||||
}
|
||||
hashSequence = ss.GetHash(); // TODO: cache this value for all signatures in a transaction
|
||||
}
|
||||
|
||||
if ((nHashType & 0x1f) != SIGHASH_SINGLE && (nHashType & 0x1f) != SIGHASH_NONE) {
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
for (unsigned int n = 0; n < txTo.vout.size(); n++) {
|
||||
ss << txTo.vout[n];
|
||||
}
|
||||
hashOutputs = ss.GetHash(); // TODO: cache this value for all signatures in a transaction
|
||||
} else if ((nHashType & 0x1f) == SIGHASH_SINGLE && nIn < txTo.vout.size()) {
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
ss << txTo.vout[nIn];
|
||||
hashOutputs = ss.GetHash();
|
||||
}
|
||||
|
||||
CHashWriter ss(SER_GETHASH, 0);
|
||||
// Version
|
||||
ss << txTo.nVersion;
|
||||
// Input prevouts/nSequence (none/all, depending on flags)
|
||||
ss << hashPrevouts;
|
||||
ss << hashSequence;
|
||||
// The input being signed (replacing the scriptSig with scriptCode + amount)
|
||||
// The prevout may already be contained in hashPrevout, and the nSequence
|
||||
// may already be contain in hashSequence.
|
||||
ss << txTo.vin[nIn].prevout;
|
||||
ss << static_cast<const CScriptBase&>(scriptCode);
|
||||
ss << amount;
|
||||
ss << txTo.vin[nIn].nSequence;
|
||||
// Outputs (none/one/all, depending on flags)
|
||||
ss << hashOutputs;
|
||||
// Locktime
|
||||
ss << txTo.nLockTime;
|
||||
// Sighash type
|
||||
ss << nHashType;
|
||||
|
||||
return ss.GetHash();
|
||||
}
|
||||
|
||||
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
|
||||
if (nIn >= txTo.vin.size()) {
|
||||
// nIn out of range
|
||||
|
@ -104,7 +104,6 @@ struct PrecomputedTransactionData
|
||||
enum SigVersion
|
||||
{
|
||||
SIGVERSION_BASE = 0,
|
||||
SIGVERSION_WITNESS_V0 = 1,
|
||||
};
|
||||
|
||||
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
|
||||
|
@ -54,7 +54,6 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
return ISMINE_SPENDABLE;
|
||||
break;
|
||||
case TX_PUBKEYHASH:
|
||||
case TX_WITNESS_V0_KEYHASH:
|
||||
keyID = CKeyID(uint160(vSolutions[0]));
|
||||
if (keystore.HaveKey(keyID))
|
||||
return ISMINE_SPENDABLE;
|
||||
@ -70,20 +69,6 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TX_WITNESS_V0_SCRIPTHASH:
|
||||
{
|
||||
uint160 hash;
|
||||
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(hash.begin());
|
||||
CScriptID scriptID = CScriptID(hash);
|
||||
CScript subscript;
|
||||
if (keystore.GetCScript(scriptID, subscript)) {
|
||||
isminetype ret = IsMine(keystore, subscript);
|
||||
if (ret == ISMINE_SPENDABLE)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TX_MULTISIG:
|
||||
{
|
||||
// Only consider transactions "mine" if we own ALL the
|
||||
|
@ -101,27 +101,15 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
||||
ret.push_back(valtype()); // workaround CHECKMULTISIG bug
|
||||
return (SignN(vSolutions, creator, scriptPubKey, ret, sigversion));
|
||||
|
||||
case TX_WITNESS_V0_KEYHASH:
|
||||
ret.push_back(vSolutions[0]);
|
||||
return true;
|
||||
|
||||
case TX_WITNESS_V0_SCRIPTHASH:
|
||||
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin());
|
||||
if (creator.KeyStore().GetCScript(h160, scriptRet)) {
|
||||
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static CScript PushAll(const vector<valtype>& values)
|
||||
static CScript PushAll(const std::vector<valtype>& values)
|
||||
{
|
||||
CScript result;
|
||||
BOOST_FOREACH(const valtype& v, values) {
|
||||
for(const valtype& v : values) {
|
||||
if (v.size() == 0) {
|
||||
result << OP_0;
|
||||
} else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
|
||||
@ -142,7 +130,6 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
||||
solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE);
|
||||
bool P2SH = false;
|
||||
CScript subscript;
|
||||
sigdata.scriptWitness.stack.clear();
|
||||
|
||||
if (solved && whichType == TX_SCRIPTHASH)
|
||||
{
|
||||
@ -154,32 +141,13 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
||||
P2SH = true;
|
||||
}
|
||||
|
||||
if (solved && whichType == TX_WITNESS_V0_KEYHASH)
|
||||
{
|
||||
CScript witnessscript;
|
||||
witnessscript << OP_DUP << OP_HASH160 << ToByteVector(result[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
txnouttype subType;
|
||||
solved = solved && SignStep(creator, witnessscript, result, subType, SIGVERSION_WITNESS_V0);
|
||||
sigdata.scriptWitness.stack = result;
|
||||
result.clear();
|
||||
}
|
||||
else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH)
|
||||
{
|
||||
CScript witnessscript(result[0].begin(), result[0].end());
|
||||
txnouttype subType;
|
||||
solved = solved && SignStep(creator, witnessscript, result, subType, SIGVERSION_WITNESS_V0) && subType != TX_SCRIPTHASH && subType != TX_WITNESS_V0_SCRIPTHASH && subType != TX_WITNESS_V0_KEYHASH;
|
||||
result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end()));
|
||||
sigdata.scriptWitness.stack = result;
|
||||
result.clear();
|
||||
}
|
||||
|
||||
if (P2SH) {
|
||||
result.push_back(std::vector<unsigned char>(subscript.begin(), subscript.end()));
|
||||
}
|
||||
sigdata.scriptSig = PushAll(result);
|
||||
|
||||
// Test solution
|
||||
return solved && VerifyScript(sigdata.scriptSig, fromPubKey, &sigdata.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker());
|
||||
return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker());
|
||||
}
|
||||
|
||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn)
|
||||
@ -187,9 +155,6 @@ SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nI
|
||||
SignatureData data;
|
||||
assert(tx.vin.size() > nIn);
|
||||
data.scriptSig = tx.vin[nIn].scriptSig;
|
||||
if (tx.wit.vtxinwit.size() > nIn) {
|
||||
data.scriptWitness = tx.wit.vtxinwit[nIn].scriptWitness;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -197,10 +162,6 @@ void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const Signatur
|
||||
{
|
||||
assert(tx.vin.size() > nIn);
|
||||
tx.vin[nIn].scriptSig = data.scriptSig;
|
||||
if (!data.scriptWitness.IsNull() || tx.wit.vtxinwit.size() > nIn) {
|
||||
tx.wit.vtxinwit.resize(tx.vin.size());
|
||||
tx.wit.vtxinwit[nIn].scriptWitness = data.scriptWitness;
|
||||
}
|
||||
}
|
||||
|
||||
bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType)
|
||||
@ -286,18 +247,16 @@ namespace
|
||||
struct Stacks
|
||||
{
|
||||
std::vector<valtype> script;
|
||||
std::vector<valtype> witness;
|
||||
|
||||
Stacks() {}
|
||||
explicit Stacks(const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_), witness() {}
|
||||
explicit Stacks(const SignatureData& data) : witness(data.scriptWitness.stack) {
|
||||
explicit Stacks(const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_) {}
|
||||
explicit Stacks(const SignatureData& data) {
|
||||
EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
|
||||
}
|
||||
|
||||
SignatureData Output() const {
|
||||
SignatureData result;
|
||||
result.scriptSig = PushAll(script);
|
||||
result.scriptWitness.stack = witness;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -321,11 +280,6 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
||||
if (sigs1.script.empty() || sigs1.script[0].empty())
|
||||
return sigs2;
|
||||
return sigs1;
|
||||
case TX_WITNESS_V0_KEYHASH:
|
||||
// Signatures are bigger than placeholders or empty scripts:
|
||||
if (sigs1.witness.empty() || sigs1.witness[0].empty())
|
||||
return sigs2;
|
||||
return sigs1;
|
||||
case TX_SCRIPTHASH:
|
||||
if (sigs1.script.empty() || sigs1.script.back().empty())
|
||||
return sigs2;
|
||||
@ -348,30 +302,6 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
||||
}
|
||||
case TX_MULTISIG:
|
||||
return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, sigversion));
|
||||
case TX_WITNESS_V0_SCRIPTHASH:
|
||||
if (sigs1.witness.empty() || sigs1.witness.back().empty())
|
||||
return sigs2;
|
||||
else if (sigs2.witness.empty() || sigs2.witness.back().empty())
|
||||
return sigs1;
|
||||
else
|
||||
{
|
||||
// Recur to combine:
|
||||
CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
|
||||
txnouttype txType2;
|
||||
vector<valtype> vSolutions2;
|
||||
Solver(pubKey2, txType2, vSolutions2);
|
||||
sigs1.witness.pop_back();
|
||||
sigs1.script = sigs1.witness;
|
||||
sigs1.witness.clear();
|
||||
sigs2.witness.pop_back();
|
||||
sigs2.script = sigs2.witness;
|
||||
sigs2.witness.clear();
|
||||
Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, SIGVERSION_WITNESS_V0);
|
||||
result.witness = result.script;
|
||||
result.script.clear();
|
||||
result.witness.push_back(valtype(pubKey2.begin(), pubKey2.end()));
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return Stacks();
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ public:
|
||||
|
||||
struct SignatureData {
|
||||
CScript scriptSig;
|
||||
CScriptWitness scriptWitness;
|
||||
|
||||
SignatureData() {}
|
||||
explicit SignatureData(const CScript& script) : scriptSig(script) {}
|
||||
|
@ -28,8 +28,6 @@ const char* GetTxnOutputType(txnouttype t)
|
||||
case TX_SCRIPTHASH: return "scripthash";
|
||||
case TX_MULTISIG: return "multisig";
|
||||
case TX_NULL_DATA: return "nulldata";
|
||||
case TX_WITNESS_V0_KEYHASH: return "witness_v0_keyhash";
|
||||
case TX_WITNESS_V0_SCRIPTHASH: return "witness_v0_scripthash";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -65,22 +63,6 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
|
||||
return true;
|
||||
}
|
||||
|
||||
int witnessversion;
|
||||
std::vector<unsigned char> witnessprogram;
|
||||
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||
if (witnessversion == 0 && witnessprogram.size() == 20) {
|
||||
typeRet = TX_WITNESS_V0_KEYHASH;
|
||||
vSolutionsRet.push_back(witnessprogram);
|
||||
return true;
|
||||
}
|
||||
if (witnessversion == 0 && witnessprogram.size() == 32) {
|
||||
typeRet = TX_WITNESS_V0_SCRIPTHASH;
|
||||
vSolutionsRet.push_back(witnessprogram);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Provably prunable, data-carrying output
|
||||
//
|
||||
// So long as script passes the IsUnspendable() test and all but the first
|
||||
|
@ -51,8 +51,6 @@ enum txnouttype
|
||||
TX_SCRIPTHASH,
|
||||
TX_MULTISIG,
|
||||
TX_NULL_DATA,
|
||||
TX_WITNESS_V0_SCRIPTHASH,
|
||||
TX_WITNESS_V0_KEYHASH,
|
||||
};
|
||||
|
||||
class CNoDestination {
|
||||
|
Loading…
Reference in New Issue
Block a user