use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class KeyUtilTest method testKeyPair.
private void testKeyPair(WalletKeyPair wkp, String name) throws Exception {
Random rnd = new Random();
byte[] b = new byte[Globals.BLOCKCHAIN_HASH_LEN];
for (int i = 0; i < 8; i++) {
rnd.nextBytes(b);
ChainHash hash = new ChainHash(b);
ByteString sig = SignatureUtil.sign(wkp, hash);
SigSpec sig_spec = SigSpec.newBuilder().setSignatureType(wkp.getSignatureType()).setPublicKey(wkp.getPublicKey()).build();
logger.info(String.format("Key report %s Pub size: %d, sig %d", name, wkp.getPublicKey().size(), sig.size()));
logger.info("Key report: " + HexUtil.getHexString(sig));
// logger.info("Key report: " + KeyUtil.decomposeASN1Encoded( sig ));
Assert.assertTrue(SignatureUtil.checkSignature(sig_spec, hash.getBytes(), sig));
}
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class DB method getBlockHashAtHeight.
@Override
public ChainHash getBlockHashAtHeight(int shard, int height) {
ByteBuffer bb = ByteBuffer.allocate(8);
bb.putInt(shard);
bb.putInt(height);
ByteString hash = block_height_map.get(ByteString.copyFrom(bb.array()));
if (hash == null) {
// old mode - height only
bb = ByteBuffer.allocate(4);
bb.putInt(height);
hash = block_height_map.get(ByteString.copyFrom(bb.array()));
}
if (hash == null)
return null;
return new ChainHash(hash);
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class DigestUtilTest method testMerkleRootSingle.
@Test
public void testMerkleRootSingle() {
ChainHash a = getRandomHash();
ChainHash result = DigestUtil.getMerkleRootForTxList(ImmutableList.of(a));
Assert.assertEquals(a, result);
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class DigestUtilTest method testMerkleRoot8.
@Test
public void testMerkleRoot8() {
ChainHash a = getRandomHash();
ChainHash b = getRandomHash();
ChainHash c = getRandomHash();
ChainHash d = getRandomHash();
ChainHash e = getRandomHash();
ChainHash f = getRandomHash();
ChainHash g = getRandomHash();
ChainHash h = getRandomHash();
ChainHash result = DigestUtil.getMerkleRootForTxList(ImmutableList.of(a, b, c, d, e, f, g, h));
ChainHash ab = treeHash(a, b);
ChainHash cd = treeHash(c, d);
ChainHash ef = treeHash(e, f);
ChainHash gh = treeHash(g, h);
ChainHash abcd = treeHash(ab, cd);
ChainHash efgh = treeHash(ef, gh);
ChainHash abcdefgh = treeHash(abcd, efgh);
Assert.assertEquals(abcdefgh, result);
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class DigestUtilTest method testMerkleRoot2.
@Test
public void testMerkleRoot2() {
ChainHash a = getRandomHash();
ChainHash b = getRandomHash();
ChainHash result = DigestUtil.getMerkleRootForTxList(ImmutableList.of(a, b));
ChainHash ab = treeHash(a, b);
Assert.assertEquals(ab, result);
}
Aggregations