Skip to content

Commit 65fd270

Browse files
committed
created NearKitWalletService to account for changed recent activity endpoint
1 parent 9f9ac5c commit 65fd270

File tree

7 files changed

+118
-29
lines changed

7 files changed

+118
-29
lines changed

near-java-api-helper/src/main/java/com/syntifi/near/api/helper/json/deserializer/RecentActivityItemDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public RecentActivityItem deserialize(JsonParser p, DeserializationContext ctxt)
5252
} else if (RecentActivityItem.RecentActivityActionKind.FUNCTION_CALL.equals(recentActivityItem.getActionKind())) {
5353
recentActivityItem.setArgs(RecentActivityArgFunctionCall.builder()
5454
.methodName(argsNode.get("method_name").asText())
55-
.args(argsNode.get("args").asText())
55+
.argsJson(argsNode.get("args_json").asText())
56+
.argsBase64(argsNode.get("args_base64").asText())
5657
.gas(argsNode.get("gas").asLong())
5758
.deposit(argsNode.get("deposit").asText())
5859
.build());

near-java-api-helper/src/main/java/com/syntifi/near/api/helper/model/RecentActivityArgFunctionCall.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ public class RecentActivityArgFunctionCall implements RecentActivityArg {
2323
@JsonProperty("method_name")
2424
private String methodName;
2525

26-
@JsonProperty("args")
27-
private String args;
26+
@JsonProperty("args_json")
27+
private String argsJson;
28+
29+
@JsonProperty("args_base64")
30+
private String argsBase64;
2831

2932
@JsonProperty("gas")
3033
private long gas;

near-java-api-helper/src/main/java/com/syntifi/near/api/helper/service/NearHelperService.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.syntifi.near.api.common.service.NearObjectMapper;
44
import com.syntifi.near.api.helper.model.NearValue;
5-
import com.syntifi.near.api.helper.model.RecentActivity;
65
import okhttp3.Headers;
76
import okhttp3.OkHttpClient;
87
import retrofit2.Call;
@@ -30,15 +29,6 @@ public interface NearHelperService {
3029
@GET("/fiat")
3130
Call<NearValue> getNearValue();
3231

33-
/**
34-
* Fetches a list of recent activities for one account
35-
*
36-
* @param accountId the account to fetch activity
37-
* @return list of recent activity for the account
38-
*/
39-
@GET("account/{accountId}/activity")
40-
Call<RecentActivity> getNearRecentActivity(@Path("accountId") String accountId);
41-
4232
/**
4333
* Fetches a list of accounts for a given public key
4434
*
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.syntifi.near.api.helper.service;
2+
3+
import com.syntifi.near.api.common.service.NearObjectMapper;
4+
import com.syntifi.near.api.helper.model.RecentActivity;
5+
import okhttp3.Headers;
6+
import okhttp3.OkHttpClient;
7+
import retrofit2.Call;
8+
import retrofit2.Retrofit;
9+
import retrofit2.converter.jackson.JacksonConverterFactory;
10+
import retrofit2.http.GET;
11+
import retrofit2.http.Path;
12+
13+
/**
14+
* Near KitWallet Helper service uses the http helper API to retrieve useful data
15+
*
16+
* @author Alexandre Carvalho
17+
* @author Andre Bertolace
18+
* @since 0.2.0
19+
*/
20+
public interface NearKitWalletService {
21+
22+
/**
23+
* NearHelperService builder
24+
*
25+
* @param url the helper url to connect to
26+
* @return the helper service instance
27+
*/
28+
static NearKitWalletService usingPeer(String url) {
29+
Headers customHeaders = new Headers.Builder()
30+
.add("Content-Type", "application/json")
31+
.add("Cache-Control", "no-cache")
32+
.build();
33+
34+
Retrofit retrofit = new Retrofit.Builder()
35+
.client(new OkHttpClient.Builder()
36+
.addInterceptor(
37+
chain -> chain.proceed(chain.request().newBuilder().headers(customHeaders).build())).build())
38+
.baseUrl("https://" + url)
39+
.addConverterFactory(JacksonConverterFactory.create(NearObjectMapper.INSTANCE))
40+
.build();
41+
42+
return retrofit.create(NearKitWalletService.class);
43+
}
44+
45+
/**
46+
* Fetches a list of recent activities for one account
47+
*
48+
* @param accountId the account to fetch activity
49+
* @return list of recent activity for the account
50+
*/
51+
@GET("account/{accountId}/activity")
52+
Call<RecentActivity> getNearRecentActivity(@Path("accountId") String accountId);
53+
}

near-java-api-helper/src/test/java/com/syntifi/near/api/helper/service/NearHelperServiceTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.syntifi.near.api.helper.service;
22

33
import com.syntifi.near.api.helper.model.NearValue;
4-
import com.syntifi.near.api.helper.model.RecentActivity;
54
import org.junit.jupiter.api.Test;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
@@ -44,21 +43,6 @@ void getNearValue_valid() throws IOException {
4443
assertNotNull(nearValue);
4544
}
4645

47-
@Test
48-
void getNearRecentActivity_valid() throws IOException {
49-
Response<RecentActivity> value = nearHelperService.getNearRecentActivity("wallet-test.testnet").execute();
50-
51-
assertTrue(value.isSuccessful());
52-
53-
RecentActivity nearValue = value.body();
54-
55-
assertNotNull(nearValue);
56-
57-
LOGGER.debug("Response {}", nearValue.size());
58-
59-
assertNotNull(nearValue);
60-
}
61-
6246
@Test
6347
void getNearAccounts_valid() throws IOException {
6448
Response<List<String>> value = nearHelperService.getNearAccounts("ed25519:F8jARHGZdHqnwrxrnv1pFVzzirXZR2vJzeYbvwQbxZyP").execute();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.syntifi.near.api.helper.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class NearKitWalletServiceHelper {
7+
8+
private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceHelper.class);
9+
10+
public static NearKitWalletService nearKitWalletService;
11+
12+
static {
13+
String peerAddress = "testnet-api.kitwallet.app";
14+
15+
LOGGER.debug("======== Running tests with helper {} ========", peerAddress);
16+
nearKitWalletService = NearKitWalletService.usingPeer(peerAddress);
17+
}
18+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.syntifi.near.api.helper.service;
2+
3+
import com.syntifi.near.api.helper.model.RecentActivity;
4+
import org.junit.jupiter.api.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import retrofit2.Response;
8+
9+
import java.io.IOException;
10+
11+
import static com.syntifi.near.api.helper.service.NearKitWalletServiceHelper.nearKitWalletService;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
/**
16+
* Basic Service call testing
17+
*
18+
* @author Alexandre Carvalho
19+
* @author Andre Bertolace
20+
* @since 0.0.1
21+
*/
22+
public class NearKitWalletServiceTest {
23+
24+
private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceTest.class);
25+
26+
@Test
27+
void getNearRecentActivity_valid() throws IOException {
28+
Response<RecentActivity> value = nearKitWalletService.getNearRecentActivity("wallet-test.testnet").execute();
29+
30+
assertTrue(value.isSuccessful());
31+
32+
RecentActivity nearValue = value.body();
33+
34+
assertNotNull(nearValue);
35+
36+
LOGGER.debug("Response {}", nearValue.size());
37+
38+
assertNotNull(nearValue);
39+
}
40+
}

0 commit comments

Comments
 (0)