Skip to content

Commit

Permalink
Merge pull request #240 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Tralala
  • Loading branch information
BlockMechanic authored Dec 6, 2022
2 parents 977c8ac + 89d85f7 commit a337346
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.0.78
0.0.0.80
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 21)
define(_CLIENT_VERSION_BUILD, 78)
define(_CLIENT_VERSION_BUILD, 80)
define(_CLIENT_VERSION_RC, )
define(_CLIENT_VERSION_IS_RELEASE, false)
define(_COPYRIGHT_YEAR, 2022)
Expand Down
37 changes: 34 additions & 3 deletions src/consensus/tx_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

#include <consensus/tx_check.h>
#include <logging.h>

#include <contractdb.h>
#include <consensus/consensus.h>
#include <primitives/transaction.h>
#include <consensus/validation.h>
#include <chainparams.h>
#include <key_io.h>

std::string removeSpaces(std::string str)
{
str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
return str;
}

static bool CheckData(TxValidationState &state, const CTxData *p)
{
Expand All @@ -26,6 +33,30 @@ static bool CheckData(TxValidationState &state, const CTxData *p)

static bool CheckContract(TxValidationState &state, const CContract *p)
{
//p.contract_url ;
//p.website_url ;
//p.description ;
//p.scriptcode ;

CTxDestination dest = DecodeDestination(p->sIssuingaddress);
if (!IsValidDestination(dest))
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Invalid Crown address");

if(ExistsContract(p->asset_name))
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Contract name already reserved");

if(p->asset_name == "" || p->asset_symbol == "")
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Contract name or symbol cannot be empty");

if(p->asset_name == p->asset_symbol)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Contract name or symbol cannot match");

if(p->asset_name.length() > 10)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Contract Name too long");

if(p->asset_symbol.length() > 4)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "Contract Symbol too long");

return true;
}

Expand All @@ -34,13 +65,13 @@ bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
// Basic checks that don't depend on any context
if (tx.vin.empty())
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vin-empty");

if (tx.nVersion < TX_ELE_VERSION && tx.vout.empty())
return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("%s , bad-txns-vout-empty, %s", __func__, tx.ToString()));

if(tx.nVersion >= TX_ELE_VERSION && tx.vpout.empty())
return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("%s , bad-txns-vpout-empty, %s", __func__, tx.ToString()));

// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-oversize");
Expand Down
2 changes: 1 addition & 1 deletion src/contractdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CContract GetContract(const std::string& name)
return cCheck;
}

CContract GetContractByHash(uint256 & hash)
CContract GetContractByHash(const uint256 & hash)
{
CContract cCheck;
for(auto const& x : pcontractCache->GetItemsMap()){
Expand Down
2 changes: 1 addition & 1 deletion src/contractdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CContractDB : public CDBWrapper
};

CContract GetContract(const std::string& name);
CContract GetContractByHash(uint256 & hash);
CContract GetContractByHash(const uint256 & hash);
/** Global variable that point to the active assets database (protected by cs_main) */
extern std::unique_ptr<CContractDB> pcontractdb;

Expand Down
10 changes: 6 additions & 4 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
CAmount nPayFee = 0;
CAmount nAfterFee = 0;
CAmount nChange = 0;
CAsset asset = CAsset();
unsigned int nBytes = 0;
unsigned int nBytesInputs = 0;
unsigned int nQuantity = 0;
Expand All @@ -444,6 +445,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *

// Amount
nAmount += out.txout.nValue;
asset = out.txout.nAsset;

// Bytes
CTxDestination address;
Expand Down Expand Up @@ -539,12 +541,12 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *

// stats
l1->setText(QString::number(nQuantity)); // Quantity
l2->setText(CrownUnits::formatWithUnit(nDisplayUnit, nAmount)); // Amount
l3->setText(CrownUnits::formatWithUnit(nDisplayUnit, nPayFee)); // Fee
l4->setText(CrownUnits::formatWithUnit(nDisplayUnit, nAfterFee)); // After Fee
l2->setText(formatAssetAmount(asset, nAmount, nDisplayUnit, CrownUnits::SeparatorStyle::ALWAYS)); // Amount
l3->setText(formatAssetAmount(asset, nPayFee, nDisplayUnit, CrownUnits::SeparatorStyle::ALWAYS) + " " + formatAssetAmount(Params().GetConsensus().subsidy_asset, nPayFee, nDisplayUnit, CrownUnits::SeparatorStyle::ALWAYS)); // Fee
l4->setText(formatAssetAmount(asset, nAfterFee, nDisplayUnit, CrownUnits::SeparatorStyle::ALWAYS)); // After Fee
l5->setText(((nBytes > 0) ? ASYMP_UTF8 : "") + QString::number(nBytes)); // Bytes
l7->setText(fDust ? tr("yes") : tr("no")); // Dust
l8->setText(CrownUnits::formatWithUnit(nDisplayUnit, nChange)); // Change
l8->setText(formatAssetAmount(asset, nChange, nDisplayUnit, CrownUnits::SeparatorStyle::ALWAYS)); // Change
if (nPayFee > 0)
{
l3->setText(ASYMP_UTF8 + l3->text());
Expand Down
37 changes: 36 additions & 1 deletion src/qt/nodemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ NodeManager::NodeManager(const PlatformStyle *_platformStyle, QWidget *parent) :
connect(startAliasAction, SIGNAL(triggered()), this, SLOT(on_startButton_clicked()));
connect(editAction, SIGNAL(triggered()), this, SLOT(on_editButton_clicked()));

connect(startSnAliasAction, SIGNAL(triggered()), this, SLOT(on_startButton_clicked()));
connect(startSnAliasAction, SIGNAL(triggered()), this, SLOT(on_startSnButton_clicked()));
connect(editSnAction, SIGNAL(triggered()), this, SLOT(on_editSnButton_clicked()));

timer = new QTimer(this);
Expand Down Expand Up @@ -550,6 +550,41 @@ void NodeManager::on_startButton_clicked()
StartAlias(strAlias);
}

void NodeManager::on_startSnButton_clicked()
{
// Find selected node alias
QItemSelectionModel* selectionModel = ui->tableWidgetMySystemnodes->selectionModel();
QModelIndexList selected = selectionModel->selectedRows();

if (selected.count() == 0) return;

QModelIndex index = selected.at(0);
int nSelectedRow = index.row();
std::string strAlias = ui->tableWidgetMySystemnodes->item(nSelectedRow, 0)->text().toStdString() ;

// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm node start"),
tr("Are you sure you want to start node %1?").arg(QString::fromStdString(strAlias)),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);

if (retval != QMessageBox::Yes) return;

WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();

if(encStatus == walletModel->Locked) {
WalletModel::UnlockContext ctx(walletModel->requestUnlock());

if (!ctx.isValid()) return; // Unlock wallet was cancelled

StartAlias(strAlias);
return;
}

StartAlias(strAlias);
}


