-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0a2ce3
commit 79fe7be
Showing
14 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
package decode | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/celenium-io/astria-indexer/internal/storage" | ||
"github.com/shopspring/decimal" | ||
) | ||
|
||
type Validators map[string]*storage.Validator | ||
|
||
func NewValidators() Validators { | ||
return make(map[string]*storage.Validator) | ||
} | ||
|
||
func (v Validators) Set(pubKey []byte, power int64) *storage.Validator { | ||
sPubKey := hex.EncodeToString(pubKey) | ||
|
||
pow := decimal.NewFromInt(power) | ||
if validator, ok := v[sPubKey]; ok { | ||
validator.Power = pow | ||
return validator | ||
} | ||
|
||
validator := &storage.Validator{ | ||
PubKey: pubKey, | ||
Power: pow, | ||
} | ||
v[sPubKey] = validator | ||
return validator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/celenium-io/astria-indexer/internal/storage" | ||
) | ||
|
||
func saveValidators( | ||
ctx context.Context, | ||
tx storage.Transaction, | ||
validators map[string]*storage.Validator, | ||
) error { | ||
if len(validators) == 0 { | ||
return nil | ||
} | ||
|
||
vals := make([]*storage.Validator, 0) | ||
for _, val := range validators { | ||
vals = append(vals, val) | ||
} | ||
|
||
return tx.UpdateValidators(ctx, vals...) | ||
} |