@@ -20,6 +20,7 @@ import (
20
20
"github.com/dedis/d-voting/contracts/evoting/types"
21
21
"github.com/dedis/d-voting/internal/testing/fake"
22
22
eproxy "github.com/dedis/d-voting/proxy"
23
+ "github.com/dedis/d-voting/proxy/txnmanager"
23
24
ptypes "github.com/dedis/d-voting/proxy/types"
24
25
"github.com/dedis/d-voting/services/dkg"
25
26
"github.com/dedis/d-voting/services/shuffle"
@@ -46,8 +47,11 @@ import (
46
47
const (
47
48
contentType = "application/json"
48
49
formPath = "/evoting/forms"
49
- formPathSlash = formPath + "/"
50
- formIDPath = formPathSlash + "{formID}"
50
+ // FormPathSlash is the path to the form with a trailing slash
51
+ FormPathSlash = formPath + "/"
52
+ formIDPath = FormPathSlash + "{formID}"
53
+ transactionSlash = "/evoting/transactions/"
54
+ transactionPath = transactionSlash + "{token}"
51
55
unexpectedStatus = "unexpected status: %s, body: %s"
52
56
failRetrieveDecryption = "failed to retrieve decryption key: %v"
53
57
selectString = "select:"
@@ -91,7 +95,9 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
91
95
return xerrors .Errorf ("failed to resolve ordering.Service: %v" , err )
92
96
}
93
97
94
- var blocks * blockstore.InDisk
98
+ // The BlockStore will be used to parse the blockchain
99
+ // to check if a transaction was included
100
+ var blocks blockstore.BlockStore
95
101
err = ctx .Injector .Resolve (& blocks )
96
102
if err != nil {
97
103
return xerrors .Errorf ("failed to resolve blockstore.InDisk: %v" , err )
@@ -163,7 +169,9 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
163
169
return xerrors .Errorf ("failed to unmarshal proxy key: %v" , err )
164
170
}
165
171
166
- ep := eproxy .NewForm (ordering , mngr , p , sjson .NewContext (), formFac , proxykey )
172
+ transactionManager := txnmanager .NewTransactionManager (mngr , p , sjson .NewContext (), proxykey , blocks , signer )
173
+
174
+ ep := eproxy .NewForm (ordering , p , sjson .NewContext (), formFac , proxykey , transactionManager )
167
175
168
176
router := mux .NewRouter ()
169
177
@@ -175,12 +183,14 @@ func (a *RegisterAction) Execute(ctx node.Context) error {
175
183
router .HandleFunc (formIDPath , eproxy .AllowCORS ).Methods ("OPTIONS" )
176
184
router .HandleFunc (formIDPath , ep .DeleteForm ).Methods ("DELETE" )
177
185
router .HandleFunc (formIDPath + "/vote" , ep .NewFormVote ).Methods ("POST" )
186
+ router .HandleFunc (transactionPath , transactionManager .StatusHandlerGet ).Methods ("GET" )
178
187
179
188
router .NotFoundHandler = http .HandlerFunc (eproxy .NotFoundHandler )
180
189
router .MethodNotAllowedHandler = http .HandlerFunc (eproxy .NotAllowedHandler )
181
190
182
191
proxy .RegisterHandler (formPath , router .ServeHTTP )
183
- proxy .RegisterHandler (formPathSlash , router .ServeHTTP )
192
+ proxy .RegisterHandler (FormPathSlash , router .ServeHTTP )
193
+ proxy .RegisterHandler (transactionSlash , router .ServeHTTP )
184
194
185
195
dela .Logger .Info ().Msg ("d-voting proxy handlers registered" )
186
196
@@ -692,7 +702,7 @@ func marshallBallot(voteStr string, actor dkg.Actor, chunks int) (ptypes.Cipherv
692
702
693
703
// formID is hex-encoded
694
704
func castVote (formID string , signed []byte , proxyAddr string ) (string , error ) {
695
- resp , err := http .Post (proxyAddr + formPathSlash + formID + "/vote" , contentType , bytes .NewBuffer (signed ))
705
+ resp , err := http .Post (proxyAddr + FormPathSlash + formID + "/vote" , contentType , bytes .NewBuffer (signed ))
696
706
697
707
if err != nil {
698
708
return "" , xerrors .Errorf (failRetrieveDecryption , err )
@@ -723,7 +733,7 @@ func updateForm(secret kyber.Scalar, proxyAddr, formIDHex, action string) (int,
723
733
return 0 , createSignedErr (err )
724
734
}
725
735
726
- req , err := http .NewRequest (http .MethodPut , proxyAddr + formPathSlash + formIDHex , bytes .NewBuffer (signed ))
736
+ req , err := http .NewRequest (http .MethodPut , proxyAddr + FormPathSlash + formIDHex , bytes .NewBuffer (signed ))
727
737
728
738
if err != nil {
729
739
return 0 , xerrors .Errorf ("failed to create request: %v" , err )
0 commit comments