2015-09-24 07:15:28 +02:00
|
|
|
#include "nameclaim.h"
|
2015-02-03 02:57:53 +01:00
|
|
|
#include "util.h"
|
2015-01-15 01:17:19 +01:00
|
|
|
|
2015-09-24 07:15:28 +02:00
|
|
|
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
CScript::const_iterator pc = scriptIn.begin();
|
2015-09-24 07:15:28 +02:00
|
|
|
return DecodeClaimScript(scriptIn, op, vvchParams, pc);
|
2015-01-15 01:17:19 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 07:15:28 +02:00
|
|
|
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
opcodetype opcode;
|
|
|
|
if (!scriptIn.GetOp(pc, opcode))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-25 23:09:21 +02:00
|
|
|
|
|
|
|
if (opcode != OP_CLAIM_NAME && opcode != OP_SUPPORT_CLAIM)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
op = opcode;
|
|
|
|
|
2015-09-25 23:09:21 +02:00
|
|
|
std::vector<unsigned char> vchParam1;
|
|
|
|
std::vector<unsigned char> vchParam2;
|
|
|
|
std::vector<unsigned char> vchParam3;
|
|
|
|
// Valid formats:
|
|
|
|
// OP_CLAIM_NAME vchName vchValue OP_2DROP OP_DROP pubkeyscript
|
|
|
|
// OP_SUPPORT_CLAIM vchName vchClaimHash vchClaimIndex OP_2DROP OP_2DROP pubkeyscript
|
2015-01-15 01:17:19 +01:00
|
|
|
// All others are invalid.
|
|
|
|
|
2015-09-25 23:09:21 +02:00
|
|
|
|
|
|
|
if (!scriptIn.GetOp(pc, opcode, vchParam1) || opcode < 0 || opcode > OP_PUSHDATA4)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-25 23:09:21 +02:00
|
|
|
if (!scriptIn.GetOp(pc, opcode, vchParam2) || opcode < 0 || opcode > OP_PUSHDATA4)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-25 23:09:21 +02:00
|
|
|
if (op == OP_SUPPORT_CLAIM)
|
|
|
|
{
|
|
|
|
if (!scriptIn.GetOp(pc, opcode) || opcode < 0 || opcode > OP_PUSHDATA4)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 01:17:19 +01:00
|
|
|
if (!scriptIn.GetOp(pc, opcode) || opcode != OP_2DROP)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-25 23:09:21 +02:00
|
|
|
if (!scriptIn.GetOp(pc, opcode) || (op == OP_CLAIM_NAME && opcode != OP_DROP) || (op == OP_SUPPORT_CLAIM && opcode != OP_2DROP))
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:09:21 +02:00
|
|
|
vvchParams.push_back(vchParam1);
|
|
|
|
vvchParams.push_back(vchParam2);
|
|
|
|
if (op == OP_SUPPORT_CLAIM)
|
|
|
|
{
|
|
|
|
vvchParams.push_back(vchParam3);
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:17:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-24 07:15:28 +02:00
|
|
|
CScript StripClaimScriptPrefix(const CScript& scriptIn)
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
int op;
|
|
|
|
std::vector<std::vector<unsigned char> > vvchParams;
|
|
|
|
CScript::const_iterator pc = scriptIn.begin();
|
|
|
|
|
2015-09-24 07:15:28 +02:00
|
|
|
if (!DecodeClaimScript(scriptIn, op, vvchParams, pc))
|
2015-01-15 01:17:19 +01:00
|
|
|
{
|
|
|
|
return scriptIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CScript(pc, scriptIn.end());
|
|
|
|
}
|
2015-01-30 16:10:36 +01:00
|
|
|
|