You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
881 B

  1. package data
  2. import (
  3. "os"
  4. "fmt"
  5. "bytes"
  6. "io/ioutil"
  7. shell "github.com/ipfs/go-ipfs-api"
  8. )
  9. type votePacket struct {
  10. PID uint
  11. Nullifier string
  12. Vote string
  13. Franchise string
  14. }
  15. func publish(object []byte) (string) {
  16. sh := shell.NewShell("localhost:5001")
  17. cid, err := sh.Add(bytes.NewBuffer(object))
  18. if err != nil {
  19. fmt.Fprintf(os.Stderr, "error: %s", err)
  20. os.Exit(1)
  21. }
  22. return cid
  23. }
  24. func pin(path string) {
  25. sh := shell.NewShell("localhost:5001")
  26. err := sh.Pin(path)
  27. if err != nil{
  28. fmt.Fprintf(os.Stderr, "error: %s", err)
  29. os.Exit(1)
  30. }
  31. }
  32. func retrieve(hash string) ([]byte){
  33. sh := shell.NewShell("localhost:5001")
  34. reader, err := sh.Cat(hash)
  35. if err != nil {
  36. fmt.Fprintf(os.Stderr, "error: %s", err)
  37. os.Exit(1)
  38. }
  39. content, err := ioutil.ReadAll(reader)
  40. if err != nil {
  41. fmt.Fprintf(os.Stderr, "error: %s", err)
  42. os.Exit(1)
  43. }
  44. return content
  45. }