Skip to content

Commit 09fffc9

Browse files
author
Jiri Malek
committed
Load empty governance proposal states to response.
1 parent 2181e93 commit 09fffc9

4 files changed

Lines changed: 12 additions & 26 deletions

File tree

internal/graphql/resolvers/gov_proposal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (gp *GovernanceProposal) OptionState(args *struct{ OptionId hexutil.Big })
4343
func (gp *GovernanceProposal) OptionStates() ([]*types.GovernanceOptionState, error) {
4444
// make sure to call this only once in parallel processing
4545
ops, err, _ := gp.cg.Do("opt_states", func() (interface{}, error) {
46-
return repository.R().GovernanceOptionStates(&gp.GovernanceId, &gp.Id)
46+
return repository.R().GovernanceOptionStates(&gp.GovernanceId, &gp.Id, len(gp.Options))
4747
})
4848
return ops.([]*types.GovernanceOptionState), err
4949
}

internal/repository/governance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func (p *proxy) GovernanceOptionState(gov *common.Address, propId *hexutil.Big,
4040
}
4141

4242
// GovernanceOptionStates returns a list of states of options of a proposal.
43-
func (p *proxy) GovernanceOptionStates(gov *common.Address, propId *hexutil.Big) ([]*types.GovernanceOptionState, error) {
44-
return p.rpc.GovernanceOptionStates(gov, propId)
43+
func (p *proxy) GovernanceOptionStates(gov *common.Address, propId *hexutil.Big, optRange int) ([]*types.GovernanceOptionState, error) {
44+
return p.rpc.GovernanceOptionStates(gov, propId, optRange)
4545
}
4646

4747
// GovernanceVote provides a single vote in the Governance Proposal context.

internal/repository/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ type Repository interface {
488488
GovernanceOptionState(*common.Address, *hexutil.Big, *hexutil.Big) (*types.GovernanceOptionState, error)
489489

490490
// GovernanceOptionStates returns a list of states of options of a proposal.
491-
GovernanceOptionStates(*common.Address, *hexutil.Big) ([]*types.GovernanceOptionState, error)
491+
GovernanceOptionStates(*common.Address, *hexutil.Big, int) ([]*types.GovernanceOptionState, error)
492492

493493
// GovernanceVote provides a single vote in the Governance Proposal context.
494494
GovernanceVote(*common.Address, *hexutil.Big, *common.Address, *common.Address) (*types.GovernanceVote, error)

internal/repository/rpc/governance.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func govConvertScales(sc []*big.Int) []hexutil.Uint64 {
165165
return res
166166
}
167167

168-
// GovernanceProposal provides a detail of Proposal of a governance contract
168+
// GovernanceProposalDetails provides a detail of Proposal of a governance contract
169169
// specified by its id.
170170
func (ftm *FtmBridge) GovernanceProposalDetails(prop *common.Address) (*govProposalExtended, error) {
171171
// get the proposal contract
@@ -216,44 +216,30 @@ func (ftm *FtmBridge) GovernanceOptionState(gov *common.Address, propId *hexutil
216216
}
217217

218218
// GovernanceOptionStates returns a list of states of options of a proposal.
219-
func (ftm *FtmBridge) GovernanceOptionStates(gov *common.Address, propId *hexutil.Big) ([]*types.GovernanceOptionState, error) {
219+
func (ftm *FtmBridge) GovernanceOptionStates(gov *common.Address, propId *hexutil.Big, optRange int) ([]*types.GovernanceOptionState, error) {
220220
// get the contract
221221
gc, err := contracts.NewGovernance(*gov, ftm.eth)
222222
if err != nil {
223223
ftm.log.Errorf("can not access governance %s; %s", gov.String(), err.Error())
224224
return nil, err
225225
}
226226

227-
// get the number of options
228-
max, err := gc.MaxOptions(nil)
229-
if err != nil {
230-
ftm.log.Errorf("unknown options on governance %s; %s", gov.String(), err.Error())
231-
return nil, err
232-
}
233-
234227
// make the container and collect the states
235-
zero := new(big.Int)
236-
res := make([]*types.GovernanceOptionState, 0)
228+
res := make([]*types.GovernanceOptionState, optRange)
237229

238230
// loop over all possible states and check them one by one
239-
for i := int64(0); i < max.Int64(); i++ {
231+
for i := 0; i < optRange; i++ {
240232
// get the state of this option
241-
gs, err := ftm.GovernanceOptionStateById(gc, propId, (*hexutil.Big)(big.NewInt(i)))
233+
res[i], err = ftm.GovernanceOptionStateById(gc, propId, (*hexutil.Big)(big.NewInt(int64(i))))
242234
if err != nil {
243235
ftm.log.Errorf("unknown option #%d on governance %s; %s", i, gov.String(), err.Error())
244236
break
245237
}
246-
247-
// is this a state we would like to keep? e.g. any votes?
248-
if 0 != zero.Cmp(gs.Votes.ToInt()) {
249-
res = append(res, gs)
250-
}
251238
}
252-
253239
return res, nil
254240
}
255241

256-
// GovernanceOptionState returns a state of the given option of a proposal.
242+
// GovernanceOptionStateById returns a state of the given option of a proposal.
257243
func (ftm *FtmBridge) GovernanceOptionStateById(gc *contracts.Governance, propId *hexutil.Big, optId *hexutil.Big) (*types.GovernanceOptionState, error) {
258244
// get the state
259245
data, err := gc.ProposalOptionState(nil, propId.ToInt(), optId.ToInt())
@@ -322,7 +308,7 @@ func (ftm *FtmBridge) GovernanceProposalsBy(gov *common.Address) ([]*types.Gover
322308
}
323309

324310
// log what we do
325-
ftm.log.Debugf("loading %d proposals of %s", maxProposalId.Uint64(), gov.String())
311+
ftm.log.Noticef("loading %d proposals of %s", maxProposalId.Uint64(), gov.String())
326312

327313
// make the array; the maxProposalId starts with 1 so we need array for one less
328314
result := make([]*types.GovernanceProposal, 0)
@@ -337,7 +323,7 @@ func (ftm *FtmBridge) GovernanceProposalsBy(gov *common.Address) ([]*types.Gover
337323
}
338324

339325
// keep the proposal in the list
340-
ftm.log.Debugf("found proposal #%d on %s", gp.Id.ToInt().Uint64(), gov.String())
326+
ftm.log.Noticef("found proposal #%d on %s", gp.Id.ToInt().Uint64(), gov.String())
341327
result = append(result, gp)
342328
}
343329

0 commit comments

Comments
 (0)