Skip to content

Commit

Permalink
created NearKitWalletService to account for changed recent activity e…
Browse files Browse the repository at this point in the history
…ndpoint
  • Loading branch information
oak committed May 19, 2022
1 parent 9f9ac5c commit 65fd270
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public RecentActivityItem deserialize(JsonParser p, DeserializationContext ctxt)
} else if (RecentActivityItem.RecentActivityActionKind.FUNCTION_CALL.equals(recentActivityItem.getActionKind())) {
recentActivityItem.setArgs(RecentActivityArgFunctionCall.builder()
.methodName(argsNode.get("method_name").asText())
.args(argsNode.get("args").asText())
.argsJson(argsNode.get("args_json").asText())
.argsBase64(argsNode.get("args_base64").asText())
.gas(argsNode.get("gas").asLong())
.deposit(argsNode.get("deposit").asText())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public class RecentActivityArgFunctionCall implements RecentActivityArg {
@JsonProperty("method_name")
private String methodName;

@JsonProperty("args")
private String args;
@JsonProperty("args_json")
private String argsJson;

@JsonProperty("args_base64")
private String argsBase64;

@JsonProperty("gas")
private long gas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.syntifi.near.api.common.service.NearObjectMapper;
import com.syntifi.near.api.helper.model.NearValue;
import com.syntifi.near.api.helper.model.RecentActivity;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import retrofit2.Call;
Expand Down Expand Up @@ -30,15 +29,6 @@ public interface NearHelperService {
@GET("/fiat")
Call<NearValue> getNearValue();

/**
* Fetches a list of recent activities for one account
*
* @param accountId the account to fetch activity
* @return list of recent activity for the account
*/
@GET("account/{accountId}/activity")
Call<RecentActivity> getNearRecentActivity(@Path("accountId") String accountId);

/**
* Fetches a list of accounts for a given public key
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.syntifi.near.api.helper.service;

import com.syntifi.near.api.common.service.NearObjectMapper;
import com.syntifi.near.api.helper.model.RecentActivity;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Path;

/**
* Near KitWallet Helper service uses the http helper API to retrieve useful data
*
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.2.0
*/
public interface NearKitWalletService {

/**
* NearHelperService builder
*
* @param url the helper url to connect to
* @return the helper service instance
*/
static NearKitWalletService usingPeer(String url) {
Headers customHeaders = new Headers.Builder()
.add("Content-Type", "application/json")
.add("Cache-Control", "no-cache")
.build();

Retrofit retrofit = new Retrofit.Builder()
.client(new OkHttpClient.Builder()
.addInterceptor(
chain -> chain.proceed(chain.request().newBuilder().headers(customHeaders).build())).build())
.baseUrl("https://" + url)
.addConverterFactory(JacksonConverterFactory.create(NearObjectMapper.INSTANCE))
.build();

return retrofit.create(NearKitWalletService.class);
}

/**
* Fetches a list of recent activities for one account
*
* @param accountId the account to fetch activity
* @return list of recent activity for the account
*/
@GET("account/{accountId}/activity")
Call<RecentActivity> getNearRecentActivity(@Path("accountId") String accountId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.syntifi.near.api.helper.service;

import com.syntifi.near.api.helper.model.NearValue;
import com.syntifi.near.api.helper.model.RecentActivity;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -44,21 +43,6 @@ void getNearValue_valid() throws IOException {
assertNotNull(nearValue);
}

@Test
void getNearRecentActivity_valid() throws IOException {
Response<RecentActivity> value = nearHelperService.getNearRecentActivity("wallet-test.testnet").execute();

assertTrue(value.isSuccessful());

RecentActivity nearValue = value.body();

assertNotNull(nearValue);

LOGGER.debug("Response {}", nearValue.size());

assertNotNull(nearValue);
}

@Test
void getNearAccounts_valid() throws IOException {
Response<List<String>> value = nearHelperService.getNearAccounts("ed25519:F8jARHGZdHqnwrxrnv1pFVzzirXZR2vJzeYbvwQbxZyP").execute();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.syntifi.near.api.helper.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NearKitWalletServiceHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceHelper.class);

public static NearKitWalletService nearKitWalletService;

static {
String peerAddress = "testnet-api.kitwallet.app";

LOGGER.debug("======== Running tests with helper {} ========", peerAddress);
nearKitWalletService = NearKitWalletService.usingPeer(peerAddress);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.syntifi.near.api.helper.service;

import com.syntifi.near.api.helper.model.RecentActivity;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import retrofit2.Response;

import java.io.IOException;

import static com.syntifi.near.api.helper.service.NearKitWalletServiceHelper.nearKitWalletService;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Basic Service call testing
*
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
public class NearKitWalletServiceTest {

private static final Logger LOGGER = LoggerFactory.getLogger(NearKitWalletServiceTest.class);

@Test
void getNearRecentActivity_valid() throws IOException {
Response<RecentActivity> value = nearKitWalletService.getNearRecentActivity("wallet-test.testnet").execute();

assertTrue(value.isSuccessful());

RecentActivity nearValue = value.body();

assertNotNull(nearValue);

LOGGER.debug("Response {}", nearValue.size());

assertNotNull(nearValue);
}
}

0 comments on commit 65fd270

Please sign in to comment.