arnaucube
arnaucube/go-dvotePublic Self-hosted repository
Publishes batches to ipfs and pins them. Assumes running ipfs daemon on 8080. Moved relay listener to 8090
imw imw@0x539.lol
Fri, 28 Dec 2018 14:01:50 +0100
commit

d09af855028804205d8c624eb6ec2364e6eb19e8

parent

6ad2f16c24b830b234861c62bf6059786de963c6

5 files changed, 26 insertions(+), 14 deletions(-)

jump to
M batch/batch.go → batch/batch.go

@@ -44,7 +44,7 @@ //create (return batch)

//k is []byte 'batch_' + nullifier //v is []byte package //returns slice of nullifiers, batch json -func Create() ([]string, []string) { +func Fetch() ([]string, []string) { var n []string var b []string iter := bdb.Iter()

@@ -73,7 +73,7 @@

//move from bdb to rdb once pinned func Compact(n []string) { for _, k := range n { - fmt.Println(k) + //fmt.Println(k) v, err := bdb.Get([]byte(k)) if err != nil { fmt.Println(err.Error())
M data/data.go → data/data.go

@@ -8,7 +8,7 @@ "io/ioutil"

shell "github.com/ipfs/go-ipfs-api" ) -func publish(object []byte) string { +func Publish(object []byte) string { sh := shell.NewShell("localhost:5001") cid, err := sh.Add(bytes.NewBuffer(object)) if err != nil {

@@ -18,7 +18,7 @@ }

return cid } -func pin(path string) { +func Pin(path string) { sh := shell.NewShell("localhost:5001") err := sh.Pin(path) if err != nil{

@@ -28,7 +28,7 @@ }

} -func retrieve(hash string) []byte { +func Retrieve(hash string) []byte { sh := shell.NewShell("localhost:5001") reader, err := sh.Cat(hash) if err != nil {
M generator/generator.go → generator/generator.go

@@ -75,7 +75,7 @@ interval := os.Args[1]

i, _ := strconv.Atoi(interval) timer := time.NewTicker(time.Millisecond * time.Duration(i)) rand.Seed(time.Now().UnixNano()) - url := "http://localhost:8080/submit" + url := "http://localhost:8090/submit" fmt.Println("URL:>", url) for {
M main.go → main.go

@@ -3,9 +3,12 @@

import ( "fmt" "time" + "encoding/gob" + "bytes" "github.com/vocdoni/dvote-relay/batch" "github.com/vocdoni/dvote-relay/net" "github.com/vocdoni/dvote-relay/db" + "github.com/vocdoni/dvote-relay/data" ) var dbPath = "~/.dvote/relay.db"

@@ -35,7 +38,7 @@ batch.BatchSignal = batchSignal

batch.BatchSize = batchSize fmt.Println("Entering main loop") - go net.Listen("8080") + go net.Listen("8090") for { select { case <- batchTimer.C:

@@ -45,12 +48,21 @@ //replace with chain link

case signal := <-batchSignal: if signal == true { fmt.Println("Signal triggered") - n, b := batch.Create() - fmt.Println("Nullifiers:") - fmt.Println(n) - fmt.Println("Batch:") - fmt.Println(b) - batch.Compact(n) + ns, bs := batch.Fetch() + buf := &bytes.Buffer{} + gob.NewEncoder(buf).Encode(bs) + bb := buf.Bytes() + cid := data.Publish(bb) + data.Pin(cid) + fmt.Printf("Batch published at: %s \n", cid) + // add to ipfs + // add to chain + // announce to pubsub + //fmt.Println("Nullifiers:") + //fmt.Println(n) + //fmt.Println("Batch:") + //fmt.Println(b) + batch.Compact(ns) } default: continue
M types/types.go → types/types.go

@@ -22,7 +22,7 @@ }

type Batch struct { Type string - Nullifiers [][]byte + Nullifiers []string URL string TXID string Nonce []byte