Commit Graph

144 Commits

Author SHA1 Message Date
ghubstan
6b2c386a7c
Fix call rate metering interceptor bug
The gRPC interceptor was not using the correct method/ratemeter
map key, and failing to find a rate meter for the server call.

- Fix the rate meter key lookup bug.

- Disable most strict, default call rate meters in tests.
  Made an adjustment to the test harness' scaffold setup so an interceptor
  testing or disabling config file is always picked up by bob and alice
  daemons.

- Set arbitration daemon's registerDisputeAgent rate @ 10/second, so
  it does not interfere with the test harness.  (There is no pre-existing
  arb node appDataDir before that daemon starts.)

Note:  The test harness cannot install the custom rate metering file in
an arb daemon's appDataDir before it starts because there is no dao-setup
file for that node type.

TODO:  Adjust api simulation scripts to interceptor bug fix.
2021-02-27 21:47:52 -03:00
ghubstan
f90d2cee57
Fix test bug 2021-02-27 18:24:57 -03:00
ghubstan
320e63c0a1
Log 'trade not found' a warning instead of full stack trace 2021-02-27 17:25:49 -03:00
ghubstan
e5a0a3998d
Permit some gRPC excptions to be logged only as warning
A new handleExceptionAsWarning method logs warn(ex.msg) instead of
the full stack trace.
2021-02-27 17:14:22 -03:00
ghubstan
e5291e9f45
Use the logger of the gRPC service throwing an exception 2021-02-27 17:09:54 -03:00
ghubstan
1154085632
Add api method 'stop'
This change gives CLI users a 'stop' command to shutdown a daemon.

- Server side gRPC boilerpate was added to :proto and :daemon.

- When the new GrpcShutdownService accepts a 'stop' request from the CLI,
  it calls UserThread.runAfter(BisqHeadlessApp.getShutDownHandler(), 500, MILLISECONDS);

- Method help file 'stop-help.txt' was added to :core.

- Client side gRPC boiler plate and 'stop' implementation was added to :cli.
2021-02-18 11:54:10 -03:00
ghubstan
c99624015b
Factor out repeated 'new CallRateMeteringInterceptor' calls
Move this into a static CallRateMeteringInterceptor.valueOf(Map) method.
2021-01-25 14:38:53 -03:00
ghubstan
4eed44d350
Define gRPC api call rate constraints
The general rule is limit calls that change p2p data to 1/minute,
others to 1/second.  An exception is made to set/remove wallet password
methods (1/5s), due to the latency of writing wallet changes to disk.

This change may affect api testing in the future.  If that happens,
further changes to the call rate metering interceptor may be made to loosen
the constraints when running in regtest/dev mode.
2021-01-22 13:45:12 -03:00
Steven Barclay
8104301b52
Use new Bitcoind(Client|Daemon) & remove btcd-cli4j
Migrate RpcService over to the new block notification daemon and RPC
client based on jsonrpc4j. Drop in own DTO classes in place of the ones
defined by btcd-cli4j and rename requestBtcBlock & addNewBtcBlockHandler
to requestDtoBlock & addNewDtoBlockHandler respectively.

Also remove now redundant filtering from the logback config and update
grade-witness.
2021-01-21 10:10:28 +00:00
ghubstan
d18b2d5a10
Run an async price feed request when CLI needs market price
The CLI was receiving stale, cached market prices from the feed service.
2021-01-20 17:46:35 -03:00
ghubstan
a067ba1228
Add new CoreHelpService and method help docs
Adds all the gRPC server boilerplate, and a simple help service
that serves method help in man page format.  Help text is maintained
in text files located in core/src/main/resources/help.

Only some of the method help text files are defined in this
change, more to be added.
2021-01-14 10:19:39 -03:00
ghubstan
a8d15d0161
Merge branch 'offer-protection-tools-api-integration' into 03-support-trigger-price 2021-01-13 20:03:03 -03:00
ghubstan
0e779a4bf6
Inject CoreContext into server, then set isApiUser=true
Do not set isApiUser=true based on hardcoded thread name ;-(

For requested change
https://github.com/bisq-network/bisq/pull/5065#pullrequestreview-567708569
2021-01-13 19:55:49 -03:00
ghubstan
0c6005ed2d
Stub out support for OpenOffer's triggerPrice in api
This is a feature that will not be included in api v1, but partial
support is added in this change to the server.  CLI will pass a
default triggerPrice of 0 (unused) with the createoffer command.

When fully implemented, an optional trigger-price param will be
added to the CLI's createoffer method, and the value will only be
visible to offer owners.  New enableoffer and disableoffer
methods will also need to be added.
2021-01-11 14:36:51 -03:00
ghubstan
18de222d38
Add new api methods 'getmyoffers' and 'getmyoffer'
Similar to 'getoffers' and 'getoffer', but filters out offers not
created by the user.  The new methods are so similar some offer list
filtering and sorting was refactored in CoreOffersService.

Also fixed some createoffer apitest cases in anticipation of a new OfferFilter,
which will filter out offers not matching any user payment account.
2021-01-04 21:43:34 -03:00
ghubstan
10727fc083
Fix GrpcCallRateMeter method and variable name
- Change method isAllowed() -> checkAndIncrement().

- Change variable allowedCallsPerTimeUnit -> allowedCallsPerTimeWindow.
2020-12-23 11:30:16 -03:00
ghubstan
63564760a8
Support more fine grained rate metering
We need to be able to define call rate meters for time spans not limited
to TimeUnit intervals of 1 SECOND, 1 HOUR, or 1 DAY.  This change allows
more flexibility, e.g., 10 per 5 seconds, 10 per 5 hrs, 100 per 7 days.
2020-12-22 21:11:04 -03:00
ghubstan
c8ef4141e3
Fix comment 2020-12-22 18:33:18 -03:00
ghubstan
0d4ed952e7
Remove redundant callCount field
The size of the timestamp queue is the call count
2020-12-22 17:00:01 -03:00
ghubstan
d61521276f
Remove unused local var 2020-12-22 16:30:37 -03:00
ghubstan
01546ad11d
Use a simpler, time windowing call rate meter
Rewrote the GrpcCallRateMeter class and adjusted afected classes.

These changes were requested in PR review
https://github.com/bisq-network/bisq/pull/4966#pullrequestreview-557040093
2020-12-22 16:14:49 -03:00
ghubstan
87f75ee10c
Configure GrpcVersionService's rate metering interceptor
This change demonstrates how a method call rate metering interceptor
is configured for a gRPC service.  GrpcVersionService uses a custom
rate metering interceptor, or none.  A commented out, 'default'
interceptor is defined as a usage example.
2020-12-19 16:41:26 -03:00
ghubstan
ea97a801e5
Don't cancel gRPC call if an interceptor does not meter all methods 2020-12-19 16:31:41 -03:00
ghubstan
9f679deb08
Add license note and toString method 2020-12-19 15:47:20 -03:00
ghubstan
830a5f009a
Add license note 2020-12-19 15:43:44 -03:00
ghubstan
455ed67f9b
Add GrpcServiceRateMeteringConfigTest 2020-12-19 15:41:55 -03:00
ghubstan
b307593c82
Make CallRateMeteringInterceptor configurable via json
This adds a GrpcServiceRateMeteringConfig class that can read and
write rate metering interceptor config files, and configure
a gRPC rate metering service interceptor at startup.

This seems excessive, but we need to be able to test and tune
method rate metering without having to change hard coded, default
interceptor rate meters.
2020-12-19 15:32:40 -03:00
ghubstan
a5ed17e43f
Add license comment, stop & toString methods, and make isRunning transient 2020-12-19 13:14:06 -03:00
ghubstan
89e2187878
Change long to int, tidy up error msg 2020-12-17 14:12:04 -03:00
ghubstan
2148a4d958
Prevent excessive api calls
This change provides a gRPC CallRateMeteringInterceptor to help protect
the server and network against being overloaded by CLI scripting mistakes.

An interceptor instance can be configured on a gRPC service to set
individual method call rate limits on one or more of the the service's
methods. For example, the GrpcOffersService could be configured with
this interceptor to set the createoffer rate limit to 5/hour, and
the takeoffer call rate limit could be set to 20/day.  Whenever a
call rate limit is exceeded, the gRPC call is aborted and the client
recieves a "rate limit exceeded" error.

Below is a simple example showing how to set rate limits for one method
in GrpcVersionService.

    final ServerInterceptor[] interceptors() {
        return new ServerInterceptor[]{
                new CallRateMeteringInterceptor(new HashMap<>() {{
                    put("getVersion", new GrpcCallRateMeter(2, SECONDS));
                }})
        };
    }

It specifies a CLI can execute getversion 2 times / second.

This is not a throttling mechansim, there is no blocking nor locking
to slow call rates.  When call rates are exceeded, calls are
simply aborted.
2020-12-17 12:33:45 -03:00
ghubstan
fa9ffa1fb2
Put arguments on separate lines 2020-12-16 15:35:12 -03:00
ghubstan
2572e8641d
Create grpc interceptor pkg, move auth interceptor into it 2020-12-16 15:30:40 -03:00
ghubstan
f7c1103848
Rename gRPC exception handler class 2020-12-16 14:42:23 -03:00
ghubstan
c60605f75c
Fix class level comment 2020-12-16 14:26:12 -03:00
ghubstan
e6c6d3b8d3
Add new CoreApiExceptionHandler to gRPC services
This change reduces gRPC service error handling duplication by moving
it into a @Singleton encapsulating everything needed to wrap
an expected or unexpected core api exception into a gRPC
StatusRuntimeException before sending it to the client.  It also
fixes some boilerpate classes were gRPC error handling was missing.
2020-12-16 13:34:21 -03:00
ghubstan
5522d0c53e
Add new api method gettransaction
This change was prompted by the recent changes in the main branch to
allow a tx memo field to be set from the UI and API.

This and the prior PR address the API's need to be able to fetch a
tx (with a memo).  The API can now get a completed trade's withdrawal
txid and pass it as a gettransaction parameter.

See previous PR "Append nullable withdrawalTxId field to Trade".

	https://github.com/bisq-network/bisq/pull/4937

A summary of changes by file:

grpc.proto

- Added withdrawalTxId field to existing TradeInfo proto & wrapper.
- Reordered fields in TradeInfo proto.
- Added new fields to be displayed by TxInfo proto in CLI.
- Fixed typo: unsetTxFeeRatePreference -> UnsetTxFeeRatePreference.
- Added new GetTransaction rpc.

GrpcWalletsService - Added new getTransaction gRPC boilerplate.

CoreWalletsService - Added new getTransaction implementation.

TxInfo - Added the new fields for displaying a tx summary from CLI.
This is not intended to be more than a brief summary;  a block explorer
or bitcoin-core client should be used to see the complete definition.

TradeInfo - Added the new withdrawalTxId field defined in grpc.proto.

CliMain - Added new 'case gettransaction'.

TransactionFormat - Formats a TxInfo sent from the server to CLI.

ColumnHeaderConstants - Added console headers used by TransactionFormat.

TradeFormat - Displays a completed trade's WithdrawalTxId if present.

Apitest - Adjusted affected tests: assert tx memo is persisted and
test gettransaction.
2020-12-14 15:01:03 -03:00
ghubstan
150e2f6851
Use Bisq's UserThread.executor in gRPC server 2020-12-11 18:33:19 -03:00
ghubstan
478c8f4eb2
Remove unused imports 2020-12-09 17:38:20 -03:00
ghubstan
bd66008062
Support tx memo field for btc withdrawals from api
- Added optional memo parameter to the api's sendbtc and
  withdrawfunds commands.

- Removed the @Nullable annotation was removed because protobuf
  does not support null.

- Visibility in two wallet check methods were changed from private
  to pkg protected so the CoreTradeService could use them.

- Adjusted affected tests.  (Asserting the memo field was set on a
  transaction cannot be checked from apitest yet.)
2020-12-09 16:51:56 -03:00
ghubstan
6c9f0c252d
Add new api method 'sendbtc' and test
Takes an address, amount, and optional txfeerate param,
returns a lightweight TxInfo proto.

Also overloaded two BtcWalletService methods to allow sendbtc
to pass in the tx fee rate -- overriding the fee service and
custom fee rate setting.
2020-12-08 21:12:02 -03:00
ghubstan
2842070afd
Merge branch 'master' into 03-add-txFeeRate-param 2020-12-08 19:04:27 -03:00
chimp1984
104b7edc99
Add memo field at withdraw to external wallet screen
Implements https://github.com/bisq-network/bisq/issues/4869
2020-12-07 12:32:56 -05:00
ghubstan
159d4cc6f5
Add optional txFeeRate parameter to api sendbsq
If present in the sendbsq command, the parameter will override the fee
service and custom fee rate setting for the BSQ transaction.

Also changed the sendbsq grpc return type to a lightweight TX proto wrapper.

Besides some small refactoring in the CLI, all the changes are
adjustments for this new sendbsq parameter and its new grpc return value.
2020-12-04 17:17:37 -03:00
ghubstan
987d89319e
Use ListenableFuture and callback when requesting tx fee
This change fixes the blocking problem in the fee rate request api.
Also redefined the TxFeeRateInfo.

- Redefined grpc.proto message TxFeeRateInfo, added
  lastFeeServiceRequestTs field. (CLI user may want to know
  TS of last fee request.)

- Adjusted TxFeeRateInfo proto wrapper.

- Adjusted CurrencyFormat and BtcTxFeeRateTest to new TxFeeRateInfo.

- Added @Getter annotation to FeeService.  (CLI user may want to know
  TS of last fee request).

- Pass resultHandler from GrpcWalletsService through CoreApi, to
  CoreWalletsService's tx fee rate api methods.
2020-12-01 21:10:47 -03:00
ghubstan
0b0f9f1120
Add gettxfeerate, settxfeerate, unsettxfeerate implementations 2020-11-26 18:36:15 -03:00
ghubstan
ff887eb339
Fix createpaymentacct validation problems
- Add missing boilerplate error handling to GrpcPaymentAccountsService.

- Edit some PaymentAccountForm & PaymentAccountTypeAdapter exception
  messages that would be passed to CLI;  they should be in the same
  style as existing CLI err msgs.
2020-11-19 13:38:34 -03:00
ghubstan
08228d07bc
Replace existing api method 'createpaymentacct' impl
In the CLI, this method now takes a single argument, the path to a json
file (a payment account form).  The json text is read from the file
and sent to the server, where it is serialized to a new PaymentAccount
instance, saved, and sent back to the CLI as a protobuf.PaymentAccount.

- Modified existing gRPC boilerplate in grpc.proto and GrpcPaymentAccountsService.

- Modified existing method signatures in CoreApi and CorePaymentAccountsService.

- Replaced existing method impl in CorePaymentAccountsService and
  removed dead code.

- Replaced the CLI's existing 'createpaymentacct' method impl.

- Modified existing tests.
2020-11-18 19:23:21 -03:00
ghubstan
8996fa1748
Add boilerplate for new 'getpaymentacctform' api method 2020-11-18 16:17:24 -03:00
ghubstan
0e0af20900
Avoid codacy issue over use of fully qualified name
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.*'"
2020-11-18 12:58:58 -03:00
ghubstan
0046b08f9d
Revert "Avoid codacy issue over use of fully qualified name"
This reverts commit a46526198d.

The service side method name change is not correct.
2020-11-18 12:47:12 -03:00
ghubstan
a46526198d
Avoid codacy issue over use of fully qualified name
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.
2020-11-18 12:29:59 -03:00
ghubstan
ec381522ff
Add api method 'getpaymentmethods'
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.
2020-11-18 12:03:22 -03:00
ghubstan
7e9ab22d65
Refactor api getbalance methods.
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.
2020-11-14 13:08:10 -03:00
ghubstan
722460e7e5
Support paying trade fees in bsq or btc (api)
- 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.
2020-11-13 16:36:06 -03:00
ghubstan
0d3b3a6ead
Stub out api method 'sendbsq' in core
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.
2020-11-13 14:57:28 -03:00
ghubstan
208a37b339
Implement and test new getbalance(s) api methods
- 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).
2020-11-13 14:21:26 -03:00
ghubstan
8dc1a74c8b
Remove trailing spaces in blank line 2020-11-13 12:55:48 -03:00
ghubstan
c1c099c832
Implement and test api method 'getunusedbsqaddress'
- 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.
2020-11-13 12:40:16 -03:00
ghubstan
027a7d5cd3
Stub out canceloffer api method
The implementation will be added to CoreOffersService in the next PR.
2020-10-27 14:54:50 -03:00
ghubstan
a8decafc2f
Stub out api methods 'keepfunds', 'withdrawfunds'
This PR adds trade closing method stubs to keep funds in the
Bisq wallet or send them to an external BTC wallet.

- Add grpc protos
- Add new methods to GrpcTradesService, CoreApi
- Stub out implementations in CoreTradesService
- Add methods to CLI
2020-10-26 17:43:08 -03:00
ghubstan
161dbade0d
Add getRole(tradeId) to core api
API users will need to see their role as maker/taker when looking at trade details.

- Add getRole(trade) to TradeUtil.
- Add getTradeRole(tradeId) to CoreApi, CoreTradesService.
- Add role field to TradeInfo proto and its wrapper class.
2020-10-25 16:22:20 -03:00
ghubstan
ac8ed8dd06
Add 'confirmpaymentreceived' api method
- Implement confirmpaymentsent on server and cli side

- Enable confirmpaymentreceived method tests
2020-10-20 16:51:48 -03:00
ghubstan
3d2b90fb96
Add 'confirmpaymentsent' api method
- Implement confirmpaymentsent on server and cli side

- Enable confirmpaymentsent method tests
2020-10-20 16:20:40 -03:00
ghubstan
e809af37cc
Add 'takeoffer' API method
- Add new core.offer.takeoffer.TakeOfferModel

	Would have been nice to move more logic from
	bisq.desktop.main.offer.takeoffer.TakeOfferDataModel,
	but it has JFX dependencies that cannot be use in :core.

- Add grpc protos to support takeoffer, confirmpaymentsent, confirmpaymentreceived

	Only takeoffer is implemented in this commit.

- Refactor OfferInfo grpc proto wrapper, and add offer state field

- Add new TradeInfo grpc proto wrapper

- Implement takeoffer on server and cli side

- Refactor offer/trade tests, add test cases
2020-10-20 16:00:05 -03:00
Christoph Atteneder
ebe4618bfe
Merge pull request #4655 from bisq-network/release/v1.4.0
Release/v1.4.0 and v1.4.1
2020-10-20 09:10:12 +02:00
chimp1984
52be126667
Apply TradeStatistics3 to client classes 2020-10-08 18:49:13 -05:00
ghubstan
3a3f456fc9
Wrap Exception in gRPC StatusRuntimeException 2020-10-07 15:58:43 -03:00
ghubstan
29d1905f31
Add new 'getoffer offer-id' api method
There are a number of use cases where a user may want to see a single
offer instead of every offer for a currency pair on the buy or sell side.
The changes are:

- Add getoffer to grpc.proto
- Add new method to GrpcOffersService, CoreApi, CoreOffersService
- Add new method to CLI
- Adjust create offer tests to use this new convenience
2020-10-07 12:09:13 -03:00
ghubstan
3f3f4f06f5
Use consumer::accept instead of a countdown latch
This is more readable and stylistically consistent.
2020-10-05 14:32:05 -03:00
ghubstan
dd67acc153
Simplify GrpcOffersService#createOffer (refactor)
Push the placeOffer call down into CoreOffersService#createOffer,
and use a countdown latch to wait for async placeOffer to
complete.
2020-10-05 12:23:54 -03:00
sqrrm
f051a03d29
Merge pull request #4559 from ghubstan/cli-create-offer
Build out 'createoffer' API method
2020-10-03 17:04:11 +02:00
chimp1984
ff1380481d
Merge branch 'master_upstream' into improve-startup-routines
# Conflicts:
#	core/src/main/java/bisq/core/app/BisqSetup.java
2020-10-01 10:34:43 -05:00
chimp1984
9232a5765b
Improve handling of UncaughtExceptionHandler 2020-09-30 22:06:51 -05:00
chimp1984
7ea3676c55
Refactor: Rename setup to setupUncaughtExceptionHandler
rename setupErrorHandler to checkCryptoPolicySetup
move UncaughtExceptionHandler code to setupUncaughtExceptionHandler
2020-09-30 21:55:50 -05:00
ghubstan
94996a5e25
Fix tx result handling in GrpcOffersService
Separates offer placement from offer creation to fix tx result
handling problem in GrpcOffersService, and readies the core api
for a new CLI 'placeoffer' implementation.  Offer placement still
happens in the api's 'createoffer', but we may want to change it
to show the created offer to a CLI user for review, prior to manual
placement via a new 'placeoffer offer-id' (of 'confirmoffer offer-id'?)
api method.
2020-09-28 11:48:56 -03:00
ghubstan
82b7b79c5b
Factor out duplicated OfferInfo wrapping 2020-09-27 17:06:08 -03:00
ghubstan
de3105a62b
Add license comment 2020-09-25 20:56:48 -03:00
ghubstan
2f3e3a31e1
Add simple mkt-price service & test calculated offer prices
A gRPC price service was added, and api create-offer tests can check
mkt based price margin calculations.
2020-09-25 20:48:26 -03:00
ghubstan
3c0c443680
Change API's createoffer return value from bool to Offer 2020-09-22 22:13:42 -03:00
ghubstan
da78465fe4
Make grpc boilerplate classes pkg protected 2020-09-18 11:46:29 -03:00
ghubstan
e2bd89f39a
Refactor API & add registerdisputeagent method to CLI
This commit contains most of the changes suggested by @chimp1984 in
his api-suggestions branch.  See
961703ecea

