chore: cleanup unecessary checksum fn

This commit is contained in:
Mohamed Sohail 2023-03-28 06:24:28 +00:00
parent fc49f2387d
commit 2d5e41eb81
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
3 changed files with 4 additions and 35 deletions

View File

@ -23,7 +23,7 @@ func (s *Sub) handler(ctx context.Context, msg *nats.Msg) error {
switch msg.Subject {
case "CHAIN.gas":
if err := s.cu.PgStore.ResetGasQuota(ctx, checksum(chainEvent.To)); err != nil {
if err := s.cu.PgStore.ResetGasQuota(ctx, chainEvent.To); err != nil {
return err
}
}

View File

@ -83,10 +83,10 @@ func (s *Sub) Process() error {
if err := s.handler(ctx, msg); err != nil {
s.logg.Error("sub: handler error", "error", err)
msg.Nak()
} else {
s.logg.Debug("sub: processed msg", "subject", msg.Subject)
msg.Ack()
}
s.logg.Debug("sub: processed msg", "subject", msg.Subject)
msg.Ack()
cancel()
}
}

View File

@ -1,31 +0,0 @@
package sub
import (
"encoding/hex"
"strconv"
"strings"
"golang.org/x/crypto/sha3"
)
// TODO: This should probably be used project wide
func checksum(address string) string {
address = strings.ToLower(address)
address = strings.Replace(address, "0x", "", 1)
sha := sha3.NewLegacyKeccak256()
sha.Write([]byte(address))
hash := sha.Sum(nil)
hashstr := hex.EncodeToString(hash)
result := []string{"0x"}
for i, v := range address {
res, _ := strconv.ParseInt(string(hashstr[i]), 16, 64)
if res > 7 {
result = append(result, strings.ToUpper(string(v)))
continue
}
result = append(result, string(v))
}
return strings.Join(result, "")
}