2WP: Refactor out GetAmountFromParentChainPegin

This commit is contained in:
Jorge Timón 2018-06-12 23:08:57 +02:00
parent 2be9cae539
commit a20986b40d
No known key found for this signature in database
GPG key ID: 8866C18EA1C944A2
2 changed files with 15 additions and 1 deletions

View file

@ -2359,6 +2359,12 @@ CScript calculate_contract(const CScript& federationRedeemScript, const CScript&
return scriptDestination;
}
bool GetAmountFromParentChainPegin(CAmount& amount, const Sidechain::Bitcoin::CTransaction& txBTC, unsigned int nOut)
{
amount = txBTC.vout[nOut].nValue;
return true;
}
template<typename T>
static bool GetBlockAndTxFromMerkleBlock(uint256& block_hash, uint256& tx_hash, T& merkle_block, const std::vector<unsigned char>& merkle_block_raw)
{
@ -2405,7 +2411,10 @@ static bool CheckPeginTx(const std::vector<unsigned char>& tx_data, T& pegtx, co
if (prevout.n >= pegtx->vout.size()) {
return false;
}
CAmount amount = pegtx->vout[prevout.n].nValue;
CAmount amount = 0;
if (!GetAmountFromParentChainPegin(amount, *pegtx, prevout.n)) {
return false;
}
// Check the transaction nout/value matches
if (claim_amount != amount) {
return false;

View file

@ -32,6 +32,10 @@
#include <boost/unordered_map.hpp>
#include <boost/filesystem/path.hpp>
namespace Sidechain { namespace Bitcoin {
class CTransaction;
}}
class CBlockIndex;
class CBlockTreeDB;
class CBloomFilter;
@ -262,6 +266,7 @@ void UnloadBlockIndex();
void ThreadScriptCheck();
/** Check if bitcoind connection via RPC is correctly working*/
bool BitcoindRPCCheck(bool init);
bool GetAmountFromParentChainPegin(CAmount& amount, const Sidechain::Bitcoin::CTransaction& txBTC, unsigned int nOut);
/** Checks pegin witness for validity */
bool IsValidPeginWitness(const CScriptWitness& pegin_witness, const COutPoint& prevout, bool check_depth = true);
/** Extracts an output from pegin witness for evaluation as a normal output */