@@ -52,14 +52,19 @@ bool SelectMasterInputOutput(CCoinControl& coin_control)
5252// !
5353// ! \param wtx_new A new transaction with a contract.
5454// ! \param reserve_key Key reserved for any change.
55- // ! \param admin \c true for an administrative contract .
55+ // ! \param burn_fee Total burn fee required for contracts in the transaction .
5656// !
5757// ! \return \c true if coin selection succeeded.
5858// !
59- bool CreateContractTx (CWalletTx& wtx_out, CReserveKey reserve_key, bool admin )
59+ bool CreateContractTx (CWalletTx& wtx_out, CReserveKey reserve_key, int64_t burn_fee )
6060{
6161 CCoinControl coin_control_out;
6262 int64_t applied_fee_out; // Unused
63+ bool admin = false ;
64+
65+ for (const auto & contract : wtx_out.vContracts ) {
66+ admin |= contract.RequiresMasterKey ();
67+ }
6368
6469 // Configure inputs/outputs for the address associated with the master key.
6570 // Nodes validate administrative contracts by checking that the containing
@@ -79,7 +84,7 @@ bool CreateContractTx(CWalletTx& wtx_out, CReserveKey reserve_key, bool admin)
7984 scriptPubKey << OP_RETURN;
8085
8186 return pwalletMain->CreateTransaction (
82- { std::make_pair (std::move (scriptPubKey), Contract::BURN_AMOUNT ) },
87+ { std::make_pair (std::move (scriptPubKey), burn_fee ) },
8388 wtx_out,
8489 reserve_key,
8590 applied_fee_out,
@@ -90,12 +95,11 @@ bool CreateContractTx(CWalletTx& wtx_out, CReserveKey reserve_key, bool admin)
9095// ! \brief Send a transaction that contains a contract.
9196// !
9297// ! \param wtx_new A new transaction with a contract.
93- // ! \param admin \c true for an administrative contract.
9498// !
9599// ! \return An empty string when successful or a description of the error that
96100// ! occurred. TODO: Refactor to remove string-based signaling.
97101// !
98- std::string SendContractTx (CWalletTx& wtx_new, const bool admin )
102+ std::string SendContractTx (CWalletTx& wtx_new)
99103{
100104 CReserveKey reserve_key (pwalletMain);
101105
@@ -112,14 +116,19 @@ std::string SendContractTx(CWalletTx& wtx_new, const bool admin)
112116 }
113117
114118 int64_t balance = pwalletMain->GetBalance ();
119+ int64_t burn_fee = 0 ;
120+
121+ for (const auto & contract : wtx_new.vContracts ) {
122+ burn_fee += contract.RequiredBurnAmount ();
123+ }
115124
116- if (balance < COIN || balance < Contract::BURN_AMOUNT + nTransactionFee) {
125+ if (balance < COIN || balance < burn_fee + nTransactionFee) {
117126 std::string strError = _ (" Balance too low to create a contract." );
118127 LogPrintf (" %s: %s" , __func__, strError);
119128 return strError;
120129 }
121130
122- if (!CreateContractTx (wtx_new, reserve_key, admin )) {
131+ if (!CreateContractTx (wtx_new, reserve_key, burn_fee )) {
123132 std::string strError = _ (" Error: Transaction creation failed." );
124133 LogPrintf (" %s: %s" , __func__, strError);
125134 return strError;
@@ -175,7 +184,7 @@ std::pair<CWalletTx, std::string> NN::SendContract(Contract contract)
175184
176185 wtx.vContracts .emplace_back (std::move (contract));
177186
178- std::string error = SendContractTx (wtx, contract. RequiresMasterKey () );
187+ std::string error = SendContractTx (wtx);
179188
180189 return std::make_pair (std::move (wtx), std::move (error));
181190}
0 commit comments