use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.
the class WalletUtil method loadNodeWalletFromConfig.
/**
* Loads or creates a single key wallet based on the config param name pointing
* to a path.
*/
public static WalletDatabase loadNodeWalletFromConfig(NetworkParams params, Config config, String param_name) throws Exception {
if (!config.isSet(param_name))
return null;
config.require(param_name);
TreeMap<String, String> wallet_config_map = new TreeMap<>();
wallet_config_map.put("wallet_path", config.get(param_name));
wallet_config_map.put("key_count", "1");
wallet_config_map.put("key_mode", WalletUtil.MODE_STANDARD);
ConfigMem config_wallet = new ConfigMem(wallet_config_map);
File wallet_path = new File(config_wallet.get("wallet_path"));
WalletDatabase wallet_db = WalletUtil.loadWallet(wallet_path, true, params);
if (wallet_db == null) {
logger.log(Level.WARNING, String.format("Directory %s does not contain keys, creating new keys", wallet_path.getPath()));
wallet_db = WalletUtil.makeNewDatabase(config_wallet, params);
WalletUtil.saveWallet(wallet_db, wallet_path);
AddressSpecHash spec = AddressUtil.getHashForSpec(wallet_db.getAddresses(0));
String addr = AddressUtil.getAddressString("node", spec);
File dir = new File(config.get(param_name));
PrintStream out = new PrintStream(new FileOutputStream(new File(dir, "address.txt"), false));
out.println(addr);
out.close();
}
return wallet_db;
}
use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.
the class PurseTest method testExtendXpub.
@Test
public void testExtendXpub() throws Exception {
File empty_sub = new File(test_folder.newFolder(), "new");
TreeMap<String, String> config_settings = new TreeMap<>();
config_settings.put("key_mode", "seed");
config_settings.put("watch_only", "true");
ConfigMem config = new ConfigMem(config_settings);
NetworkParams params = new NetworkParamsRegtest();
String seed = SeedUtil.generateSeed(12);
String xpub = SeedUtil.getSeedXpub(params, seed, "", 0);
WalletDatabase db = WalletUtil.importXpub(params, xpub);
db = WalletUtil.fillKeyPool(db, empty_sub, config, params);
Assert.assertEquals(1, db.getXpubsCount());
Assert.assertEquals(0, db.getUsedAddressesCount());
Assert.assertEquals(20, db.getAddressesCount());
Purse purse = new Purse(null, empty_sub, config, params);
purse.maintainKeys(false);
Assert.assertEquals(1, purse.getDB().getXpubsCount());
Assert.assertEquals(0, purse.getDB().getUsedAddressesCount());
Assert.assertEquals(20, purse.getDB().getAddressesCount());
for (int i = 20; i < 100; i++) {
Assert.assertTrue(purse.getDB().getAddressesCount() >= i);
purse.getUnusedAddress(true, false);
purse.maintainKeys(false);
Assert.assertTrue(purse.getDB().getAddressesCount() - purse.getDB().getUsedAddressesCount() >= 20);
}
}
use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.
the class PurseTest method testMarkRaceGen.
@Test
public void testMarkRaceGen() throws Exception {
File empty_sub = new File(test_folder.newFolder(), "new");
TreeMap<String, String> config_settings = new TreeMap<>();
config_settings.put("key_pool_size", "100");
config_settings.put("key_mode", "standard");
ConfigMem config = new ConfigMem(config_settings);
NetworkParams params = new NetworkParamsRegtest();
WalletDatabase db = WalletUtil.makeNewDatabase(config, params);
db = WalletUtil.fillKeyPool(db, empty_sub, config, params);
Purse purse = new Purse(null, empty_sub, config, params);
purse.maintainKeys(false);
ThreadPoolExecutor exec = TaskMaster.getBasicExecutor(100, "test_fresh_race");
TaskMaster<AddressSpecHash> tm = new TaskMaster<>(exec);
for (int i = 0; i < 1000; i++) {
tm.addTask(new Callable() {
public AddressSpecHash call() throws Exception {
return purse.getUnusedAddress(true, true);
}
});
}
ArrayList<AddressSpecHash> list = tm.getResults();
Assert.assertEquals(1000, list.size());
HashSet<AddressSpecHash> set = new HashSet<>();
set.addAll(list);
Assert.assertEquals(1000, set.size());
Assert.assertEquals(1000, purse.getDB().getUsedAddressesCount());
Assert.assertEquals(1100, purse.getDB().getAddressesCount());
exec.shutdown();
}
use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.
the class SpoonTest method startMrPlow.
protected MrPlow startMrPlow(List<Integer> node_ports, AddressSpecHash pool_addr, String network) throws Exception {
NetworkParams params = NetworkParams.loadFromName(network);
String plow_db_path = test_folder.newFolder().getPath();
Map<String, String> config_map = new TreeMap<>();
StringBuilder uris = new StringBuilder();
boolean first = true;
for (int port : node_ports) {
if (!first)
uris.append(",");
uris.append("grpc://localhost:" + port + "/");
first = false;
}
config_map.put("node_uri", uris.toString());
config_map.put("db_type", "rocksdb");
config_map.put("db_type", "atomic_file");
config_map.put("db_path", plow_db_path + "/plowdb");
config_map.put("pool_fee", "0.01");
config_map.put("pool_address", pool_addr.toAddressString(params));
config_map.put("mining_pool_port", "0");
config_map.put("tls_mining_pool_port", "0");
config_map.put("tls_key_path", plow_db_path + "/plow_tls");
config_map.put("network", network);
config_map.put("min_diff", "11");
return new MrPlow(new ConfigMem(config_map));
}
use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.
the class SpoonTest method startClientWithWallet.
protected SnowBlossomClient startClientWithWallet(int port) throws Exception {
String wallet_path = test_folder.newFolder().getPath();
Map<String, String> config_map = new TreeMap<>();
config_map.put("node_uri", "grpc://localhost:" + port);
config_map.put("network", "spoon");
config_map.put("wallet_path", wallet_path);
return new SnowBlossomClient(new ConfigMem(config_map));
}
Aggregations