Skip to content

Commit

Permalink
Merge branch 'master' of github.com:snowblossomcoin/snowblossom into …
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
fireduck64 committed Aug 30, 2020
2 parents 41491c2 + dd59f1d commit 4bfb9a3
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 54 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Expand Up @@ -3,6 +3,7 @@
* Added History panel to iceleaf GUI
* Added SubscribeAddressUpdates gRPC api to node to monitor addresses
* Added MonitorTool to use SubscribeAddressUpdates to monitor addresses
* Update seed nodes

## 1.7.0

Expand Down
4 changes: 2 additions & 2 deletions client/src/MonitorInterface.java
Expand Up @@ -4,8 +4,8 @@

public interface MonitorInterface
{
public void onInbound(Transaction tx, int tx_in_idx);
public void onInbound(Transaction tx, int tx_out_idx);

public void onOutbound(Transaction tx, int tx_out_idx);
public void onOutbound(Transaction tx, int tx_in_idx);

}
6 changes: 6 additions & 0 deletions client/src/MonitorTool.java
Expand Up @@ -19,6 +19,12 @@

import java.util.HashSet;

/**
* For any addresses added via addAddress this will cause the MonitorInterface
* to be called for any transactions in or out of that address.
*
* Includes all historical transactions.
*/
public class MonitorTool implements StreamObserver<AddressUpdate>
{
private NetworkParams params;
Expand Down
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;
}

}
160 changes: 116 additions & 44 deletions iceleaf-ui/src/SendPanel.java
@@ -1,13 +1,15 @@
package snowblossom.iceleaf;

import com.google.protobuf.ByteString;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Base64;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import snowblossom.client.OfferPayInterface;
import snowblossom.client.SnowBlossomClient;
import snowblossom.client.TransactionFactory;
import snowblossom.lib.AddressSpecHash;
Expand All @@ -18,12 +20,13 @@
import snowblossom.proto.TransactionOutput;
import snowblossom.util.proto.*;

public class SendPanel extends BasePanel
public class SendPanel extends BasePanel implements OfferPayInterface
{
protected WalletComboBox wallet_select_box;

protected JTextField dest_field;
protected JTextField send_amount_field;
protected JTextField extra_field;
protected JProgressBar send_bar;
protected JButton send_button;

Expand All @@ -34,6 +37,7 @@ public class SendPanel extends BasePanel
private String saved_dest;
private String saved_amount;
private String saved_wallet;
private String saved_extra;
private Object state_obj = new Object();
private TransactionFactoryResult tx_result;

Expand All @@ -43,11 +47,11 @@ public class SendPanel extends BasePanel
public SendPanel(IceLeaf ice_leaf)
{
super(ice_leaf);
}
}

