Skip to content

Commit

Permalink
Merge pull request jl777#258 from VerusCoin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Asherda authored Dec 17, 2019
2 parents 51d3123 + c8674f5 commit fbb532c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/pbaas/identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ bool PrecheckIdentityReservation(const CTransaction &tx, int32_t outNum, CValida
CTxIn idTxIn;
uint32_t priorHeightOut;
CIdentity dupID = newIdentity.LookupIdentity(newIdentity.GetID(), height - 1, &priorHeightOut, &idTxIn);
uint256 inputBlockHash;

CCoinsViewCache view(pcoinsTip);
if (dupID.IsValid())
Expand All @@ -509,13 +510,13 @@ bool PrecheckIdentityReservation(const CTransaction &tx, int32_t outNum, CValida
else
{
CCommitmentHash ch;
int idx = -1;
CTransaction txInput;

// from here, we must spend a matching name commitment
for (auto &oneTxIn : tx.vin)
{
CTransaction txInput;
uint256 blockHash;
if (!myGetTransaction(oneTxIn.prevout.hash, txInput, blockHash))
if (!myGetTransaction(oneTxIn.prevout.hash, txInput, inputBlockHash))
{
return state.Error("Cannot access input");
}
Expand All @@ -532,23 +533,33 @@ bool PrecheckIdentityReservation(const CTransaction &tx, int32_t outNum, CValida
COptCCParams p;
if (txInput.vout[oneTxIn.prevout.n].scriptPubKey.IsPayToCryptoCondition(p) && p.IsValid() && p.evalCode == EVAL_IDENTITY_COMMITMENT && p.vData.size())
{
idx = oneTxIn.prevout.n;
::FromVector(p.vData[0], ch);
break;
}
}

if (ch.hash.IsNull())
CBlockIndex priorBlkIdx = chainActive.
if (idx = -1 || ch.hash.IsNull() || inputBlockHash.IsNull())
{
return state.Error("Invalid identity commitment");
}

auto priorIt = mapBlockIndex.find(inputBlockHash);
if (priorIt == mapBlockIndex.end() || !chainActive.contains(priorIt->second))
{
return state.Error("Identity commitment not in current chain");
}

priorHeightOut = priorIt->second->GetHeight();

// are we spending a matching name commitment?
if (ch.hash != newName.GetCommitment().hash)
{
return state.Error("Mismatched identity commitment");
}

if (!newName.referral.IsNull() && referrals && !(CIdentity::LookupIdentity(newName.referral, coins.nHeight - 1).IsValid()))
if (!newName.referral.IsNull() && referrals && !(CIdentity::LookupIdentity(newName.referral, priorHeightOut - 1).IsValid()))
{
// invalid referral identity
return state.Error("Invalid referral identity specified");
Expand Down

0 comments on commit fbb532c

Please sign in to comment.