Skip to content

Commit

Permalink
Enabled recognition of time locked transactions as watch only or spen…
Browse files Browse the repository at this point in the history
…dable, depending on time
  • Loading branch information
miketout committed May 3, 2018
1 parent 48d800c commit 90e7502
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ src/komodo-cli
src/komodod
src/komodo-tx
src/komodo-test
src/wallet-utility
2 changes: 1 addition & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CMainParams : public CChainParams {

vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));

fMiningRequiresPeers = true;
//fMiningRequiresPeers = true;
fDefaultConsistencyChecks = false;
fRequireStandard = true;
fMineBlocksOnDemand = false;
Expand Down
Binary file modified src/wallet-utility
Binary file not shown.
30 changes: 22 additions & 8 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
bool fExisted = mapWallet.count(tx.GetHash()) != 0;
if (fExisted && !fUpdate) return false;
auto noteData = FindMyNotes(tx);
if (fExisted || IsMine(tx) || IsFromMe(tx) || noteData.size() > 0)
if (fExisted || IsMineOrWatch(tx) || IsFromMe(tx) || noteData.size() > 0)
{
CWalletTx wtx(this,tx);

Expand Down Expand Up @@ -1458,11 +1458,23 @@ CAmount CWallet::GetChange(const CTxOut& txout) const
return (IsChange(txout) ? txout.nValue : 0);
}

bool CWallet::IsMine(const CTransaction& tx) const
bool CWallet::IsMine(const CTransaction& tx)
{
BOOST_FOREACH(const CTxOut& txout, tx.vout)
if (IsMine(txout))
for (int i = 0; i < tx.vout.size(); i++)
{
if (IsMine(tx, i) == ISMINE_SPENDABLE)
return true;
}
return false;
}

bool CWallet::IsMineOrWatch(const CTransaction& tx)
{
for (int i = 0; i < tx.vout.size(); i++)
{
if (IsMine(tx, i) & ISMINE_ALL)
return true;
}
return false;
}

Expand All @@ -1471,18 +1483,19 @@ bool CWallet::IsMine(const CTransaction& tx) const
isminetype CWallet::IsCLTVMine(CScriptExt &script, CScriptID &scriptID, int64_t locktime)
{
uint8_t pushOp = script.data()[0];
uint32_t scriptStart = pushOp + 2;
uint32_t scriptStart = pushOp + 3;

// check post CLTV script
CScriptExt postfix = CScriptExt(script.size() > scriptStart ? script.begin() + scriptStart : script.end(), script.end());

// check again with postfix subscript
isminetype ret = ::IsMine(*this, postfix);
if (ret != ISMINE_NO)
if (ret == ISMINE_SPENDABLE)
{
// once we get here, we should have this script in our
// wallet, either as watch only if still time locked, or spendable
if (!chainActive.Tip()->nHeight >= locktime)
CBlockIndex &tip = *(chainActive.Tip());
if (!(locktime < LOCKTIME_THRESHOLD ? tip.nHeight >= locktime : tip.GetBlockTime() >= locktime))
{
ret = ISMINE_WATCH_ONLY;
if (!this->HaveWatchOnly(script))
Expand Down Expand Up @@ -1518,7 +1531,7 @@ isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum)
}

CKeyID keyID;
CScriptID scriptID = CScriptID(uint160(vSolutions[0]));
CScriptID scriptID;
CScriptExt subscript;
int voutNext = voutNum + 1;

Expand All @@ -1541,6 +1554,7 @@ isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum)
break;

case TX_SCRIPTHASH:
scriptID = CScriptID(uint160(vSolutions[0]));
if (this->GetCScript(scriptID, subscript))
{
// if this is a CLTV, handle it differently
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
bool IsChange(const CTxOut& txout) const;
CAmount GetChange(const CTxOut& txout) const;
bool IsMine(const CTransaction& tx) const;
bool IsMine(const CTransaction& tx);
bool IsMineOrWatch(const CTransaction& tx);
/** should probably be renamed to IsRelevantToMe */
bool IsFromMe(const CTransaction& tx) const;
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
Expand Down

0 comments on commit 90e7502

Please sign in to comment.