Skip to content

Commit

Permalink
minor tweaks (BinTree usage in McBlockExtra, McStateExtra and ShardHa…
Browse files Browse the repository at this point in the history
…shes)
  • Loading branch information
h6x0r committed Aug 17, 2024
1 parent 3f17a56 commit 1e22ca5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cell/src/main/java/org/ton/java/cell/BinTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private Cell addToBinTree(BinTree left, BinTree right) {
}

public static BinTree deserialize(CellSlice cs) {
if (cs.isExotic()) {
return new BinTree();
if (cs.bits.getLength() == 0 || cs.isExotic()) {
return null;
}

if (cs.loadBit()) {
Expand Down
18 changes: 5 additions & 13 deletions cell/src/main/java/org/ton/java/tlb/types/McBlockExtra.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
public class McBlockExtra {
long magic;
boolean keyBlock;
// ShardHashes shardHashes;
TonHashMapE shardHashes;
ShardHashes shardHashes;
// ShardFees shardFees;
TonHashMapAugE shardFees;
McBlockExtraInfo info;
Expand All @@ -41,12 +40,8 @@ public Cell toCell() {
return CellBuilder.beginCell()
.storeUint(0xcca5, 32)
.storeBit(keyBlock)
// .storeCell(shardHashes.toCell())
.storeDict(shardHashes.toCell())
// .storeCell(shardFees.toCell())
.storeDict(shardHashes.serialize(
k -> CellBuilder.beginCell().storeUint((Long) k, 32).endCell().getBits(),
v -> CellBuilder.beginCell().storeRef((Cell) v).endCell() // todo ShardDescr
))
.storeDict(shardFees.serialize(
k -> CellBuilder.beginCell().storeUint((Long) k, 96).endCell().getBits(),
v -> CellBuilder.beginCell().storeCell((Cell) v), // todo ShardFeeCreated
Expand All @@ -66,13 +61,10 @@ public static McBlockExtra deserialize(CellSlice cs) {
McBlockExtra mcBlockExtra = McBlockExtra.builder()
.magic(0xcca5L)
.keyBlock(keyBlock)
// .shardHashes(ShardHashes.deserialize(cs))
.shardHashes(ShardHashes.deserialize(cs))
// .shardFees(ShardFees.deserialize(cs))
.shardHashes(cs.loadDictE(32,
k -> k.readInt(32),
v -> CellSlice.beginParse(v).loadRef())) // ref
.shardFees(cs.loadDictAugE(92,
k -> k.readInt(92),
.shardFees(cs.loadDictAugE(96,
k -> k.readInt(96),
v -> v,
e -> e))
.build();
Expand Down
14 changes: 3 additions & 11 deletions cell/src/main/java/org/ton/java/tlb/types/McStateExtra.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*/
public class McStateExtra {
long magic;
// ShardHashes shardHashes;
TonHashMapE shardHashes;
ShardHashes shardHashes;
ConfigParams configParams;
McStateExtraInfo info;
CurrencyCollection globalBalance;
Expand All @@ -43,11 +42,7 @@ private String getMagic() {
public Cell toCell() {
return CellBuilder.beginCell()
.storeUint(0xcc26, 16)
// .storeDict(shardHashes.toCell())
.storeDict(shardHashes.serialize(
k -> CellBuilder.beginCell().storeUint((Long) k, 32).endCell().getBits(),
v -> CellBuilder.beginCell().storeRef((Cell) v).endCell() // todo ShardDescr
))
.storeDict(shardHashes.toCell())
.storeCell(configParams.toCell())
.storeRef(info.toCell())
.storeCell(globalBalance.toCell())
Expand All @@ -67,10 +62,7 @@ public static McStateExtra deserialize(CellSlice cs) {

McStateExtra mcStateExtra = McStateExtra.builder()
.magic(0xcc26L)
// .shardHashes(ShardHashes.deserialize(cs))
.shardHashes(cs.loadDictE(32,
k -> k.readInt(32),
v -> v)) // todo BinTree
.shardHashes(ShardHashes.deserialize(cs))
.build();

mcStateExtra.setConfigParams(ConfigParams.deserialize(cs));
Expand Down
2 changes: 1 addition & 1 deletion cell/src/main/java/org/ton/java/tlb/types/ShardHashes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static ShardHashes deserialize(CellSlice cs) {
return ShardHashes.builder()
.shardHashes(cs.loadDictE(32,
k -> k.readInt(32),
v -> BinTree.deserialize(CellSlice.beginParse(cs.loadRef()))))
v -> BinTree.deserialize(CellSlice.beginParse(v))))
.build();
}

Expand Down

0 comments on commit 1e22ca5

Please sign in to comment.