Skip to content

Commit

Permalink
Merge pull request #73 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Segwit
  • Loading branch information
BlockMechanic authored Jun 7, 2022
2 parents 7c1157c + 7f6fa6d commit 15d5728
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ class CTestNetParams : public CChainParams {
m_assumed_blockchain_size = 1;
m_assumed_chain_state_size = 1;

genesis = CreateGenesisBlock(1652728167, 313229, 0x1e0ffff0, 1, 10 * COIN, consensus);
genesis = CreateGenesisBlock(1654102950, 194002, 0x1e0ffff0, 1, 10 * COIN, consensus);
consensus.hashGenesisBlock = genesis.GetHash();
//MineNewGenesisBlock(consensus,genesis);
assert(consensus.hashGenesisBlock == uint256S("0x000002e98cb578ba29508547f36cf87f8aee2e94d8fcdd873ac41aa7e8f95e9c"));
assert(consensus.hashGenesisBlock == uint256S("0x00000a25d3a25466f7fae5b6803a68d7a158631111202ec194b37ee17de2401b"));
assert(genesis.hashMerkleRoot == uint256S("0x80ad356118a9ab8db192db66ef77146cc36d958f959251feace550e4ca3d1446"));

vFixedSeeds.clear();
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
for (const auto& txin : wtx.tx->vin) {
result.txin_is_mine.emplace_back(wallet.IsMine(txin));
}
result.txout_is_mine.reserve(wtx.tx->vout.size());
result.txout_address.reserve(wtx.tx->vout.size());
result.txout_address_is_mine.reserve(wtx.tx->vout.size());
for (const auto& txout : wtx.tx->vout) {
result.txout_is_mine.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size());
result.txout_address.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size());
result.txout_address_is_mine.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size());
for(unsigned int i = 0; i < (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()) ; i++){
CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]);

