Files
dejo-node/internal/transactions/transaction.go
2025-05-23 10:44:32 -03:00

29 lines
684 B
Go

package transactions
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
type Transaction struct {
Type string // TRANSFER, STAKE, MINT, etc.
From string
To string
Value float64
Nonce uint64
Gas uint64
Signature string
}
// Hash gera um hash SHA256 da transação para identificação única
func (tx *Transaction) Hash() string {
data := fmt.Sprintf("%s:%s:%f:%d:%d", tx.From, tx.To, tx.Value, tx.Nonce, tx.Gas)
sum := sha256.Sum256([]byte(data))
return hex.EncodeToString(sum[:])
}
// IsZero valida se os campos obrigatórios estão presentes
func (tx *Transaction) IsZero() bool {
return tx.From == "" || tx.To == "" || tx.Value == 0
}