-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Occurs While Generating buildMerkleProof - Assistance with Debugging #81
Comments
Hello! You serialize keys wrong, try this: CellSlice.beginParse(CellBuilder.beginCell()
.storeUint((BigInteger) k, 256).endCell())
.loadBits(256) worked for me: @Setter
@Getter
static class AirdropEntry {
Address address;
BigInteger amount;
public AirdropEntry(Address address, BigInteger amount) {
this.address = address;
this.amount = amount;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AirdropEntry that = (AirdropEntry) o;
return Objects.equals(address, that.address) && Objects.equals(amount, that.amount);
}
@Override
public int hashCode() {
return Objects.hash(address, amount);
}
@Override
public String toString() {
return "AirdropEntry{" +
"address=" + address +
", amount=" + amount +
'}';
}
}
@Test
public void test() {
List<AirdropEntry> entries = new ArrayList<>();
entries.add(new AirdropEntry(Address.of("UQAoXYmx-AhONJM4sJtvDIxpyjGOpnhChHVgIfPMhYXnc2T_"), BigInteger.valueOf(3_150_000_000L)));
entries.add(new AirdropEntry(Address.of("EQBKgXCNLPexWhs2L79kiARR1phGH1LwXxRbNsCFF9doc2lN"), BigInteger.valueOf(10_000_000_000L)));
val dct = new TonHashMap(256);
for (int i = 0; i < entries.size(); i++) {
dct.elements.put(
BigInteger.valueOf(i)
, entries.get(i));
}
var p = dct.buildMerkleProof(BigInteger.valueOf(0),
k -> CellSlice.beginParse(CellBuilder.beginCell()
.storeUint((BigInteger) k, 256).endCell())
.loadBits(256),
v -> {
AirdropEntry e = (AirdropEntry) v;
return CellBuilder.beginCell().storeRef(
CellBuilder.beginCell()
.storeAddress(e.address)
.storeCoins(e.amount)
.endCell()
).endCell();
}
);
System.out.println(p.print());
} Btw, I added ref to value serializer, because JS library works with same way. Moreover, Are you sure you need to use keys as integer? I suppose it should be addresses, this will be cheaper due to less gas consumption. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An error occurs during the process of generating buildMerkleProof. Below is the test code along with the error logs. I would appreciate it if you could let me know whether this issue is caused by a bug in the library or an issue in my code. If the issue is in my code, I would be grateful for any guidance on how to resolve it.
The text was updated successfully, but these errors were encountered: