From d49b950190b24307e2be7a3ee65ce25bf3a0d3dd Mon Sep 17 00:00:00 2001 From: fireduck64 Date: Sat, 29 Aug 2020 22:13:04 -0700 Subject: [PATCH] Adding send to offer interface --- client/src/OfferPayInterface.java | 10 ++++++++ client/src/StubHolder.java | 8 +++++++ iceleaf-ui/src/SendPanel.java | 38 ++++++++++++++++++++++++++++++- protolib/util.proto | 2 +- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 client/src/OfferPayInterface.java diff --git a/client/src/OfferPayInterface.java b/client/src/OfferPayInterface.java new file mode 100644 index 00000000..e84b2b3c --- /dev/null +++ b/client/src/OfferPayInterface.java @@ -0,0 +1,10 @@ +package snowblossom.client; + +import snowblossom.util.proto.Offer; +import snowblossom.util.proto.OfferAcceptance; + +public interface OfferPayInterface +{ + public void maybePayOffer(Offer offer, OfferAcceptance oa); + +} diff --git a/client/src/StubHolder.java b/client/src/StubHolder.java index 0d239ef7..4e98e5f3 100644 --- a/client/src/StubHolder.java +++ b/client/src/StubHolder.java @@ -14,6 +14,8 @@ public class StubHolder private volatile UserServiceStub stub; private volatile UserServiceBlockingStub blocking_stub; + private volatile OfferPayInterface offer_pay_interface; + public StubHolder() { @@ -34,4 +36,10 @@ public void update(ManagedChannel channel) public UserServiceBlockingStub getBlockingStub(){return blocking_stub;} public UserServiceStub getAsyncStub(){return stub;} + public OfferPayInterface getOfferPayInterface(){return offer_pay_interface;} + public void setOfferPayInterface(OfferPayInterface offer_pay_interface) + { + this.offer_pay_interface = offer_pay_interface; + } + } diff --git a/iceleaf-ui/src/SendPanel.java b/iceleaf-ui/src/SendPanel.java index 88b202b7..b5623a2d 100644 --- a/iceleaf-ui/src/SendPanel.java +++ b/iceleaf-ui/src/SendPanel.java @@ -19,8 +19,9 @@ import snowblossom.util.proto.*; import java.util.Base64; import com.google.protobuf.ByteString; +import snowblossom.client.OfferPayInterface; -public class SendPanel extends BasePanel +public class SendPanel extends BasePanel implements OfferPayInterface { protected WalletComboBox wallet_select_box; @@ -101,6 +102,8 @@ public void setupPanel() send_button.addActionListener(new SendButtonListner()); + ice_leaf.getStubHolder().setOfferPayInterface(this); + } @@ -253,4 +256,37 @@ public void run() }); } + @Override + public void maybePayOffer(Offer offer, OfferAcceptance oa) + { + OfferAcceptance.Builder accept = OfferAcceptance.newBuilder(); + + accept.mergeFrom(oa); + accept.setOfferId(offer.getOfferId()); + + OfferCurrency oc_snow = offer.getOfferPriceMap().get("SNOW"); + + + try + { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() + { + dest_field.setText( oc_snow.getAddress() ); + send_amount_field.setText( "" + oc_snow.getPrice()); + + extra_field.setText( Base64.getEncoder().encodeToString( accept.build().toByteString().toByteArray() )); + } + }); + } + catch(Exception e) + { + throw new RuntimeException(e); + + } + + + + + } } diff --git a/protolib/util.proto b/protolib/util.proto index c61bed78..ed69b09d 100644 --- a/protolib/util.proto +++ b/protolib/util.proto @@ -96,7 +96,7 @@ message OfferCurrency // To be stuffed in extra field of transaction message OfferAcceptance { - bytes offer_id = 1; // Identifier of the offer accepted + string offer_id = 1; // Identifier of the offer accepted oneof z { // That that are doing PKI to sign messages for the recipient will need the full spec AddressSpec for_address_spec = 2; // address spec of the beneficiary of the offer (if applicable)