commit inicial do projeto
This commit is contained in:
29
internal/transactions/transaction.go
Normal file
29
internal/transactions/transaction.go
Normal file
@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user