Search in sources :

Example 6 with SnowBlossomClient

use of snowblossom.client.SnowBlossomClient in project snowblossom by snowblossomcoin.

the class WalletPanel method getWalletSummary.

private String getWalletSummary(String name, File db_dir, File config_file, boolean first_pass) throws Exception {
    SnowBlossomClient client = loadWallet(name, db_dir, config_file);
    if (!first_pass) {
        setMessageBox("Maintaining: " + name);
        client.maintainKeys();
    }
    setMessageBox("Fresh address: " + name);
    AddressSpecHash hash = client.getPurse().getUnusedAddress(false, false);
    String addr = AddressUtil.getAddressString(client.getParams().getAddressPrefix(), hash);
    setMessageBox("Checking balance: " + name);
    String summary = String.format("%s - %s\n    %s", name, SnowBlossomClient.getBalanceInfoPrint(client.getBalance()), addr);
    if (client.getPurse().isWatchOnly()) {
        summary = summary + "\n    WATCH ONLY";
    }
    return summary;
}
Also used : SnowBlossomClient(snowblossom.client.SnowBlossomClient) AddressSpecHash(snowblossom.lib.AddressSpecHash)

Example 7 with SnowBlossomClient

use of snowblossom.client.SnowBlossomClient 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 8 with SnowBlossomClient

use of snowblossom.client.SnowBlossomClient in project snowblossom by snowblossomcoin.

the class SpoonTest method startClient.

protected SnowBlossomClient startClient(int port) throws Exception {
    Map<String, String> config_map = new TreeMap<>();
    config_map.put("node_uri", "grpc://localhost:" + port);
    config_map.put("network", "spoon");
    return new SnowBlossomClient(new ConfigMem(config_map));
}
Also used : SnowBlossomClient(snowblossom.client.SnowBlossomClient) ByteString(com.google.protobuf.ByteString) ConfigMem(duckutil.ConfigMem)

Example 9 with SnowBlossomClient

use of snowblossom.client.SnowBlossomClient in project snowblossom by snowblossomcoin.

the class SpoonTestFbo method fboTest.