A new 'registerdisputeagent' method was also added to MainCli, finishing
the work to support registration of mediators and refund agents on
arbitration daemons running in regtest mode.  This method cannot be
used to register dispute agents on mainnet;  users will see an error
msg if they try.
2020-09-18 11:33:16 -03:00
ghubstan
3386b43e52
Add GrpcDisputeAgentsService to GrpcServer 2020-09-14 11:39:36 -03:00
ghubstan
bbf4f09181
Add core impl for registering dispute agents
This change supports registering mediators and refund agents on
daemons running on regest or testnet chains.  Registering
arbitrators is not supported.
2020-09-14 11:04:10 -03:00
ghubstan
d0397c1c62
Move gRPC boilerplate from :core to :daemon
This change moves gRPC boilerplate classes from the :core.grpc pkg
into a new :daemon.grpc pkg.

* The :core.grpc pkg was renamed :core.api, and no longer has any
  dependencies on gRPC libraries.

* All core service classes in the :core.api pkg are now package
  protected, excepting CoreApi, making CoreApi the only possible
  entry point for all Grpc*Service -> -Core*Service calls.

* All grpc service classes in the :daemon.grpc pkg are now package
  protected, excepting GrpcServer;  the only class depending on
  Grpc*Service class is GrpcServer.

* gRPC dependencies were moved from the gradle.build file's :core
  subproject to :daemon.
