Skip to content
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

feat(p/demo/merkle): add constructor w/ getter for merkle.Node struct #2784

Merged

Conversation

MikaelVallenet
Copy link
Contributor

@MikaelVallenet MikaelVallenet commented Sep 11, 2024

Hello,

This pull request asks to modify the merkle tree package by adding a constructor for Node and add Position getter
The reason is that in my usage, I receive a json string containing the merkle proofs that I transform into a merkle.Node struct, but since these fields are not exported and no constructor available, I can't do it.

Example of the usage of modified pkg:

func ClaimJSON(airdropID uint64, proofsJSON string) {
	nodes, err := json.Unmarshal([]byte(proofsJSON))
	if err != nil {
		panic("invalid json proofs")
	}
	vals := nodes.MustArray()
	proofs := make([]merkle.Node, 0, len(vals))
	for _, val := range vals {
		obj := val.MustObject()
		data, err := hex.DecodeString(obj["hash"].MustString())
		if err != nil {
			panic("invalid hex encoded hash")
		}
                node := merkle.NewNode(data, jsonutil.MustUint8(obj["pos"])
		proofs = append(proofs, node)
	}
	Claim(airdropID, proofs)
}

P.S: I thought adding getter and constructor would avoid to break contract that already use this like the demo airdrop, it's why i prefer this method over exporting field from the struct


Related PRs:

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@MikaelVallenet MikaelVallenet requested review from a team as code owners September 11, 2024 22:55
@MikaelVallenet MikaelVallenet requested review from thehowl and zivkovicmilos and removed request for a team September 11, 2024 22:55
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Sep 11, 2024
@MikaelVallenet MikaelVallenet changed the title feat(p/demo/merkle): export hash & position field of nodes feat(p/demo/merkle): add constructor w/ getter/setter for merkle.Node struct Sep 11, 2024
@MikaelVallenet MikaelVallenet marked this pull request as draft September 11, 2024 22:59
@MikaelVallenet MikaelVallenet changed the title feat(p/demo/merkle): add constructor w/ getter/setter for merkle.Node struct feat(p/demo/merkle): add constructor w/ getter for merkle.Node struct Sep 11, 2024
@MikaelVallenet MikaelVallenet marked this pull request as ready for review September 11, 2024 23:08
Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.43%. Comparing base (f04ec89) to head (a725789).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2784      +/-   ##
==========================================
- Coverage   60.44%   60.43%   -0.01%     
==========================================
  Files         563      563              
  Lines       75159    75159              
==========================================
- Hits        45427    45422       -5     
- Misses      26343    26349       +6     
+ Partials     3389     3388       -1     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 67.21% <ø> (ø)
gnovm 64.46% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leohhhn leohhhn merged commit 30e4a59 into gnolang:master Sep 12, 2024
119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants