Search in sources :

Example 21 with ChainHash

use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.

the class WalletUtil method testWallet.

public static List<AddressSpecHash> testWallet(WalletDatabase db) throws ValidationException {
    Random rnd = new Random();
    byte[] rnd_bytes = new byte[32];
    rnd.nextBytes(rnd_bytes);
    ChainHash rnd_hash = new ChainHash(rnd_bytes);
    for (WalletKeyPair pair : db.getKeysList()) {
        SigSpec sig_spec = SigSpec.newBuilder().setSignatureType(pair.getSignatureType()).setPublicKey(pair.getPublicKey()).build();
        ByteString sig = SignatureUtil.sign(pair, rnd_hash);
        if (!SignatureUtil.checkSignature(sig_spec, rnd_hash.getBytes(), sig)) {
            throw new ValidationException("Signature check failure on keypair: " + pair);
        }
    }
    LinkedList<AddressSpecHash> addresses = new LinkedList<>();
    for (AddressSpec spec : db.getAddressesList()) {
        addresses.add(AddressUtil.getHashForSpec(spec));
    }
    return addresses;
}
Also used : ChainHash(snowblossom.lib.ChainHash) ValidationException(snowblossom.lib.ValidationException) Random(java.util.Random) ByteString(com.google.protobuf.ByteString) AddressSpecHash(snowblossom.lib.AddressSpecHash) LinkedList(java.util.LinkedList)

Example 22 with ChainHash

use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.

the class SpoonTest method testConsolidateFunds.

protected void testConsolidateFunds(SnowBlossomNode node, SnowBlossomClient client, KeyPair key_pair, AddressSpecHash from_addr) throws Exception {
    List<TransactionBridge> funds = client.getSpendable(from_addr);
    System.out.println("Funds: " + funds.size());
    Assert.assertTrue(funds.size() > 3);
    KeyPair key_pair_to = KeyUtil.generateECCompressedKey();
    AddressSpec claim = AddressUtil.getSimpleSpecForKey(key_pair_to.getPublic(), SignatureUtil.SIG_TYPE_ECDSA_COMPRESSED);
    AddressSpecHash to_addr = AddressUtil.getHashForSpec(claim);
    long value = 0;
    LinkedList<TransactionInput> in_list = new LinkedList<>();
    for (TransactionBridge b : funds) {
        value += b.value;
        in_list.add(b.in);
    }
    TransactionOutput out = TransactionOutput.newBuilder().setRecipientSpecHash(to_addr.getBytes()).setValue(value).build();
    Transaction tx = TransactionUtil.createTransaction(in_list, ImmutableList.of(out), key_pair);
    Assert.assertTrue(client.submitTransaction(tx));
    waitForMoreBlocks(node, 2);
    List<TransactionBridge> new_funds = client.getSpendable(to_addr);
    Assert.assertEquals(1, new_funds.size());
    TransactionBridge b = new_funds.get(0);
    Assert.assertEquals(value, b.value);
    Assert.assertNotNull(node.getDB());
    TransactionStatus status = TransactionMapUtil.getTxStatus(new ChainHash(tx.getTxHash()), node.getDB(), node.getBlockIngestor().getHead());
    System.out.println(status);
    Assert.assertTrue(status.getConfirmed());
    {
        HistoryList hl = AddressHistoryUtil.getHistory(to_addr, node.getDB(), node.getBlockIngestor().getHead());
        Assert.assertEquals(1, hl.getEntriesCount());
    }
    {
        HistoryList hl = AddressHistoryUtil.getHistory(from_addr, node.getDB(), node.getBlockIngestor().getHead());
        Assert.assertTrue(hl.getEntriesCount() > 5);
    }
    System.out.println(tx);
}
Also used : KeyPair(java.security.KeyPair) ChainHash(snowblossom.lib.ChainHash) TransactionBridge(snowblossom.lib.TransactionBridge) AddressSpecHash(snowblossom.lib.AddressSpecHash)

Example 23 with ChainHash

use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.

the class SpoonTest method printNodeShardStatus.

/**
 * Print a bunch of information about what a node knows about the shards
 */
protected void printNodeShardStatus(SnowBlossomNode node, String label) {
    System.out.println("-------------- Node Shard Report ----------------------");
    System.out.println("NODE: " + label);
    System.out.println("Interest shards: " + node.getInterestShards());
    System.out.println("Active shards: " + node.getActiveShards());
    System.out.println("Building shards: " + node.getCurrentBuildingShards());
    for (int shard = 0; shard <= node.getParams().getMaxShardId(); shard++) {
        for (BlockHeader bh : node.getForgeInfo().getShardHeads(shard)) {
            ChainHash hash = new ChainHash(bh.getSnowHash());
            boolean has_summary = (node.getForgeInfo().getSummary(hash) != null);
            boolean has_export = (node.getShardUtxoImport().getImportBlock(hash) != null);
            System.out.println(String.format("Shard head %d sum:%b exp:%b - %s", shard, has_summary, has_export, node.getForgeInfo().getHeaderString(bh)));
        }
    }
    System.out.println("-------------- Node Shard Report End ------------------");
}
Also used : ChainHash(snowblossom.lib.ChainHash)

Example 24 with ChainHash

use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.

the class GraphOutput method getName.

public static String getName(BlockHeader bh) {
    ChainHash hash = new ChainHash(bh.getSnowHash());
    String hash_str = hash.toString().substring(0, 12);
    return String.format("s%dh%d-%s", bh.getShardId(), bh.getBlockHeight(), hash_str);
}
Also used : ChainHash(snowblossom.lib.ChainHash) ByteString(com.google.protobuf.ByteString)

Aggregations

ChainHash (snowblossom.lib.ChainHash)24 ByteString (com.google.protobuf.ByteString)10 Test (org.junit.Test)5 AddressSpecHash (snowblossom.lib.AddressSpecHash)5 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Random (java.util.Random)2 Pair (duckutil.Pair)1 ByteBuffer (java.nio.ByteBuffer)1 KeyPair (java.security.KeyPair)1 MessageDigest (java.security.MessageDigest)1 DecimalFormat (java.text.DecimalFormat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1 TransactionBridge (snowblossom.lib.TransactionBridge)1 ValidationException (snowblossom.lib.ValidationException)1 BlockHeader (snowblossom.proto.BlockHeader)1