Skip to content

Commit

Permalink
Merge branch 'main' into unikernel-combine-shares
Browse files Browse the repository at this point in the history
  • Loading branch information
nkcr committed May 11, 2022
2 parents 890b337 + d49a531 commit b77502f
Show file tree
Hide file tree
Showing 66 changed files with 2,297 additions and 1,067 deletions.
1 change: 1 addition & 0 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
router.HandleFunc("/evoting/elections/{electionID}", ep.Election).Methods("GET")
router.HandleFunc("/evoting/elections/{electionID}", ep.EditElection).Methods("PUT")
router.HandleFunc("/evoting/elections/{electionID}", eproxy.AllowCORS).Methods("OPTIONS")
router.HandleFunc("/evoting/elections/{electionID}", ep.DeleteElection).Methods("DELETE")
router.HandleFunc("/evoting/elections/{electionID}/vote", ep.NewElectionVote).Methods("POST")

router.NotFoundHandler = http.HandlerFunc(eproxy.NotFoundHandler)
Expand Down
84 changes: 78 additions & 6 deletions contracts/evoting/evoting.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions contracts/evoting/json/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package json

import (
"encoding/json"

"github.com/dedis/d-voting/contracts/evoting/types"
"go.dedis.ch/dela/serde"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -111,6 +112,12 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e
}

m = TransactionJSON{CancelElection: &ce}
case types.DeleteElection:
de := DeleteElectionJSON{
ElectionID: t.ElectionID,
}

m = TransactionJSON{DeleteElection: &de}
default:
return nil, xerrors.Errorf("unknown type: '%T", msg)
}
Expand Down Expand Up @@ -178,6 +185,10 @@ func (transactionFormat) Decode(ctx serde.Context, data []byte) (serde.Message,
ElectionID: m.CancelElection.ElectionID,
UserID: m.CancelElection.UserID,
}, nil
case m.DeleteElection != nil:
return types.DeleteElection{
ElectionID: m.DeleteElection.ElectionID,
}, nil
}

return nil, xerrors.Errorf("empty type: %s", data)
Expand All @@ -194,6 +205,7 @@ type TransactionJSON struct {
RegisterPubShares *RegisterPubSharesJSON `json:",omitempty"`
CombineShares *CombineSharesJSON `json:",omitempty"`
CancelElection *CancelElectionJSON `json:",omitempty"`
DeleteElection *DeleteElectionJSON `json:",omitempty"`
}

// CreateElectionJSON is the JSON representation of a CreateElection transaction
Expand Down Expand Up @@ -251,6 +263,11 @@ type CancelElectionJSON struct {
UserID string
}

// DeleteElectionJSON is the JSON representation of a DeleteElection transaction
type DeleteElectionJSON struct {
ElectionID string
}

func decodeCastVote(ctx serde.Context, m CastVoteJSON) (serde.Message, error) {
factory := ctx.GetFactory(types.CiphervoteKey{})
if factory == nil {
Expand Down
50 changes: 50 additions & 0 deletions contracts/evoting/mod.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package evoting

import (
dvoting "github.com/dedis/d-voting"
"github.com/dedis/d-voting/contracts/evoting/types"
"github.com/dedis/d-voting/services/dkg"
"github.com/prometheus/client_golang/prometheus"
"go.dedis.ch/dela/core/access"
"go.dedis.ch/dela/core/execution"
"go.dedis.ch/dela/core/execution/native"
Expand All @@ -19,6 +21,36 @@ import (
_ "github.com/dedis/d-voting/contracts/evoting/json"
)

var (
PromElectionStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "dvoting_status",
Help: "status of election",
},
[]string{"election"},
)

PromElectionBallots = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "dvoting_ballots_total",
Help: "number of cast ballots",
},
[]string{"election"},
)

PromElectionShufflingInstances = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "dvoting_shufflings_total",
Help: "number of shuffling instances",
},
[]string{"election"},
)

PromElectionPubShares = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "dvoting_pubshares_total",
Help: "published public shares",
},
[]string{"election"},
)
)

const (
// ElectionsMetadataKey is the key at which election metadata are saved in
// the storage.
Expand Down Expand Up @@ -55,6 +87,7 @@ type commands interface {
registerPubshares(snap store.Snapshot, step execution.Step) error
combineShares(snap store.Snapshot, step execution.Step) error
cancelElection(snap store.Snapshot, step execution.Step) error
deleteElection(snap store.Snapshot, step execution.Step) error
}

// Command defines a type of command for the value contract
Expand All @@ -72,12 +105,16 @@ const (
// CmdShuffleBallots is the command to shuffle ballots
CmdShuffleBallots Command = "SHUFFLE_BALLOTS"

// CmdRegisterPubShares is the command to register the pubshares
CmdRegisterPubShares Command = "REGISTER_PUB_SHARES"

// CmdCombineShares is the command to decrypt ballots
CmdCombineShares Command = "COMBINE_SHARES"
// CmdCancelElection is the command to cancel an election
CmdCancelElection Command = "CANCEL_ELECTION"

// CmdDeleteElection is the command to delete an election
CmdDeleteElection Command = "DELETE_ELECTION"
)

// NewCreds creates new credentials for a evoting contract execution. We might
Expand Down Expand Up @@ -209,9 +246,22 @@ func (c Contract) Execute(snap store.Snapshot, step execution.Step) error {
if err != nil {
return xerrors.Errorf("failed to cancel election: %v", err)
}
case CmdDeleteElection:
err := c.cmd.deleteElection(snap, step)
if err != nil {
return xerrors.Errorf("failed to delete election: %v", err)
}
default:
return xerrors.Errorf("unknown command: %s", cmd)
}

return nil
}

func init() {
dvoting.PromCollectors = append(dvoting.PromCollectors,
PromElectionStatus,
PromElectionBallots,
PromElectionShufflingInstances,
PromElectionPubShares)
}
Loading

0 comments on commit b77502f

Please sign in to comment.