Search in sources :

Example 11 with ConfigMem

use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.

the class PurseTest method testMarkRace.

@Test
public void testMarkRace() 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");
    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, false);
            }
        });
    }
    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(1000, 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 12 with ConfigMem

use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.

the class PurseTest method saveNew.

@Test
public void saveNew() throws Exception {
    File empty_sub = new File(test_folder.newFolder(), "new");
    TreeMap<String, String> config_settings = new TreeMap<>();
    config_settings.put("key_pool_size", "19");
    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);
    Assert.assertEquals(19, db.getKeysCount());
    Assert.assertEquals(19, db.getAddressesCount());
    Assert.assertEquals(19, db.getAddressCreateTimeCount());
    Assert.assertEquals(0, db.getUsedAddressesCount());
}
Also used : TreeMap(java.util.TreeMap) File(java.io.File) ConfigMem(duckutil.ConfigMem) Test(org.junit.Test)

Example 13 with ConfigMem

use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.

the class WalletPanel method loadWallet.

private SnowBlossomClient loadWallet(String name, File db_dir, File config_file) throws Exception {
    synchronized (client_map) {
        if (client_map.containsKey(name))
            return client_map.get(name);
    }
    TreeMap<String, String> config_map = new TreeMap<>();
    config_map.put("wallet_path", db_dir.getPath());
    config_map.put("network", ice_leaf.getParams().getNetworkName());
    Config conf = new ConfigCat(new ConfigMem(config_map), new ConfigFile(config_file.getPath()));
    SnowBlossomClient client = new SnowBlossomClient(conf, null, ice_leaf.getStubHolder());
    synchronized (client_map) {
        client_map.put(name, client);
    }
    return client;
}
Also used : ConfigFile(duckutil.ConfigFile) Config(duckutil.Config) SnowBlossomClient(snowblossom.client.SnowBlossomClient) ConfigCat(duckutil.ConfigCat) TreeMap(java.util.TreeMap) ConfigMem(duckutil.ConfigMem)

Example 14 with ConfigMem

use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.

the class SpoonTest method startNode.

protected SnowBlossomNode startNode(int port, String network, Map<String, String> extra) throws Exception {
    String test_folder_base = test_folder.newFolder().getPath();
    Map<String, String> config_map = new TreeMap<>();
    config_map.put("db_path", test_folder_base + "/db");
    config_map.put("db_type", "rocksdb");
    config_map.put("service_port", "" + port);
    config_map.put("network", network);
    config_map.put("tx_index", "true");
    config_map.put("addr_index", "true");
    config_map.put("peer_count", "64");
    if (extra != null) {
        config_map.putAll(extra);
    }
    return new SnowBlossomNode(new ConfigMem(config_map));
}
Also used : SnowBlossomNode(snowblossom.node.SnowBlossomNode) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Example 15 with ConfigMem

use of duckutil.ConfigMem in project snowblossom by snowblossomcoin.

the class SpoonTest method genWallet.

public static WalletDatabase genWallet() {
    TreeMap<String, String> config_map = new TreeMap<>();
    config_map.put("key_count", "20");
    WalletDatabase db = WalletUtil.makeNewDatabase(new ConfigMem(config_map), new NetworkParamsRegtest());
    return db;
}
Also used : NetworkParamsRegtest(snowblossom.lib.NetworkParamsRegtest) 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