Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.0-release' into 2.0-release
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-schmidtke committed Apr 10, 2019
2 parents ce25414 + fceed91 commit 6d21f0f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 27 deletions.
69 changes: 48 additions & 21 deletions src/rpc/rpcstreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Value liststreams(const Array& params, bool fHelp)
if(streams == NULL)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot open entity database");

output_level=0x1E;
output_level=0x9E;

if (params.size() > 1)
{
Expand Down Expand Up @@ -1108,7 +1108,7 @@ Value subscribe(const Array& params, bool fHelp)
}

// Whether to perform rescan after import
bool fRescan = true;
bool fRescan = true;
string indexes="all";

if (params.size() > 1)
Expand Down Expand Up @@ -1176,6 +1176,13 @@ Value subscribe(const Array& params, bool fHelp)
fNewFound=true;
}
}
else
{
if (params.size() > 2)
{
throw JSONRPCError(RPC_NOT_ALLOWED, "Subscription parameters can be specified only for streams");
}
}

if(lpEntity->GetEntityType() == MC_ENT_TYPE_ASSET)
{
Expand Down Expand Up @@ -1613,11 +1620,11 @@ Value liststreamblockitems(const Array& params, bool fHelp)
}


void getSubKeyEntityFromKey(string str,mc_TxEntityStat entStat,mc_TxEntity *entity)
bool getSubKeyEntityFromKey(string str,mc_TxEntityStat entStat,mc_TxEntity *entity,bool ignore_unsubscribed)
{
if(str == "*")
{
return;
return false;
}
uint160 key_string_hash;
uint160 stream_subkey_hash;
Expand All @@ -1627,15 +1634,21 @@ void getSubKeyEntityFromKey(string str,mc_TxEntityStat entStat,mc_TxEntity *enti
entity->m_EntityType=entStat.m_Entity.m_EntityType | MC_TET_SUBKEY;
if(pEF->STR_IsIndexSkipped(NULL,&(entStat.m_Entity),entity))
{
if(ignore_unsubscribed)
{
return false;
}
CheckWalletError(MC_ERR_NOT_ALLOWED);
}

return true;
}

void getSubKeyEntityFromPublisher(string str,mc_TxEntityStat entStat,mc_TxEntity *entity)
bool getSubKeyEntityFromPublisher(string str,mc_TxEntityStat entStat,mc_TxEntity *entity,bool ignore_unsubscribed)
{
if(str == "*")
{
return;
return false;
}
uint160 stream_subkey_hash;
CBitcoinAddress address(str);
Expand Down Expand Up @@ -1664,10 +1677,17 @@ void getSubKeyEntityFromPublisher(string str,mc_TxEntityStat entStat,mc_TxEntity

memcpy(entity->m_EntityID,&stream_subkey_hash,MC_TDB_ENTITY_ID_SIZE);
entity->m_EntityType=entStat.m_Entity.m_EntityType | MC_TET_SUBKEY;

if(pEF->STR_IsIndexSkipped(NULL,&(entStat.m_Entity),entity))
{
if(ignore_unsubscribed)
{
return false;
}
CheckWalletError(MC_ERR_NOT_ALLOWED);
}

return true;
}

Value getstreamsummary(const Array& params, bool fPublisher)
Expand Down Expand Up @@ -1703,12 +1723,12 @@ Value getstreamsummary(const Array& params, bool fPublisher)

if(fPublisher)
{
getSubKeyEntityFromPublisher(params[1].get_str(),entStat,&entity);
getSubKeyEntityFromPublisher(params[1].get_str(),entStat,&entity,false);
conditions.push_back(mc_QueryCondition(MC_QCT_PUBLISHER,params[1].get_str()));
}
else
{
getSubKeyEntityFromKey(params[1].get_str(),entStat,&entity);
getSubKeyEntityFromKey(params[1].get_str(),entStat,&entity,false);
conditions.push_back(mc_QueryCondition(MC_QCT_KEY,params[1].get_str()));
}

Expand Down Expand Up @@ -2063,7 +2083,7 @@ Value liststreamkeyitems(const Array& params, bool fHelp)
}

string key_string=params[1].get_str();
getSubKeyEntityFromKey(params[1].get_str(),entStat,&entity);
getSubKeyEntityFromKey(params[1].get_str(),entStat,&entity,false);

vector <mc_QueryCondition> conditions;

Expand Down Expand Up @@ -2168,7 +2188,7 @@ Value liststreampublisheritems(const Array& params, bool fHelp)
}

string key_string=params[1].get_str();
getSubKeyEntityFromPublisher(params[1].get_str(),entStat,&entity);
getSubKeyEntityFromPublisher(params[1].get_str(),entStat,&entity,false);

vector <mc_QueryCondition> conditions;

Expand Down Expand Up @@ -2412,11 +2432,11 @@ Value liststreamkeys_or_publishers(const Array& params,bool is_publishers)

