Search in sources :

Example 1 with ConfigMem

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;
}
Also used : PrintStream(java.io.PrintStream) AtomicFileOutputStream(duckutil.AtomicFileOutputStream) FileOutputStream(java.io.FileOutputStream) ByteString(com.google.protobuf.ByteString) TreeMap(java.util.TreeMap) ConfigMem(duckutil.ConfigMem) File(java.io.File) AddressSpecHash(snowblossom.lib.AddressSpecHash)

Example 2 with ConfigMem

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);
    }
}
Also used : Purse(snowblossom.client.Purse) TreeMap(java.util.TreeMap) File(java.io.File) ConfigMem(duckutil.ConfigMem) Test(org.junit.Test)

Example 3 with ConfigMem

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();
}
Also used : Purse(snowblossom.client.Purse) TreeMap(java.util.TreeMap) ConfigMem(duckutil.ConfigMem) Callable(java.util.concurrent.Callable) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TaskMaster(duckutil.TaskMaster) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ConfigMem

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));
}
Also used : NetworkParams(snowblossom.lib.NetworkParams) MrPlow(snowblossom.miner.plow.MrPlow) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Example 5 with ConfigMem

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));
}
Also used : SnowBlossomClient(snowblossom.client.SnowBlossomClient) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Aggregations

ConfigMem (duckutil.ConfigMem)18 ByteString (com.google.protobuf.ByteString)12 TreeMap (java.util.TreeMap)8 File (java.io.File)6 Test (org.junit.Test)5 NetworkParams (snowblossom.lib.NetworkParams)5 Purse (snowblossom.client.Purse)3 SnowBlossomClient (snowblossom.client.SnowBlossomClient)3 Config (duckutil.Config)2 TaskMaster (duckutil.TaskMaster)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 NetworkParamsRegtest (snowblossom.lib.NetworkParamsRegtest)2 PoolMiner (snowblossom.miner.PoolMiner)2 SnowBlossomNode (snowblossom.node.SnowBlossomNode)2 AtomicFileOutputStream (duckutil.AtomicFileOutputStream)1 ConfigCat (duckutil.ConfigCat)1 ConfigFile (duckutil.ConfigFile)1 FileOutputStream (java.io.FileOutputStream)1