package utils

import (
	"bytes"
	"strings"

	"github.com/ethereum/go-ethereum/common"
)

const (
	ethAddrPrefix = "0x"
)

func TrimEvmAddrPrefix(addr string) string {
	if strings.HasPrefix(addr, ethAddrPrefix) {
		addr = strings.TrimPrefix(addr, ethAddrPrefix)
	}
	return addr
}

func CompareEvmAddr(a1, a2 string) bool {
	a1 = TrimEvmAddrPrefix(a1)
	a2 = TrimEvmAddrPrefix(a2)
	addr1 := common.HexToAddress(a1)
	addr2 := common.HexToAddress(a2)
	if bytes.Compare(addr1.Bytes(), addr2.Bytes()) == 0 {
		return true
	}
	return false
}
