The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/transaction.go

41 lines
617 B

7 years ago
package main
import (
7 years ago
"bytes"
"crypto/sha256"
"encoding/gob"
"log"
7 years ago
)
// Transaction represents a Bitcoin transaction
type Transaction struct {
7 years ago
id []byte
txInput []TXInput
txOutput []TXOutput
7 years ago
}
type TXOutput struct {
7 years ago
address string
value int
}
type TXInput struct {
7 years ago
txId []byte
txOutputIndex int
address string
7 years ago
}
// SetID sets ID of a transaction
func (tx *Transaction) SetId() {
7 years ago
var encoded bytes.Buffer
var hash [32]byte
7 years ago
7 years ago
enc := gob.NewEncoder(&encoded)
err := enc.Encode(tx)
if err != nil {
log.Panic(err)
}
hash = sha256.Sum256(encoded.Bytes())
tx.ID = hash[:]
7 years ago
}