Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor BtcWalletService to add tx-fee-rate param to 'sendbsq' #4867

Conversation

ghubstan
Copy link
Member

@ghubstan ghubstan commented Nov 30, 2020

This change gives an API user the option to transfer bsq with a one off tx fee rate, overriding both the network FeeService's tx fee rate, and the user preference set in the UI or API.

Use of this optional sendbsq param does not alter any preferences, nor does its existence affect the functionality of the UI.

  • Refactored BtcWalletService.

    Renamed completePreparedSendBsqTx -> completePreparedBsqTx.

    Removed the isSendTx parmater in completePreparedBsqTx(Transaction preparedBsqTx, boolean isSendTx),

    Overloaded Transaction completePreparedBsqTx to make it possible for the api to override the txFeePerVbyte via the sendbsq command, instead of having to set preferences. (Added new txFeePerVbyte param.)

  • Adjusted BsqSendView, UnlockTxService and LockupTxService to the refactored BtcWalletService. (Removed redundant params, used new method name.)

  • Added txFeePerVbyte param to BsqTransferService#getBsqTransferModel signature.

  • Adjusted GrpcWalletsService, CoreApi, CoreWalletsService, BsqTransferService to allow txFeePerVbyte override via sendbsq api method, and wrap a TxInfo in the gRPC response.

  • Aded new SendBsqRequest gRPC param: txFeeRate.

  • Added SendBsqReply gRPC return value: TxInfo.

  • Added new Transactions section to grpc.proto, moved existing TxFeeRateInfo message def into it, and added new TxInfo message def.

  • Added new TxInfo proto wrapper, now returned to CLI from api's sendbsq.

  • Adjusted CLI for new sendbsq param and TxInfo return value.

  • Adjusted affected tests.

This is the 22nd in a chain of PRs beginning with #4793.

PR #4858 should be reviewed before this one.

This change adds proto serivces and messages to support new api
implementations for serving bsq, btc or all wallet balances.

- RPC GetBsqBalances will return complete BSQ balance info.
- Message BsqBalanceInfo is proto returned by rpc GetBsqBalances.

- RPC GetBtcBalances wil return complete BTC balance info.
- Message BtcBalanceInfo is proto returned by rpc GetBtcBalances.

- RPC GetBalances returns complete BTC and BSQ balance info.
- Message BalancesInfo is proto returned by rpc GetBalances.

RPC GetBalance remains unchnaged, still returns only the available
BTC balance.  It may be deprecated and removed in a future PR.
This change adds proto wrappers for sending bsq, btc, or all balances
to the CLI.  They will be used in future api method implementations:
getbsqbalance, getbtcbalance and getbalances.
This change adds a proto to support a future api implementation for
getting an unused, bsq funding address.
This change adds the proto to support a future api implementation for
transfering bsq.
This change adds proto support for paying maker fees in bsq or btc.
The implementation will come in a future PR.

- Added makerFeeCurrencyCode field to CreateOfferRequest proto.

- Added isCurrencyForMakerFeeBtc field to OfferInfo proto wrapper.

- Add takerFeeCurrencyCode field to TakeOfferRequest proto.
- Added new method to CLI, split some long msg strings into two lines,
  and added a white space after a braceless else statement.

- Added the gRPC server boilerplate.

- Added the core implementation.

- Added a test, and moved method wallet tests into their own package.
- Added three new methods to CLI:

      getbalances   ...	returns complete bsq and btc balance info
      getbsqbalance ...	returns complete bsq balance info
      getbtcbalance ...	returns complete btc balance info

      The old getbalance method is deprecated and will be removed
      if there is agreement to do that.

- Made the needed changes in the CLI's output formatting classes.

- Added new tests to existing BsqWalletTest, added new BtcWalletTest
  and WalletBalancesTest.

- Added disabled tests for funding a bsq wallet (todo in next PR).
All the boilerplate for this method is included in this change, but
the implementation in CoreWalletsService#sendBsq is commented out
until the needed logic to send bsq is refactored out of desktop's
BsqSendView class -- to be included in the next PR.

- Added new method to CLI.

- Added the gRPC server boilerplate.

- Added the core implementation, commented out.

- Enabled tests.
Moved just enough code out of BsqSendView to avoid desktop/api
'sendbsq' duplication, at the cost of adding 1 new method to
BsqSendView.

- Created new BsqTransferModel to hold tx details shared by desktop and api.

- Created new BsqTransferService to send bsq using a BsqTransferModel shared
  by desktop and api.

- Uncommented CoreWalletsService#sendBsq implementation.

- Uncommented sendbsq tests.
- Add optional makerFeeCurrencyCode argument to CLI's 'createoffer'.

- Add optional takerFeeCurrencyCode argument to CLI's 'takeoffer'.

- Add isCurrencyForMakerFeeBtc field to OfferInfo proto wrapper.

- Pass fee currency argument down to CoreOffersService and CoreTradesService's
  create and take offer methods.

- Add maybeSetFeePaymentCurrencyPreference method to OfferUtil to
  conditionally set the 'payFeeInBtc' preference before creating
  or taking an offer.

- Adjust affected tests.
This change fixes the recently bloated wallet balances api.  Now there
is one CLI getbalance [bsq|btc] method that calls a getbalances(currency-code)
on the server.  The server returns full wallet balance information for
BSQ, BTC, or both if the CLI's currency argument is absent.

- grpc.proto:  Reduced number of getbalance(s) proto services from
  four to one.

- GrpcWalletsService:  Reduced number of getbalance(s) gRPC service
  boilerplate methods from four to one.

- CoreApi, CoreWalletsService:  Reduced number of getbalance(s) gRPC
  service implementation methods from four to one.

- CliMain:  Reduced number of getbalance(s) commands from four to one.

- BalancesInfo: Changed BsqBalanceInfo & BtcBalanceInfo field names
  to bsq and btc, respectively, to make calling their accessors
  more readable, less verbose.

- BtcBalanceInfo, BsqBalanceInfo: Defined static final EMPTY instances
  as place holders in a BalancesInfo returned by the gRPC server, when
  one or the other balance types is not requested.  Would be nice
  to serve Optional.empty() instead, but protobuf does not support
  it or null.

- Adjusted affected api tests and build doc.
Returns a list of supported payment method IDs.  This gives CLI users
the correct payment method id for creating a new payment account.

- Added gRPC service GetPaymentMethods to grpc.proto.

- Added gRPC boilerplate method to GrpcPaymentAccountsService.

- Added implimentation to CoreApi -> CorePaymentAccountsService.

- Refactored PaymentAccountTest hierarchy.

- Add api method to CLI.
Had to change the getPaymentMethods() names to getPaymentMethodIds() to
avoid this codacy issue:

"Unnecessary use of fully qualified name 'PaymentMethod.getPaymentMethods'
due to existing static import 'bisq.core.payment.payload.PaymentMethod.*'"

If 'PaymentMethod.getPaymentMethods' was changed to 'getPaymentMethods',
a recursive loop would result, ending in an out of stack heap crash.

This renaming of the method on the server is correct, but the CLI's
'getpaymentmethods' name was not changed.
This reverts commit a465261.

The service side method name change is not correct.
Changed the core getPaymentMethods() -> getFiatPaymentMethods() to avoid

"Unnecessary use of fully qualified name 'PaymentMethod.getPaymentMethods'
due to existing static import 'bisq.core.payment.payload.PaymentMethod.*'"
This class will aid the api's (create) PaymentAccount json form
serialization/de-serialization.
This class does most of the work of the api's (create) PaymentAccount
json form serialization/de-serialization.
This class uses the gson PaymentAccountTypeAdapter to generate editable
json forms for PaymentAccount sub-types, and instantiate PaymentAccount
instances from edited json forms.
- Change the getbalance tests to just check a sucessful '0' status code.

  The api's getbalance method returns full balance info now, not just a
  formatted long.  We still assert the cmd did not fail, but don't check
  the value string.

- Remove obsolete createpaymentacct tests.

  This is well tested in apitest, and testing this cmd is unnecesarily
  complex to do in a bats script.
Keeping the bats test simple.  More complex use cases are tested in
apitest, and we don't want to be trading on mainnet with a bats test.

- Add new getunusedbsqaddress test, assert success return status.
- Add new getpaymentmethods test, assert success return status.
Running the bats test exposed a bug that shows BSQ and BTC balance
info no matter what currency code argument is passed to the server.
Restore BsqSendView to version @ commit 48a515b.
Author: jmacxx
Date:   Tue Nov 10 19:35:31 2020 -0600

    Add encrypted wallet password prompt when sending funds from BSQ wallet

    Correct wording of transaction confirmation popup to use 'mining fee'
    instead of 'transaction fee' to make it consistent with wording of
    the BTC confirmation popup.
And remove some unecessary single quotes.
This is marked unused, but it will be in future tests.
This change gives an API user the option to transfer bsq with a one off
tx fee rate, overriding both the network FeeService's tx fee rate,
and the user preference set in the UI or API.

Use of this optional 'sendbsq' param does not alter any preferences, nor
does it's existence affect the functionality of the UI.

- Refactored BtcWalletService.

	Renamed completePreparedSendBsqTx -> completePreparedBsqTx.

	Removed the isSendTx parmater in
	completePreparedBsqTx(Transaction preparedBsqTx, boolean isSendTx),

	Overloaded Transaction completePreparedBsqTx to make it possible
	for the api to override the txFeePerVbyte via the sendbsq command,
	instead of having to set preferences.
	(Added new txFeePerVbyte param.)

- Adjusted BsqSendView, UnlockTxService, LockupTxService to the
  refactored BtcWalletService.  (Removed redundant params, used new
  method name.)

- Added txFeePerVbyte param to BsqTransferService#getBsqTransferModel signature.

- Adjusted GrpcWalletsService, CoreApi, CoreWalletsService, BsqTransferService
  to allow txFeePerVbyte override via sendbsq api method, and wrap a TxInfo
  in the gRPC response.

- Aded new SendBsqRequest param: txFeeRate.

- Added SendBsqReply return value: txInfo.

- Added new 'Transactions' section to grpc.proto, moved existing TxFeeRateInfo
  message def into it, and added new TxInfo message def.

- Added new TxInfo proto wrapper, now returned to CLI from api's sendbsq.

- Adjusted CLI for new sendbsq param and TxInfo return value.

- Adjust affected tests.
@ghubstan
Copy link
Member Author

ghubstan commented Nov 30, 2020

This PR may seem too much or too risky for just adding a tx-fee-rate param to sendbsq, but a careful look at the changes will show some redundant code was removed from BtcWalletService.
And,

  • it may seem more reasonable when the sendbtc api method is added in one of the next PRs.
  • it makes sense that both sendbsq and sendbtc have this parameter, not just one.
  • sendbtc's txFeeRate parameter support should not require (m)any changes to BtcWalletService.

@ripcurlx ripcurlx added the in:api label Dec 1, 2020
@ghubstan
Copy link
Member Author

ghubstan commented Dec 1, 2020

Excluding this PR #4867 from the review chain.

Fixes for @sqrrm's requested PR changes (since @ghubstan's #4793) are to be added to #4858 (now the last PR in the chain, starting at #4793).

When #4858 is merged, this PR will be re-created off master, with a clean history.

@ghubstan ghubstan closed this Dec 1, 2020
@ghubstan ghubstan deleted the 22-refactor-btcwalletservice-override-feerate branch December 7, 2020 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants