Repository: hyperledger/quilt
Pull request #460 (2020-05-06 00:18:25)

Add denomination to send money result


Patch:
diff --git a/examples-parent/send-money/src/main/java/org/interledger/examples/SendMoneyExample.java b/examples-parent/send-money/src/main/java/org/interledger/examples/SendMoneyExample.java
index af67289..783179c 100644
--- a/examples-parent/send-money/src/main/java/org/interledger/examples/SendMoneyExample.java
+++ b/examples-parent/send-money/src/main/java/org/interledger/examples/SendMoneyExample.java
@@ -74,7 +74,9 @@ public class SendMoneyExample {
     // Send payment using STREAM
     SendMoneyResult result = simpleStreamSender.sendMoney(
         SendMoneyRequest.builder()
-            // No source address because the client/sender is not routable (i.e., can't receive).
+            // The client is not routable, so while we could send an empty ConnectionNewAddress frame, this breaks older
+            // version of the Java receiver, so for now we specify an address here.
+            .sourceAddress(OPERATOR_ADDRESS)
             .amount(UnsignedLong.valueOf(ONE_DROP_IN_SCALE_9))
             .denomination(Denominations.XRP_MILLI_DROPS)
             .destinationAddress(connectionDetails.destinationAddress())
diff --git a/stream-parent/stream-client/src/main/java/org/interledger/stream/sender/SimpleStreamSender.java b/stream-parent/stream-client/src/main/java/org/interledger/stream/sender/SimpleStreamSender.java
index ee02188..232e707 100644
--- a/stream-parent/stream-client/src/main/java/org/interledger/stream/sender/SimpleStreamSender.java
+++ b/stream-parent/stream-client/src/main/java/org/interledger/stream/sender/SimpleStreamSender.java
@@ -367,7 +367,9 @@ public class SimpleStreamSender implements StreamSender {
             this.sendMoneyPacketized();
             return SendMoneyResult.builder()
                 .senderAddress(this.computeSenderAddressForReportingPurposes())
+                .senderDenomination(senderDenomination)
                 .destinationAddress(destinationAddress)
+                .destinationDenomination(receiverDenomination)
                 .amountDelivered(paymentTracker.getDeliveredAmountInReceiverUnits())
                 .amountSent(paymentTracker.getDeliveredAmountInSenderUnits())
                 .amountLeftToSend(paymentTracker.getOriginalAmountLeft())
@@ -400,7 +402,9 @@ public class SimpleStreamSender implements StreamSender {
       Objects.requireNonNull(startPreflight);
       return SendMoneyResult.builder()
           .senderAddress(this.computeSenderAddressForReportingPurposes())
+          .senderDenomination(senderDenomination)
           .destinationAddress(destinationAddress)
+          .destinationDenomination(receiverDenomination)
           .sendMoneyDuration(Duration.between(startPreflight, DateUtils.now()))
           .numRejectPackets(0)
           .numFulfilledPackets(0)
@@ -596,8 +600,8 @@ public class SimpleStreamSender implements StreamSender {
 
         // Create the ILP Prepare packet
         final byte[] streamPacketData = this.toEncrypted(sharedSecret, streamPacket);
-        final InterledgerCondition executionCondition;
-        executionCondition = generatedFulfillableFulfillment(sharedSecret, streamPacketData).getCondition();
+        final InterledgerCondition executionCondition
+            = generatedFulfillableFulfillment(sharedSecret, streamPacketData).getCondition();
 
         final Supplier<InterledgerPreparePacket> preparePacket = () -> InterledgerPreparePacket.builder()
             .destination(destinationAddress)
diff --git a/stream-parent/stream-core/src/main/java/org/interledger/stream/SendMoneyResult.java b/stream-parent/stream-core/src/main/java/org/interledger/stream/SendMoneyResult.java
index 6ed48fc..cbc994e 100644
--- a/stream-parent/stream-core/src/main/java/org/interledger/stream/SendMoneyResult.java
+++ b/stream-parent/stream-core/src/main/java/org/interledger/stream/SendMoneyResult.java
@@ -25,6 +25,13 @@ public interface SendMoneyResult {
    */
   Optional<InterledgerAddress> senderAddress();
 
+  /**
+   * The {@link Denomination} of the sender address (i.e., the STREAM sender).
+   *
+   * @return The {@link Denomination} of the STREAM sender.
+   */
+  Denomination senderDenomination();
+
   /**
    * The ILP address of the receiver.
    *
@@ -32,6 +39,14 @@ public interface SendMoneyResult {
    */
   InterledgerAddress destinationAddress();
 
+  /**
+   * The optionally-present {@link Denomination} of the destination address (i.e., the STREAM receiver). This value is
+   * optional because some receivers don't advertise their asset details.
+   *
+   * @return A {@link Denomination} of the STREAM receiver.
+   */
+  Optional<Denomination> destinationDenomination();
+
   /**
    * The original amount that was requested to be sent.
    *


Test patch:
diff --git a/stream-parent/stream-core/src/test/java/org/interledger/stream/SendMoneyResultTest.java b/stream-parent/stream-core/src/test/java/org/interledger/stream/SendMoneyResultTest.java
index bf6ace3..b7ccf0f 100644
--- a/stream-parent/stream-core/src/test/java/org/interledger/stream/SendMoneyResultTest.java
+++ b/stream-parent/stream-core/src/test/java/org/interledger/stream/SendMoneyResultTest.java
@@ -15,9 +15,20 @@ import java.time.Duration;
  */
 public class SendMoneyResultTest {
 
+  private static final Denomination SENDER_DENOMINATION = Denomination.builder()
+      .assetCode("USD")
+      .assetScale((short) 2)
+      .build();
+
+  private static final Denomination DESTINATION_DENOMINATION = Denomination.builder()
+      .assetCode("XRP")
+      .assetScale((short) 9)
+      .build();
+
   @Test
   public void testBuilderWithNoOptionals() {
     SendMoneyResult result = SendMoneyResult.builder()
+        .senderDenomination(SENDER_DENOMINATION)
         .destinationAddress(InterledgerAddress.of("example.destination"))
         .originalAmount(ZERO)
         .amountDelivered(UnsignedLong.ONE)
@@ -30,6 +41,7 @@ public class SendMoneyResultTest {
         .build();
     assertThat(result.senderAddress()).isEmpty();
     assertThat(result.destinationAddress()).isEqualTo(InterledgerAddress.of("example.destination"));
+    assertThat(result.destinationDenomination()).isEmpty();
     assertThat(result.originalAmount()).isEqualTo(ZERO);
     assertThat(result.amountDelivered()).isEqualTo(UnsignedLong.ONE);
     assertThat(result.amountSent()).isEqualTo(UnsignedLong.valueOf(2));
@@ -45,7 +57,9 @@ public class SendMoneyResultTest {
   public void testBuilderWithOptionals() {
     SendMoneyResult result = SendMoneyResult.builder()
         .senderAddress(InterledgerAddress.of("example.sender"))
+        .senderDenomination(SENDER_DENOMINATION)
         .destinationAddress(InterledgerAddress.of("example.destination"))
+        .destinationDenomination(DESTINATION_DENOMINATION)
         .originalAmount(ZERO)
         .amountDelivered(UnsignedLong.ONE)
         .amountSent(UnsignedLong.valueOf(2))
@@ -55,8 +69,11 @@ public class SendMoneyResultTest {
         .sendMoneyDuration(Duration.ofMillis(1000))
         .successfulPayment(false)
         .build();
+
     assertThat(result.senderAddress().get()).isEqualTo(InterledgerAddress.of("example.sender"));
+    assertThat(result.senderDenomination()).isEqualTo(SENDER_DENOMINATION);
     assertThat(result.destinationAddress()).isEqualTo(InterledgerAddress.of("example.destination"));
+    assertThat(result.destinationDenomination().get()).isEqualTo(DESTINATION_DENOMINATION);
     assertThat(result.originalAmount()).isEqualTo(ZERO);
     assertThat(result.amountDelivered()).isEqualTo(UnsignedLong.ONE);
     assertThat(result.amountSent()).isEqualTo(UnsignedLong.valueOf(2));