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

API POC: Use json form to create fiat payment accts #4813

Closed

Conversation

ghubstan
Copy link
Member

@ghubstan ghubstan commented Nov 16, 2020

These changes show how the API could create any exiting fiat PaymentAccount with a single CLI parameter, using reflection and json.

The idea is to use the CLI to create fiat accounts in four simple steps, as opposed to figuring out how to correctly pass a complicated set of parameters to a CLI createpaymentacct command. The steps are:

  1. Get a list of payment account method IDs, e.g.,

    $ getpaymentmethods -- returns list of payment method IDs and descriptions

  2. Ask for a payment account (json) form, e.g.,

    $ getpaymentacctform japan_bank (a paymentMethodId) -- returns a json file with fields specific to the payment method

  3. Edit the returned json file, i.e., japan_bank_form.json with the user's file editor.

  4. Submit the payment account json form via the CLI.

    $ createpaymentacct japan_bank_form.json

The PR adds the new classes needed to generate a payment account json form for a given paymentMethodId (serialize only the necessary fields in a PaymentAccount subclass to json file), and de-serialize an edited json form into a PaymentAccount instance.

Changes include

  • A new isCountryBasedPaymentAccount method in the abstract PaymentAccount, to help in serialization / de-serialization.

  • A new ReflectionUtils class in the common.util.pkg.

  • A new gson PaymentAccountTypeAdapter in core.api.model, for doing the PaymentAccount serialization and de-serialization work.

  • A new PaymentAccountForm class in core.api.model, to be used by the server, for creating new fiat accounts from json forms.

  • A new PaymentAccountFormTest to prove this scheme works.

This new PaymentAccount serialization / de-serialization scheme is not exposed in the API yet, nor are de-serialized PaymentAccount instances persisted. The only change to existing code is the new boolean isCountryBasedPaymentAccount() method added to abstract PaymentAccount.

This is the 13th in a chain of PRs beginning with #4793.

PR #4808 should be reviewed before this one.

Note: Several log statements exist to aid travis ci debugging of the test case, if it fails. They will be removed.

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.
Print the test stdout after the travis build to find out
why this test fails on travis, but not my dev machine.
Only the sepa form test is failing on travie;  try to find out why.
@ghubstan ghubstan marked this pull request as draft November 17, 2020 14:41
On the travis server, gson is loading a Mock(PaymentMethod) into the
type adapter's write method.  The test case does not use mockito,
and this is a gson or mockito bug.  See if upgrading mockito
fixes this dog's breakfast.
@ghubstan
Copy link
Member Author

Closing and will be moving the failing test case to apitest, which does not load mockito.

@ghubstan ghubstan closed this Nov 17, 2020
@ghubstan ghubstan deleted the 13-json-paymentacct-form-poc branch December 3, 2020 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant