Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.0-dev' into 2.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-schmidtke committed Jan 24, 2019
2 parents e788d52 + 42e424a commit e0f34c1
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/core/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ bool AppInit2(boost::thread_group& threadGroup,int OutputPipe)
}
}
LogPrintf("Wallet file exists. WalletDBVersion: %d.\n", currentwalletdatversion);
if( (currentwalletdatversion == 3) && (GetArg("-walletdbversion",0) != 3) )
if( (currentwalletdatversion == 3) && (GetArg("-walletdbversion",MC_TDB_WALLET_VERSION) != 3) )
{
return InitError(_("Wallet downgrade is not allowed"));
}
Expand Down
33 changes: 32 additions & 1 deletion src/rpc/rpchelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3685,7 +3685,7 @@ void mc_InitRPCHelpMap16()
"3. approve (object, required) Approve or disapprove\n"
" {\n"
" \"approve\" : approve (boolean, required) Approve or disapprove\n"
" \"for\" : \"stream-identifier\" (string, required) Stream identifier - one of: create txid, upgrade name.\n"
" \"for\" : \"stream-identifier\" (string, required) Stream identifier - one of: create txid, stream name.\n"
" }\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id.\n"
Expand Down Expand Up @@ -3927,6 +3927,19 @@ void mc_InitRPCHelpMap16()
" \"approve\" : approve (boolean, required) Approve or disapprove\n"
" \"for\" : \"upgrade-identifier\" (string, required) Upgrade identifier - one of: create txid, upgrade name.\n"
" }\n"
" or\n"
"create-new-filter (object, required) A json object with new filter details\n"
" {\n"
" \"create\" : \"filter-type\" (string, required) txfilter or stream filter\n"
" \"name\" : \"filter-name\" (string, optional) Upgrade name\n"
" \"restrictions\" : (object, optional) Only for tx filters\n"
" {\n"
" \"for\": \"entity-identifier\" (string, optional) Asset/stream identifier - one of: create txid, stream reference, stream name.\n"
" or\n"
" \"for\": entity-identifier(s) (array, optional) A json array of asset/stream identifiers .\n"
" }\n"
" \"code\" (string, required) JavaScript filter code, see help filters. Example:\n"
" }\n"
));

mapHelpStrings.insert(std::make_pair("data-with",
Expand Down Expand Up @@ -4045,6 +4058,24 @@ void mc_InitRPCHelpMap16()

" ,...\n"
"}\n"
" or \n"
"{\n"
" \"tx-filter-identifier\": (string, required) Tx Filter identifier - one of: create txid, filter name.\n"
" {\n"
" \"approve\" : approve (boolean, required) Approve or disapprove\n"
" }\n"
"}\n"
" or \n"
"{\n"
" \"stream-filter-identifier\": (string, required) Stream Filter identifier - one of: create txid, filter name.\n"
" {\n"
" \"approve\" : (object, required) \n"
" {\n"
" \"approve\" : approve (boolean, required) Approve or disapprove\n"
" \"for\" : \"stream-identifier\" (string, required) Stream identifier - one of: create txid, stream name.\n"
" }\n"
" }\n"
"}\n"
));

}
Expand Down
152 changes: 151 additions & 1 deletion src/rpc/rpcrawdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using namespace std;
using namespace json_spirit;

void ParseFilterRestrictions(Value param,mc_Script *lpDetailsScript,uint32_t filter_type);