@Override
public void setupPanel()
{
public void setupPanel()
{

GridBagConstraints c = new GridBagConstraints();
c.weightx = 0.0;
Expand Down Expand Up @@ -80,6 +84,15 @@ public void setupPanel()
send_amount_field.setColumns(15);
panel.add(send_amount_field, c);

c.gridwidth = 1;
panel.add(new JLabel("Extra transaction data (public):"), c);
c.gridwidth = GridBagConstraints.REMAINDER;

extra_field = new JTextField();
extra_field.setColumns(80);
panel.add(extra_field, c);


send_bar = new JProgressBar(0, SEND_DELAY);
panel.add(send_bar, c);

Expand All @@ -88,6 +101,8 @@ public void setupPanel()

send_button.addActionListener(new SendButtonListner());

ice_leaf.getStubHolder().setOfferPayInterface(this);


}

Expand All @@ -97,13 +112,13 @@ public class SendButtonListner extends ThreadActionListener
{
public void threadActionPerformed(ActionEvent e)
{
try
{
synchronized(state_obj)
{
if (send_state == 1) return;
if (send_state == 2)
{
try
{
synchronized(state_obj)
{
if (send_state == 1) return;
if (send_state == 2)
{
if (!saved_dest.equals(dest_field.getText()))
{
throw new Exception("Parameters changed before second send press");
Expand All @@ -116,56 +131,79 @@ public void threadActionPerformed(ActionEvent e)
{
throw new Exception("Parameters changed before second send press");
}
if (!saved_extra.equals(extra_field.getText()))
{
throw new Exception("Parameters changed before second send press");
}
SubmitReply reply = ice_leaf.getStubHolder().getBlockingStub().submitTransaction(tx_result.getTx());
ChainHash tx_hash = new ChainHash(tx_result.getTx().getTxHash());
setMessageBox(String.format("%s\n%s", tx_hash.toString(), reply.toString()));
setStatusBox("");

send_state = 0;
setProgressBar(0, SEND_DELAY);
send_state = 0;
setProgressBar(0, SEND_DELAY);
setStatusBox("");

return;
}
if (send_state == 0)
{
saved_dest = dest_field.getText();
saved_amount = send_amount_field.getText();
return;
}
if (send_state == 0)
{
saved_dest = dest_field.getText();
saved_amount = send_amount_field.getText();
saved_wallet = (String)wallet_select_box.getSelectedItem();
send_state = 1;
}
}
saved_extra = extra_field.getText();
send_state = 1;
}
}

setupTx();


setStatusBox("Time delay to review");
for(int i=0; i<SEND_DELAY; i+=SEND_DELAY_STEP)
{
setProgressBar(i, SEND_DELAY);
Thread.sleep(SEND_DELAY_STEP);
}
for(int i=0; i<SEND_DELAY; i+=SEND_DELAY_STEP)
{
setProgressBar(i, SEND_DELAY);
Thread.sleep(SEND_DELAY_STEP);
}
setStatusBox("Ready to broadcast");
setProgressBar(SEND_DELAY, SEND_DELAY);
synchronized(state_obj)
{
send_state=2;
}
}
catch(Throwable t)
{
setProgressBar(SEND_DELAY, SEND_DELAY);
synchronized(state_obj)
{
send_state=2;
}
}
catch(Throwable t)
{
setStatusBox("Error");
setMessageBox(ErrorUtil.getThrowInfo(t));
synchronized(state_obj)
{
send_state=0;
}
}
setMessageBox(ErrorUtil.getThrowInfo(t));
synchronized(state_obj)
{
send_state=0;
}
}
}

}

private ByteString convertExtra(String extra)
{
try
{
if (extra.startsWith("base64:"))
{
byte[] buff = Base64.getDecoder().decode(extra.substring(7));
return ByteString.copyFrom(buff);
}
}
catch(IllegalArgumentException e)
{
// not base64 - just use string
}

return ByteString.copyFrom(extra.getBytes());
}

private void setupTx() throws Exception
{
setStatusBox("Creating transaction");
Expand All @@ -175,6 +213,7 @@ private void setupTx() throws Exception
config.setChangeFreshAddress(true);
config.setInputConfirmedThenPending(true);
config.setFeeUseEstimate(true);
config.setExtra(convertExtra(saved_extra));

AddressSpecHash dest_addr = new AddressSpecHash(saved_dest.trim(), ice_leaf.getParams());

Expand Down Expand Up @@ -204,7 +243,7 @@ private void setupTx() throws Exception
}

public void setProgressBar(int curr, int net)
throws Exception
throws Exception
{
int enet = Math.max(net, curr);
SwingUtilities.invokeAndWait(new Runnable() {
Expand All @@ -216,4 +255,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:" + Base64.getEncoder().encodeToString( accept.build().toByteString().toByteArray() ));
}
});
}
catch(Exception e)
{
throw new RuntimeException(e);

}




}
}
4 changes: 2 additions & 2 deletions lib/src/CipherUtil.java
Expand Up @@ -40,7 +40,7 @@ public static ByteString encrypt(SigSpec sig_spec, ByteString plain_data)
Cipher c = null;
if (algo.equals("ECDSA"))
{
c = Cipher.getInstance("ECIES");
c = Cipher.getInstance("ECIES","BC");
c.init(Cipher.ENCRYPT_MODE, pub_key);
}
else
Expand Down Expand Up @@ -68,7 +68,7 @@ public static ByteString decrypt(WalletKeyPair wkp, ByteString cipher_data)

if (algo.equals("ECDSA"))
{
c = Cipher.getInstance("ECIES");
c = Cipher.getInstance("ECIES","BC");
c.init(Cipher.DECRYPT_MODE, kp.getPrivate());
}
else
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Globals.java
Expand Up @@ -4,7 +4,7 @@

public class Globals
{
public static final String VERSION = "1.7.1-release";
public static final String VERSION = "1.7.1-dev";

public static final int POW_LOOK_PASSES = 6;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/NetworkParamsProd.java
Expand Up @@ -53,8 +53,9 @@ public List<String> getSeedNodes()
{
return ImmutableList.of(
"seed.snowblossom.org",
"snowday.fun",
"node.snowblossom.cluelessperson.com",
"snow-tx1.snowblossom.org",
"snow-de1.snowblossom.org",
"snow-a.1209k.com",
"snow-b.1209k.com");
}
Expand Down
7 changes: 6 additions & 1 deletion lib/src/db/ProtoDBMap.java
Expand Up @@ -53,7 +53,12 @@ public M get(ByteString key)

public Map<ByteString, M> getByPrefix(ByteString prefix, int max_reply)
{
Map<ByteString, ByteString> inner_result = inner.getByPrefix(prefix, max_reply);
return getByPrefix(prefix, max_reply, false);

}
public Map<ByteString, M> getByPrefix(ByteString prefix, int max_reply, boolean allow_partial)
{
Map<ByteString, ByteString> inner_result = inner.getByPrefix(prefix, max_reply, allow_partial);

TreeMap<ByteString, M> m = new TreeMap<>(new ByteStringComparator());

Expand Down

0 comments on commit 4bfb9a3

Please sign in to comment.