Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lijamie98 committed Sep 19, 2023
1 parent 96261d5 commit 5fc94c9
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.stellar.anchor.reference.model;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.stellar.anchor.api.sep.sep38.RateFee;
import org.stellar.anchor.util.GsonUtils;
import shadow.com.google.common.reflect.TypeToken;

@Converter
public class RateFeeConverter implements AttributeConverter<RateFee, String> {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/stellar/anchor/auth/JwtToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public JwtToken() {}
long iat; // Issued At
long exp; // Expiration Time
String jti; // JWT ID // Stellar Transaction ID

// String aud; // Audience
// long nbf; // Not Before

Expand Down Expand Up @@ -81,7 +82,7 @@ public static JwtToken of(
token.muxedAccount = sub;
byte[] pubKeyBytes = muxedAccount.getEd25519().getUint256();
token.account = KeyPair.fromPublicKey(pubKeyBytes).getAccountId();
token.muxedAccountId = muxedAccount.getId().getUint64();
token.muxedAccountId = muxedAccount.getId().getUint64().getNumber().longValue();
} catch (Exception ignored) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ String generateSep10Jwt(String challengeXdr, String clientDomain)
sep10Config.getHomeDomain(),
getDomainFromURI(appConfig.getHostUrl()));
debug("challenge:", challenge);
long issuedAt = challenge.getTransaction().getTimeBounds().getMinTime();
long issuedAt = challenge.getTransaction().getTimeBounds().getMinTime().longValue();
Memo memo = challenge.getTransaction().getMemo();
JwtToken jwtToken =
JwtToken.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.stellar.anchor.sep10

import com.google.common.io.BaseEncoding
import com.google.gson.annotations.SerializedName
import io.mockk.*
import io.mockk.impl.annotations.MockK
import java.io.IOException
Expand Down Expand Up @@ -47,7 +48,6 @@ import org.stellar.anchor.util.NetUtil
import org.stellar.sdk.*
import org.stellar.sdk.requests.ErrorResponse
import org.stellar.sdk.responses.AccountResponse
import shadow.com.google.gson.annotations.SerializedName

