package main import ( "bytes" "crypto/sha256" "encoding/gob" "log" ) // Transaction represents a Bitcoin transaction type Transaction struct { ID []byte Vin []TXInput Vout []TXOutput } type TXOutput struct { Addresss string Value int } type TXInput struct { Txid []byte outIndex 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[:] }