Skip to content

Commit

Permalink
Sore lowercase addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Rozinko committed Apr 15, 2021
1 parent 3a993ae commit 3165df1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/httpserver/rest/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (s *Service) AccountTransactionsHandler(w http.ResponseWriter, r *http.Requ
}

vars := mux.Vars(r)
idStr := vars["id"]
idStr := strings.ToLower(vars["id"])

filter := &bson.D{
{"$or", bson.A{
Expand Down
26 changes: 3 additions & 23 deletions utils/bytes-to-string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@ package utils

import (
"encoding/hex"
"github.com/spacemeshos/go-spacemesh/crypto/sha3"
"github.com/spacemeshos/go-spacemesh/common/util"
)

// Hex returns an EIP55-compliant hex string representation of the address.
func BytesToAddressString(a []byte) string {
unchecksummed := hex.EncodeToString(a[:])
sha := sha3.NewKeccak256()
sha.Write([]byte(unchecksummed))
hash := sha.Sum(nil)

result := []byte(unchecksummed)
for i := 0; i < len(result); i++ {
hashByte := hash[i/2]
if i%2 == 0 {
hashByte = hashByte >> 4
} else {
hashByte &= 0xf
}
if result[i] > '9' && hashByte > 7 {
result[i] -= 32
}
}
return "0x" + string(result)
return "0x" + hex.EncodeToString(a[:])
}

func BytesToHex(a []byte) string { return util.Encode(a[:]) }
func BytesToHex(a []byte) string { return hex.EncodeToString(a[:]) }

func NBytesToHex(a []byte, n int) string { return util.Encode(a[:n]) }
func NBytesToHex(a []byte, n int) string { return hex.EncodeToString(a[:n]) }

0 comments on commit 3165df1

Please sign in to comment.