2020-08-24 15:09:15 -03:00
Chris Beams
7f05f379ab
Remove unused import
This should have been done in commit c7a6c87b.
2020-05-18 14:11:50 +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
Chris Beams
a33e030e04
Rename BisqGrpcServer => GrpcServer 2020-04-27 19:49:10 +02:00
Chris Beams
506e12da46
Inject Config directly into BisqGrpcServer
There is no need or benefit to injecting Config into CoreApi for the
purpose of accessing it indirectly through BisqGrpcServer.
2020-04-23 09:50:08 +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
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
f5a1854762
Remove now unused BisqEnvironment class
In previous commits, BisqEnvironment functionality has been fully ported
to the new, simpler and more type-safe Config class. This change removes
BisqEnvironment and all dependencies on the Spring Framework Environment
interface that it implements.

The one exception is the pricenode module, which is separate and apart
from the rest of the codebase in that it is a standalone, Spring-based
HTTP service.
2020-01-20 16:41:19 +01:00
Chris Beams
b34d59c0a9
Introduce Config as replacement for BisqEnvironment
Prior to this commit, BisqExecutable has been responsible for parsing
command line and config file options and BisqEnvironment has been
responsible for assigning default values to those options and providing
access to option values to callers throughout the codebase.

This approach has worked, but at considerable costs in complexity,
verbosity, and lack of any type-safety in option values. BisqEnvironment
is based on the Spring Framework's Environment abstraction, which
provides a great deal of flexibility in handling command line options,
environment variables, and more, but also operates on the assumption
that such inputs have String-based values.