@Test
public void fboTest() throws Exception {
    File snow_path = setupSnow();
    Random rnd = new Random();
    int port = 20000 + rnd.nextInt(30000);
    SnowBlossomNode node = startNode(port);
    Thread.sleep(100);
    SnowBlossomClient client = startClientWithWallet(port);
    SnowBlossomClient client_lock = startClientWithWallet(port);
    WalletDatabase lock_db = genWallet();
    WalletDatabase social_db = genWallet();
    AddressSpecHash mine_to_addr = client.getPurse().getUnusedAddress(false, false);
    AddressSpecHash lock_to_addr = client_lock.getPurse().getUnusedAddress(false, false);
    AddressSpecHash social_addr = AddressUtil.getHashForSpec(social_db.getAddresses(0));
    SnowBlossomMiner miner = startMiner(port, mine_to_addr, snow_path);
    testMinedBlocks(node);
    LinkedList<Transaction> tx_list = new LinkedList<>();
    LinkedList<Transaction> tx_list_jumbo = new LinkedList<>();
    LinkedList<Transaction> tx_list_swoopo = new LinkedList<>();
    for (int i = 0; i < 10; i++) {
        TransactionFactoryConfig.Builder config = TransactionFactoryConfig.newBuilder();
        config.setSign(true);
        config.setChangeRandomFromWallet(true);
        config.setInputConfirmedThenPending(true);
        config.setFeeUseEstimate(true);
        config.addOutputs(TransactionOutput.newBuilder().setValue(Globals.SNOW_VALUE).setRecipientSpecHash(lock_to_addr.getBytes()).setForBenefitOfSpecHash(social_addr.getBytes()).build());
        config.addOutputs(TransactionOutput.newBuilder().setValue(Globals.SNOW_VALUE).setRecipientSpecHash(lock_to_addr.getBytes()).setForBenefitOfSpecHash(social_addr.getBytes()).setIds(ClaimedIdentifiers.newBuilder().setUsername(ByteString.copyFrom("jumbo".getBytes()))).build());
        config.addOutputs(TransactionOutput.newBuilder().setValue(Globals.SNOW_VALUE).setRecipientSpecHash(lock_to_addr.getBytes()).setForBenefitOfSpecHash(social_addr.getBytes()).setIds(ClaimedIdentifiers.newBuilder().setChannelname(ByteString.copyFrom("swoopo".getBytes()))).build());
        config.addOutputs(TransactionOutput.newBuilder().setValue(Globals.SNOW_VALUE).setRecipientSpecHash(lock_to_addr.getBytes()).setForBenefitOfSpecHash(social_addr.getBytes()).setIds(ClaimedIdentifiers.newBuilder().setUsername(ByteString.copyFrom(("name-" + i).getBytes()))).build());
        TransactionFactoryResult tr = TransactionFactory.createTransaction(config.build(), client.getPurse().getDB(), client);
        for (Transaction tx : tr.getTxsList()) {
            SubmitReply submit = client.getStub().submitTransaction(tx);
            System.out.println(submit);
            Assert.assertTrue(submit.getErrorMessage(), submit.getSuccess());
        }
        tx_list.addAll(tr.getTxsList());
        waitForMoreBlocks(node, 2);
    }
    // TODO - test FBO
    TxOutList fbo_out_list = ForBenefitOfUtil.getFBOList(social_addr, node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(40, fbo_out_list.getOutListCount());
    // TODO - test user name
    TxOutList jumbo_list = ForBenefitOfUtil.getIdListUser(ByteString.copyFrom("jumbo".getBytes()), node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(10, jumbo_list.getOutListCount());
    // TODO - test channel name
    TxOutList swoopo_list = ForBenefitOfUtil.getIdListChannel(ByteString.copyFrom("swoopo".getBytes()), node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(10, swoopo_list.getOutListCount());
    // So the first is the oldest
    for (int i = 0; i < tx_list.size(); i++) {
        ByteString tx = tx_list.get(i).getTxHash();
        Assert.assertEquals(tx, jumbo_list.getOutList(i).getTxHash());
        Assert.assertEquals(tx, swoopo_list.getOutList(i).getTxHash());
        Assert.assertEquals(1, ForBenefitOfUtil.getIdListUser(ByteString.copyFrom(("name-" + i).getBytes()), node.getDB(), node.getBlockIngestor().getHead()).getOutListCount());
    }
    {
        // Send back - spend all
        TransactionFactoryConfig.Builder config = TransactionFactoryConfig.newBuilder();
        config.setSign(true);
        config.setChangeRandomFromWallet(true);
        config.setInputConfirmedThenPending(true);
        config.setFeeUseEstimate(true);
        config.setSendAll(true);
        config.addOutputs(TransactionOutput.newBuilder().setValue(0L).setRecipientSpecHash(mine_to_addr.getBytes()).build());
        TransactionFactoryResult tr = TransactionFactory.createTransaction(config.build(), client_lock.getPurse().getDB(), client_lock);
        for (Transaction tx : tr.getTxsList()) {
            SubmitReply submit = client_lock.getStub().submitTransaction(tx);
            System.out.println(submit);
            Assert.assertTrue(submit.getErrorMessage(), submit.getSuccess());
        }
        waitForMoreBlocks(node, 1);
    }
    // TODO - test FBO
    TxOutList fbo_out_list_a = ForBenefitOfUtil.getFBOList(social_addr, node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(0, fbo_out_list_a.getOutListCount());
    // TODO - test user name
    TxOutList jumbo_list_a = ForBenefitOfUtil.getIdListUser(ByteString.copyFrom("jumbo".getBytes()), node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(0, jumbo_list_a.getOutListCount());
    // TODO - test channel name
    TxOutList swoopo_list_a = ForBenefitOfUtil.getIdListChannel(ByteString.copyFrom("swoopo".getBytes()), node.getDB(), node.getBlockIngestor().getHead());
    Assert.assertEquals(0, swoopo_list_a.getOutListCount());
    miner.stop();
    node.stop();
}
Also used : ByteString(com.google.protobuf.ByteString) SnowBlossomMiner(snowblossom.miner.SnowBlossomMiner) SnowBlossomNode(snowblossom.node.SnowBlossomNode) SnowBlossomClient(snowblossom.client.SnowBlossomClient) File(java.io.File) AddressSpecHash(snowblossom.lib.AddressSpecHash) Test(org.junit.Test)

Aggregations

SnowBlossomClient (snowblossom.client.SnowBlossomClient)9 AddressSpecHash (snowblossom.lib.AddressSpecHash)6 File (java.io.File)4 Test (org.junit.Test)4 SnowBlossomNode (snowblossom.node.SnowBlossomNode)4 ByteString (com.google.protobuf.ByteString)3 ConfigMem (duckutil.ConfigMem)3 KeyPair (java.security.KeyPair)3 PoolMiner (snowblossom.miner.PoolMiner)2 SnowBlossomMiner (snowblossom.miner.SnowBlossomMiner)2 MrPlow (snowblossom.miner.plow.MrPlow)2 Config (duckutil.Config)1 ConfigCat (duckutil.ConfigCat)1 ConfigFile (duckutil.ConfigFile)1 TreeMap (java.util.TreeMap)1 Transaction (snowblossom.proto.Transaction)1