~edwargix/tallyard

456f6a027f1041ca0244dc0340c86aa89e4a24e8 — David Florness 4 years ago 5a0610f
Store local voter in data.json

This way, we don't generate a private key on every program invocation.
2 files changed, 16 insertions(+), 11 deletions(-)

M cmd/tallyard/main.go
M matrix/data.go
M cmd/tallyard/main.go => cmd/tallyard/main.go +9 -6
@@ 49,7 49,10 @@ func main() {
		panic(err)
	}

	localVoter := election.NewLocalVoter(client.UserID)
	if data.LocalVoter == nil {
		data.LocalVoter = election.NewLocalVoter(client.UserID)
		data.Save()
	}

	elections := election.NewElectionsMap()



@@ 69,7 72,7 @@ func main() {
	})
	syncer.OnEventType(election.EvalMessage, func(source mautrix.EventSource, evt *event.Event) {
		DebugCB(source, evt)
		election.OnEvalMessage(source, evt, elections, localVoter)
		election.OnEvalMessage(source, evt, elections, data.LocalVoter)
	})
	syncer.OnEventType(election.SumMessage, func(source mautrix.EventSource, evt *event.Event) {
		DebugCB(source, evt)


@@ 92,17 95,17 @@ func main() {
		}
	}()

	el, ballot := ui.TUI(client, elections, localVoter)
	el, ballot := ui.TUI(client, elections, data.LocalVoter)

	localVoter.Poly = math.NewRandomPoly(uint(len(el.Voters)-1), 1024, ballot)
	data.LocalVoter.Poly = math.NewRandomPoly(uint(len(el.Voters)-1), 1024, ballot)

	// TODO we may not have all voters' info
	err = localVoter.SendEvals(client, el)
	err = data.LocalVoter.SendEvals(client, el)
	if err != nil {
		panic(err)
	}

	err = localVoter.SendSum(client, el)
	err = data.LocalVoter.SendSum(client, el)
	if err != nil {
		panic(err)
	}

M matrix/data.go => matrix/data.go +7 -5
@@ 10,14 10,16 @@ import (
	"github.com/kyoh86/xdg"
	"maunium.net/go/mautrix"
	"maunium.net/go/mautrix/id"
	"tallyard.xyz/election"
)

type Data struct {
	Homeserver  string      `json:"homeserver"`
	Username    string      `json:"username"`
	AccessToken string      `json:"access_token"`
	DeviceID    id.DeviceID `json:"device_id"`
	UserID      id.UserID   `json:"user_id"`
	Homeserver  string               `json:"homeserver"`
	Username    string               `json:"username"`
	AccessToken string               `json:"access_token"`
	DeviceID    id.DeviceID          `json:"device_id"`
	UserID      id.UserID            `json:"user_id"`
	LocalVoter  *election.LocalVoter `json:"local_voter,omitempty"`
}

var dataFname = xdg.DataHome() + "/tallyard/data.json"