Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ Call<List<AccountRewardsHistory>> getAccountRewards(@Path("stakeAddress") String
Call<List<AccountUtxo>> getAccountUtxos(@Path("stakeAddress") String stakeAddress,
@Query("network") String network);

@GET("api/account/{stakeAddress}/assets")
Call<List<AccountAsset>> getAccountAssets(@Path("stakeAddress") String stakeAddress,
@Query("network") String network,
@Query("policy") String policyId,
@Query("page") Integer page,
@Query("pageSize") Integer pageSize);

@GET("api/account/{stakeAddress}/txs")
Call<List<AccountTransaction>> getAccountTransactions(@Path("stakeAddress") String stakeAddress,
@Query("network") String network,
@Query("from") Integer fromBlockHeight);
@Query("from") Integer fromBlockHeight,
@Query("to") Integer toBlockHeight,
@Query("order") String order);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ public interface AccountService {
Result<List<AccountUtxo>> getAccountUtxos(Network network, String stakeAddress) throws ApiException;

/** {@code fromBlockHeight} is required by Nexus; pass {@code 1} for the full history. */
/**
* Native-asset balances held under a stake account, aggregated server-side across
* all unspent UTxOs. Prefer this to summing {@link #getAccountUtxos} asset lists:
* that costs wire bytes proportional to the number of UTxOs for a figure the
* server already computes.
*/
Result<List<AccountAsset>> getAccountAssets(Network network, String stakeAddress,
int page, int pageSize) throws ApiException;

/** As above, restricted to a single policy id. */
Result<List<AccountAsset>> getAccountAssets(Network network, String stakeAddress, String policyId,
int page, int pageSize) throws ApiException;

Result<List<AccountTransaction>> getAccountTransactions(Network network, String stakeAddress,
int fromBlockHeight) throws ApiException;

/**
* As above, with an upper block-height bound and an explicit ordering.
*
* <p>Without these a caller wanting one end of an account's history has to download
* all of it. Pass {@code order} "asc" (oldest first) or "desc"; null leaves the
* server default, which is ascending.
*/
Result<List<AccountTransaction>> getAccountTransactions(Network network, String stakeAddress,
int fromBlockHeight, Integer toBlockHeight,
String order) throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,32 @@ public Result<List<AccountUtxo>> getAccountUtxos(Network network, String stakeAd
return ApiUtil.process(api.getAccountUtxos(stakeAddress, network.queryValue()));
}

@Override
public Result<List<AccountAsset>> getAccountAssets(Network network, String stakeAddress,
int page, int pageSize) throws ApiException {
return getAccountAssets(network, stakeAddress, null, page, pageSize);
}

@Override
public Result<List<AccountAsset>> getAccountAssets(Network network, String stakeAddress, String policyId,
int page, int pageSize) throws ApiException {
return ApiUtil.process(api.getAccountAssets(stakeAddress, network.queryValue(), policyId, page, pageSize));
}

@Override
public Result<List<AccountTransaction>> getAccountTransactions(Network network, String stakeAddress,
int fromBlockHeight) throws ApiException {
return ApiUtil.process(api.getAccountTransactions(stakeAddress, network.queryValue(), fromBlockHeight));
// null order/to: leave the server defaults alone, so this overload behaves exactly
// as it did before the parameters were exposed.
return ApiUtil.process(
api.getAccountTransactions(stakeAddress, network.queryValue(), fromBlockHeight, null, null));
}

@Override
public Result<List<AccountTransaction>> getAccountTransactions(Network network, String stakeAddress,
int fromBlockHeight, Integer toBlockHeight,
String order) throws ApiException {
return ApiUtil.process(
api.getAccountTransactions(stakeAddress, network.queryValue(), fromBlockHeight, toBlockHeight, order));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package adlabs.nexus.client.backend.api.account;

import adlabs.nexus.client.backend.api.account.impl.AccountServiceImpl;
import adlabs.nexus.client.backend.api.account.model.AccountAsset;
import adlabs.nexus.client.backend.api.account.model.AccountInformation;
import adlabs.nexus.client.backend.api.account.model.AccountTransaction;
import adlabs.nexus.client.backend.api.base.Result;
import adlabs.nexus.client.http.RetrofitClient;
import adlabs.nexus.client.util.Network;
Expand All @@ -13,6 +15,7 @@
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -68,4 +71,76 @@ void getAccountInformation_returnsError_on404() throws Exception {
assertFalse(result.isSuccessful());
assertEquals(404, result.getCode());
}

// ------------------------------------------------------------------
// GET /api/account/{stake}/assets (issue #7)
//
// Nexus aggregates native-asset balances server-side, but the client never
// wrapped it, so consumers had to pull every account UTxO and sum the asset
// lists themselves -- O(number of UTxOs) in wire bytes for a figure the
// server already knows. cardano-shield-api does exactly that today.
// ------------------------------------------------------------------

@Test
void getAccountAssets_callsTheAssetsEndpointWithPaging() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody(
"[{\"policyId\":\"policyA\",\"assetName\":\"TOKEN\",\"quantity\":\"350\"}]"));

Result<List<AccountAsset>> result =
service.getAccountAssets(Network.MAINNET, "stake1xyz", 1, 100);

RecordedRequest request = server.takeRequest();
assertTrue(request.getPath().startsWith("/api/account/stake1xyz/assets"),
"unexpected path: " + request.getPath());
assertTrue(request.getPath().contains("page=1"), request.getPath());
assertTrue(request.getPath().contains("pageSize=100"), request.getPath());
assertTrue(result.isSuccessful());
assertEquals(1, result.getValue().size());
assertEquals("policyA", result.getValue().get(0).getPolicyId());
assertEquals("350", result.getValue().get(0).getQuantity());
}

@Test
void getAccountAssets_passesThePolicyFilterWhenGiven() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));

service.getAccountAssets(Network.MAINNET, "stake1xyz", "policyA", 1, 100);

RecordedRequest request = server.takeRequest();
assertTrue(request.getPath().contains("policy=policyA"), request.getPath());
}

// ------------------------------------------------------------------
// GET /api/account/{stake}/txs — order / to (issue #8)
//
// The endpoint accepts both, the client exposed neither, so a caller wanting
// one end of an account's history had to download all of it. cardano-shield
// needs only the oldest transaction to decide whether an address is new.
// ------------------------------------------------------------------

@Test
void getAccountTransactions_sendsOrderAndUpperBound() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));

service.getAccountTransactions(Network.MAINNET, "stake1xyz", 1, 12_000_000, "desc");

RecordedRequest request = server.takeRequest();
assertTrue(request.getPath().contains("from=1"), request.getPath());
assertTrue(request.getPath().contains("to=12000000"), request.getPath());
assertTrue(request.getPath().contains("order=desc"), request.getPath());
}

@Test
void getAccountTransactions_shortOverloadIsUnchanged() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));

Result<List<AccountTransaction>> result =
service.getAccountTransactions(Network.MAINNET, "stake1xyz", 1);

RecordedRequest request = server.takeRequest();
assertTrue(request.getPath().contains("from=1"), request.getPath());
assertFalse(request.getPath().contains("order="),
"the existing overload must keep relying on the server default");
assertTrue(result.isSuccessful());
}
}
Loading