@Suppress("unused")
internal class TestSigner(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform

import com.google.common.reflect.TypeToken
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
Expand All @@ -12,7 +13,6 @@ import org.stellar.anchor.api.sep.sep12.Sep12DeleteCustomerRequest
import org.stellar.anchor.api.sep.sep12.Sep12GetCustomerResponse
import org.stellar.anchor.api.sep.sep12.Sep12PutCustomerRequest
import org.stellar.anchor.api.sep.sep12.Sep12PutCustomerResponse
import shadow.com.google.common.reflect.TypeToken

const val APPLICATION_JSON_CHARSET_UTF_8 = "application/json; charset=utf-8"
val TYPE_JSON = APPLICATION_JSON_CHARSET_UTF_8.toMediaType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.stellar.anchor.platform.callback.PlatformIntegrationHelper.*;
import static org.stellar.anchor.platform.callback.RestCustomerIntegration.Converter.*;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.net.URI;
Expand All @@ -24,7 +25,6 @@
import org.stellar.anchor.api.sep.sep12.Sep12PutCustomerResponse;
import org.stellar.anchor.auth.AuthHelper;
import org.stellar.anchor.util.Log;
import shadow.com.google.common.reflect.TypeToken;

public class RestCustomerIntegration implements CustomerIntegration {
private final String anchorEndpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static okhttp3.HttpUrl.get;
import static org.stellar.anchor.platform.callback.PlatformIntegrationHelper.*;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.net.URI;
Expand All @@ -19,7 +20,6 @@
import org.stellar.anchor.api.exception.AnchorException;
import org.stellar.anchor.api.exception.ServerErrorException;
import org.stellar.anchor.auth.AuthHelper;
import shadow.com.google.common.reflect.TypeToken;

public class RestFeeIntegration implements FeeIntegration {
private final String feeIntegrationEndPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static okhttp3.HttpUrl.get;
import static org.stellar.anchor.platform.callback.PlatformIntegrationHelper.*;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.net.URI;
Expand All @@ -21,7 +22,6 @@
import org.stellar.anchor.api.exception.ServerErrorException;
import org.stellar.anchor.auth.AuthHelper;
import org.stellar.anchor.util.Log;
import shadow.com.google.common.reflect.TypeToken;

public class RestRateIntegration implements RateIntegration {
private final String anchorEndpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.stellar.anchor.util.StellarNetworkHelper.toStellarNetwork;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonObject;
import io.netty.handler.codec.http.HttpHeaderNames;
import java.lang.reflect.Type;
Expand All @@ -26,7 +27,6 @@
import reactor.netty.http.client.HttpClient;
import reactor.util.annotation.NonNull;
import reactor.util.annotation.Nullable;
import shadow.com.google.common.reflect.TypeToken;

public class CirclePaymentService
implements PaymentService, CircleResponseErrorHandler, StellarReconciliation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform.payment.observer.circle.model;

import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.time.Instant;
Expand All @@ -10,7 +11,6 @@
import org.stellar.anchor.platform.payment.common.Payment;
import org.stellar.anchor.platform.payment.common.PaymentNetwork;
import org.stellar.anchor.util.GsonUtils;
import shadow.com.google.common.reflect.TypeToken;

@Data
public class CirclePayment {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform.payment.observer.circle.model;

import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import com.google.gson.annotations.SerializedName;
import java.lang.reflect.Type;
Expand All @@ -10,7 +11,6 @@
import org.stellar.anchor.platform.payment.common.Payment;
import org.stellar.anchor.platform.payment.common.PaymentNetwork;
import org.stellar.anchor.util.GsonUtils;
import shadow.com.google.common.reflect.TypeToken;

@Data
public class CirclePayout {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform.payment.observer.circle.model;

import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.time.Instant;
Expand All @@ -8,7 +9,6 @@
import org.stellar.anchor.platform.payment.common.Account;
import org.stellar.anchor.platform.payment.common.Payment;
import org.stellar.anchor.util.GsonUtils;
import shadow.com.google.common.reflect.TypeToken;

@Data
public class CircleTransfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform.payment.observer.circle.model;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.util.Map;
Expand All @@ -8,7 +9,6 @@
import org.stellar.anchor.platform.payment.common.PaymentNetwork;
import org.stellar.anchor.platform.payment.observer.circle.util.CircleAsset;
import org.stellar.anchor.util.GsonUtils;
import shadow.com.google.common.reflect.TypeToken;

@Data
public class CircleWireDepositInstructions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@
import org.stellar.sdk.responses.operations.OperationResponse;
import org.stellar.sdk.responses.operations.PathPaymentBaseOperationResponse;
import org.stellar.sdk.responses.operations.PaymentOperationResponse;
import shadow.com.google.common.base.Optional;

public class StellarPaymentObserver implements HealthCheckable {
/** The maximum number of results the Stellar Blockchain can return. */
private static final int MAX_RESULTS = 200;

/** The minimum number of results the Stellar Blockchain can return. */
private static final int MIN_RESULTS = 1;

/**
* If the observer had been silent for longer than SILENC_TIMEOUT, a SilenceTimeoutException will
* be thrown to trigger reconnections.
*/
private static final long SILENCE_TIMEOUT = 90;

/** If the observer has more than 2 SILENCE_TIMEOUT_RETRIES, it will be marked unhealthy */
private static final long SILENCE_TIMEOUT_RETRIES = 2;

/** The time interval between silence checks */
private static final long SILENCE_CHECK_INTERVAL = 5;

Expand Down Expand Up @@ -165,14 +168,15 @@ public void onEvent(OperationResponse operationResponse) {
}

@Override
public void onFailure(Optional<Throwable> exception, Optional<Integer> statusCode) {
handleFailure(exception);
public void onFailure(
java.util.Optional<Throwable> error, java.util.Optional<Integer> responseCode) {
handleFailure(error);
}
});
}

private void updateReceivedMetrics(OperationResponse operationResponse) {
if (metricLatestBlockReceived == null) {
if (metricLatestBlockReceived == null && operationResponse.getTransaction().isPresent()) {
metricLatestBlockReceived =
new AtomicLong(operationResponse.getTransaction().get().getLedger());
Metrics.gauge(
Expand All @@ -189,7 +193,7 @@ private void updateReceivedMetrics(OperationResponse operationResponse) {
}

private void updateProcessedMetrics(OperationResponse operationResponse) {
if (metricLatestBlockProcessed == null) {
if (metricLatestBlockProcessed == null && operationResponse.getTransaction().isPresent()) {
metricLatestBlockProcessed =
new AtomicLong(operationResponse.getTransaction().get().getLedger());
Metrics.gauge(
Expand Down Expand Up @@ -379,11 +383,13 @@ void handleEvent(OperationResponse operationResponse) {
observedPayment = ObservedPayment.fromPathPaymentOperationResponse(pathPayment);
}
} catch (SepException ex) {
Log.warn(
String.format(
"Payment of id %s contains unsupported memo %s.",
operationResponse.getId(),
operationResponse.getTransaction().get().getMemo().toString()));
if (operationResponse.getTransaction().isPresent()) {
Log.warn(
String.format(
"Payment of id %s contains unsupported memo %s.",
operationResponse.getId(),
operationResponse.getTransaction().get().getMemo().toString()));
}
Log.warnEx(ex);
}

Expand Down Expand Up @@ -422,10 +428,8 @@ void handleEvent(OperationResponse operationResponse) {

void handleFailure(Optional<Throwable> exception) {
// The SSEStreamer has internal errors. We will give up and let the container
// manager to
// restart.
errorEx("stellar payment observer stream error: ", exception.get());

// manager to restart.
exception.ifPresent(throwable -> errorEx("stellar payment observer stream error: ", throwable));
// Mark the observer unhealthy
setStatus(STREAM_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.paymentservice.circle

import com.google.common.reflect.TypeToken
import com.google.gson.Gson
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -44,7 +45,6 @@ import org.stellar.sdk.Server
import org.stellar.sdk.responses.Page
import org.stellar.sdk.responses.operations.OperationResponse
import reactor.core.publisher.Mono
import shadow.com.google.common.reflect.TypeToken

class CirclePaymentServiceTest {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.anchor.platform.payment.observer.stellar

import com.google.common.base.Optional
import com.google.gson.reflect.TypeToken
import io.mockk.*
import io.mockk.impl.annotations.MockK
Expand All @@ -17,7 +18,6 @@ import org.stellar.sdk.requests.SSEStream
import org.stellar.sdk.responses.GsonSingleton
import org.stellar.sdk.responses.Page
import org.stellar.sdk.responses.operations.OperationResponse
import shadow.com.google.common.base.Optional

class StellarPaymentObserverTest {
companion object {
Expand Down

0 comments on commit 5fc94c9

Please sign in to comment.