diff --git a/src/fluid/dynode.cpp b/src/fluid/dynode.cpp index c8c29ec1a..5930e33ce 100644 --- a/src/fluid/dynode.cpp +++ b/src/fluid/dynode.cpp @@ -13,35 +13,15 @@ CFluidDynodeDB* pFluidDynodeDB = NULL; -bool GetFluidDynodeData(const CTransaction& tx, CFluidDynode& entry, int& nOut) -{ - int n = 0; - for (const CTxOut& txout : tx.vout) { - CScript txOut = txout.scriptPubKey; - if (WithinFluidRange(txOut.GetFlag())) { - nOut = n; - return ParseScript(txOut, entry); - } - n++; - } - return false; -} - bool CFluidDynode::UnserializeFromTx(const CTransaction& tx) { int nOut; - if (!GetFluidDynodeData(tx, *this, nOut)) { - return false; - } - return true; + return ParseData(tx, *this, nOut); } bool CFluidDynode::UnserializeFromScript(const CScript& fluidScript) { - if (!ParseScript(fluidScript, *this)) { - return false; - } - return true; + return ParseScript(fluidScript, *this); } void CFluidDynode::Serialize(std::vector& vchData) diff --git a/src/fluid/fluid.cpp b/src/fluid/fluid.cpp index 79ce9cf1b..6184fe2c6 100644 --- a/src/fluid/fluid.cpp +++ b/src/fluid/fluid.cpp @@ -672,7 +672,26 @@ bool ParseScript(const CScript& scriptPubKey, T1& object) return object.IsNull(); } +template +bool ParseData(const CTransaction& tx, T1& entry, int& nOut) +{ + nOut = 0; + for (const CTxOut& txout : tx.vout) { + CScript txOut = txout.scriptPubKey; + if (WithinFluidRange(txOut.GetFlag())) { + return ParseScript(txOut, entry); + } + nOut++; + } + return false; +} + template bool ParseScript(const CScript& scriptPubKey, CFluidMint& object); template bool ParseScript(const CScript& scriptPubKey, CFluidMining& object); template bool ParseScript(const CScript& scriptPubKey, CFluidDynode& object); template bool ParseScript(const CScript& scriptPubKey, CFluidSovereign& object); + +template bool ParseData(const CTransaction& tx, CFluidMint& entry, int& nOut); +template bool ParseData(const CTransaction& tx, CFluidMining& entry, int& nOut); +template bool ParseData(const CTransaction& tx, CFluidDynode& entry, int& nOut); +template bool ParseData(const CTransaction& tx, CFluidSovereign& entry, int& nOut); diff --git a/src/fluid/fluid.h b/src/fluid/fluid.h index ec14418ad..1197c740e 100644 --- a/src/fluid/fluid.h +++ b/src/fluid/fluid.h @@ -205,6 +205,9 @@ std::vector FluidScriptToCharVector(const CScript& fluidScript); template bool ParseScript(const CScript& scriptPubKey, T1& object); +template +bool ParseData(const CTransaction& tx, T1& entry, int& nOut); + extern CFluid fluid; #endif // FLUID_PROTOCOL_H diff --git a/src/fluid/mining.cpp b/src/fluid/mining.cpp index 415861811..c92368488 100644 --- a/src/fluid/mining.cpp +++ b/src/fluid/mining.cpp @@ -13,35 +13,15 @@ CFluidMiningDB* pFluidMiningDB = NULL; -bool GetFluidMiningData(const CTransaction& tx, CFluidMining& entry, int& nOut) -{ - int n = 0; - for (const CTxOut& txout : tx.vout) { - CScript txOut = txout.scriptPubKey; - if (WithinFluidRange(txOut.GetFlag())) { - nOut = n; - return ParseScript(txOut, entry); - } - n++; - } - return false; -} - bool CFluidMining::UnserializeFromTx(const CTransaction& tx) { int nOut; - if (!GetFluidMiningData(tx, *this, nOut)) { - return false; - } - return true; + return ParseData(tx, *this, nOut); } bool CFluidMining::UnserializeFromScript(const CScript& fluidScript) { - if (!ParseScript(fluidScript, *this)) { - return false; - } - return true; + return ParseScript(fluidScript, *this); } void CFluidMining::Serialize(std::vector& vchData) diff --git a/src/fluid/mint.cpp b/src/fluid/mint.cpp index a5ef1010a..0db9316a6 100644 --- a/src/fluid/mint.cpp +++ b/src/fluid/mint.cpp @@ -14,35 +14,15 @@ CFluidMintDB* pFluidMintDB = NULL; -bool GetFluidMintData(const CTransaction& tx, CFluidMint& entry, int& nOut) -{ - int n = 0; - for (const CTxOut& txout : tx.vout) { - CScript txOut = txout.scriptPubKey; - if (WithinFluidRange(txOut.GetFlag())) { - nOut = n; - return ParseScript(txOut, entry); - } - n++; - } - return false; -} - bool CFluidMint::UnserializeFromTx(const CTransaction& tx) { int nOut; - if (!GetFluidMintData(tx, *this, nOut)) { - return false; - } - return true; + return ParseData(tx, *this, nOut); } bool CFluidMint::UnserializeFromScript(const CScript& fluidScript) { - if (!ParseScript(fluidScript, *this)) { - return false; - } - return true; + return ParseScript(fluidScript, *this); } void CFluidMint::Serialize(std::vector& vchData) @@ -68,7 +48,6 @@ bool CFluidMintDB::AddFluidMintEntry(const CFluidMint& entry, const int op) LOCK(cs_fluid_mint); writeState = Write(make_pair(std::string("script"), entry.GetTransactionScript()), entry) && Write(make_pair(std::string("txid"), entry.GetTransactionHash()), entry.GetTransactionScript()); } - return writeState; } diff --git a/src/fluid/sovereign.cpp b/src/fluid/sovereign.cpp index b0fe44731..b284e76f3 100644 --- a/src/fluid/sovereign.cpp +++ b/src/fluid/sovereign.cpp @@ -13,35 +13,15 @@ CFluidSovereignDB* pFluidSovereignDB = NULL; -bool GetFluidSovereignData(const CTransaction& tx, CFluidSovereign& entry, int& nOut) -{ - int n = 0; - for (const CTxOut& txout : tx.vout) { - CScript txOut = txout.scriptPubKey; - if (WithinFluidRange(txOut.GetFlag())) { - nOut = n; - return ParseScript(txOut, entry); - } - n++; - } - return false; -} - bool CFluidSovereign::UnserializeFromTx(const CTransaction& tx) { int nOut; - if (!GetFluidSovereignData(tx, *this, nOut)) { - return false; - } - return true; + return ParseData(tx, *this, nOut); } bool CFluidSovereign::UnserializeFromScript(const CScript& fluidScript) { - if (!ParseScript(fluidScript, *this)) { - return false; - } - return true; + return ParseScript(fluidScript, *this); } void CFluidSovereign::Serialize(std::vector& vchData)