begin adding txns

This commit is contained in:
Alexander Matson 2019-05-17 17:12:40 -04:00
parent e329da4c31
commit b692058bb2
2 changed files with 45 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import (
"os" "os"
"fmt" "fmt"
"strings" "strings"
"encoding/gob"
"bytes"
) )
type peer struct { type peer struct {
@ -62,6 +64,15 @@ func (p peer) Version(remote peer) {
fmt.Println(string(result)) 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) { func handleConnection(conn net.Conn) {
// close connection on exit // close connection on exit
defer conn.Close() defer conn.Close()

34
transactions.go Normal file
View File

@ -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,
}
}