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

40 lines
617 B

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