diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index 527520c40e..34f0d8305a 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -464,6 +464,9 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, bool lockUnspents = false; UniValue subtractFeeFromOutputs; std::set setSubtractFeeFromOutputs; + if (g_con_any_asset_fees && !tx.vout.empty()) { + coinControl.m_fee_asset = tx.vout[0].nAsset.GetAsset(); + } if (!options.isNull()) { if (options.type() == UniValue::VBOOL) { @@ -516,8 +519,6 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown label and invalid asset hex for fee: %s", feeAsset.GetHex())); } coinControl.m_fee_asset = feeAsset; - } else { - coinControl.m_fee_asset = tx.vout[0].nAsset.GetAsset(); } } diff --git a/test/functional/feature_any_asset_fee.py b/test/functional/feature_any_asset_fee.py index dd1b963868..82d2ba452b 100755 --- a/test/functional/feature_any_asset_fee.py +++ b/test/functional/feature_any_asset_fee.py @@ -169,6 +169,26 @@ def transfer_asset_amount_including_fee(self): node1_new_balance = self.nodes[1].getbalances()["mine"] assert len(node1_new_balance["trusted"]) == 0 + def raw_transfer_asset_to_node1(self): + node0 = self.nodes[0] + node1 = self.nodes[1] + + node1_balance = node1.getbalances()['mine'] + + raw_tx = node0.createrawtransaction(outputs=[{self.node1_address: 1.0, 'asset': self.asset }]) + funded_tx = node0.fundrawtransaction(raw_tx)['hex'] + assert node0.decoderawtransaction(funded_tx)['fee'] == { self.asset: Decimal('0.00049820')} + blinded_tx = node0.blindrawtransaction(funded_tx) + signed_tx = node0.signrawtransactionwithwallet(blinded_tx)['hex'] + sent_tx = node0.sendrawtransaction(signed_tx) + tx = node0.gettransaction(sent_tx) + assert tx['fee'] == { self.asset: Decimal('-0.00049820') } + + self.generatetoaddress(node0, 1, self.node1_address) + self.sync_all() + node1_new_balance = node1.getbalances()['mine'] + assert_equal(node1_new_balance['trusted'][self.asset], Decimal('1')) + def run_test(self): self.init() @@ -178,5 +198,7 @@ def run_test(self): self.transfer_asset_amount_including_fee() + self.raw_transfer_asset_to_node1() + if __name__ == '__main__': AnyAssetFeeTest().main()