Commit Graph

175 Commits

Author SHA1 Message Date
ghubstan
69792098c6
Check param count only, not param order correctness
This change simplifies client 'getoffers' method parameter
validation.  It no longer assumes parameter ordering is correct, nor
validates the direction parameter value.  The client only verifies
the correct number of string parameters are present.
2020-06-23 15:29:32 -03:00
ghubstan
9691f35082
Check param count only, not param order correctness
This change simplifies client 'createpaymentacct' method parameter
validation.  It no longer assumes parameter ordering is correct, and
only verifies the string parameter count is correct.

A unit test was also added to cli/test.sh

This commit is in response to the requested change in PR 4308.
https://github.com/bisq-network/bisq/pull/4308#pullrequestreview-435052357
2020-06-23 12:42:56 -03:00
ghubstan
52529a912e
Move getpaymentaccts tbl formatting to TableFormat
Created a new TableFormat.formatPaymentAcctTbl method.

Also:

 * Defined new "Currency" and "Name" column headers in TableFormat.

 * Changed syntax of stream().map() calls in some TableFormat methods.

 * Fixed verbose return statement in TableFormat.getLengthOfLongestColumn.

This commit is out of scope for the getoffers PR (4329), but is
included as part of the migration of all console tbl formatting
from the client into TableFormat.
2020-06-22 18:20:09 -03:00
ghubstan
8dcfa50bde
Define reusable headers from balance-info tbl 2020-06-22 17:49:46 -03:00
ghubstan
0d9bdefa00
Add 'getoffers' smoke test 2020-06-22 15:23:27 -03:00
ghubstan
61285a7602
Do not change case of input params in client
This commit is for a change requested in PR 4308:
https://github.com/bisq-network/bisq/pull/4308#pullrequestreview-435055483

  ".toUpperCase() seems misplaced here. It would soon get repetive.
  Whether the underlying logic differentiates between capitalizations
  is a low-level implementation detail and would do better at the
  lowest practical level."
2020-06-22 15:08:46 -03:00
ghubstan
a48af7c052
Add 'getoffers' unit tests 2020-06-22 14:43:59 -03:00
ghubstan
b25abf1b6b
Refactor CLI output table formatting
This change moves logic for formatting BTC balances, dates and
tables out of CliMain.  Two new output formatting classes were
added:  CurrencyFormat and TableFormat.
2020-06-21 19:46:37 -03:00
ghubstan
1756258e81
Do not use protobuf.OfferPayload.Direction in client 2020-06-20 20:09:18 -03:00
ghubstan
88cb90e209
Add rpc method 'getoffers'
The new method returns current buy or sell offers for a fiat ccy.

