diff --git a/openbook/src/main/java/com/mmorrell/openbook/model/AnyNode.java b/openbook/src/main/java/com/mmorrell/openbook/model/AnyNode.java index ef70eb3..9036816 100644 --- a/openbook/src/main/java/com/mmorrell/openbook/model/AnyNode.java +++ b/openbook/src/main/java/com/mmorrell/openbook/model/AnyNode.java @@ -13,6 +13,7 @@ public class AnyNode { private byte tag; private byte[] data; // 87 bytes + private NodeTag nodeTag; public static List readAnyNodes(byte[] data) { List nodes = new ArrayList<>(); @@ -28,6 +29,7 @@ public static List readAnyNodes(byte[] data) { nodes.add( AnyNode.builder() .tag(newTag) + .nodeTag(NodeTag.getNodeTag(newTag)) .data(newData) .build() ); diff --git a/openbook/src/main/java/com/mmorrell/openbook/model/NodeTag.java b/openbook/src/main/java/com/mmorrell/openbook/model/NodeTag.java new file mode 100644 index 0000000..f9782db --- /dev/null +++ b/openbook/src/main/java/com/mmorrell/openbook/model/NodeTag.java @@ -0,0 +1,24 @@ +package com.mmorrell.openbook.model; + +import lombok.Getter; + +@Getter +public enum NodeTag { + Uninitialized((byte) 0), InnerNode((byte) 1), LeafNode((byte) 2), FreeNode((byte) 3), LastFreeNode((byte) 4); + + private final byte tag; + + NodeTag(byte tag) { + this.tag = tag; + } + + public static NodeTag getNodeTag(byte tag) { + for (NodeTag node : NodeTag.values()) { + if (node.getTag() == tag) { + return node; + } + } + + return Uninitialized; + } +} diff --git a/openbook/src/test/java/OpenBookTest.java b/openbook/src/test/java/OpenBookTest.java index ccdabfd..3dafa5f 100644 --- a/openbook/src/test/java/OpenBookTest.java +++ b/openbook/src/test/java/OpenBookTest.java @@ -1,6 +1,6 @@ -import com.google.common.io.Files; import com.mmorrell.openbook.manager.OpenBookManager; import com.mmorrell.openbook.model.BookSide; +import com.mmorrell.openbook.model.NodeTag; import com.mmorrell.openbook.model.OpenBookMarket; import com.mmorrell.openbook.program.OpenbookProgram; import lombok.extern.slf4j.Slf4j; @@ -11,7 +11,6 @@ import org.p2p.solanaj.rpc.RpcException; import org.p2p.solanaj.rpc.types.ProgramAccount; -import java.io.File; import java.io.IOException; import java.util.List; @@ -55,8 +54,13 @@ public void orderBookTest() throws RpcException, IOException { .getDecodedData(); BookSide bookSide = BookSide.readBookSide(data); - - Files.write(data, new File("fMeta.bin")); log.info("fMETA Bids: {}", bookSide); + +// Files.write(data, new File("fMeta.bin")); + bookSide.getOrderTreeNodes().getNodes().stream() + .filter(anyNode -> anyNode.getNodeTag() == NodeTag.LeafNode) + .forEach(anyNode -> { + log.info("Leaf node: {}", anyNode); + }); } }