Files

70 lines
2.2 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* 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/>.
*/
2014-09-10 16:16:09 +02:00
2018-01-16 10:47:52 +00:00
#ifndef FLOWEE_SCRIPT_SIGCACHE_H
#define FLOWEE_SCRIPT_SIGCACHE_H
2014-09-10 16:16:09 +02:00
#include "script/interpreter.h"
2021-01-20 19:21:53 +01:00
#include <uint256.h>
2014-09-10 16:16:09 +02:00
#include <vector>
2021-01-20 19:21:53 +01:00
#include <cstring>
2014-09-10 16:16:09 +02:00
2026-05-12 15:46:48 +02:00
#include <primitives/Tx.h>
2022-07-06 21:56:34 +02:00
class PublicKey;
2014-09-10 16:16:09 +02:00
2018-08-10 12:33:29 +03:00
/**
* 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
2014-09-10 16:16:09 +02:00
{
private:
bool store;
2014-09-10 16:16:09 +02:00
public:
2026-05-14 12:45:20 +02:00
CachingTransactionSignatureChecker(const CTransaction* oldTxToIn, const Tx &txIn, unsigned int nInIn, int64_t amount, bool storeIn=true,
2026-05-12 15:46:48 +02:00
const std::vector<Tx::Output> *spentOutputsIn = nullptr)
2026-05-14 12:45:20 +02:00
: TransactionSignatureChecker(oldTxToIn, txIn, nInIn, amount, spentOutputsIn), store(storeIn) {}
2022-07-06 21:56:34 +02:00
bool VerifySignature(const std::vector<unsigned char>& vchSig, const PublicKey& vchPubKey, const uint256& sighash, uint32_t flags) const override;
2014-09-10 16:16:09 +02:00
};
2018-08-10 10:33:34 +03:00
void InitSignatureCache();
2018-01-16 10:47:52 +00:00
#endif