Skip to content

Commit

Permalink
Merge develop into sep-6 (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipliu authored Sep 13, 2023
2 parents 678b9e8 + 1fd02f8 commit 067a41f
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
@AllArgsConstructor
@NoArgsConstructor
public class SendEventRequest {
/** The seconds since the Unix epoch, UTC. */
Long timestamp;
/** The ID of the event */
String id;
/** The ISO 8601 UTC datetime string */
String timestamp;
/** The type of event */
String type;
/** The event payload. */
AnchorEvent payload;
SendEventRequestPayload payload;

/**
* Creates a SendEventRequest from an AnchorEvent.
Expand All @@ -24,8 +28,10 @@ public class SendEventRequest {
*/
public static SendEventRequest from(AnchorEvent event) {
SendEventRequest request = new SendEventRequest();
request.setTimestamp(Instant.now().getEpochSecond());
request.setPayload(event);
request.setId(event.getId());
request.setType(event.getType().toString().toLowerCase());
request.setTimestamp(Instant.now().toString());
request.setPayload(SendEventRequestPayload.from(event));
return request;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.stellar.anchor.api.callback;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.stellar.anchor.api.event.AnchorEvent;
import org.stellar.anchor.api.platform.GetQuoteResponse;
import org.stellar.anchor.api.platform.GetTransactionResponse;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SendEventRequestPayload {
GetTransactionResponse transaction;
GetQuoteResponse quote;

/**
* Creates a SendEventRequestPayload from an AnchorEvent.
*
* @param event
* @return a SendEventRequestPayload
*/
public static SendEventRequestPayload from(AnchorEvent event) {
SendEventRequestPayload payload = new SendEventRequestPayload();
switch (event.getType()) {
case QUOTE_CREATED:
payload.setQuote(event.getQuote());
case TRANSACTION_CREATED:
payload.setTransaction(event.getTransaction());
case TRANSACTION_ERROR:
payload.setTransaction(event.getTransaction());
case TRANSACTION_STATUS_CHANGED:
payload.setTransaction(event.getTransaction());
}
return payload;
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ subprojects {

allprojects {
group = "org.stellar.anchor-sdk"
version = "2.2.1"
version = "2.2.2"

tasks.jar {
manifest {
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![License](https://badgen.net/badge/license/Apache%202/blue?icon=github&label=License)](https://github.com/stellar/java-stellar-anchor-sdk/blob/develop/LICENSE)
[![GitHub Version](https://badgen.net/github/release/stellar/java-stellar-anchor-sdk?icon=github&label=Latest%20release)](https://github.com/stellar/java-stellar-anchor-sdk/releases)
[![Docker](https://badgen.net/badge/Latest%20Release/v2.2.1/blue?icon=docker)](https://hub.docker.com/r/stellar/anchor-platform/tags?page=1&name=2.2.1)
[![Docker](https://badgen.net/badge/Latest%20Release/v2.2.2/blue?icon=docker)](https://hub.docker.com/r/stellar/anchor-platform/tags?page=1&name=2.2.2)
![Develop Branch](https://github.com/stellar/java-stellar-anchor-sdk/actions/workflows/wk_push_to_develop.yml/badge.svg?branch=develop)

<div style="text-align: center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,33 @@ internal class KotlinReferenceServerIntegrationTest {
client.sendEvent(sendEventRequest1)
var latestEvent = client.getLatestEvent()
Assertions.assertNotNull(latestEvent)
JSONAssert.assertEquals(json(latestEvent), json(sendEventRequest1.payload), true)
JSONAssert.assertEquals(json(latestEvent), json(sendEventRequest1), true)
// send event2
client.sendEvent(sendEventRequest2)
latestEvent = client.getLatestEvent()
Assertions.assertNotNull(latestEvent)
JSONAssert.assertEquals(json(latestEvent), json(sendEventRequest2.payload), true)
JSONAssert.assertEquals(json(latestEvent), json(sendEventRequest2), true)
// check if there are totally two events recorded
assertEquals(client.getEvents().size, 2)
JSONAssert.assertEquals(json(client.getEvents()[0]), json(sendEventRequest1.payload), true)
JSONAssert.assertEquals(json(client.getEvents()[1]), json(sendEventRequest2.payload), true)
JSONAssert.assertEquals(json(client.getEvents()[0]), json(sendEventRequest1), true)
JSONAssert.assertEquals(json(client.getEvents()[1]), json(sendEventRequest2), true)
}
}

companion object {
val sendEventRequestJson =
"""
{
"timestamp": 1000000,
"timestamp": "2011-10-05T14:48:00.000Z",
"id": "2a419880-0dde-4821-90cb-f3bfcb671ea3",
"type": "transaction_created",
"payload": {
"type": "TRANSACTION_CREATED",
"id": 100,
"sep": 24,
"transaction": {
"amount_in": {
"amount": "10.0",
"asset": "USDC"
}
"transaction": {
"amount_in": {
"amount": "10.0",
"asset": "USDC"
}
}
}
}
"""
Expand All @@ -77,11 +76,10 @@ internal class KotlinReferenceServerIntegrationTest {
val sendEventRequestJson2 =
"""
{
"timestamp": 1000000,
"id": "2a419880-0dde-4821-90cb-f3bfcb671ea3",
"timestamp": "2011-10-05T14:48:00.000Z",
"type": "quote_created",
"payload": {
"type": "TRANSACTION_CREATED",
"id": 100,
"sep": 24,
"quote": {
"sell_amount": "10.0",
"buy_amount": "1"
Expand Down
Loading

0 comments on commit 067a41f

Please sign in to comment.