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
683 B

7 years ago
package main
import (
"bytes"
"crypto/sha256"
"encoding/gob"
"log"
7 years ago
)
// Transaction represents a Bitcoin transaction
type Transaction struct {
id []byte
txInput []TXInput
txOutput []TXOutput
7 years ago
}
type TXOutput struct {
address string
value int
}
type TXInput struct {
txId []byte
txOutputIndex int
address string
7 years ago
}
// SetID sets ID of a transaction
func (tx *Transaction) SetId() {
var encoded bytes.Buffer
var hash [32]byte
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
}