Skip to content

Commit

Permalink
qhard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed May 22, 2018
1 parent 66bc0ba commit dc6575f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 26 deletions.
19 changes: 19 additions & 0 deletions src/AddressUtil.java
Expand Up @@ -15,6 +15,9 @@
import com.google.common.collect.ImmutableSet;


import org.junit.Assert;
import java.util.List;

public class AddressUtil
{
public static AddressSpecHash getHashForSpec(AddressSpec spec)
Expand Down Expand Up @@ -58,6 +61,22 @@ public static AddressSpec getSimpleSpecForKey(ByteString key_data, int sig_type)
.build())
.build();
}

public static AddressSpec getMultiSig(int required, List<WalletKeyPair> wkp_list)
{
AddressSpec.Builder addrspec = AddressSpec.newBuilder();
addrspec.setRequiredSigners(required);

Assert.assertTrue(required >= wkp_list.size());
for(WalletKeyPair wkp : wkp_list)
{
addrspec.addSigSpecs ( SigSpec.newBuilder()
.setSignatureType( wkp.getSignatureType() )
.setPublicKey ( wkp.getPublicKey() )
.build() );
}
return addrspec.build();
}

public static AddressSpec getSimpleSpecForKey(WalletKeyPair wkp)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Config.java
Expand Up @@ -12,6 +12,15 @@ public abstract class Config

public abstract String get(String key);

public String getWithDefault(String key, String def)
{
if (isSet(key))
{
return get(key);
}
return def;
}

public void require(String key)
{
if(get(key) == null)
Expand Down
29 changes: 3 additions & 26 deletions src/client/SnowBlossomClient.java
Expand Up @@ -147,9 +147,11 @@ else if (command.equals("loadtest"))

private File wallet_path;
private WalletDatabase wallet_database;
private Config config;

public SnowBlossomClient(Config config) throws Exception
{
this.config = config;
config.require("node_host");

String host = config.get("node_host");
Expand Down Expand Up @@ -201,7 +203,7 @@ public void loadWallet()
else
{
logger.log(Level.WARNING, String.format("File %s does not exist, creating new wallet", db_file.getPath()));
wallet_database = makeNewDatabase();
wallet_database = WalletUtil.makeNewDatabase(config);
saveWallet();
}

Expand Down Expand Up @@ -247,31 +249,6 @@ public void saveWallet()

}

public WalletDatabase makeNewDatabase()
{
WalletDatabase.Builder builder = WalletDatabase.newBuilder();

for(int i=0;i<8; i++)
{
genNewKey(builder);
}

return builder.build();
}

public void genNewKey(WalletDatabase.Builder wallet_builder)
{

WalletKeyPair wkp = KeyUtil.generateWalletStandardECKey();

wallet_builder.addKeys(wkp);

AddressSpec claim = AddressUtil.getSimpleSpecForKey(wkp);

wallet_builder.addAddresses(claim);

}

public void showBalances()
{
long total_confirmed = 0;
Expand Down
67 changes: 67 additions & 0 deletions src/client/WalletUtil.java
@@ -0,0 +1,67 @@
package snowblossom.client;

import snowblossom.*;
import snowblossom.proto.*;
import com.google.common.collect.ImmutableList;

import java.util.logging.Logger;
import java.util.logging.Level;


public class WalletUtil
{
public static final String MODE_STANDARD="standard";
public static final String MODE_QHARD="qhard";

private static final Logger logger = Logger.getLogger("snowblossom.client");

public static WalletDatabase makeNewDatabase(Config config)
{
WalletDatabase.Builder builder = WalletDatabase.newBuilder();

int count = config.getIntWithDefault("key_count", 8);
for(int i=0;i<count; i++)
{
genNewKey(builder, config);
}

return builder.build();
}

public static void genNewKey(WalletDatabase.Builder wallet_builder, Config config)
{
String key_mode = config.getWithDefault("key_mode", MODE_STANDARD).toLowerCase();

if (key_mode.equals(MODE_STANDARD))
{

WalletKeyPair wkp = KeyUtil.generateWalletStandardECKey();
wallet_builder.addKeys(wkp);
AddressSpec claim = AddressUtil.getSimpleSpecForKey(wkp);
wallet_builder.addAddresses(claim);
}
else if (key_mode.equals(MODE_QHARD))
{
logger.info("Creating QHARD key set. This takes a while.");
WalletKeyPair k_ec = KeyUtil.generateWalletStandardECKey();
WalletKeyPair k_rsa = KeyUtil.generateWalletRSAKey(8192);
WalletKeyPair k_dstu = KeyUtil.generateWalletDSTU4145Key(9);

wallet_builder.addKeys(k_ec);
wallet_builder.addKeys(k_rsa);
wallet_builder.addKeys(k_dstu);

AddressSpec claim = AddressUtil.getMultiSig(3, ImmutableList.of(k_ec, k_rsa, k_dstu));
wallet_builder.addAddresses(claim);


}
else
{
throw new RuntimeException("Unknown key_mode: " + key_mode);
}

}


}

0 comments on commit dc6575f

Please sign in to comment.