-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8088cab
commit 084462a
Showing
31 changed files
with
752 additions
and
229 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
10 changes: 10 additions & 0 deletions
10
api/src/main/java/org/cardanofoundation/rosetta/api/account/mapper/AddressBalanceMapper.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.cardanofoundation.rosetta.api.account.mapper; | ||
|
||
import org.cardanofoundation.rosetta.api.account.model.domain.AddressBalance; | ||
import org.cardanofoundation.rosetta.client.model.domain.StakeAccountInfo; | ||
|
||
public interface AddressBalanceMapper { | ||
|
||
AddressBalance convertToAdaAddressBalance(StakeAccountInfo stakeAccountInfo, Long number); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../main/java/org/cardanofoundation/rosetta/api/account/mapper/AddressBalanceMapperImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.cardanofoundation.rosetta.api.account.mapper; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import org.cardanofoundation.rosetta.api.account.model.domain.AddressBalance; | ||
import org.cardanofoundation.rosetta.client.model.domain.StakeAccountInfo; | ||
|
||
import static org.cardanofoundation.rosetta.common.util.Constants.LOVELACE; | ||
|
||
@Service | ||
@Slf4j | ||
public class AddressBalanceMapperImpl implements AddressBalanceMapper { | ||
|
||
@Override | ||
public AddressBalance convertToAdaAddressBalance(StakeAccountInfo stakeAccountInfo, Long number) { | ||
return AddressBalance.builder() | ||
.address(stakeAccountInfo.getStakeAddress()) | ||
.unit(LOVELACE) | ||
.quantity(stakeAccountInfo.getWithdrawableAmount()) | ||
.number(number) | ||
.build(); | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
9 changes: 9 additions & 0 deletions
9
api/src/main/java/org/cardanofoundation/rosetta/client/YaciHttpGateway.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.cardanofoundation.rosetta.client; | ||
|
||
import org.cardanofoundation.rosetta.client.model.domain.StakeAccountInfo; | ||
|
||
public interface YaciHttpGateway { | ||
|
||
StakeAccountInfo getStakeAccountRewards(String stakeAddress); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
api/src/main/java/org/cardanofoundation/rosetta/client/YaciHttpGatewayImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.cardanofoundation.rosetta.client; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.time.Duration; | ||
import jakarta.annotation.PostConstruct; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.cardanofoundation.rosetta.client.model.domain.StakeAccountInfo; | ||
import org.cardanofoundation.rosetta.common.exception.ExceptionFactory; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class YaciHttpGatewayImpl implements YaciHttpGateway { | ||
|
||
private final HttpClient httpClient; | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Value("${cardano.rosetta.YACI_HTTP_BASE_URL}") | ||
protected String yaciBaseUrl; | ||
|
||
@Value("${cardano.rosetta.HTTP_REQUEST_TIMEOUT_SECONDS}") | ||
protected int httpRequestTimeoutSeconds; | ||
|
||
@PostConstruct | ||
public void init() { | ||
log.info("YaciHttpGatewayImpl initialized with yaciBaseUrl: {}, httpRequestTimeoutSeconds: {}", yaciBaseUrl, httpRequestTimeoutSeconds); | ||
} | ||
|
||
@Override | ||
public StakeAccountInfo getStakeAccountRewards(String stakeAddress) { | ||
var getStakeAccountDetailsHttpRequest = HttpRequest.newBuilder() | ||
.uri(URI.create(yaciBaseUrl + "/rosetta/account/by-stake-address/" + stakeAddress)) | ||
.GET() | ||
.timeout(Duration.ofSeconds(httpRequestTimeoutSeconds)) | ||
.header("Content-Type", "application/json") | ||
.build(); | ||
|
||
try { | ||
HttpResponse<String> response = httpClient.send(getStakeAccountDetailsHttpRequest, HttpResponse.BodyHandlers.ofString()); | ||
|
||
int statusCode = response.statusCode(); | ||
String responseBody = response.body(); | ||
|
||
if (statusCode >= 200 && statusCode < 300) { | ||
return objectMapper.readValue(responseBody, StakeAccountInfo.class); | ||
} else if (statusCode == 400) { | ||
throw ExceptionFactory.gatewayError(false); | ||
} else if (statusCode == 500) { | ||
throw ExceptionFactory.gatewayError(true); | ||
} else { | ||
throw ExceptionFactory.gatewayError(false); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
log.error("Error during yaci-indexer HTTP request", e); | ||
|
||
Thread.currentThread().interrupt(); | ||
|
||
throw ExceptionFactory.gatewayError(true); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
api/src/main/java/org/cardanofoundation/rosetta/client/model/domain/StakeAccountInfo.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.cardanofoundation.rosetta.client.model.domain; | ||
|
||
import java.math.BigInteger; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public class StakeAccountInfo { | ||
|
||
private String stakeAddress; | ||
private BigInteger withdrawableAmount; | ||
private BigInteger controlledAmount; | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.