Skip to content

Commit

Permalink
Fix issue #2 - Expired names are now displayed as 'expired' in name_l…
Browse files Browse the repository at this point in the history
…ist, name_scan and name_history
  • Loading branch information
khalahan committed Nov 1, 2011
1 parent 0044518 commit 3e3a016
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/namecoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ Value name_list(const Array& params, bool fHelp)
oName.push_back(Pair("value", value));
if (!hooks->IsMine(pwalletMain->mapWallet[hash]))
oName.push_back(Pair("transferred", 1));
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
int op;
int nOut;
vector<vector<unsigned char> > vvch;
Expand All @@ -530,6 +529,14 @@ Value name_list(const Array& params, bool fHelp)
const CTxOut& txout = tx.vout[nOut];
const CScript& scriptPubKey = RemoveNameScriptPrefix(txout.scriptPubKey);
oName.push_back(Pair("address", scriptPubKey.GetBitcoinAddress()));
if(nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight <= 0)
{
oName.push_back(Pair("expired", 1));
}
else
{
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
}
oRes.push_back(oName);
}
}
Expand Down Expand Up @@ -642,14 +649,21 @@ Value name_history(const Array& params, bool fHelp)
string value = stringFromVch(vchValue);
oName.push_back(Pair("value", value));
oName.push_back(Pair("txid", tx.GetHash().GetHex()));
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
int op;
int nOut;
vector<vector<unsigned char> > vvch;
DecodeNameTx(tx, op, nOut, vvch);
const CTxOut& txout = tx.vout[nOut];
const CScript& scriptPubKey = RemoveNameScriptPrefix(txout.scriptPubKey);
oName.push_back(Pair("address", scriptPubKey.GetBitcoinAddress()));
if(nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight <= 0)
{
oName.push_back(Pair("expired", 1));
}
else
{
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
}
oRes.push_back(oName);
}
}
Expand Down Expand Up @@ -696,12 +710,17 @@ Value name_scan(const Array& params, bool fHelp)
vector<unsigned char> vchValue;
int nHeight;
uint256 hash;
if (!txPos.IsNull() && GetValueOfTxPos(txPos, vchValue, hash, nHeight))
if (txPos.IsNull() ||
!GetValueOfTxPos(txPos, vchValue, hash, nHeight) ||
(GetValueOfTxPos(txPos, vchValue, hash, nHeight) && nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight <= 0))
{
oName.push_back(Pair("expired", 1));
}
else
{
string value = stringFromVch(vchValue);
oName.push_back(Pair("value", value));
oName.push_back(Pair("txid", hash.GetHex()));
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
int op;
int nOut;
vector<vector<unsigned char> > vvch;
Expand All @@ -711,10 +730,7 @@ Value name_scan(const Array& params, bool fHelp)
const CTxOut& txout = tx.vout[nOut];
const CScript& scriptPubKey = RemoveNameScriptPrefix(txout.scriptPubKey);
oName.push_back(Pair("address", scriptPubKey.GetBitcoinAddress()));
}
else
{
oName.push_back(Pair("expired", 1));
oName.push_back(Pair("expires_in", nHeight + GetDisplayExpirationDepth(nHeight) - pindexBest->nHeight));
}
oRes.push_back(oName);
}
Expand Down

0 comments on commit 3e3a016

Please sign in to comment.