3bf765e2a3
Similar to the previous commit; make sure that the ValidationContext has access to the new Tx format so new code can use it directly. In practically all cases (outside of the unit tests) callers already had a Tx instance. Making it just a matter of sending it with. Notice that the Tx object is immutable and implicitly shared which makes it cheaper to pass around.
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
* Copyright (C) 2009-2015 The Bitcoin Core developers
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef FLOWEE_SCRIPT_SIGCACHE_H
|
|
#define FLOWEE_SCRIPT_SIGCACHE_H
|
|
|
|
#include "script/interpreter.h"
|
|
#include <uint256.h>
|
|
|
|
#include <vector>
|
|
#include <cstring>
|
|
|
|
#include <primitives/Tx.h>
|
|
|
|
class PublicKey;
|
|
|
|
/**
|
|
* We're hashing a nonce into the entries themselves, so we don't need extra
|
|
* blinding in the set hash computation.
|
|
*
|
|
* This may exhibit platform endian dependent behavior but because these are
|
|
* nonced hashes (random) and this state is only ever used locally it is safe.
|
|
* All that matters is local consistency.
|
|
*/
|
|
class SignatureCacheHasher
|
|
{
|
|
public:
|
|
template <uint8_t hash_select>
|
|
uint32_t operator()(const uint256& key) const
|
|
{
|
|
static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available.");
|
|
uint32_t u;
|
|
std::memcpy(&u, key.begin()+4*hash_select, 4);
|
|
return u;
|
|
}
|
|
};
|
|
|
|
class CachingTransactionSignatureChecker : public TransactionSignatureChecker
|
|
{
|
|
private:
|
|
bool store;
|
|
|
|
public:
|
|
CachingTransactionSignatureChecker(const CTransaction* oldTxToIn, const Tx &txIn, unsigned int nInIn, int64_t amount, bool storeIn=true,
|
|
const std::vector<Tx::Output> *spentOutputsIn = nullptr)
|
|
: TransactionSignatureChecker(oldTxToIn, txIn, nInIn, amount, spentOutputsIn), store(storeIn) {}
|
|
|
|
bool VerifySignature(const std::vector<unsigned char>& vchSig, const PublicKey& vchPubKey, const uint256& sighash, uint32_t flags) const override;
|
|
};
|
|
|
|
void InitSignatureCache();
|
|
|
|
#endif
|