Skip to content

Commit

Permalink
Replace: CScript::mscore_parse(..) by GetScriptPushes(..)
Browse files Browse the repository at this point in the history
Instead of using a modified version of CScript::ToString(),
CScript::mscore_parse(,,) was replaced by an external function,
which collects pushed values in a script.

The original state of script.h is now contained.
  • Loading branch information
dexX7 committed Feb 18, 2015
1 parent 1f78743 commit 770749d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ BITCOIN_CORE_H = \
mastercore_rpc.h \
mastercore_sp.h \
mastercore_errors.h \
mastercore_script.h \
mastercore_version.h \
crypter.h \
db.h \
Expand Down Expand Up @@ -140,6 +141,7 @@ libbitcoin_common_a_SOURCES = \
mastercore_tx.cpp \
mastercore_rpc.cpp \
mastercore_dex.cpp \
mastercore_script.cpp \
mastercore_sp.cpp \
hash.cpp \
key.cpp \
Expand Down
39 changes: 5 additions & 34 deletions src/mastercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ using namespace mastercore;
#include "mastercore_tx.h"
#include "mastercore_sp.h"
#include "mastercore_errors.h"
#include "mastercore_script.h"
#include "mastercore_version.h"

// part of 'breakout' feature
Expand Down Expand Up @@ -1146,7 +1147,7 @@ uint64_t txFee = 0;
if (msc_debug_parser_data) file_log("saving address_data #%d: %s:%s\n", i, strAddress.c_str(), wtx.vout[i].scriptPubKey.ToString().c_str());

// saving for Class A processing or reference
wtx.vout[i].scriptPubKey.mscore_parse(script_data);
GetScriptPushes(wtx.vout[i].scriptPubKey, script_data);
address_data.push_back(strAddress);
value_data.push_back(wtx.vout[i].nValue);
}
Expand Down Expand Up @@ -1305,7 +1306,9 @@ uint64_t txFee = 0;
}
if (msc_debug_script) file_log("\n");

wtx.vout[i].scriptPubKey.mscore_parse(multisig_script_data, false);
// ignore first public key, as it should belong to the sender
// and it be used to avoid the creation of unspendable dust
GetScriptPushes(wtx.vout[i].scriptPubKey, multisig_script_data, true);
}
}
} // end of the outputs' for loop
Expand Down Expand Up @@ -3954,38 +3957,6 @@ int validity = 0;
return true;
}

std::string CScript::mscore_parse(std::vector<std::string>&msc_parsed, bool bNoBypass) const
{
int count = 0;
std::string str;
opcodetype opcode;
std::vector<unsigned char> vch;
const_iterator pc = begin();
while (pc < end())
{
if (!str.empty())
{
str += "\n";
}
if (!GetOp(pc, opcode, vch))
{
str += "[error]";
return str;
}
if (0 <= opcode && opcode <= OP_PUSHDATA4)
{
str += ValueString(vch);
if (count || bNoBypass) msc_parsed.push_back(ValueString(vch));
count++;
}
else
{
str += GetOpName(opcode);
}
}
return str;
}

int mastercore_handler_block_begin(int nBlockPrev, CBlockIndex const * pBlockIndex) {
if (reorgRecoveryMode > 0) {
reorgRecoveryMode = 0; // clear reorgRecovery here as this is likely re-entrant
Expand Down
23 changes: 23 additions & 0 deletions src/mastercore_script.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "mastercore_script.h"

#include "script.h"
#include "util.h"

#include <string>
#include <vector>

bool GetScriptPushes(const CScript& scriptIn, std::vector<std::string>& vstrRet, bool fSkipFirst)
{
int count = 0;
CScript::const_iterator pc = scriptIn.begin();
while (pc < scriptIn.end())
{
opcodetype opcode;
std::vector<unsigned char> data;
if (!scriptIn.GetOp(pc, opcode, data))
return false;
if (0 <= opcode && opcode <= OP_PUSHDATA4)
if (count++ || !fSkipFirst) vstrRet.push_back(HexStr(data));
}
return true;
}
11 changes: 11 additions & 0 deletions src/mastercore_script.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef MASTERCOIN_SCRIPT_H
#define MASTERCOIN_SCRIPT_H

#include <string>
#include <vector>

class CScript;

bool GetScriptPushes(const CScript& scriptIn, std::vector<std::string>& vstrRet, bool fSkipFirst = false);

#endif // MASTERCOIN_SCRIPT_H
2 changes: 0 additions & 2 deletions src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,6 @@ class CScript : public std::vector<unsigned char>
{
return CScriptID(Hash160(*this));
}

std::string mscore_parse(std::vector<std::string>&msc_parsed, bool bNoBypass = true) const;
};

/** Compact serializer for scripts.
Expand Down

0 comments on commit 770749d

Please sign in to comment.