5 #include <validation.h> 46 return update(tokenAbi, modified);
59 std::string strBalance;
63 int256_t val(strBalance);
95 wallet(_wallet), first(true) {}
102 int64_t fromBlock = 0;
103 int64_t toBlock = -1;
110 int64_t backInPast = first ? COINBASE_MATURITY : 10;
121 std::map<uint256, CTokenInfo>::iterator mi = wallet->
mapToken.find(tokenHash);
122 found = mi != wallet->
mapToken.end();
126 tokenInfo = mi->second;
141 fromBlock = toBlock - backInPast;
154 std::vector<TokenEvent> tokenEvents;
158 for(
size_t i = 0; i < tokenEvents.size(); i++)
165 tokenTx.
nValue =
event.value;
177 #include <tokenitemmodel.moc> 203 wallet(_wallet), parent(_parent) {}
207 cachedTokenItem.clear();
210 for(std::map<uint256, CTokenInfo>::iterator it = wallet->
mapToken.begin(); it != wallet->
mapToken.end(); ++it)
217 cachedTokenItem.append(tokenItem);
226 QList<TokenItemEntry>::iterator lower = qLowerBound(
228 QList<TokenItemEntry>::iterator upper = qUpperBound(
230 int lowerIndex = (lower - cachedTokenItem.begin());
231 int upperIndex = (upper - cachedTokenItem.begin());
232 bool inModel = (lower != upper);
239 qWarning() <<
"TokenItemPriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
242 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
243 cachedTokenItem.insert(lowerIndex, item);
244 parent->endInsertRows();
249 qWarning() <<
"TokenItemPriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
252 cachedTokenItem[lowerIndex] = item;
258 qWarning() <<
"TokenItemPriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
261 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
262 cachedTokenItem.erase(lower, upper);
263 parent->endRemoveRows();
270 return cachedTokenItem.size();
275 if(idx >= 0 && idx < cachedTokenItem.size())
277 return &cachedTokenItem[idx];
287 QAbstractItemModel(parent),
294 columns << tr(
"Token Name") << tr(
"Token Symbol") << tr(
"Balance");
334 return createIndex(row, column,
priv->
index(row));
336 return QModelIndex();
342 return QModelIndex();
365 case Qt::DisplayRole:
366 switch(index.column())
400 return QString::fromStdString(rec->
balance.str());
420 updated.
SetHex(hash.toStdString());
421 std::map<uint256, CTokenInfo>::iterator mi =
wallet->
mapToken.find(updated);
432 tokenEntry.
hash = updated;
445 bool modified =
false;
456 QString hash = QString::fromStdString(tokenEntry.
hash.
ToString());
457 QMetaObject::invokeMethod(
worker,
"updateTokenTx", Qt::QueuedConnection,
458 Q_ARG(QString, hash));
465 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
473 hash(_hash), status(_status), showToken(_showToken) {}
477 QString strHash = QString::fromStdString(hash.GetHex());
478 qDebug() <<
"NotifyTokenChanged: " + strHash +
" status= " + QString::number(status);
480 QMetaObject::invokeMethod(tim,
"updateToken", Qt::QueuedConnection,
481 Q_ARG(QString, strHash),
483 Q_ARG(
bool, showToken));
496 std::map<uint256, CTokenInfo>::iterator mi = wallet->
mapToken.find(hash);
497 bool showToken = mi != wallet->
mapToken.end();
bool operator()(const uint256 &a, const TokenItemEntry &b) const
std::string strTokenSymbol
std::string strReceiverAddress
CCriticalSection cs_wallet
int rowCount(const QModelIndex &parent=QModelIndex()) const
std::map< uint256, CTokenInfo > mapToken
void invoke(QObject *tim)
std::string strSenderAddress
bool update(Token *tokenAbi)
bool AddTokenEntry(const CTokenInfo &token, bool fFlushOnClose=true)
TokenItemEntry(uint256 tokenHash, CTokenInfo tokenInfo)
bool operator()(const TokenItemEntry &a, const TokenItemEntry &b) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
TokenItemPriv(CWallet *_wallet, TokenItemModel *_parent)
bool operator()(const TokenItemEntry &a, const uint256 &b) const
std::string ToString() const
std::string strContractAddress
void emitDataChanged(int index)
Notify listeners that data changed.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void updateToken(const QString &hash, int status, bool showToken)
ChangeType
General change type (added, updated, removed).
std::string strContractAddress
TokenItemEntry(const TokenItemEntry &obj)
uint256 uint256S(const char *str)
void setAddress(const std::string &address)
void unsubscribeFromCoreSignals()
QModelIndex parent(const QModelIndex &child) const
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
bool transferEvents(std::vector< TokenEvent > &tokenEvents, int64_t fromBlock=0, int64_t toBlock=-1)
TokenItemModel(CWallet *wallet, WalletModel *parent=0)
void subscribeToCoreSignals()
static QString formatToken(int decimal_units, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
void updateEntry(const TokenItemEntry &item, int status)
friend class TokenItemPriv
TokenItemEntry * index(int idx)
void updateTokenTx(const QString &hash)
int columnCount(const QModelIndex &parent=QModelIndex()) const
The block chain is a tree shaped structure starting with the genesis block at the root...
Interface to Fabcoin wallet from Qt view code.
bool update(Token *tokenAbi, bool &modified)
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
bool balanceOf(std::string &result, bool sendTo=false)
void checkTokenBalanceChanged()
std::string strSenderAddress
TokenNotification(uint256 _hash, ChangeType _status, bool _showToken)
QList< TokenItemEntry > cachedTokenItem
void SetHex(const char *psz)
void setSender(const std::string &sender)
TokenTxWorker(CWallet *_wallet)
bool AddTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose=true)
uint256 GetBlockHash() const
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashToken, ChangeType status)> NotifyTokenChanged
Wallet transaction added, removed or updated.