if(is_publishers)
{
getSubKeyEntityFromPublisher(str,entStat,&entity);
getSubKeyEntityFromPublisher(str,entStat,&entity,false);
}
else
{
getSubKeyEntityFromKey(str,entStat,&entity);
getSubKeyEntityFromKey(str,entStat,&entity,false);
}
inputEntities.push_back(entity);
}
Expand Down Expand Up @@ -2491,17 +2511,18 @@ int GetAndQueryDirtyList(vector<mc_QueryCondition>& conditions, mc_EntityDetails
vConditionMerged[i]=0;

entStat.m_Entity.m_EntityType &= MC_TET_ORDERMASK;
bool index_found=true;
if(i<conditions_count)
{
switch(conditions[i].m_Type)
{
case MC_QCT_KEY:
entStat.m_Entity.m_EntityType |= MC_TET_STREAM_KEY;
getSubKeyEntityFromKey(conditions[i].m_Value,entStat,&vConditionEntities[i]);
index_found=getSubKeyEntityFromKey(conditions[i].m_Value,entStat,&vConditionEntities[i],true);
break;
case MC_QCT_PUBLISHER:
entStat.m_Entity.m_EntityType |= MC_TET_STREAM_PUBLISHER;
getSubKeyEntityFromPublisher(conditions[i].m_Value,entStat,&vConditionEntities[i]);
index_found=getSubKeyEntityFromPublisher(conditions[i].m_Value,entStat,&vConditionEntities[i],true);
break;
}
}
Expand All @@ -2510,12 +2531,15 @@ int GetAndQueryDirtyList(vector<mc_QueryCondition>& conditions, mc_EntityDetails
entStat.m_Entity.m_EntityType |= MC_TET_STREAM;
memcpy(&vConditionEntities[i],&entStat.m_Entity,sizeof(mc_TxEntity));
}
if(vConditionEntities[i].m_EntityType)
if(index_found)
{
vConditionListSizes[i]=pwalletTxsMain->GetListSize(&vConditionEntities[i],entStat.m_Generation,NULL);
if(vConditionListSizes[i]>max_size)
if(vConditionEntities[i].m_EntityType)
{
max_size=vConditionListSizes[i];
vConditionListSizes[i]=pwalletTxsMain->GetListSize(&vConditionEntities[i],entStat.m_Generation,NULL);
if(vConditionListSizes[i]>max_size)
{
max_size=vConditionListSizes[i];
}
}
}
}
Expand All @@ -2531,10 +2555,13 @@ int GetAndQueryDirtyList(vector<mc_QueryCondition>& conditions, mc_EntityDetails
{
if(vConditionMerged[i] == 0)
{
if(vConditionListSizes[i]<=min_size)
if(vConditionListSizes[i] > 0)
{
min_size=vConditionListSizes[i];
min_condition=i;
if(vConditionListSizes[i]<=min_size)
{
min_size=vConditionListSizes[i];
min_condition=i;
}
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/rpc/rpcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void CheckWalletError(int err)
throw JSONRPCError(RPC_NOT_SUPPORTED, "This feature is not supported in this build");
break;
case MC_ERR_NOT_ALLOWED:
throw JSONRPCError(RPC_NOT_SUPPORTED, "The index required for this API is not built for this subscription.");
throw JSONRPCError(RPC_NOT_SUPPORTED, "The index required is not available for this subscription.");
break;
case MC_ERR_INTERNAL_ERROR:
throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal wallet error");
Expand Down Expand Up @@ -1004,14 +1004,17 @@ Object StreamEntry(const unsigned char *txid,uint32_t output_level,mc_EntityDeta
bool fSynchronized=true;
if(pEF->ENT_EditionNumeric() == 0)
{
mc_TxEntityStat entStatTmp;
entStatTmp.Zero();
memcpy(&entStatTmp,entity.GetTxID()+MC_AST_SHORT_TXID_OFFSET,MC_AST_SHORT_TXID_SIZE);
for(unsigned int ind=1;ind<index_types.size();ind++)
{
if(fSynchronized)
{
entStat.m_Entity.m_EntityType=index_types[ind].second;
if(pwalletTxsMain->FindEntity(&entStat))
entStatTmp.m_Entity.m_EntityType=index_types[ind].second;
if(pwalletTxsMain->FindEntity(&entStatTmp))
{
if( (entStat.m_Flags & MC_EFL_NOT_IN_SYNC) != 0)
if( (entStatTmp.m_Flags & MC_EFL_NOT_IN_SYNC) != 0)
{
fSynchronized=false;
}
Expand Down Expand Up @@ -4225,7 +4228,14 @@ vector<int> ParseBlockSetIdentifier(Value blockset_identifier)
else
{
vector<string> inputStrings;
inputStrings=ParseStringList(blockset_identifier);
if(blockset_identifier.type() == int_type)
{
inputStrings.push_back(strprintf("%d",blockset_identifier.get_int()));
}
else
{
inputStrings=ParseStringList(blockset_identifier);
}

for(unsigned int i=0;i<inputStrings.size();i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/version/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int mc_State::VersionInfo(int version)
return custom_version;
}

int this_build=20000901;
int this_build=20001901;
int this_protocol=20009;

if(version < 0)
Expand Down

0 comments on commit 6d21f0f

Please sign in to comment.