Skip to content

Commit

Permalink
fixed voting
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Dec 14, 2023
1 parent 661531f commit ad36a1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/services/evm/tree_changed_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (l *listener) msgFromEvent(ctx context.Context, evt *worldid.WorldIdTreeCha

return &oracletypes.MsgCreateWorldCoinIdentityTransferOp{
Creator: l.txCreatorAddr,
Contract: evt.Raw.Address.String(),
Contract: evt.Raw.Address.Hex(),
Chain: l.homeChain,
PrevState: hexutil.Encode(evt.PreRoot.Bytes()),
State: hexutil.Encode(evt.PostRoot.Bytes()),
Expand Down
32 changes: 12 additions & 20 deletions internal/services/voting/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func (v *verifier) verify(ctx context.Context, op rarimocore.WorldCoinIdentityTr
return fmt.Errorf("failed to get event: %w", err)
}

num := new(big.Int).SetUint64(evt.Raw.BlockNumber)
header, err := v.header.HeaderByNumber(ctx, num)
header, err := v.header.HeaderByNumber(ctx, new(big.Int).SetUint64(evt.Raw.BlockNumber))
if err != nil {
return fmt.Errorf("failed to get block header by number from event: %w", err)
}
Expand All @@ -102,38 +101,31 @@ func (v *verifier) getEvent(ctx context.Context, op rarimocore.WorldCoinIdentity
Context: ctx,
Start: op.BlockNumber,
End: &op.BlockNumber, // end block is inclusive
}, toBigIntFilter(op.PrevState), nil, toBigIntFilter(op.State))
}, nil, nil, nil)

if err != nil {
return nil, fmt.Errorf("failed to filter WorldID changed events: %w", err)
}
if !iter.Next() || iter.Event == nil {
return nil, errors.New("event not found")
}

res := *iter.Event
if iter.Next() {
return nil, errors.New("multiple events found for given block, preRoot and postRoot")
for iter.Next() {
evt := iter.Event
if evt != nil {
if hexutil.Encode(evt.PostRoot.Bytes()) == op.State {
return evt, nil
}
}
}

return &res, nil
return nil, errors.New("event not found")
}

func opFromExternalData(evt *worldid.WorldIdTreeChanged, chain string, timestamp uint64) *rarimocore.WorldCoinIdentityTransfer {
return &rarimocore.WorldCoinIdentityTransfer{
Contract: evt.Raw.Address.Hex(),
Chain: chain,
PrevState: hexutil.EncodeBig(evt.PreRoot),
State: hexutil.EncodeBig(evt.PostRoot),
PrevState: hexutil.Encode(evt.PreRoot.Bytes()),
State: hexutil.Encode(evt.PostRoot.Bytes()),
Timestamp: strconv.FormatUint(timestamp, 10),
BlockNumber: evt.Raw.BlockNumber,
}
}

func toBigIntFilter(s string) []*big.Int {
b, ok := new(big.Int).SetString(s, 16)
if !ok {
return nil
}
return []*big.Int{b}
}

0 comments on commit ad36a1d

Please sign in to comment.