result.txout_is_mine.emplace_back(wallet.IsMine(txout));
result.txout_address.emplace_back();
result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
Expand Down Expand Up @@ -95,7 +97,7 @@ WalletTxOut MakeWalletTxOut(CWallet& wallet,
int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
{
WalletTxOut result;
result.txout = wtx.tx->vout[n];
result.txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[n] : wtx.tx->vout[n]);
result.time = wtx.GetTxTime();
result.depth_in_main_chain = depth;
result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
Expand Down
69 changes: 65 additions & 4 deletions src/qt/forms/sendcoinsentry.ui
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,19 @@
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,0,1,0">
<item>
<widget class="CrownAmountField" name="payAmount">
<property name="toolTip">
<string>The amount to send in the selected unit</string>
</property>
<property name="toolTip">
<string>The amount to send in the selected unit</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="assetBox">
<property name="toolTip">
<string>Select Asset</string>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -358,6 +365,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
Expand Down Expand Up @@ -495,6 +511,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
Expand Down Expand Up @@ -632,6 +657,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
Expand Down Expand Up @@ -869,6 +903,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
Expand Down Expand Up @@ -1015,6 +1058,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
Expand Down Expand Up @@ -1161,6 +1213,15 @@
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="NoBrush">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
Expand Down
7 changes: 5 additions & 2 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
ui->labelBalance->setText(formatMultiAssetAmount(balances.balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelUnconfirmed->setText(formatMultiAssetAmount(balances.unconfirmed_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelImmature->setText(formatMultiAssetAmount(balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelTotal->setText(formatMultiAssetAmount(balances.balance + balances.unconfirmed_balance + balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
CAmountMap nm = balances.balance + balances.unconfirmed_balance + balances.immature_balance;

ui->labelTotal->setText(formatMultiAssetAmount(nm, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelWatchAvailable->setText(formatMultiAssetAmount(balances.watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelWatchPending->setText(formatMultiAssetAmount(balances.unconfirmed_watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelWatchImmature->setText(formatMultiAssetAmount(balances.immature_watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
Expand All @@ -224,7 +226,8 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
ui->labelBalance->setText(formatMultiAssetAmount(balances.balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelUnconfirmed->setText(formatMultiAssetAmount(balances.unconfirmed_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelImmature->setText(formatMultiAssetAmount(balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
ui->labelTotal->setText(formatMultiAssetAmount(balances.balance + balances.unconfirmed_balance + balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
CAmountMap nm = balances.balance + balances.unconfirmed_balance + balances.immature_balance;
ui->labelTotal->setText(formatMultiAssetAmount(nm, unit, CrownUnits::SeparatorStyle::ALWAYS, ""));
}
// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
// for the non-mining users
Expand Down
32 changes: 32 additions & 0 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include <qt/optionsmodel.h>
#include <qt/platformstyle.h>
#include <qt/walletmodel.h>
#include <assetdb.h>

#include <QApplication>
#include <QClipboard>
#include <QStringListModel>

SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
QStackedWidget(parent),
Expand Down Expand Up @@ -57,6 +59,29 @@ SendCoinsEntry::~SendCoinsEntry()
delete ui;
}


void SendCoinsEntry::assetList(){
// Keep up to date with wallet
interfaces::Wallet& wallet = model->wallet();
m_balances = wallet.getBalances();
QStringList list;

for(auto const& x : m_balances.balance){
list << QString::fromStdString(x.first.getName());
}

std::sort(list.begin(), list.end());

QStringListModel *a_model = new QStringListModel();
a_model->setStringList(list);
ui->assetBox->setModel(a_model);
}

void SendCoinsEntry::setBalance(const interfaces::WalletBalances& balances)
{
assetList();
}

void SendCoinsEntry::on_pasteButton_clicked()
{
// Paste text from clipboard into recipient field
Expand Down Expand Up @@ -88,6 +113,8 @@ void SendCoinsEntry::setModel(WalletModel *_model)
if (_model && _model->getOptionsModel())
connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &SendCoinsEntry::updateDisplayUnit);

connect(model, &WalletModel::balanceChanged, this, &SendCoinsEntry::setBalance);

clear();
}

Expand Down Expand Up @@ -172,6 +199,11 @@ SendAssetsRecipient SendCoinsEntry::getValue()
recipient.message = ui->messageTextLabel->text();
recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);

for(auto const& x : passetsCache->GetItemsMap()){
if(QString::fromStdString(x.second->second.asset.getName()) == ui->assetBox->currentText())
recipient.asset = x.second->second.asset;
}

return recipient;
}

Expand Down
6 changes: 6 additions & 0 deletions src/qt/sendcoinsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CROWN_QT_SENDCOINSENTRY_H

#include <qt/sendcoinsrecipient.h>
#include <interfaces/wallet.h>

#include <QStackedWidget>

Expand Down Expand Up @@ -50,6 +51,7 @@ class SendCoinsEntry : public QStackedWidget
QWidget *setupTabChain(QWidget *prev);

void setFocus();
QList<QString> assetListModel;

public Q_SLOTS:
void clear();
Expand All @@ -74,8 +76,12 @@ private Q_SLOTS:
Ui::SendCoinsEntry *ui;
WalletModel *model;
const PlatformStyle *platformStyle;
interfaces::WalletBalances m_balances;

bool updateLabel(const QString &address);
void assetList();
void setBalance(const interfaces::WalletBalances &balances);

};

#endif // CROWN_QT_SENDCOINSENTRY_H
12 changes: 10 additions & 2 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]);

//const CTxOut& txout = wtx.tx->vout[i];
const CAsset& asset = wtx.txout_assets[i];
//const CAsset& asset = wtx.txout_assets[i];
if (txout.IsFee()) {
// explicit fee; ignore
continue;
Expand Down Expand Up @@ -106,8 +106,16 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
}

CAmountMap nChange = wtx.change;
TransactionRecord sub(hash, nTime);
sub.idx = 0;
sub.involvesWatchAddress = involvesWatchAddress;
sub.type = TransactionRecord::SendToSelf;
sub.address = address;
//sub.debit = -nValue;
//sub.credit = -nValue;
parts.append(sub);

//parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, address, (nDebit - nChange) * -1, nCredit - nChange));
parts.last().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument
}
else if (fAllFromMe)
{
Expand Down
Loading

0 comments on commit 15d5728

Please sign in to comment.