@@ -17,7 +17,7 @@ module.exports.get = async (event, _context, callback) => {
1717 }
1818 } ,
1919 KeyConditionExpression : 'disputeIDAndAppeal = :disputeIDAndAppeal' ,
20- TableName : ' justifications'
20+ TableName : ` ${ payload . network } - justifications`
2121 } )
2222 }
2323 } )
@@ -32,71 +32,63 @@ module.exports.put = async (event, _context, callback) => {
3232 process . env . KLEROS_LIQUID_ADDRESS
3333 )
3434
35- // Validate signature
3635 const payload = JSON . parse ( event . body ) . payload
37- try {
38- if (
39- ( await web3 . eth . accounts . recover (
40- JSON . stringify ( payload . justification ) ,
41- payload . signature
42- ) ) !==
43- ( await dynamoDB . getItem ( {
44- Key : { address : { S : payload . address } } ,
45- TableName : 'user-settings' ,
46- ProjectionExpression : 'derivedAccountAddress'
47- } ) ) . Item . derivedAccountAddress . S
48- )
49- throw new Error (
50- "Signature does not match the supplied address' derived account address for justifications."
51- )
52- } catch ( err ) {
53- console . error ( err )
54- return callback ( null , {
55- statusCode : 403 ,
56- headers : { 'Access-Control-Allow-Origin' : '*' } ,
57- body : JSON . stringify ( {
58- error :
59- "Signature is invalid or does not match the supplied address' derived account address for justifications."
60- } )
61- } )
62- }
6336
6437 // Verify votes belong to user
65- for ( const voteID of payload . justification . voteIDs ) {
38+ const dispute = await klerosLiquid . methods . getDispute (
39+ payload . justification . disputeID
40+ ) . call ( )
41+
42+ // Get number of votes in current round
43+ const votesInRound = dispute . votesLengths [ payload . justification . appeal ]
44+
45+ let drawn = false
46+ let voteID
47+ for ( let i = 0 ; i < Number ( votesInRound ) ; i ++ ) {
6648 const vote = await klerosLiquid . methods
67- . getVote (
68- payload . justification . disputeID ,
69- payload . justification . appeal ,
70- voteID
71- )
49+ . getVote ( payload . justification . disputeID , payload . justification . appeal , i )
7250 . call ( )
73- if ( vote . account !== payload . address || vote . voted )
74- return callback ( null , {
75- statusCode : 403 ,
76- headers : { 'Access-Control-Allow-Origin' : '*' } ,
77- body : JSON . stringify ( {
78- error :
79- 'Not all of the supplied vote IDs belong to the supplied address and are not cast.'
51+ if ( vote . account === payload . address ) {
52+ // If voted, can no longer submit justification.
53+ if ( vote . voted ) {
54+ return callback ( null , {
55+ statusCode : 403 ,
56+ headers : { 'Access-Control-Allow-Origin' : '*' } ,
57+ body : JSON . stringify ( {
58+ error : 'This address has already cast their vote.'
59+ } )
8060 } )
61+ }
62+ // Once we know address has been drawn we can stop searching.
63+ drawn = true
64+ voteID = i
65+ break
66+ }
67+ }
68+
69+ if ( ! drawn ) {
70+ return callback ( null , {
71+ statusCode : 403 ,
72+ headers : { 'Access-Control-Allow-Origin' : '*' } ,
73+ body : JSON . stringify ( {
74+ error : 'This address was not drawn.'
8175 } )
76+ } )
8277 }
8378
84- // Save justification
79+ // Save justification.
8580 await dynamoDB . putItem ( {
8681 Item : {
8782 disputeIDAndAppeal : {
8883 S : `${ payload . justification . disputeID } -${ payload . justification . appeal } `
8984 } ,
90- voteID : {
91- N : String (
92- payload . justification . voteIDs [
93- payload . justification . voteIDs . length - 1
94- ]
95- )
85+ address : {
86+ S : payload . address
9687 } ,
88+ voteID : { N : String ( voteID ) } ,
9789 justification : { S : payload . justification . justification }
9890 } ,
99- TableName : ' justifications'
91+ TableName : ` ${ payload . network } - justifications`
10092 } )
10193 callback ( null , {
10294 statusCode : 200 ,
0 commit comments