package util

import (
	"crypto/md5"
	"encoding/hex"
	"ktogame/enums"
	"time"

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

func NowTimeString() string {
	return time.Now().Format("2006-01-02 15:04:05")
}

func NowTimeDayString() string {
	return time.Now().Format("2006-01-02")
}

func Md5(str string) string {
	hash := md5.New()
	hash.Write([]byte(str))
	return hex.EncodeToString(hash.Sum(nil))
}

func Sign(amountStr, addr, timeStr string) string {
	keccakA := crypto.Keccak256([]byte(amountStr), []byte(enums.DIGIT))
	keccakS := crypto.Keccak256(keccakA, []byte(timeStr), []byte(addr))
	return "0x" + hex.EncodeToString(keccakS)
}
