Skip to content

Commit

Permalink
Merge pull request #125 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Less
  • Loading branch information
BlockMechanic authored Oct 8, 2022
2 parents 158ee31 + 03d2324 commit 8c48654
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/masternode/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool CMasternodePayments::CanVote(COutPoint outMasternode, int nBlockHeight)
return true;
}

void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment)
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment)
{
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if(!pindexPrev) return;
Expand All @@ -160,12 +160,12 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
}
}

void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasPayment)
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment)
{
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if(!pindexPrev) return;

//bool hasPayment = true;
bool hasPayment = true;
CScript payee;

//spork
Expand Down Expand Up @@ -206,6 +206,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe

LogPrint(BCLog::NET, "Masternode payment to %s\n", EncodeDestination(address1));
}
hasMNPayment = hasPayment;
}

int CMasternodePayments::GetMinMasternodePaymentsProto() {
Expand Down
4 changes: 2 additions & 2 deletions src/masternode/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool IsReferenceNode(CTxIn& vin);
bool IsBlockPayeeValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
std::string GetRequiredPaymentsString(int nBlockHeight);
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment);

class CMasternodePayee
{
Expand Down Expand Up @@ -224,7 +224,7 @@ class CMasternodePayments
int GetMinMasternodePaymentsProto();
void ProcessMessageMasternodePayments(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment);
std::string ToString() const;
int GetOldestBlock();
int GetNewestBlock();
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc

// Masternode and general budget payments
if (IsSporkActive(SPORK_4_ENABLE_MASTERNODE_PAYMENTS) || Params().NetworkIDString() == CBaseChainParams::TESTNET) {
bool hasMNPayment =true;
bool hasMNPayment = true;
FillBlockPayee(coinbaseTx, nFees, hasMNPayment);
SNFillBlockPayee(coinbaseTx, nFees, hasMNPayment);
}
Expand Down
4 changes: 2 additions & 2 deletions src/systemnode/systemnode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ bool CSystemnodePayments::CanVote(COutPoint outSystemnode, int nBlockHeight)
return true;
}

void SNFillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment)
void SNFillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment)
{
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if (!pindexPrev)
Expand All @@ -204,7 +204,7 @@ std::string SNGetRequiredPaymentsString(int nBlockHeight)
}
}

void CSystemnodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment)
void CSystemnodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment)
{
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if(!pindexPrev) return;
Expand Down
4 changes: 2 additions & 2 deletions src/systemnode/systemnode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern CSystemnodePayments systemnodePayments;
#define SNPAYMENTS_SIGNATURES_TOTAL 10
#define SN_PMT_SLOT 2

void SNFillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment);
void SNFillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment);
bool SNIsBlockPayeeValid(const CAmount& nValueCreated, const CTransaction& txNew, int nBlockHeight, const uint32_t& nTime, const uint32_t& nTimePrevBlock);
std::string SNGetRequiredPaymentsString(int nBlockHeight);

Expand Down Expand Up @@ -216,7 +216,7 @@ class CSystemnodePayments
bool IsScheduled(CSystemnode& sn, int nNotBlockHeight);
bool CanVote(COutPoint outSystemnode, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool hasMNPayment);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees, bool &hasMNPayment);
std::string ToString() const;

SERIALIZE_METHODS(CSystemnodePayments, obj)
Expand Down
59 changes: 52 additions & 7 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,7 @@ bool CWallet::CreateContract(CContract& contract, CTransactionRef& tx, std::stri
cctl.m_avoid_address_reuse = false;
cctl.m_min_depth = 1;
cctl.m_max_depth = 9999999;
AvailableCoins(vecOutputs, false, &cctl, 0, nAmount, MAX_MONEY, 0);
AvailableCoins(vecOutputs, false, &cctl, 0, MAX_MONEY, MAX_MONEY, 0);
}

for (const COutput& out : vecOutputs) {
Expand Down Expand Up @@ -3320,7 +3320,7 @@ bool CWallet::CreateContract(CContract& contract, CTransactionRef& tx, std::stri

mapValue_t mapValue;

//coin_control.m_add_inputs = false;
coin_control.m_add_inputs = false;
std::vector<CRecipient> recipients;

CRecipient recipient = {Params().GetConsensus().mandatory_coinbase_destination, nAmount, 0, asset, CAsset(), false, false};
Expand Down Expand Up @@ -3406,19 +3406,64 @@ bool CWallet::CreateAsset(CAsset& asset, CTransactionRef& tx, std::string& asset

CAsset assetNew = CAsset(meta);

std::vector<CRecipient> recipients;

CRecipient recipient = {GetScriptForDestination(DecodeDestination(contract.sIssuingaddress)), outputamt/100, outputamt, Params().GetConsensus().subsidy_asset, assetNew, false, true};
recipients.push_back(recipient);

// Send
CAmount nFeeRequired;
int nChangePosRet = -1;
bilingual_str error;
FeeCalculation fee_calc_out;
CCoinControl coin_control;
CTxDestination dest = DecodeDestination(contract.sIssuingaddress);

std::vector<COutput> vecOutputs;
{
CCoinControl cctl;
cctl.m_avoid_address_reuse = false;
cctl.m_min_depth = 1;
cctl.m_max_depth = 9999999;
AvailableCoins(vecOutputs, false, &cctl, 0, MAX_MONEY, MAX_MONEY, 0);
}

for (const COutput& out : vecOutputs) {
CTxDestination address;
const CScript& scriptPubKey = (out.tx->tx->nVersion >= TX_ELE_VERSION ? out.tx->tx->vpout[out.i].scriptPubKey : out.tx->tx->vout[out.i].scriptPubKey) ;
bool fValidAddress = ExtractDestination(scriptPubKey, address);

if(std::get<PKHash>(dest) != std::get<PKHash>(address))
continue;

if (!fValidAddress)
continue;

// Elements
CAmount amount = (out.tx->tx->nVersion >= TX_ELE_VERSION ? out.tx->tx->vpout[out.i].nValue : out.tx->tx->vout[out.i].nValue) ;
CAsset assetid;
if(out.tx->tx->nVersion >= TX_ELE_VERSION)
assetid = out.tx->tx->vpout[out.i].nAsset;

if ((amount < 0 || assetid.IsNull())) {
WalletLogPrintf("Bad amount or asset: %s:%d\n", out.tx->tx->GetHash().GetHex(), out.i);
continue;
}

if (assetid != Params().GetConsensus().subsidy_asset) {
continue;
}

coin_control.Select(COutPoint(out.tx->GetHash(), out.i));
}

if(coin_control.setSelected.size() < 1){
strFailReason ="No suitable output found";
return false;
}

mapValue_t mapValue;
coin_control.m_add_inputs = false;

std::vector<CRecipient> recipients;

CRecipient recipient = {GetScriptForDestination(dest), inputamt, outputamt, Params().GetConsensus().subsidy_asset, assetNew, false, true};
recipients.push_back(recipient);

bool fCreated = CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, !IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
if (!fCreated) {
Expand Down

0 comments on commit 8c48654

Please sign in to comment.