From b692058bb25fdefdbb0b6fe142ab93f57766b037 Mon Sep 17 00:00:00 2001 From: Alexander Matson Date: Fri, 17 May 2019 17:12:40 -0400 Subject: [PATCH] begin adding txns --- peers.go | 11 +++++++++++ transactions.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 transactions.go diff --git a/peers.go b/peers.go index b4d31df..7f0a79a 100644 --- a/peers.go +++ b/peers.go @@ -5,6 +5,8 @@ import ( "os" "fmt" "strings" + "encoding/gob" + "bytes" ) type peer struct { @@ -62,6 +64,15 @@ func (p peer) Version(remote peer) { fmt.Println(string(result)) } +func (p peer) Transact(remote peer, txn transaction) { + var b bytes.Buffer + e := gob.NewEncoder(&b) + err := e.Encode(txn) + Check(err) + + fmt.Println("Encoded struct ", b) +} + func handleConnection(conn net.Conn) { // close connection on exit defer conn.Close() diff --git a/transactions.go b/transactions.go new file mode 100644 index 0000000..1d469a9 --- /dev/null +++ b/transactions.go @@ -0,0 +1,34 @@ +package main + +import ( +) + +type transaction struct { + inputs [1]txIn + outputs [1]txOut +} + +type txIn struct { + prev_hash string + prev_index int + script_sig string // for now, just assume "script_sig" will be "public-key" (i.e., integer value) of recipient + sequence_no int +} + +type txOut struct { + value int + script_pub_key string // for now, just assume "script_pub_key" needs to just equal script_sig +} + +func makeTxn(pubkey string, privkey string, value int) transaction { + var ins [1]txIn + var outs [1]txOut + + ins[0] = txIn{script_sig: pubkey} + outs[0] = txOut{value: value, script_pub_key: privkey} + + return transaction { + inputs: ins, + outputs: outs, + } +}