2021-05-12 19:34:14 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Transaction struct {
|
|
|
|
Hash []byte
|
2021-05-14 19:42:22 +00:00
|
|
|
Timestamp time.Time
|
2021-05-12 19:34:14 +00:00
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateTransaction(data []byte) *Transaction {
|
2021-05-14 19:42:22 +00:00
|
|
|
timestamp := time.Now()
|
2021-05-12 19:34:14 +00:00
|
|
|
encodedData := hex.EncodeToString(data)
|
|
|
|
hash := crypto.Keccak256([]byte(fmt.Sprintf("%d_%s", timestamp, encodedData)))
|
|
|
|
return &Transaction{
|
|
|
|
Hash: hash,
|
|
|
|
Timestamp: timestamp,
|
|
|
|
Data: data,
|
|
|
|
}
|
|
|
|
}
|