|
6 | 6 | import java.util.Deque; |
7 | 7 | import java.util.List; |
8 | 8 | import lombok.extern.slf4j.Slf4j; |
| 9 | +import org.tron.common.utils.ByteUtil; |
| 10 | +import org.tron.core.capsule.IncrementalMerkleTreeCapsule; |
| 11 | +import org.tron.core.capsule.PedersenHashCapsule; |
9 | 12 | import org.tron.protos.Contract.PedersenHash; |
10 | 13 |
|
11 | 14 | @Slf4j |
@@ -275,7 +278,7 @@ public MerklePath path(Deque<PedersenHash> fillerHashes) { |
275 | 278 | List<List<Boolean>> merklePath = new ArrayList<>(); |
276 | 279 |
|
277 | 280 | for (PedersenHash b : path) { |
278 | | - merklePath.add(MerkleUtils.convertBytesVectorToVector(b.getContent().toByteArray())); |
| 281 | + merklePath.add(ByteUtil.convertBytesVectorToVector(b.getContent().toByteArray())); |
279 | 282 | } |
280 | 283 | merklePath = Lists.reverse(merklePath); |
281 | 284 | index = Lists.reverse(index); |
@@ -306,4 +309,41 @@ private boolean leftIsPresent() { |
306 | 309 | private boolean rightIsPresent() { |
307 | 310 | return !treeCapsule.getRight().getContent().isEmpty(); |
308 | 311 | } |
| 312 | + |
| 313 | + public static class PathFiller { |
| 314 | + |
| 315 | + private Deque<PedersenHash> queue; |
| 316 | + |
| 317 | + public PathFiller(Deque<PedersenHash> queue) { |
| 318 | + this.queue = queue; |
| 319 | + } |
| 320 | + |
| 321 | + public PedersenHash next(int depth) { |
| 322 | + if (queue.size() > 0) { |
| 323 | + return queue.poll(); |
| 324 | + } else { |
| 325 | + return EmptyMerkleRoots.emptyMerkleRootsInstance.emptyRoot(depth); |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + public static class EmptyMerkleRoots { |
| 331 | + |
| 332 | + public static EmptyMerkleRoots emptyMerkleRootsInstance = new EmptyMerkleRoots(); |
| 333 | + |
| 334 | + private List<PedersenHashCapsule> emptyRoots = new ArrayList<>(); |
| 335 | + |
| 336 | + public EmptyMerkleRoots() { |
| 337 | + emptyRoots.add(PedersenHashCapsule.uncommitted()); |
| 338 | + for (int d = 1; d <= DEPTH; d++) { |
| 339 | + emptyRoots.add( |
| 340 | + PedersenHashCapsule.combine( |
| 341 | + emptyRoots.get(d - 1).getInstance(), emptyRoots.get(d - 1).getInstance(), d - 1)); |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + public PedersenHash emptyRoot(int depth) { |
| 346 | + return emptyRoots.get(depth).getInstance(); |
| 347 | + } |
| 348 | + } |
309 | 349 | } |
0 commit comments