This repository was archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Implement GetBalance client call and server endpoint #217
Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5894279
adding balance, fixing offerings. wip
0dba7c2
adding optional success field to close message
f21cdf0
fixing test data message and resource constructions. more tests are p…
35aa08d
in the middle of refactoring - all tests using test vectors are still…
a1d2f91
adding a todo
09f4762
Merge branch 'main' of github.com:TBD54566975/tbdex-kt into 207-proto…
494156b
refactoring method name in vector test
6a57244
bumping submodule commit
6b74577
adding ktdocs
7a0ae63
more ktdocs
18dd13f
adding balance and resource tests for balance. adding balance test ve…
ceadf77
adding new client method to fetch balances
0ce5957
wrote client tests
da2aafe
adding server endpoint for balance api
15d18d3
Merge branch 'main' of github.com:TBD54566975/tbdex-kt into 133-get-b…
8a31cda
adding detekt fixes. still 1 test failing due to rfq schema error
61a1446
Merge branch 'main' of github.com:TBD54566975/tbdex-kt into 133-get-b…
393e9eb
adding requesterDid to balanceApi.getBalance param. doing an auth tok…
1fad2ed
refactoring existing tests. add new test for getbalance
01d6a12
adding ktdoc for fakeBalancesApi#addBalance
9f90c3c
Apply suggestions from code review
0e8d498
adding try catch around parsing balance and offering
c67f00a
Update httpserver/src/main/kotlin/tbdex/sdk/httpserver/TbdexHttpServe…
43bf4c8
adding balancesEnabled config
f500e35
aligning with tbdex-js way of making balancesapi optional
c71048d
removed testserver
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
adding new client method to fetch balances
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import tbdex.sdk.httpclient.models.GetExchangesFilter | |
| import tbdex.sdk.httpclient.models.GetOfferingsFilter | ||
| import tbdex.sdk.httpclient.models.TbdexResponseException | ||
| import tbdex.sdk.protocol.Validator | ||
| import tbdex.sdk.protocol.models.Balance | ||
| import tbdex.sdk.protocol.models.Close | ||
| import tbdex.sdk.protocol.models.Message | ||
| import tbdex.sdk.protocol.models.Offering | ||
|
|
@@ -72,6 +73,42 @@ object TbdexHttpClient { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetches balances from a PFI. | ||
| * | ||
| * @param pfiDid The decentralized identifier of the PFI. | ||
| * @param requesterDid The decentralized identifier of the entity requesting the balances. | ||
| * @return A list of [Balance] matching the request. | ||
| * @throws TbdexResponseException for request or response errors. | ||
| */ | ||
| fun getBalances(pfiDid: String, requesterDid: BearerDid): List<Balance> { | ||
| val pfiServiceEndpoint = getPfiServiceEndpoint(pfiDid) | ||
| val baseUrl = "$pfiServiceEndpoint/balances/" | ||
| val requestToken = RequestToken.generate(requesterDid, pfiDid) | ||
|
|
||
| val request = Request.Builder() | ||
| .url(baseUrl) | ||
| .addHeader("Content-Type", JSON_HEADER) | ||
| .addHeader("Authorization", "Bearer $requestToken") | ||
| .get() | ||
| .build() | ||
|
|
||
| val response: Response = client.newCall(request).execute() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah does this throw an exception if the request fails? e.g. timeout,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct. from the docs: |
||
| when { | ||
| response.isSuccessful -> { | ||
| val responseString = response.body?.string() | ||
| // response body is an object with a data field | ||
| val jsonNode = jsonMapper.readTree(responseString) | ||
| return jsonNode.get("data").elements() | ||
| .asSequence() | ||
| .map { Balance.parse(it.toString()) } | ||
|
||
| .toList() | ||
| } | ||
|
|
||
| else -> throw buildResponseException(response) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Send RFQ message to the PFI. | ||
| * | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud: in tbdex-js, we have both
TbdexRequestErrorandTbdexResponseError, representing errors that happen before and after the client call respectively. It's a slight misnomer to throw a RequestException for both request and response errors, so I'm making a mental note that in my next tidy-up PR, I may explore introducing aTbdexRequestExceptionclass. In any case, it's relatively low priority and outside the scope of this PR.