begin adding txns
This commit is contained in:
parent
e329da4c31
commit
b692058bb2
11
peers.go
11
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()
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue