Skip to content

Commit

Permalink
fix: Launchpad service: add missing GetID to respect merkletree Conte…
Browse files Browse the repository at this point in the history
…nt interface
  • Loading branch information
WaDadidou committed Oct 3, 2024
1 parent e5c6abf commit 6e1955c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go/pkg/launchpad/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Launchpad) buildWhitelistMerkleTree(addresses []string) (*merkletree.Me
}

// NOTE: Don't sort leaves to keep the same order of uploaded file
tree, err := merkletree.New(leaves,)
tree, err := merkletree.New(leaves)
if err != nil {
return nil, errors.Wrap(err, "failed to created merkle tree")
}
Expand Down
29 changes: 27 additions & 2 deletions go/pkg/launchpad/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (addr *WhitelistAddress) toBytes() []byte {
return []byte(addr.toStr())
}

func (addr *WhitelistAddress) GetID() string {
return addr.value
}

func (addr *WhitelistAddress) CalculateHash() ([]byte, error) {
res := crypto.Keccak256(addr.toBytes())
return res, nil
Expand Down Expand Up @@ -72,7 +76,28 @@ func (m *Metadata) proto_encode() ([]byte, error) {
return bytes, nil
}

// CalculateHash hashes the values of a TestContent
// Converts the Metadata data into one string
func (m *Metadata) GetID() string {
id := ""
for _, attribute := range m.Attributes {
id += *attribute.DisplayType
id += attribute.TraitType
id += attribute.Value
}
id += *m.Image
id += *m.ImageData
id += *m.ExternalUrl
id += *m.Description
id += *m.Name
id += *m.BackgroundColor
id += *m.AnimationUrl
id += *m.YoutubeUrl
id += fmt.Sprintf(":%d", *m.RoyaltyPercentage)
id += *m.RoyaltyPaymentAddress
return id
}

// CalculateHash hashes the values of a Metadata
func (m *Metadata) CalculateHash() ([]byte, error) {
bytes, err := m.proto_encode()
if err != nil {
Expand All @@ -83,7 +108,7 @@ func (m *Metadata) CalculateHash() ([]byte, error) {
return res, nil
}

// Equals tests for equality of two Contents
// Equals tests for equality of two Metadata
func (m *Metadata) Equals(other merkletree.Content) (bool, error) {
thisBytes, err := m.proto_encode()
if err != nil {
Expand Down

0 comments on commit 6e1955c

Please sign in to comment.