Skip to content

Commit

Permalink
Adding send to offer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Aug 30, 2020
1 parent bfeab2e commit d49b950
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions 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);

}
8 changes: 8 additions & 0 deletions client/src/StubHolder.java
Expand Up @@ -14,6 +14,8 @@ public class StubHolder
private volatile UserServiceStub stub;
private volatile UserServiceBlockingStub blocking_stub;

private volatile OfferPayInterface offer_pay_interface;

public StubHolder()
{

Expand All @@ -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;
}

}
38 changes: 37 additions & 1 deletion iceleaf-ui/src/SendPanel.java
Expand Up @@ -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;

Expand Down Expand Up @@ -101,6 +102,8 @@ public void setupPanel()

send_button.addActionListener(new SendButtonListner());

ice_leaf.getStubHolder().setOfferPayInterface(this);


}

Expand Down Expand Up @@ -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);

}




}
}
2 changes: 1 addition & 1 deletion protolib/util.proto
Expand Up @@ -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)
Expand Down

0 comments on commit d49b950

Please sign in to comment.