Skip to content

Commit

Permalink
Merge pull request #34 from icon-project/mksong-refactor-classes
Browse files Browse the repository at this point in the history
Move MerkleTreeAccumulator and MerklePatriciaTree to library
  • Loading branch information
sink772 authored Aug 16, 2023
2 parents 1992706 + dff8ede commit dada8bb
Show file tree
Hide file tree
Showing 17 changed files with 400 additions and 1,723 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import foundation.icon.btp.lib.BMV;
import foundation.icon.btp.lib.BMVStatus;
import foundation.icon.btp.lib.BTPAddress;
import foundation.icon.btp.lib.MTAException;
import foundation.icon.btp.lib.MerklePatriciaTree;
import foundation.icon.btp.lib.MerkleTreeAccumulator;
import score.Address;
import score.Context;
import score.DictDB;
Expand Down Expand Up @@ -48,9 +51,7 @@ public BTPMessageVerifier(Address bmc, BigInteger chainId, byte[] header,
Context.require(config.isEpoch(head.getNumber()), "No epoch block");
verify(config, head);

MerkleTreeAccumulator mta = new MerkleTreeAccumulator();
mta.setHeight(head.getNumber().longValue());
mta.setOffset(head.getNumber().longValue());
MerkleTreeAccumulator mta = new MerkleTreeAccumulator(head.getNumber().longValueExact());
mta.add(head.getHash().toBytes());

if (head.getNumber().compareTo(BigInteger.ZERO) == 0) {
Expand Down Expand Up @@ -192,7 +193,7 @@ private Header handleBlockProof(BlockProof bp, MerkleTreeAccumulator mta) {

try {
mta.verify(bp.getWitness(), head.getHash().toBytes(),
head.getNumber().longValue()+1, bp.getHeight().intValue());
head.getNumber().longValue(), bp.getHeight().intValue());
} catch (MTAException.InvalidWitnessOldException e) {
throw BMVException.invalidBlockWitnessOld(e.getMessage());
} catch (MTAException e) {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit dada8bb

Please sign in to comment.