After having this infrastructure in place for years now, it has become
evident that using Spring's Environment abstraction was both overkill
for what we needed and limited us from getting the kind of concision and
type saftey that we want. The Environment abstraction is by default
actually too flexible. For example, Bisq does not want or need to have
environment variables potentially overriding configuration file values,
as this increases our attack surface and makes our threat model more
complex. This is why we explicitly removed support for handling
environment variables quite some time ago.

The BisqEnvironment class has also organically evolved toward becoming a
kind of "God object", responsible for more than just option handling. It
is also, for example, responsible for tracking the status of the user's
local Bitcoin node, if any. It is also responsible for writing values to
the bisq.properties config file when certain ban filters arrive via the
p2p network. In the commits that follow, these unrelated functions will
be factored out appropriately in order to separate concerns.

As a solution to these problems, this commit begins the process of
eliminating BisqEnvironment in favor of a new, bespoke Config class
custom-tailored to Bisq's needs. Config removes the responsibility for
option parsing from BisqExecutable, and in the end provides "one-stop
shopping" for all option parsing and access needs.

The changes included in this commit represent a proof of concept for the
Config class, where handling of a number of options has been moved from
BisqEnvironment and BisqExecutable over to Config. Because the migration
is only partial, both Config and BisqEnvironment are injected
side-by-side into calling code that needs access to options. As the
migration is completed, BisqEnvironment will be removed entirely, and
only the Config object will remain.

An additional benefit of the elimination of BisqEnvironment is that it
will allow us to remove our dependency on the Spring Framework (with the
exception of the standalone pricenode application, which is Spring-based
by design).

Note that while this change and those that follow it are principally a
refactoring effort, certain functional changes have been introduced. For
example, Bisq now supports a `--configFile` argument at the command line
that functions very similarly to Bitcoin Core's `-conf` option.
2020-01-20 16:37:54 +01:00
Chris Beams
9fceba63e2
Remove duplicate attempt to start BisqGrpcServer
Problem: a stack trace was being thrown during daemon startup from
BisqDaemonMain.onSetupComplete when it attempted to start a
second BisqGrpcServer and failed to bind to the already-bound port.
The first BisqGrpcServer is started in
BisqDaemonMain.onApplicationStarted much earlier in the startup process.

Solution: remove the second attempt to start the server by removing
BisqDaemonMain's implementation of onSetupComplete, and in turn remove
the now-obsolete bisqGrpcServer field as well.

This change also eliminates the BisqGrpcServer.blockUntilShutdown
method, which in turn called the underlying grpc server's
awaitTermination method. As the comment there explained, this was
thought to be necessary because grpc "does not use daemon threads by
default", but this is actually incorrect. According to the grpc Javadoc
at [1], "Grpc uses non-daemon Threads by default and thus a Server will
continue to run even after the main thread has terminated."

[1]: https://git.io/JePjn
2020-01-20 12:14:33 +01:00
Chris Beams
900c13ef8f
Rename submodule grpc => daemon
- Rename package bisq.grpc => bisq.daemon.app
 - Rename BisqGrpcApp => BisqDaemon
 - Rename BisqGrpcServerMain => BisqDaemonMain

The script `bisq-grpc` has been renamed to `bisq-daemon` accordingly
(and will later be customized to `bisqd`). To see everything in action,
issue the following commands:

    $ gradle build
    $ ./bisq-daemon --appName=Bisq-throwaway --daoActivated=false
    $ echo getVersion | ./bisq-cli         # in a second terminal
    1.2.3
2020-01-20 12:13:30 +01:00