void NodeManager::on_editButton_clicked()
{

Expand Down
1 change: 1 addition & 0 deletions src/qt/nodemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private Q_SLOTS:

void on_filterLineEdit_textChanged(const QString &filterString);
void on_startButton_clicked();
void on_startSnButton_clicked();
void on_editButton_clicked();
void on_editSnButton_clicked();
void on_startAllButton_clicked();
Expand Down
10 changes: 10 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <chainparams.h>
#include <interfaces/node.h>
#include <key_io.h>
#include <contractdb.h>

#include <node/ui_interface.h>
#include <policy/fees.h>
#include <txmempool.h>
Expand Down Expand Up @@ -433,6 +435,14 @@ void SendCoinsDialog::send(const QList<SendAssetsRecipient> &recipients, QString
WalletModelTransaction currentTransaction(recipients);
WalletModel::SendCoinsReturn prepareStatus;
CCoinControl coinControl;

//Restricted assets should always have change set to go to the contract address
for (const SendAssetsRecipient& rcp : recipients){
const CContract &contract = GetContractByHash(rcp.asset.contract_hash);
if(rcp.asset.isRestricted())
coinControl.destChange = DecodeDestination(contract.sIssuingaddress);
}

if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled
prepareStatus = model->prepareTransaction(currentTransaction, coinControl);

Expand Down
9 changes: 9 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <amount.h>
#include <assetdb.h>
#include <contractdb.h>

#include <core_io.h>
#include <interfaces/chain.h>
Expand Down Expand Up @@ -517,6 +518,10 @@ static RPCHelpMan sendtoaddress()
}

CCoinControl coin_control;
const CContract &contract = GetContractByHash(asset.contract_hash);
if(asset.isRestricted())
coin_control.destChange = DecodeDestination(contract.sIssuingaddress);

if (!request.params[6].isNull()) {
coin_control.m_signal_bip125_rbf = request.params[6].get_bool();
}
Expand Down Expand Up @@ -960,6 +965,10 @@ static RPCHelpMan sendmany()
subtractFeeFromAmount = request.params[5].get_array();

CCoinControl coin_control;
const CContract &contract = GetContractByHash(asset.contract_hash);
if(asset.isRestricted())
coin_control.destChange = DecodeDestination(contract.sIssuingaddress);

if (!request.params[6].isNull()) {
coin_control.m_signal_bip125_rbf = request.params[6].get_bool();
}
Expand Down
22 changes: 22 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,8 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmountMap& nFeeRet, int&
if (tx.nVersion >= 3 && tx.nType != TRANSACTION_NORMAL)
extraPayloadSize = (int)tx.extraPayload.size();



// Acquire the locks to prevent races to the new locked unspents between the
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
LOCK(cs_wallet);
Expand Down Expand Up @@ -3285,6 +3287,15 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
return m_default_address_type;
}

void removeSpaces(char *str)
{
int count = 0;
for (int i = 0; str[i]; i++)
if (str[i] != ' ')
str[count++] = str[i];

str[count] = '\0';
}

bool CWallet::CreateContract(CContract& contract, CTransactionRef& tx, std::string& address, std::string& contract_url, std::string& website_url, std::string& description, CScript& script, std::string& name, std::string& shortname, std::string& strFailReason)
{
Expand Down Expand Up @@ -3317,6 +3328,16 @@ bool CWallet::CreateContract(CContract& contract, CTransactionRef& tx, std::stri
return false;
}

if(name.length() > 10) {
strFailReason = "Name too long";
return false;
}

if(shortname.length() > 4) {
strFailReason = "Symbol too long";
return false;
}

CContract newcontract;
newcontract.contract_url = contract_url;
newcontract.website_url = website_url;
Expand Down Expand Up @@ -3984,6 +4005,7 @@ bool CWallet::CreateTransactionInternal(
// Reserve a new key pair from key pool. If it fails, provide a dummy
// destination in case we don't need change.
CTxDestination dest;

if (!reservedest.GetReservedDestination(dest, true)) {
error = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.");
}
Expand Down

0 comments on commit a337346

Please sign in to comment.