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;
}
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);
}
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 ------------------");
}
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);
}
Aggregations