mirror of
https://github.com/luxfi/sdk.git
synced 2026-10-30 15:19:23 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue. Co-authored-by: Hanzo Dev <[email protected]>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
// Copyright (C) 2025, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package validatormanager
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
|
|
evmWarp "github.com/luxfi/evm/precompile/contracts/warp"
|
|
ethereum "github.com/luxfi/geth"
|
|
"github.com/luxfi/geth/common"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/sdk/evm"
|
|
warpMessage "github.com/luxfi/sdk/validatormanager/warp"
|
|
)
|
|
|
|
func GetValidatorNonce(
|
|
ctx context.Context,
|
|
rpcURL string,
|
|
validationID ids.ID,
|
|
) (uint64, error) {
|
|
client, err := evm.GetClient(rpcURL)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
height, err := client.BlockNumber()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
count := uint64(0)
|
|
maxBlock := int64(height)
|
|
minBlock := int64(0)
|
|
blockStep := int64(5000)
|
|
for blockNumber := maxBlock; blockNumber >= minBlock; blockNumber -= blockStep {
|
|
select {
|
|
case <-ctx.Done():
|
|
return 0, ctx.Err()
|
|
default:
|
|
}
|
|
fromBlock := big.NewInt(blockNumber - blockStep)
|
|
if fromBlock.Sign() < 0 {
|
|
fromBlock = big.NewInt(0)
|
|
}
|
|
toBlock := big.NewInt(blockNumber)
|
|
logs, err := client.FilterLogs(ethereum.FilterQuery{
|
|
FromBlock: fromBlock,
|
|
ToBlock: toBlock,
|
|
Addresses: []common.Address{evmWarp.Module.Address},
|
|
})
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
msgs := evm.GetWarpMessagesFromLogs(pointersSlice(logs))
|
|
for _, msg := range msgs {
|
|
payload := msg.Payload
|
|
addressedCall, err := warpMessage.ParseAddressedCall(payload)
|
|
if err == nil {
|
|
weightMsg, err := warpMessage.ParseL1ValidatorWeight(addressedCall.Payload)
|
|
if err == nil {
|
|
if weightMsg.ValidationID == validationID {
|
|
count++
|
|
}
|
|
}
|
|
regMsg, err := warpMessage.ParseRegisterL1Validator(addressedCall.Payload)
|
|
if err == nil {
|
|
if regMsg.ValidationID() == validationID {
|
|
return count, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return count, nil
|
|
}
|