These changes need refactoring and polishing before merging, but they're
committed in this state to be safe (don't lose work).  Changes include:

* New core.grpc classes
    CoreOffersService
    GrpcOffersService
    model.OfferInfo

* CoreApi -- The new CoreOffersService is injected into CoreApi and
  the old getOffers() and placeOffer() impls were moved into the
  new CoreOffersService.  The getOffers implementation was re-done.
  Other changes are just rearranging location of core method calls.

* GrpcServer -- The new GrpcOffersService replaced the old
  GetOffersService and PlaceOfferService.

* grpc.proto -- The old GetOffers and PlaceOffer services were combined
  into a single Offers service, and the PlaceOffer rpc was renamed
  as CreateOffer.  These are the only substantive changes; the rest
  is just rearranging location of the service defs in the file.
  Also created a lighterweight OfferInfo proto message wrapper to
  be passed between server & client (client has no access to core's
  Offer and OfferPayload).

* OfferInfo -- A new wrapper around the OfferInfo proto message.

* CliMain -- The new GetOffers service stub was added.
  Some (maybe too much) number and ccy formatting logic was
  copied & modified from core.  Some tedius string formatting
  was added too (needs to be tidied up).

* License comments were also copied to several classes, and I
  made a mistake in reverting changes to the wrong file.

TODO add unit tests
2020-06-20 19:56:28 -03:00
ghubstan
37fb60672f
Add license comment
This is not in scope of current PR, but easy enough to review.
2020-06-20 09:59:06 -03:00
ghubstan
612bafe59a
Refactor AddressBalanceInfo display logic 2020-06-20 08:42:58 -03:00
ghubstan
331f488057
Return protos from funding address methods
The 'getaddressbalance' and 'getfundingaddresses' methods now send
new AddressBalanceInfo proto messages instead of a formatted String
to the client.  The AddressBalanceInfo message contains addressString,
balance, and # of confirmations (transaction confidence) fields.

Changes include:
* A new AddressBalanceInfo proto message
* A wrapper class for the new AddressBalanceInfo proto
* New 'getaddressbalance' and 'getfundingaddresses' signatures in server
* AddressBalanceInfo display logic in client
* Removal of balance formatting logic in server
* Refactoring of balance formatting logic in client
2020-06-19 20:00:28 -03:00
ghubstan
435672a5ee
Add rpc method 'getpaymentaccts'
This addresses task 5 in issue 4257
	https://github.com/bisq-network/bisq/issues/4257

This new gRPC PaymentAccounts service method displays the user's
saved payment accounts.

A unit test to check a successful return status code was added
to cli/test.sh.

This PR should be reviewed/merged after PR 4322.
	https://github.com/bisq-network/bisq/pull/4322
2020-06-19 12:45:04 -03:00
ghubstan
bac3ed5697
Call core wallets service methods from CoreApi
This change is a refactoring of the gRPC Wallets service
for the purpose of making CoreApi the entry point to
all core implementations.  These changes should have been
made in PR 4295.
See https://github.com/bisq-network/bisq/pull/4295

The gRPC Wallet proto def name was changed to Wallets because
this service manages BSQ and BTC wallets, and GrpcWalletService
was changed to GrpcWalletsService for the same reason.

This PR should be reviewed/merged after PR 4308.
See https://github.com/bisq-network/bisq/pull/4308

This PR's branch was created from the PR 4308 branch.
2020-06-15 16:43:26 -03:00
ghubstan
a7542e98bf
Add rpc method 'createpaymentacct'
This addresses task 4 in issue 4257.
    https://github.com/bisq-network/bisq/issues/4257

This PR should be reviewed/merged after PR 4304.
    https://github.com/bisq-network/bisq/pull/4304

This new gRPC PaymentAccounts service method creates a dummy
PerfectMoney payment account for the given name, number and fiat
currency code, as part of the required "simplest possible trading
API" (for demo).   An implementation supporting all payment
methods is not in the scope.

Changes specific to the new rpc method implementation follow:

* New createpaymentacct method + help text was added to CliMain.
  Help text formatting was also changed to make room for larger
  method names and argument lists.

* The PaymentAccount proto service def was renamed PaymentAccounts
  to avoid a name collision, and the new rpc CreatePaymentAccount
  was made part of the newly named PaymentAccounts service def.

* New GrpcPaymentAccountsService (gRPC boilerplate) and
  CorePaymentAccountsService (method implementations) classes were
  added.

* The gRPC GetPaymentAccountsService stub was moved from GrpcServer
  to the new GrpcPaymentAccountsService class, and
  GrpcPaymentAccountsService is injected into GrpcServer.

* A new createpaymentacct unit test was added to the bats test
  suite (checks for successful return status code).

Maybe bit out of scope, some small changes were made towards making
sure the entire API is defined in CoreApi, which is used as a
pass-through object to the new CorePaymentAccountsService.  In the
next PR, similar refactoring will be done to make CoreApi the
pass-through object for all of the existing CoreWalletsService
methods.  (CoreWalletsService will be injected into CoreApi.)
In the future, all Grpc*Service implementations will call core
services through CoreApi, for the sake of consistency.
2020-06-15 14:32:14 -03:00
ghubstan
b1228e5ea7
Add rpc method 'getaddressbalance'
This addresses task 2 in issue 4257
	https://github.com/bisq-network/bisq/issues/4257

This new gRPC Wallet service method displays the balance and number
of confimirmations of the most recent transaction for the given BTC
wallet address.

The new method required the usual boilerplate changes to grpc.proto,
CliMain, and GrpcWalletService.

Two unit tests to check error msgs was added to cli/test.sh.
2020-06-14 14:23:47 -03:00
ghubstan
2e415de4ad
Replace duplicate code in getFundingAddresses
Cleaned up the method body and improved the returned string's
formatting.  Also added a line for this method in the CLI help text.
2020-06-14 13:05:37 -03:00
ghubstan
85c96764fb
Add rpc method 'getfundingaddresses'
This addresses task #1 in issue https://github.com/bisq-network/bisq/issues/4257.

This new gRPC WalletService method displays the BTC wallet's list of
receiving addresses.  The balance and number of confirmations
for the most recent transaction is displayed to the right of each
address.  Instead of returning a gRPC data structure to the client,
the service method returns a formatted String.

If the BTC wallet has no unused addresses, one will be created and
included in the returned list, and it can be used to fund the wallet.

The new method required injection of the BtcWalletService into CoreWalletsService,
and the usual boilerplate changes to grpc.proto, CliMain, and GrpcWalletService.

Some of the next PRs (for #4257) will require some common functionality within
CoreWalletsService, so these additional changes were included:

  * a private, class level formatSatoshis function
  * a public getNumConfirmationsForMostRecentTransaction method
  * a public getAddressBalance method
  * a private getAddressEntry method

A unit test that verifies a successful return status was added to cli/test.sh.
2020-06-13 19:59:45 -03:00
ghubstan
ec66b14986
Add rpc wallet(s) protection tests
This commit includes the following changes:

 * New tests for methods `lockwallet`, `unlockwallet`,
   `removewalletpassword`, and `setwalletpassword`.

 * New `getbalance` method error handing tests to verify
   error message correctness when wallet is locked.

 * Update to `getversion` method test -- now expects `1.3.4`.

 * Check for new `[params]` column header in help text.
2020-06-12 15:56:19 -03:00
Chris Beams
2e33c2c87a
Merge pull request #4214 from ghubstan/rpc-wallet-protection
Add rpc wallet protection endpoints
2020-05-18 14:18:05 +02:00
ghubstan
9b156b86dd
Remove unlockwallet timeout variable initializer
This variable no longer needs to be initialized to avoid a compiler error.
2020-05-04 15:19:18 -03:00
Chris Beams
d48f9eb6f0
Tighten up error handling
This commit factors out a run() method in CliMain that either returns
(void) or throws an exception. This eliminates the need to call
System.exit in so many places as were previously. Indeed, now there is
only one place where System.exit is called.

It also removes the duplication of printing "Error: ..." to stderr when
something goes wrong by doing this once in the global catch clause in
the main method.
2020-05-04 13:58:46 +02:00
Chris Beams
b0e5da8e2e
Refactor setwalletpassword handling to eliminate duplication 2020-05-04 12:22:13 +02:00
Chris Beams
6334c5478c
Generalize gRPC exception message cleanup 2020-05-03 15:47:26 +02:00
Chris Beams
c7a6c87bd1
Refactor grpc wallet service
Previously, each wallet-related method was implemented with its own grpc
service. There is no need to do this, as a grpc service may declare
multiple rpc methods. This commit refactors everything wallet-related
into a single GrpcWalletService and also extracts a CoreWalletService
from CoreApi in order to avoid the latter becoming overly large.
Ideally, there would be no need for an abstraction in bisq.grpc called
CoreWalletService; we would ideally use such a service implemented in
bisq.core. The closest we have is WalletsManager, but it is not designed
to be used the way we are using it here in the grpc context. Rather than
making changes directly to core (which can be very risky), we will
rather make them here in this layer, designing exactly the "core wallet
service" we need, and can then later see about folding it into the
actual core.
2020-05-03 15:46:41 +02:00
ghubstan
2a9d1f6d34
Improve gRPC error handling
This change removes non-idiomatic gRPC *Reply proto message fields.
The client should not receive success/fail values from server methods
with a void return type, nor an optional error_message from any server
method.  This change improves error handling by wrapping an appropriate
gRPC Status with a meaningful error description in a StatusRuntimeException,
and placing it in the server's response StreamObserver.  User error
messages are mapped to general purpose gRPC Status codes in a new ApiStatus
enum class.  (Maybe ApiStatus should be renamed to CoreApiStatus.)
2020-05-01 17:29:14 -03:00
Chris Beams
765da55daa
Polish cli test suite documentation 2020-05-01 11:48:59 +02:00
Chris Beams
b88f1bf84f
Polish whitespace
Per https://github.com/bisq-network/style/issues/10
2020-05-01 11:11:50 +02:00
ghubstan
ca68d0567f
Add wallet protection methods to printHelp(opts) 2020-04-30 11:21:04 -03:00
ghubstan
2096275722
Handle unlockwallet parameter errors 2020-04-30 11:00:22 -03:00
ghubstan
de50692daa
Add rpc wallet protection endpoints
Implemented lockwallet, unlockwallet, removewalletpassword, and
setwalletpassword methods with basic error handling.

Also added basic error handling to existing getbalance method,
and removed unused BalancePresentation from CoreAPI.

TODO:  update help text
2020-04-29 19:25:23 -03:00
ghubstan
5d3abef3fc
Migrate expect based test to bats 2020-04-29 11:59:05 -03:00
ghubstan
cfb7e32e70
Remove note to self 2020-04-26 16:54:10 -03:00
Chris Beams
312ef30b70
Revert marking password as required in JOpt parser
This is a partial reversion of the earlier commit. Marking the password
option as required at the parser level made it impossible to run
./bisq-cli without options or arguments and get the help text. This is a
useful thing to do, and not worth creating a bad user experience to get
the free required option error handling and error messaging.
2020-04-26 21:44:03 +02:00
Chris Beams
a6a8702084
Touch up help output
Stop attempting to align Option and Method description columns with one
another. It's a moving target as we add options and method names, and
this help output format will probably change in the future anyway.
2020-04-26 21:29:29 +02:00
Chris Beams
f5803492bd
Add comment explaining exception message mangling 2020-04-26 21:27:24 +02:00
Chris Beams
f4b4f5ad89
Update cli/test.sh instructions
Don't instruct the user to create a fresh data directory every time, as
this takes quite a bit longer to initialize the wallet than running
against the same data directory repeatedly. Just be clear that the
requirement is an unencrypted wallet with 0 BTC balance.
2020-04-26 21:10:25 +02:00
Chris Beams
5fa7939ec4
Set --password as a required option in JOpt parser 2020-04-26 21:05:22 +02:00
Chris Beams
822e6813f8
Touch up test descriptions and parameter naming 2020-04-26 21:04:06 +02:00
Chris Beams
a3f9faf7ab
Move cli-test.sh => cli/test.sh
- Ensure script runs from root directory regardless of where it is
   invoked from

 - Touch up documentation and whitespace
2020-04-26 20:46:52 +02:00
Chris Beams
b7fda8de5e
Declare channel outside try/catch
No StatusRuntimeException can be thrown from this code, so it is not
necessary to include in the try block.
2020-04-26 19:38:06 +02:00
Chris Beams
0a2aac00d3
Shutdown channel using a JVM shutdown hook
Versus needing to manage calling custom shutdown method in all the right
places.
2020-04-26 19:35:48 +02:00
Chris Beams
e10e29a211
Handle OptionException immediately 2020-04-26 19:32:14 +02:00
ghubstan
dee5e4cf7e
Revert 16c2efc
No need to strip quotes from password.  The problem was a bug
in my expect/tcl script's quote escape syntax.
2020-04-26 10:29:01 -03:00
ghubstan
56f2923ade
Remove redundant text from console err msg
The client was displaying
	Error: UNAUTHENTICATED: incorrect 'password' rpc header value
from the StatusRuntimeException message.

Strip "UNAUTHENTICATED: " from the exception message string before
printing it.
2020-04-25 18:16:23 -03:00
ghubstan
16c2efc8e1
Allow double-quoted multiword apiPassword
Strip double quotes from :cli --password arg before it is passed
to server.  Otherwise, a correct "password" will fail authentication.
2020-04-25 17:52:54 -03:00
Chris Beams
d923d07781
Fix typo in help output 2020-04-25 13:34:32 +02:00
Chris Beams
653856f79b
Refactor 'auth*' naming to 'password'
To increase simplicity and make the implementation more
intention-revealing.
2020-04-25 13:28:10 +02:00
Chris Beams
42e9bb1433
Refine help output 2020-04-25 11:31:19 +02:00
Chris Beams
c1931d2fb2
Use 'method' vs 'command' naming 2020-04-25 11:27:19 +02:00
Chris Beams
7bf854c86e
Improve error handling
Fail fast if the specified command is unknown
2020-04-25 11:22:01 +02:00
Chris Beams
c6e5670fbd
Print nested exception error message on connect failure 2020-04-25 10:42:53 +02:00
Chris Beams
b67ad6cd74
Print help text when no command is specified 2020-04-25 10:25:54 +02:00
Chris Beams
423b2ad4ae
Handle OptionException gracefully
When e.g. a given option is not recognized, print a clean error message
and exit 1 as opposed to printing a stack trace.
2020-04-25 10:10:27 +02:00
Chris Beams
0b338bbbea
Rename/repackage bisq.cli.{app.Bisq=>CliMain} 2020-04-25 09:59:22 +02:00
Chris Beams
d19581a089
Reduce AuthHeaderCallCredentials visibility to package-private 2020-04-25 09:55:32 +02:00
Chris Beams
e84123c20a
Refactor auth infrastructure naming 2020-04-25 09:52:50 +02:00
Chris Beams
3fe7848c4e
Use var declarations where appropriate 2020-04-25 08:17:22 +02:00
Chris Beams
04defcb66d
Update comments and console output 2020-04-25 08:17:19 +02:00
Chris Beams
31aed4b082
Simplify implementation to a single main class 2020-04-25 08:16:38 +02:00
Chris Beams
1a133f4b67
Use a single auth token vs username:password
There is actually no use case for both username and password forming the
authentication token. This change simplifies the arrangement such that a
single token is passed.

--rpcUser and --rpcPassword are no longer used and are replaced by
--apiToken on both cli and daemon sides.
2020-04-23 11:32:19 +02:00
Chris Beams
ca0658229b
Rename AuthenticationInterceptor => TokenAuthInterceptor 2020-04-23 11:21:52 +02:00
Chris Beams
24c245c2ea
Polish BisqCallCredentials style
See https://github.com/bisq-network/style/issues/12
2020-04-23 11:21:52 +02:00
ghubstan
fe9e57babb
Implement simple cleartext gRPC authentication
* Renamed CliCommand to RpcCommand, differentiating it from cmd
   string token(s)

 * Added new CliConfig, based on :common Config

 * Injected Config into CoreApi to make bisq.properties and cmd line
   args available to server

 * Added cleartext username:password BisqCallCredentials to :cli, and
   an AuthenticationInterceptor to :core (server)

 * Moved :daemon resources folder to expected location under src/main

 * Duplicated CompositeOptionSet, ConfigException and BisqException
   in :cli because they are not visible from :common.  (TODO refactor?)
   CompositeOptionSet will be used to let command line parameters
   override params set in config file.

 * Removed outdated references to :cli in a couple of comments in
   :common Config

 * gRPC parameters & command names are lowercase to mimic bitcoind/rpc

TBD

 * Decide what rpc auth param names to use, to differentiate them from
   bitcoind rpc user/passord param names
2020-04-22 18:16:01 -03:00
ghubstan
aba595b8e8
Implement requested changes in PR #4097
Change member name OptionParser cmdParser -> parser.
Change server listening port to 9998, client port to 9998.
Change constructor argument from String[] param -> args.
Print the result only, w/out exec time.
Handle help command & print that to stdout;  print help
triggered by user error to stderr.
Use explicit system SUCCESS/FAIL codes in System.exit(0 || 1).
2020-03-30 12:53:45 -03:00
ghubstan
94ee49c5af
Remove read stdin loop
Replaced the Scanner input read loop with upgraded joptsimple
dependency. Cli now takes a single, non-option program argument, runs
it and exits.  Also removed the "stop client" command because there is
no input loop, but shutdown() is called for orderly channel shudown
before the jvm terminates.  Also changed cmd syntax from camel case
to lowercase, mimicking bitcoin-cli.

Configured logback to supress all debug & info level netty output, and
bypassed logback to print results to System.out.
2020-03-27 12:27:36 -03:00
Chris Beams
ccde089af3
Rename :protodefintion subproject to :proto
This is done primarily for concision. This change also repackages
bisq.grpc => bisq.proto.grpc in anticipation of repackaging the
definitions in pb.proto from 'protobuf' to 'bisq.proto'. There should
not be any compatibility issues with doing this, but it's out of scope
here. When complete, the relationship between bisq.proto.grpc and
bisq.proto will be more intuitively clear, i.e. that bisq.proto.grpc has
certain dependencies on bisq.proto classes, but not the other way
around.
2020-03-26 17:37:37 +01:00
Chris Beams
b8db1cdf78
Organize grpc/protobuf imports properly 2020-03-26 17:10:59 +01:00
ghubstan
aed3453142
Move command & core proto defs to new subproject
Protobuf definition files were moved from common and core to a new
protodefinition subproject.

The two main reasons for doing this are to speed up builds by not
having to regenerate common and core protobuf classes
every time a change is made in those subprojects, and to remove
the grpc cli's direct dependency on core, and the transitive dependency
on common.

In order to accomplish this, cli's BisqCliMain was stripped of
its dependencies on common and core.  Cli can only get the version
and balance now.

gRPC stub boilerplate was moved from BisqCliMain to a CliCommand
class to avoid some of the bloat that is going to happen as the
read-response loop supports more rpc commands.
2020-03-26 10:14:33 -03:00
Chris Beams
d77ff101fb
Reflect higher security deposit in placeOffer RPC comment
Per review comment at
https://github.com/bisq-network/bisq/pull/3888#discussion_r368481607
2020-01-20 12:58:13 +01:00
Chris Beams
1e8633b03b
Organize io.grpc imports correctly
And remove entry for the no longer used io.bisq.generated package.
2020-01-20 12:16:57 +01:00
Chris Beams
aff760514b
Sever dependency from :desktop => :grpc
The :grpc module will soon be renamed to :daemon. These two modules
represent two separate and equal modes of running bisq, either as a
desktop GUI or as a daemon. They are both applications, and one should
not depend on the other as it would be illogical and confusing to model
things that way. The reason for the current dependency from :desktop to
:grpc is because :grpc is the home of BisqGrpcServer. This change moves
this class up to :core, in a new bisq.core.grpc package, such that both
the :desktop and :daemon applications can pull it in cleanly.

The CoreApi 'facade' that BisqGrpcServer uses to abstract away bisq
internals has been moved from bisq.core to bisq.core.grpc as well and
for the same reasons detailed in 8b30c22d6.

This change also renames the Java package for generated grpc types from
bisq.grpc.protobuf to bisq.core.grpc (the same new package that
BisqGrpcServer and CoreApi now live in). Again, this is for reasons of
cohesion: BisqGrpcServer is the only user of these grpc-generated types,
and they should logically live in the same package (even if they
physically live in separate source dirs at the build level).
2020-01-20 12:12:09 +01:00
Chris Beams
07d98a3aba
Move bisq.{grpc.BisqGrpcClient=>cli.BisqCliMain}
This change replaces the previous "Hello, World!" :cli main stub with
the contents of the BisqGrpcClient as originally implemented in :grpc,
such that the following now works:

    $ gradle build
    $ ./bisq-daemon # in first terminal
    $ ./bisq-cli    # in second terminal
    getVersion      # user input to stdin
    1.2.3           # rpc response
    getBalance      # user input to stdin
    0.00            # rpc response
    ...

Or for a user experience closer to where things are headed:

    $ echo getVersion | ./bisq-cli
    1.2.3

Note that processing the above command is currently far too slow:

    $ time echo getVersion | ./bisq-cli
    1.2.3

    real    0m1.634s   # ouch
    user    0m1.746s
    sys     0m0.180s

Subsequent commits will work to bring this time down to a minimum.

Note: Includes the code quality changes originally made to
BisqGrpcClient in commit 7595387.
2020-01-20 12:07:55 +01:00
Chris Beams
29698fd58a
Introduce 'cli' subproject
This change stubs out the `bisq-cli` utility with a placeholder main
method, such that the following now works:

    $ gradle :cli:build
    $ ./bisq-cli
    Hello, World!
2020-01-20 12:07:55 +01:00