diff --git a/batch/batch.go b/batch/batch.go index 36ac453..f69387f 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -44,7 +44,7 @@ func Add(ballot types.Ballot) error { //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 @@ func Create() ([]string, []string) { //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()) diff --git a/data/data.go b/data/data.go index d0a33ac..c48997e 100644 --- a/data/data.go +++ b/data/data.go @@ -8,7 +8,7 @@ import ( 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 @@ func publish(object []byte) string { 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 pin(path string) { } -func retrieve(hash string) []byte { +func Retrieve(hash string) []byte { sh := shell.NewShell("localhost:5001") reader, err := sh.Cat(hash) if err != nil { diff --git a/generator/generator.go b/generator/generator.go index 5e0bd40..e51f1eb 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -75,7 +75,7 @@ func main() { 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 { diff --git a/main.go b/main.go index 7c1309b..fed06bc 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,12 @@ package main 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 @@ func main() { 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 @@ func main() { 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 diff --git a/types/types.go b/types/types.go index 87ad322..03eee3a 100644 --- a/types/types.go +++ b/types/types.go @@ -22,7 +22,7 @@ type Envelope struct { type Batch struct { Type string - Nullifiers [][]byte + Nullifiers []string URL string TXID string Nonce []byte