Skip to content

Commit

Permalink
fixup! CA: Use fee asset instead of BITCOINID
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimon authored and instagibbs committed Jun 16, 2017
1 parent 745194e commit 0f79b48
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vout[0].nAsset = BITCOINID;
coinbaseTx.vout[0].nValue = nFees;
coinbaseTx.vout[0].nAsset = policyAsset;
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
Expand Down
3 changes: 2 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "primitives/transaction.h"
#include "init.h"
#include "policy/policy.h"
#include "policy/policy.h"
#include "protocol.h"
#include "script/script.h"
#include "script/standard.h"
Expand Down Expand Up @@ -256,7 +257,7 @@ bool isDust(const QString& address, const CAmount& amount)
{
CTxDestination dest = CBitcoinAddress(address.toStdString()).Get();
CScript script = GetScriptForDestination(dest);
CTxOut txOut(BITCOINID, amount, script);
CTxOut txOut(policyAsset, amount, script);
return txOut.IsDust(dustRelayFee);
}

Expand Down
6 changes: 3 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C

if (!tx.HasValidFee())
return state.DoS(0, false, REJECT_INVALID, "bad-fees");
CAmount nFees = tx.GetFee()[BITCOINID];
CAmount nFees = tx.GetFee()[policyAsset];

// nModifiedFees includes any fee deltas from PrioritiseTransaction
CAmount nModifiedFees = nFees;
Expand Down Expand Up @@ -2608,7 +2608,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!VerifyCoinbaseAmount(*(block.vtx[0]), blockReward))
return state.DoS(100,
error("ConnectBlock(): coinbase pays too much (limit=%d)",
blockReward[BITCOINID]),
blockReward[policyAsset]),
REJECT_INVALID, "bad-cb-amount");

//Don't DoS ban in case of RPC script check failure
Expand Down Expand Up @@ -3663,7 +3663,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
CHash256().Write(witnessroot.begin(), 32).Write(&ret[0], 32).Finalize(witnessroot.begin());
CTxOut out;
out.nValue = 0;
out.nAsset = BITCOINID;
out.nAsset = policyAsset;
out.scriptPubKey.resize(38);
out.scriptPubKey[0] = OP_RETURN;
out.scriptPubKey[1] = 0x24;
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "validation.h"
#include "net.h"
#include "policy/policy.h"
#include "policy/policy.h"
#include "policy/rbf.h"
#include "primitives/bitcoin/merkleblock.h"
#include "primitives/bitcoin/transaction.h"
Expand Down Expand Up @@ -406,7 +407,7 @@ static void SendMoney(const CScript& scriptPubKey, CAmount nValue, CAsset asset,
vChangeKey.reserve(2);
vChangeKey.emplace_back(pwalletMain);
vpChangeKey.push_back(&vChangeKey[0]);
if (pwalletMain->GetAssetFromLabel("bitcoin") != asset) {
if (policyAsset != asset) {
vChangeKey.emplace_back(pwalletMain);
vpChangeKey.push_back(&vChangeKey[1]);
}
Expand Down Expand Up @@ -1061,7 +1062,7 @@ UniValue sendmany(const JSONRPCRequest& request)
std::vector<CReserveKey> vChangeKey;
std::vector<CReserveKey*> vpChangeKey;
std::set<CAsset> setAssets;
setAssets.insert(pwalletMain->GetAssetFromLabel("bitcoin"));
setAssets.insert(policyAsset);
for (auto recipient : vecSend) {
setAssets.insert(recipient.asset);
}
Expand Down Expand Up @@ -1975,9 +1976,9 @@ UniValue gettransaction(const JSONRPCRequest& request)
CAmountMap nCredit = wtx.GetCredit(filter);
CAmountMap nDebit = wtx.GetDebit(filter);
assert(wtx.tx->HasValidFee());
CAmount nFee = (wtx.IsFromMe(filter) ? -wtx.tx->GetFee()[BITCOINID] : 0);
CAmount nFee = (wtx.IsFromMe(filter) ? -wtx.tx->GetFee()[policyAsset] : 0);
CAmountMap nNet = nCredit - nDebit;
nNet[pwalletMain->GetAssetFromLabel("bitcoin")] -= nFee;
nNet[policyAsset] -= nFee;

entry.push_back(Pair("amount", PushAssetBalance(nNet, pwalletMain, strasset)));
if (wtx.IsFromMe(filter))
Expand Down
26 changes: 12 additions & 14 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,13 +1475,13 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
CAmountMap nDebit = GetDebit(filter);
if (nDebit > CAmountMap()) // debit>0 means we signed/sent this transaction
{
nFee = tx->GetFee()[BITCOINID];
nFee = tx->GetFee()[policyAsset];
}

CTxDestination addressUnaccounted = CNoDestination();
int voutUnaccounted = -1;
CAmountMap nValueUnaccounted = nDebit;
nValueUnaccounted[BITCOINID] -= nFee;
nValueUnaccounted[policyAsset] -= nFee;
int nUnaccountedOutputs = 0;

// Sent/received.
Expand Down Expand Up @@ -2352,7 +2352,7 @@ bool CWallet::SelectCoinsMinConf(const CAmountMap& mapTargetValue, const int nCo

// TODO Remove dust rule, remove need for this
CAmountMap mapTargetValuePlusMinChange = mapTargetValue;
mapTargetValuePlusMinChange[GetAssetFromLabel("bitcoin")] += MIN_CHANGE;
mapTargetValuePlusMinChange[policyAsset] += MIN_CHANGE;

BOOST_FOREACH(const COutput &output, vCoins)
{
Expand Down Expand Up @@ -2567,8 +2567,8 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov
setAssets.insert(txOut.nAsset.GetAsset());
}
}
// Always add bitcoin, as fees via bitcoin may create change
if (setAssets.count(GetAssetFromLabel("bitcoin")) == 0) {
// Always add policyAsset, as fees via policyAsset may create change
if (setAssets.count(policyAsset) == 0) {
vChangeKey.push_back(CReserveKey(this));
vpChangeKey.push_back(&vChangeKey[vChangeKey.size()-1]);
}
Expand Down Expand Up @@ -2622,7 +2622,6 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign, std::vector<CAmount> *outAmounts)
{
CAmountMap mapValue;
CAsset BITCOINID = GetAssetFromLabel("bitcoin");
int nChangePosRequest = nChangePosInOut;
unsigned int nSubtractFeeFromAmount = 0;
for (const auto& recipient : vecSend)
Expand Down Expand Up @@ -2701,7 +2700,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

CAmountMap mapValueToSelect = mapValue;
if (nSubtractFeeFromAmount == 0)
mapValueToSelect[BITCOINID] += nFeeRet;
mapValueToSelect[policyAsset] += nFeeRet;
double dPriority = 0;
// vouts to the payees
for (const auto& recipient : vecSend)
Expand All @@ -2710,8 +2709,8 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

if (recipient.fSubtractFeeFromAmount)
{
if (recipient.asset != BITCOINID) {
strFailReason = _("Wallet does not support non-bitcoin fees, therefore can not subtract fee from address amount.");
if (recipient.asset != policyAsset) {
strFailReason = strprintf(_("Wallet does not support more than one type of fee at a time, therefore can not subtract fee from address amount, which is of a different asset id. fee asset: %s recipient asset: %s"), policyAsset.GetHex(), recipient.asset.GetHex());
return false;
}
txout.nValue = recipient.nAmount - (nFeeRet / nSubtractFeeFromAmount); // Subtract fee equally from each selected recipient
Expand All @@ -2723,7 +2722,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
}
}

if (recipient.asset == BITCOINID && txout.IsDust(::minRelayTxFee))
if (recipient.asset == policyAsset && txout.IsDust(::minRelayTxFee))
{
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
{
Expand Down Expand Up @@ -2808,7 +2807,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
// We do not move dust-change to fees, because the sender would end up paying more than requested.
// This would be against the purpose of the all-inclusive feature.
// So instead we raise the change and deduct from the recipient.
if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(::minRelayTxFee) && it->first == BITCOINID)
if (nSubtractFeeFromAmount > 0 && newTxOut.IsDust(::minRelayTxFee) && it->first == policyAsset)
{
CAmount nDust = newTxOut.GetDustThreshold(::minRelayTxFee) - newTxOut.nValue.GetAmount();
newTxOut.nValue = newTxOut.nValue.GetAmount() + nDust; // raise change until no more dust
Expand All @@ -2829,7 +2828,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

// Never create dust outputs; if we would, just
// add the dust to the fee.
if (newTxOut.IsDust(dustRelayFee) && it->first == BITCOINID)
if (newTxOut.IsDust(dustRelayFee) && it->first == policyAsset)
{
nChangePosInOut = -1;
nFeeRet += it->second;
Expand Down Expand Up @@ -2933,7 +2932,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

// Add fee
if (nFeeRet > 0) {
CTxOut fee(BITCOINID, nFeeRet, CScript());
CTxOut fee(policyAsset, nFeeRet, CScript());
assert(fee.IsFee());
txNew.vout.push_back(fee);
strFailReason = _("Signing transaction failed");
Expand Down Expand Up @@ -4009,7 +4008,6 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
// All wallets should understand native peg-in currency
walletInstance->SetAssetPair("bitcoin", BITCOINID);


walletInstance->SetBestChain(chainActive.GetLocator());
}
else if (IsArgSet("-usehd")) {
Expand Down

0 comments on commit 0f79b48

Please sign in to comment.