uint32_t ParseRawDataParamType(Value *param,mc_EntityDetails *given_entity,mc_EntityDetails *entity,uint32_t *data_format,int *errorCode,string *strError)
{
uint32_t param_type=MC_DATA_API_PARAM_TYPE_NONE;
Expand Down Expand Up @@ -47,6 +49,14 @@ uint32_t ParseRawDataParamType(Value *param,mc_EntityDetails *given_entity,mc_En
{
this_param_type=MC_DATA_API_PARAM_TYPE_CREATE_UPGRADE;
}
if(d.value_.get_str() == "txfilter")
{
this_param_type=MC_DATA_API_PARAM_TYPE_CREATE_FILTER;
}
if(d.value_.get_str() == "streamfilter")
{
this_param_type=MC_DATA_API_PARAM_TYPE_CREATE_FILTER;
}
}
if(this_param_type == MC_DATA_API_PARAM_TYPE_NONE)
{
Expand Down Expand Up @@ -1053,7 +1063,7 @@ CScript RawDataScriptCreateUpgrade(Value *param,mc_Script *lpDetails,mc_Script *
{
if(!missing_startblock)
{
*strError=string("open field can appear only once in the object");
*strError=string("startblock field can appear only once in the object");
}
if(d.value_.type() == int_type)
{
Expand Down Expand Up @@ -1174,6 +1184,143 @@ CScript RawDataScriptCreateUpgrade(Value *param,mc_Script *lpDetails,mc_Script *
return scriptOpReturn;
}

CScript RawDataScriptCreateFilter(Value *param,mc_Script *lpDetails,mc_Script *lpDetailsScript,int *errorCode,string *strError)
{
CScript scriptOpReturn=CScript();
bool field_parsed;
size_t bytes;
const unsigned char *script;
string entity_name;
uint32_t filter_type=MC_FLT_TYPE_TX;

bool missing_name=true;
bool missing_code=true;
bool missing_for=true;

lpDetails->Clear();
lpDetails->AddElement();

lpDetailsScript->Clear();
lpDetailsScript->AddElement();

BOOST_FOREACH(const Pair& d, param->get_obj())
{
field_parsed=false;
if(d.name_ == "name")
{
if(!missing_name)
{
*strError=string("open field can appear only once in the object");
}
if(d.value_.type() != null_type && !d.value_.get_str().empty())
{
entity_name=d.value_.get_str();
if(entity_name.size())
{
if(entity_name.size() > MC_ENT_MAX_NAME_SIZE)
{
*strError=string("Invalid filter name - too long");
}
lpDetails->SetSpecialParamValue(MC_ENT_SPRM_NAME,(const unsigned char*)(entity_name.c_str()),entity_name.size());
}
}
else
{
*strError=string("Invalid name");
}
missing_name=false;
field_parsed=true;
}
if(d.name_ == "restrictions")
{
if(!missing_for)
{
*strError=string("restrictions field can appear only once in the object");
}

ParseFilterRestrictions(d.value_,lpDetailsScript,MC_FLT_TYPE_TX);

script = lpDetailsScript->GetData(0,&bytes);

if(bytes)
{
lpDetails->SetSpecialParamValue(MC_ENT_SPRM_FILTER_RESTRICTIONS,script,bytes);
}

missing_for=false;
field_parsed=true;
}

if(d.name_ == "code")
{
if(!missing_code)
{
*strError=string("code field can appear only once in the object");
}
if(d.value_.type() == str_type)
{
lpDetails->SetSpecialParamValue(MC_ENT_SPRM_FILTER_CODE,(unsigned char*)d.value_.get_str().c_str(),d.value_.get_str().size());
}
else
{
*strError=string("Invalid code field type");
}
missing_code=false;
field_parsed=true;
}
if(d.name_ == "create")
{
if (strcmp(d.value_.get_str().c_str(),"streamfilter") == 0)
{
filter_type=MC_FLT_TYPE_STREAM;
}
lpDetails->SetSpecialParamValue(MC_ENT_SPRM_FILTER_TYPE,(unsigned char*)&filter_type,4);


field_parsed=true;
}
if(!field_parsed)
{
*strError=strprintf("Invalid field: %s",d.name_.c_str());
}
}

if(strError->size() == 0)
{
if(filter_type != MC_FLT_TYPE_TX)
{
if(!missing_for)
{
*strError=string("restrictions field is allowed only for tx filters");
*errorCode=RPC_NOT_ALLOWED;
}
}

if(missing_code)
{
*strError=string("Missing code");
}
}

if(strError->size() == 0)
{
int err;
script=lpDetails->GetData(0,&bytes);
lpDetailsScript->Clear();
err=lpDetailsScript->SetNewEntityType(MC_ENT_TYPE_FILTER,0,script,bytes);
if(err)
{
*strError=string("Invalid code, too long");
}
else
{
script = lpDetailsScript->GetData(0,&bytes);
scriptOpReturn << vector<unsigned char>(script, script + bytes) << OP_DROP << OP_RETURN;
}
}

return scriptOpReturn;
}

CScript RawDataScriptPublish(Value *param,mc_EntityDetails *entity,uint32_t *data_format,mc_Script *lpDetailsScript,vector<uint256>* vChunkHashes,int *errorCode,string *strError)
{
Expand Down Expand Up @@ -1618,6 +1765,9 @@ CScript ParseRawMetadata(Value param,uint32_t allowed_objects,mc_EntityDetails *
case MC_DATA_API_PARAM_TYPE_CREATE_UPGRADE:
scriptOpReturn=RawDataScriptCreateUpgrade(&param,lpDetails,lpDetailsScript,&errorCode,&strError);
break;
case MC_DATA_API_PARAM_TYPE_CREATE_FILTER:
scriptOpReturn=RawDataScriptCreateFilter(&param,lpDetails,lpDetailsScript,&errorCode,&strError);
break;
case MC_DATA_API_PARAM_TYPE_APPROVAL:
scriptOpReturn=RawDataScriptApprove(&param,&entity,lpDetailsScript,&errorCode,&strError);
break;
Expand Down
Loading

0 comments on commit e0f34c1

Please sign in to comment.