Search in sources :

Example 1 with MerkleTreeBranch

use of io.nem.symbol.sdk.model.state.MerkleTreeBranch 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 2 with MerkleTreeBranch

use of io.nem.symbol.sdk.model.state.MerkleTreeBranch 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 MerkleTreeBranch

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

the class MerkleMapper method toMerkleTreeBranch.

private MerkleTreeBranch toMerkleTreeBranch(Object dto, MerkleTreeNodeType type) {
    MerkleTreeBranchDTO branch = getJsonHelper().convert(dto, MerkleTreeBranchDTO.class);
    List<MerkleTreeBranchLink> links = branch.getLinks().stream().map(link -> new MerkleTreeBranchLink(link.getBit(), link.getLink())).collect(Collectors.toList());
    return new MerkleTreeBranch(type, branch.getPath(), branch.getEncodedPath(), branch.getLinkMask(), links, branch.getBranchHash());
}
Also used : MerkleStateInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MerkleStateInfoDTO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MerkleTreeBranchDTO(io.nem.symbol.sdk.openapi.vertx.model.MerkleTreeBranchDTO) List(java.util.List) MerkleTreeNodeType(io.nem.symbol.sdk.model.state.MerkleTreeNodeType) MerkleTree(io.nem.symbol.sdk.model.state.MerkleTree) MerkleTreeBranch(io.nem.symbol.sdk.model.state.MerkleTreeBranch) JsonHelper(io.nem.symbol.sdk.model.transaction.JsonHelper) MerkleTreeLeaf(io.nem.symbol.sdk.model.state.MerkleTreeLeaf) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MerkleTreeBranchLink(io.nem.symbol.sdk.model.state.MerkleTreeBranchLink) MerkleTreeLeafDTO(io.nem.symbol.sdk.openapi.vertx.model.MerkleTreeLeafDTO) MerkleTreeBranchLink(io.nem.symbol.sdk.model.state.MerkleTreeBranchLink) MerkleTreeBranchDTO(io.nem.symbol.sdk.openapi.vertx.model.MerkleTreeBranchDTO) MerkleTreeBranch(io.nem.symbol.sdk.model.state.MerkleTreeBranch)

Aggregations

MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)3 MerkleTree (io.nem.symbol.sdk.model.state.MerkleTree)3 MerkleTreeBranch (io.nem.symbol.sdk.model.state.MerkleTreeBranch)3 MerkleTreeLeaf (io.nem.symbol.sdk.model.state.MerkleTreeLeaf)3 Objects (java.util.Objects)3 MerkleTreeBranchLink (io.nem.symbol.sdk.model.state.MerkleTreeBranchLink)1 MerkleTreeNodeType (io.nem.symbol.sdk.model.state.MerkleTreeNodeType)1 JsonHelper (io.nem.symbol.sdk.model.transaction.JsonHelper)1 MerkleStateInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MerkleStateInfoDTO)1 MerkleTreeBranchDTO (io.nem.symbol.sdk.openapi.vertx.model.MerkleTreeBranchDTO)1 MerkleTreeLeafDTO (io.nem.symbol.sdk.openapi.vertx.model.MerkleTreeLeafDTO)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1