struct CC_info
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -45,14 +45,14 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
|||||||
key = *pprivKey;
|
key = *pprivKey;
|
||||||
else if (!keystore || !keystore->GetKey(address, key))
|
else if (!keystore || !keystore->GetKey(address, key))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
try {
|
try {
|
||||||
hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId);
|
hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId);
|
||||||
} catch (logic_error ex) {
|
} catch (logic_error ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scriptCode.IsPayToCryptoCondition())
|
if (scriptCode.IsPayToCryptoCondition())
|
||||||
{
|
{
|
||||||
CC *cc = (CC *)extraData;
|
CC *cc = (CC *)extraData;
|
||||||
@@ -75,9 +75,9 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vchSig.push_back((unsigned char)nHashType);
|
vchSig.push_back((unsigned char)nHashType);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ std::vector<CCcontract_info> &GetCryptoConditions()
|
|||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
static std::vector<CCcontract_info> vCC = std::vector<CCcontract_info>();
|
static std::vector<CCcontract_info> vCC = std::vector<CCcontract_info>();
|
||||||
CCcontract_info C;
|
CCcontract_info C;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
// this should initialize any desired auto-signed crypto-conditions
|
// this should initialize any desired auto-signed crypto-conditions
|
||||||
@@ -140,7 +140,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr)
|
|||||||
{
|
{
|
||||||
std::vector<CCcontract_info> &vCC = GetCryptoConditions();
|
std::vector<CCcontract_info> &vCC = GetCryptoConditions();
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; i < vCC.size(); i++)
|
for (int i = 0; i < vCC.size(); i++)
|
||||||
{
|
{
|
||||||
if (strcmp(addrstr, vCC[i].unspendableCCaddr) == 0)
|
if (strcmp(addrstr, vCC[i].unspendableCCaddr) == 0)
|
||||||
@@ -157,7 +157,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode)
|
|||||||
{
|
{
|
||||||
std::vector<CCcontract_info> &vCC = GetCryptoConditions();
|
std::vector<CCcontract_info> &vCC = GetCryptoConditions();
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; i < vCC.size(); i++)
|
for (int i = 0; i < vCC.size(); i++)
|
||||||
{
|
{
|
||||||
if (vCC[i].evalcode == evalcode)
|
if (vCC[i].evalcode == evalcode)
|
||||||
@@ -172,7 +172,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode)
|
|||||||
|
|
||||||
bool _Getscriptaddress(char *destaddr, const CScript &scriptPubKey)
|
bool _Getscriptaddress(char *destaddr, const CScript &scriptPubKey)
|
||||||
{
|
{
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
std::vector<std::vector<unsigned char>> vvch = std::vector<std::vector<unsigned char>>();
|
std::vector<std::vector<unsigned char>> vvch = std::vector<std::vector<unsigned char>>();
|
||||||
if (Solver(scriptPubKey, whichType, vvch) && vvch[0].size() == 20)
|
if (Solver(scriptPubKey, whichType, vvch) && vvch[0].size() == 20)
|
||||||
@@ -199,10 +199,10 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
vector<CPubKey> vPK;
|
vector<CPubKey> vPK;
|
||||||
vector<valtype> vParams = vector<valtype>();
|
vector<valtype> vParams = vector<valtype>();
|
||||||
COptCCParams p;
|
COptCCParams p;
|
||||||
|
|
||||||
// get information to sign with
|
// get information to sign with
|
||||||
CCcontract_info C;
|
CCcontract_info C;
|
||||||
|
|
||||||
scriptPubKey.IsPayToCryptoCondition(&subScript, vParams);
|
scriptPubKey.IsPayToCryptoCondition(&subScript, vParams);
|
||||||
if (vParams.empty())
|
if (vParams.empty())
|
||||||
{
|
{
|
||||||
@@ -219,12 +219,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
{
|
{
|
||||||
p = COptCCParams(vParams[0]);
|
p = COptCCParams(vParams[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.IsValid() && p.vKeys.size() >= p.n)
|
if (p.IsValid() && p.vKeys.size() >= p.n)
|
||||||
{
|
{
|
||||||
bool is1of2 = (p.m == 1 && p.n == 2);
|
bool is1of2 = (p.m == 1 && p.n == 2);
|
||||||
CKey privKey;
|
CKey privKey;
|
||||||
|
|
||||||
// must be a valid cc eval code
|
// must be a valid cc eval code
|
||||||
if (CCinitLite(&C, p.evalCode))
|
if (CCinitLite(&C, p.evalCode))
|
||||||
{
|
{
|
||||||
@@ -232,7 +232,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
if (!is1of2)
|
if (!is1of2)
|
||||||
{
|
{
|
||||||
bool havePriv = creator.KeyStore().GetKey(p.vKeys[0].GetID(), privKey);
|
bool havePriv = creator.KeyStore().GetKey(p.vKeys[0].GetID(), privKey);
|
||||||
|
|
||||||
// if we don't have the private key, it must be the unspendable address
|
// if we don't have the private key, it must be the unspendable address
|
||||||
if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(C.CChexstr))))
|
if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(C.CChexstr))))
|
||||||
{
|
{
|
||||||
@@ -240,9 +240,9 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
std::vector<unsigned char> vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv));
|
std::vector<unsigned char> vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv));
|
||||||
privKey.Set(vch.begin(), vch.end(), false);
|
privKey.Set(vch.begin(), vch.end(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CC *cc = CCcond1(p.evalCode, p.vKeys[0]);
|
CC *cc = CCcond1(p.evalCode, p.vKeys[0]);
|
||||||
|
|
||||||
if (cc)
|
if (cc)
|
||||||
{
|
{
|
||||||
vector<unsigned char> vch;
|
vector<unsigned char> vch;
|
||||||
@@ -254,7 +254,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
{
|
{
|
||||||
fprintf(stderr,"vin has 1of1 CC signing error with address.(%s)\n", p.vKeys[0].GetID().ToString().c_str());
|
fprintf(stderr,"vin has 1of1 CC signing error with address.(%s)\n", p.vKeys[0].GetID().ToString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_free(cc);
|
cc_free(cc);
|
||||||
return ret.size() != 0;
|
return ret.size() != 0;
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
{
|
{
|
||||||
if (creator.IsKeystoreValid() && creator.KeyStore().GetKey(pk.GetID(), privKey) && privKey.IsValid())
|
if (creator.IsKeystoreValid() && creator.KeyStore().GetKey(pk.GetID(), privKey) && privKey.IsValid())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (pk == CPubKey(ParseHex(C.CChexstr)))
|
if (pk == CPubKey(ParseHex(C.CChexstr)))
|
||||||
{
|
{
|
||||||
privKey = CKey();
|
privKey = CKey();
|
||||||
@@ -275,12 +275,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!privKey.IsValid())
|
if (!privKey.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CC *cc = CCcond1of2(p.evalCode, p.vKeys[0], p.vKeys[1]);
|
CC *cc = CCcond1of2(p.evalCode, p.vKeys[0], p.vKeys[1]);
|
||||||
|
|
||||||
if (cc)
|
if (cc)
|
||||||
{
|
{
|
||||||
vector<unsigned char> vch;
|
vector<unsigned char> vch;
|
||||||
@@ -292,7 +292,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
|
|||||||
{
|
{
|
||||||
fprintf(stderr,"vin has 1of2 CC signing error with addresses.(%s)\n(%s)\n", p.vKeys[0].GetID().ToString().c_str(), p.vKeys[1].GetID().ToString().c_str());
|
fprintf(stderr,"vin has 1of2 CC signing error with addresses.(%s)\n(%s)\n", p.vKeys[0].GetID().ToString().c_str(), p.vKeys[1].GetID().ToString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_free(cc);
|
cc_free(cc);
|
||||||
return ret.size() != 0;
|
return ret.size() != 0;
|
||||||
}
|
}
|
||||||
@@ -314,9 +314,9 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
|||||||
CScript scriptRet;
|
CScript scriptRet;
|
||||||
uint160 h160;
|
uint160 h160;
|
||||||
ret.clear();
|
ret.clear();
|
||||||
|
|
||||||
vector<valtype> vSolutions;
|
vector<valtype> vSolutions;
|
||||||
|
|
||||||
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
|
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
|
||||||
{
|
{
|
||||||
// if this is a CLTV script, solve for the destination after CLTV
|
// if this is a CLTV script, solve for the destination after CLTV
|
||||||
@@ -324,10 +324,10 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
|||||||
{
|
{
|
||||||
uint8_t pushOp = scriptPubKey[0];
|
uint8_t pushOp = scriptPubKey[0];
|
||||||
uint32_t scriptStart = pushOp + 3;
|
uint32_t scriptStart = pushOp + 3;
|
||||||
|
|
||||||
// check post CLTV script
|
// check post CLTV script
|
||||||
CScript postfix = CScript(scriptPubKey.size() > scriptStart ? scriptPubKey.begin() + scriptStart : scriptPubKey.end(), scriptPubKey.end());
|
CScript postfix = CScript(scriptPubKey.size() > scriptStart ? scriptPubKey.begin() + scriptStart : scriptPubKey.end(), scriptPubKey.end());
|
||||||
|
|
||||||
// check again with only postfix subscript
|
// check again with only postfix subscript
|
||||||
if (!Solver(postfix, whichTypeRet, vSolutions))
|
if (!Solver(postfix, whichTypeRet, vSolutions))
|
||||||
return false;
|
return false;
|
||||||
@@ -335,44 +335,44 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CKeyID keyID;
|
CKeyID keyID;
|
||||||
|
|
||||||
switch (whichTypeRet)
|
switch (whichTypeRet)
|
||||||
{
|
{
|
||||||
case TX_NONSTANDARD:
|
case TX_NONSTANDARD:
|
||||||
case TX_NULL_DATA:
|
case TX_NULL_DATA:
|
||||||
return false;
|
|
||||||
case TX_PUBKEY:
|
|
||||||
keyID = CPubKey(vSolutions[0]).GetID();
|
|
||||||
return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId);
|
|
||||||
case TX_PUBKEYHASH:
|
|
||||||
keyID = CKeyID(uint160(vSolutions[0]));
|
|
||||||
if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId))
|
|
||||||
return false;
|
return false;
|
||||||
else
|
case TX_PUBKEY:
|
||||||
{
|
keyID = CPubKey(vSolutions[0]).GetID();
|
||||||
CPubKey vch;
|
return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId);
|
||||||
creator.KeyStore().GetPubKey(keyID, vch);
|
case TX_PUBKEYHASH:
|
||||||
ret.push_back(ToByteVector(vch));
|
keyID = CKeyID(uint160(vSolutions[0]));
|
||||||
}
|
if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId))
|
||||||
return true;
|
return false;
|
||||||
case TX_SCRIPTHASH:
|
else
|
||||||
if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) {
|
{
|
||||||
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
|
CPubKey vch;
|
||||||
|
creator.KeyStore().GetPubKey(keyID, vch);
|
||||||
|
ret.push_back(ToByteVector(vch));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
case TX_SCRIPTHASH:
|
||||||
return false;
|
if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) {
|
||||||
|
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
|
||||||
case TX_CRYPTOCONDITION:
|
return true;
|
||||||
return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId);
|
}
|
||||||
|
return false;
|
||||||
case TX_MULTISIG:
|
|
||||||
ret.push_back(valtype()); // workaround CHECKMULTISIG bug
|
case TX_CRYPTOCONDITION:
|
||||||
return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId));
|
return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId);
|
||||||
|
|
||||||
default:
|
case TX_MULTISIG:
|
||||||
return false;
|
ret.push_back(valtype()); // workaround CHECKMULTISIG bug
|
||||||
|
return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId));
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +399,7 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
|||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
solved = SignStep(creator, script, result, whichType, consensusBranchId);
|
solved = SignStep(creator, script, result, whichType, consensusBranchId);
|
||||||
CScript subscript;
|
CScript subscript;
|
||||||
|
|
||||||
if (solved && whichType == TX_SCRIPTHASH)
|
if (solved && whichType == TX_SCRIPTHASH)
|
||||||
{
|
{
|
||||||
// Solver returns the subscript that needs to be evaluated;
|
// Solver returns the subscript that needs to be evaluated;
|
||||||
@@ -409,9 +409,9 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
|||||||
solved = solved && SignStep(creator, script, result, whichType, consensusBranchId) && whichType != TX_SCRIPTHASH;
|
solved = solved && SignStep(creator, script, result, whichType, consensusBranchId) && whichType != TX_SCRIPTHASH;
|
||||||
result.push_back(std::vector<unsigned char>(subscript.begin(), subscript.end()));
|
result.push_back(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, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId);
|
return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId);
|
||||||
}
|
}
|
||||||
@@ -431,19 +431,19 @@ void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const Signatur
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SignSignature(
|
bool SignSignature(
|
||||||
const CKeyStore &keystore,
|
const CKeyStore &keystore,
|
||||||
const CScript& fromPubKey,
|
const CScript& fromPubKey,
|
||||||
CMutableTransaction& txTo,
|
CMutableTransaction& txTo,
|
||||||
unsigned int nIn,
|
unsigned int nIn,
|
||||||
const CAmount& amount,
|
const CAmount& amount,
|
||||||
int nHashType,
|
int nHashType,
|
||||||
uint32_t consensusBranchId)
|
uint32_t consensusBranchId)
|
||||||
{
|
{
|
||||||
assert(nIn < txTo.vin.size());
|
assert(nIn < txTo.vin.size());
|
||||||
|
|
||||||
CTransaction txToConst(txTo);
|
CTransaction txToConst(txTo);
|
||||||
TransactionSignatureCreator creator(&keystore, &txToConst, nIn, amount, nHashType);
|
TransactionSignatureCreator creator(&keystore, &txToConst, nIn, amount, nHashType);
|
||||||
|
|
||||||
SignatureData sigdata;
|
SignatureData sigdata;
|
||||||
bool ret = ProduceSignature(creator, fromPubKey, sigdata, consensusBranchId);
|
bool ret = ProduceSignature(creator, fromPubKey, sigdata, consensusBranchId);
|
||||||
UpdateTransaction(txTo, nIn, sigdata);
|
UpdateTransaction(txTo, nIn, sigdata);
|
||||||
@@ -451,24 +451,24 @@ bool SignSignature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SignSignature(
|
bool SignSignature(
|
||||||
const CKeyStore &keystore,
|
const CKeyStore &keystore,
|
||||||
const CTransaction& txFrom,
|
const CTransaction& txFrom,
|
||||||
CMutableTransaction& txTo,
|
CMutableTransaction& txTo,
|
||||||
unsigned int nIn,
|
unsigned int nIn,
|
||||||
int nHashType,
|
int nHashType,
|
||||||
uint32_t consensusBranchId)
|
uint32_t consensusBranchId)
|
||||||
{
|
{
|
||||||
assert(nIn < txTo.vin.size());
|
assert(nIn < txTo.vin.size());
|
||||||
CTxIn& txin = txTo.vin[nIn];
|
CTxIn& txin = txTo.vin[nIn];
|
||||||
assert(txin.prevout.n < txFrom.vout.size());
|
assert(txin.prevout.n < txFrom.vout.size());
|
||||||
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
||||||
|
|
||||||
return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, consensusBranchId);
|
return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, consensusBranchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||||
const vector<valtype>& vSolutions,
|
const vector<valtype>& vSolutions,
|
||||||
const vector<valtype>& sigs1, const vector<valtype>& sigs2, uint32_t consensusBranchId)
|
const vector<valtype>& sigs1, const vector<valtype>& sigs2, uint32_t consensusBranchId)
|
||||||
{
|
{
|
||||||
// Combine all the signatures we've got:
|
// Combine all the signatures we've got:
|
||||||
set<valtype> allsigs;
|
set<valtype> allsigs;
|
||||||
@@ -482,7 +482,7 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
allsigs.insert(v);
|
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];
|
||||||
@@ -495,7 +495,7 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
|
|||||||
const valtype& pubkey = vSolutions[i+1];
|
const valtype& pubkey = vSolutions[i+1];
|
||||||
if (sigs.count(pubkey))
|
if (sigs.count(pubkey))
|
||||||
continue; // Already got a sig for this pubkey
|
continue; // Already got a sig for this pubkey
|
||||||
|
|
||||||
if (checker.CheckSig(sig, pubkey, scriptPubKey, consensusBranchId))
|
if (checker.CheckSig(sig, pubkey, scriptPubKey, consensusBranchId))
|
||||||
{
|
{
|
||||||
sigs[pubkey] = sig;
|
sigs[pubkey] = sig;
|
||||||
@@ -517,108 +517,108 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
|
|||||||
// Fill any missing with OP_0:
|
// Fill any missing with OP_0:
|
||||||
for (unsigned int i = nSigsHave; i < nSigsRequired; i++)
|
for (unsigned int i = nSigsHave; i < nSigsRequired; i++)
|
||||||
result.push_back(valtype());
|
result.push_back(valtype());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct Stacks
|
struct Stacks
|
||||||
{
|
{
|
||||||
std::vector<valtype> script;
|
std::vector<valtype> script;
|
||||||
|
|
||||||
Stacks() {}
|
Stacks() {}
|
||||||
explicit Stacks(const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_) {}
|
explicit Stacks(const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_) {}
|
||||||
explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) {
|
explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) {
|
||||||
EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId);
|
EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignatureData Output() const {
|
SignatureData Output() const {
|
||||||
SignatureData result;
|
SignatureData result;
|
||||||
result.scriptSig = PushAll(script);
|
result.scriptSig = PushAll(script);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||||
const txnouttype txType, const vector<valtype>& vSolutions,
|
const txnouttype txType, const vector<valtype>& vSolutions,
|
||||||
Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId)
|
Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId)
|
||||||
{
|
{
|
||||||
switch (txType)
|
switch (txType)
|
||||||
{
|
{
|
||||||
case TX_NONSTANDARD:
|
case TX_NONSTANDARD:
|
||||||
case TX_NULL_DATA:
|
case TX_NULL_DATA:
|
||||||
// Don't know anything about this, assume bigger one is correct:
|
// Don't know anything about this, assume bigger one is correct:
|
||||||
if (sigs1.script.size() >= sigs2.script.size())
|
if (sigs1.script.size() >= sigs2.script.size())
|
||||||
return sigs1;
|
return sigs1;
|
||||||
return sigs2;
|
|
||||||
case TX_PUBKEY:
|
|
||||||
case TX_PUBKEYHASH:
|
|
||||||
case TX_CRYPTOCONDITION:
|
|
||||||
// Signatures are bigger than placeholders or empty scripts:
|
|
||||||
if (sigs1.script.empty() || sigs1.script[0].empty())
|
|
||||||
return sigs2;
|
return sigs2;
|
||||||
return sigs1;
|
case TX_PUBKEY:
|
||||||
case TX_SCRIPTHASH:
|
case TX_PUBKEYHASH:
|
||||||
if (sigs1.script.empty() || sigs1.script.back().empty())
|
case TX_CRYPTOCONDITION:
|
||||||
return sigs2;
|
// Signatures are bigger than placeholders or empty scripts:
|
||||||
else if (sigs2.script.empty() || sigs2.script.back().empty())
|
if (sigs1.script.empty() || sigs1.script[0].empty())
|
||||||
|
return sigs2;
|
||||||
return sigs1;
|
return sigs1;
|
||||||
else
|
case TX_SCRIPTHASH:
|
||||||
{
|
if (sigs1.script.empty() || sigs1.script.back().empty())
|
||||||
// Recur to combine:
|
return sigs2;
|
||||||
valtype spk = sigs1.script.back();
|
else if (sigs2.script.empty() || sigs2.script.back().empty())
|
||||||
CScript pubKey2(spk.begin(), spk.end());
|
return sigs1;
|
||||||
|
else
|
||||||
txnouttype txType2;
|
{
|
||||||
vector<vector<unsigned char> > vSolutions2;
|
// Recur to combine:
|
||||||
Solver(pubKey2, txType2, vSolutions2);
|
valtype spk = sigs1.script.back();
|
||||||
sigs1.script.pop_back();
|
CScript pubKey2(spk.begin(), spk.end());
|
||||||
sigs2.script.pop_back();
|
|
||||||
Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId);
|
txnouttype txType2;
|
||||||
result.script.push_back(spk);
|
vector<vector<unsigned char> > vSolutions2;
|
||||||
return result;
|
Solver(pubKey2, txType2, vSolutions2);
|
||||||
}
|
sigs1.script.pop_back();
|
||||||
case TX_MULTISIG:
|
sigs2.script.pop_back();
|
||||||
return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId));
|
Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId);
|
||||||
default:
|
result.script.push_back(spk);
|
||||||
return Stacks();
|
return result;
|
||||||
|
}
|
||||||
|
case TX_MULTISIG:
|
||||||
|
return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId));
|
||||||
|
default:
|
||||||
|
return Stacks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||||
const SignatureData& scriptSig1, const SignatureData& scriptSig2,
|
const SignatureData& scriptSig1, const SignatureData& scriptSig2,
|
||||||
uint32_t consensusBranchId)
|
uint32_t consensusBranchId)
|
||||||
{
|
{
|
||||||
txnouttype txType;
|
txnouttype txType;
|
||||||
vector<vector<unsigned char> > vSolutions;
|
vector<vector<unsigned char> > vSolutions;
|
||||||
Solver(scriptPubKey, txType, vSolutions);
|
Solver(scriptPubKey, txType, vSolutions);
|
||||||
|
|
||||||
return CombineSignatures(
|
return CombineSignatures(
|
||||||
scriptPubKey, checker, txType, vSolutions,
|
scriptPubKey, checker, txType, vSolutions,
|
||||||
Stacks(scriptSig1, consensusBranchId),
|
Stacks(scriptSig1, consensusBranchId),
|
||||||
Stacks(scriptSig2, consensusBranchId),
|
Stacks(scriptSig2, consensusBranchId),
|
||||||
consensusBranchId).Output();
|
consensusBranchId).Output();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/** Dummy signature checker which accepts all signatures. */
|
/** Dummy signature checker which accepts all signatures. */
|
||||||
class DummySignatureChecker : public BaseSignatureChecker
|
class DummySignatureChecker : public BaseSignatureChecker
|
||||||
{
|
|
||||||
public:
|
|
||||||
DummySignatureChecker() {}
|
|
||||||
|
|
||||||
bool CheckSig(
|
|
||||||
const std::vector<unsigned char>& scriptSig,
|
|
||||||
const std::vector<unsigned char>& vchPubKey,
|
|
||||||
const CScript& scriptCode,
|
|
||||||
uint32_t consensusBranchId) const
|
|
||||||
{
|
{
|
||||||
return true;
|
public:
|
||||||
}
|
DummySignatureChecker() {}
|
||||||
};
|
|
||||||
const DummySignatureChecker dummyChecker;
|
bool CheckSig(
|
||||||
|
const std::vector<unsigned char>& scriptSig,
|
||||||
|
const std::vector<unsigned char>& vchPubKey,
|
||||||
|
const CScript& scriptCode,
|
||||||
|
uint32_t consensusBranchId) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const DummySignatureChecker dummyChecker;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BaseSignatureChecker& DummySignatureCreator::Checker() const
|
const BaseSignatureChecker& DummySignatureCreator::Checker() const
|
||||||
@@ -627,12 +627,12 @@ const BaseSignatureChecker& DummySignatureCreator::Checker() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DummySignatureCreator::CreateSig(
|
bool DummySignatureCreator::CreateSig(
|
||||||
std::vector<unsigned char>& vchSig,
|
std::vector<unsigned char>& vchSig,
|
||||||
const CKeyID& keyid,
|
const CKeyID& keyid,
|
||||||
const CScript& scriptCode,
|
const CScript& scriptCode,
|
||||||
uint32_t consensusBranchId,
|
uint32_t consensusBranchId,
|
||||||
CKey *key,
|
CKey *key,
|
||||||
void *extraData) const
|
void *extraData) const
|
||||||
{
|
{
|
||||||
// Create a dummy signature that is a valid DER-encoding
|
// Create a dummy signature that is a valid DER-encoding
|
||||||
vchSig.assign(72, '\000');
|
vchSig.assign(72, '\000');
|
||||||
@@ -647,3 +647,4 @@ bool DummySignatureCreator::CreateSig(
|
|||||||
vchSig[6 + 33 + 32] = SIGHASH_ALL;
|
vchSig[6 + 33 + 32] = SIGHASH_ALL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user