Search in sources :

Example 1 with MerkleTree

use of io.nem.symbol.sdk.model.state.MerkleTree in project nem2-sdk-java by nemtech.

the class MerkleStateInfoTest method equals.

@Test
void equals() {
    MerkleTree tree1 = new MerkleTree(Collections.singletonList(createBranch("abc")), createLeaf("ABCD"));
    MerkleStateInfo info1 = new MerkleStateInfo("1234", tree1);
    MerkleTree tree2 = new MerkleTree(Collections.singletonList(createBranch("abc")), createLeaf("ABCD"));
    MerkleStateInfo info2 = new MerkleStateInfo("1234", tree2);
    MerkleTree tree3 = new MerkleTree(Collections.singletonList(createBranch("abc")), createLeaf("1234"));
    MerkleStateInfo info3 = new MerkleStateInfo("1234", tree3);
    Assertions.assertEquals(info1, info1);
    Assertions.assertEquals(info2, info1);
    Assertions.assertNotEquals(info2, info3);
}
Also used : MerkleTree(io.nem.symbol.sdk.model.state.MerkleTree) Test(org.junit.jupiter.api.Test)

Example 2 with MerkleTree

use of io.nem.symbol.sdk.model.state.MerkleTree in project nem2-sdk-java by nemtech.

the class MerkleMapper method toMerkleStateInfo.

public MerkleStateInfo toMerkleStateInfo(MerkleStateInfoDTO dto) {
    MerkleTreeLeaf leaf = dto.getTree().stream().map(this::toLeaf).filter(Objects::nonNull).findFirst().orElse(null);
    List<MerkleTreeBranch> branches = dto.getTree().stream().map(this::toBranch).filter(Objects::nonNull).collect(Collectors.toList());
    MerkleTree tree = new MerkleTree(branches, leaf);
    return new MerkleStateInfo(dto.getRaw(), tree);
}
Also used : MerkleTree(io.nem.symbol.sdk.model.state.MerkleTree) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) Objects(java.util.Objects) MerkleTreeLeaf(io.nem.symbol.sdk.model.state.MerkleTreeLeaf) MerkleTreeBranch(io.nem.symbol.sdk.model.state.MerkleTreeBranch)

Example 3 with MerkleTree

use of io.nem.symbol.sdk.model.state.MerkleTree in project nem2-sdk-java by nemtech.

the class MerkleMapper method toMerkleStateInfo.

public MerkleStateInfo toMerkleStateInfo(MerkleStateInfoDTO dto) {
    MerkleTreeLeaf leaf = dto.getTree().stream().map(this::toLeaf).filter(Objects::nonNull).findFirst().orElse(null);
    List<MerkleTreeBranch> branches = dto.getTree().stream().map(this::toBranch).filter(Objects::nonNull).collect(Collectors.toList());
    MerkleTree tree = new MerkleTree(branches, leaf);
    return new MerkleStateInfo(dto.getRaw(), tree);
}
Also used : MerkleTree(io.nem.symbol.sdk.model.state.MerkleTree) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) Objects(java.util.Objects) MerkleTreeLeaf(io.nem.symbol.sdk.model.state.MerkleTreeLeaf) MerkleTreeBranch(io.nem.symbol.sdk.model.state.MerkleTreeBranch)

Example 4 with MerkleTree

use of io.nem.symbol.sdk.model.state.MerkleTree in project nem2-sdk-java by nemtech.

the class MerkleStateInfoTest method constructor.

@Test
void constructor() {
    MerkleTree tree = new MerkleTree(Collections.singletonList(createBranch("abc")), createLeaf("ABCD"));
    MerkleStateInfo info = new MerkleStateInfo("1234", tree);
    Assertions.assertEquals("1234", info.getRaw());
    Assertions.assertEquals(tree, info.getTree());
}
Also used : MerkleTree(io.nem.symbol.sdk.model.state.MerkleTree) Test(org.junit.jupiter.api.Test)

Aggregations

MerkleTree (io.nem.symbol.sdk.model.state.MerkleTree)4 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)2 MerkleTreeBranch (io.nem.symbol.sdk.model.state.MerkleTreeBranch)2 MerkleTreeLeaf (io.nem.symbol.sdk.model.state.MerkleTreeLeaf)2 Objects (java.util.Objects)2 Test (org.junit.jupiter.api.Test)2