Skip to content

Commit c5db5fb

Browse files
committed
processarchive: quick fix on JSON naming and add weight field
TODO: the current weight is just equal to the number of votes, so its not valid when voting are over ERC20, instead the sum of all vote weights should be returned. Signed-off-by: p4u <[email protected]>
1 parent 6833fc3 commit c5db5fb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

vochain/processarchive/processarchive.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package processarchive
33
import (
44
"encoding/json"
55
"fmt"
6+
"math/big"
67
"os"
78
"path/filepath"
89
"sync"
@@ -26,8 +27,9 @@ type ProcessArchive struct {
2627
}
2728

2829
type Process struct {
29-
Process *models.Process
30-
Votes uint32
30+
Process *models.Process `json:"process"`
31+
Votes uint32 `json:"votes"`
32+
Weight *big.Int `json:"weight,omitempty"`
3133
}
3234

3335
type jsonStorage struct {
@@ -128,9 +130,11 @@ func (i *ProcessArchive) OnProcessResults(pid []byte,
128130
return fmt.Errorf("cannot get process %x info: %w", pid, err)
129131
}
130132
process.Results = &models.ProcessResult{Votes: results, ProcessId: pid}
133+
votes := i.vochain.State.CountVotes(pid, false)
131134
i.pprocs = append(i.pprocs, &Process{
132-
Votes: i.vochain.State.CountVotes(pid, false),
135+
Votes: votes,
133136
Process: process,
137+
Weight: new(big.Int).SetUint64(uint64(votes)), // TODO: return the correct weight
134138
})
135139
return nil
136140
}
@@ -145,7 +149,7 @@ func (i *ProcessArchive) Close() {
145149
// OnCancel does nothing
146150
func (i *ProcessArchive) OnCancel(pid []byte, txindex int32) {}
147151

148-
// OnCancOnVoteel does nothing
152+
// OnVote does nothing
149153
func (i *ProcessArchive) OnVote(v *models.Vote, txindex int32) {}
150154

151155
// OnNewTx does nothing

0 commit comments

Comments
 (0)