Browse Source

Fixed keva op.

0.16.3-insta
Jianping Wu 6 years ago
parent
commit
7d75d17f04
  1. 28
      src/script/keva.cpp
  2. 33
      src/script/keva.h

28
src/script/keva.cpp

@ -10,31 +10,33 @@ CKevaScript::CKevaScript (const CScript& script)
: op(OP_NOP), address(script) : op(OP_NOP), address(script)
{ {
opcodetype nameOp; opcodetype nameOp;
CScript::const_iterator pc = script.begin (); CScript::const_iterator pc = script.begin();
if (!script.GetOp (pc, nameOp)) if (!script.GetOp(pc, nameOp)) {
return; return;
}
opcodetype opcode; opcodetype opcode;
while (true) { while (true) {
valtype vch; valtype vch;
if (!script.GetOp (pc, opcode, vch)) { if (!script.GetOp(pc, opcode, vch)) {
return; return;
} }
if (opcode == OP_DROP || opcode == OP_2DROP || opcode == OP_NOP) { if (opcode == OP_DROP || opcode == OP_2DROP || opcode == OP_NOP) {
break; break;
} }
if (!(opcode >= 0 && opcode <= OP_PUSHDATA4)) { if (!(opcode >= 0 && opcode <= OP_PUSHDATA4)) {
return; return;
} }
args.push_back (vch); args.push_back (vch);
} }
// Move the pc to after any DROP or NOP. // Move the pc to after any DROP or NOP.
while (opcode == OP_DROP || opcode == OP_2DROP || opcode == OP_NOP) { while (opcode == OP_DROP || opcode == OP_2DROP || opcode == OP_NOP) {
if (!script.GetOp (pc, opcode)) if (!script.GetOp(pc, opcode)) {
break; break;
}
} }
pc--; pc--;
@ -43,15 +45,15 @@ CKevaScript::CKevaScript (const CScript& script)
op and address members, if everything is valid. */ op and address members, if everything is valid. */
switch (nameOp) { switch (nameOp) {
case OP_KEVA_PUT: case OP_KEVA_PUT:
if (args.size () != 1) { if (args.size() != 3) {
return; return;
} }
break; break;
case OP_KEVA_NAMESPACE: case OP_KEVA_NAMESPACE:
if (args.size () != 1) { if (args.size() != 3) {
return; return;
} }
break; break;
default: default:
@ -59,7 +61,7 @@ CKevaScript::CKevaScript (const CScript& script)
} }
op = nameOp; op = nameOp;
address = CScript (pc, script.end ()); address = CScript(pc, script.end());
} }
CScript CScript

33
src/script/keva.h

@ -7,8 +7,6 @@
#include <script/script.h> #include <script/script.h>
typedef std::vector<unsigned char> valtype;
class uint160; class uint160;
/** /**
@ -36,7 +34,7 @@ public:
* Default constructor. This enables us to declare a variable * Default constructor. This enables us to declare a variable
* and initialise it later via assignment. * and initialise it later via assignment.
*/ */
inline CKevaScript () inline CKevaScript()
: op(OP_NOP) : op(OP_NOP)
{} {}
@ -45,14 +43,13 @@ public:
* the member variables representing the "picked apart" name script. * the member variables representing the "picked apart" name script.
* @param script The ordinary script to parse. * @param script The ordinary script to parse.
*/ */
explicit CKevaScript (const CScript& script); explicit CKevaScript(const CScript& script);
/** /**
* Return whether this is a (valid) name script. * Return whether this is a (valid) name script.
* @return True iff this is a name operation. * @return True iff this is a name operation.
*/ */
inline bool inline bool isKevaOp() const
isKevaOp () const
{ {
switch (op) { switch (op) {
case OP_KEVA_PUT: case OP_KEVA_PUT:
@ -86,10 +83,10 @@ public:
inline opcodetype getKevaOp() const inline opcodetype getKevaOp() const
{ {
switch (op) { switch (op) {
case OP_KEVA_PUT: case OP_KEVA_PUT:
return op; return op;
case OP_KEVA_NAMESPACE: case OP_KEVA_NAMESPACE:
return op; return op;
default: default:
@ -136,16 +133,15 @@ public:
} }
/** /**
* Return the name operation value. This call is only valid for * Return namespace's display name. This call is only valid for
* OP_KEVA_PUT. * OP_KEVA_NAMESPACE.
* @return The name operation's value. * @return The namespace's display name.
*/ */
inline const valtype& getOpNamespaceValue() const inline const valtype& getOpNamespaceDisplayName() const
{ {
switch (op) { switch (op) {
case OP_KEVA_PUT: case OP_KEVA_NAMESPACE:
// args[1] is namespace return args[1];
return args[2];
default: default:
assert (false); assert (false);
@ -161,10 +157,7 @@ public:
{ {
switch (op) { switch (op) {
case OP_KEVA_PUT: case OP_KEVA_PUT:
return args[0]; return args[1];
case OP_KEVA_NAMESPACE:
return args[0];
default: default:
assert(false); assert(false);
@ -180,7 +173,7 @@ public:
{ {
switch (op) { switch (op) {
case OP_KEVA_PUT: case OP_KEVA_PUT:
// args[1] is namespace // args[0] is namespace, args[1] is key
return args[2]; return args[2];
default: default:

Loading…
Cancel
Save