mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-12-22 01:47:31 +01:00
chore: cleanup unecessary checksum fn
This commit is contained in:
parent
fc49f2387d
commit
2d5e41eb81
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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, "")
|
||||
}
|
Loading…
Reference in New Issue
Block a user