erigon-pulse/cmd/devnet/accounts/accounts.go
Mark Holt 529d359ca6
Bor span testing (#7897)
An update to the devnet to introduce a local heimdall to facilitate
multiple validators without the need for an external process, and hence
validator registration/staking etc.

In this initial release only span generation is supported.  

It has the following changes:

* Introduction of a local grpc heimdall interface
* Allocation of accounts via a devnet account generator ()
* Introduction on 'Services' for the network config

"--chain bor-devnet --bor.localheimdall" will run a 2 validator network
with a local service
"--chain bor-devnet --bor.withoutheimdall" will sun a single validator
with no heimdall service as before

---------

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
2023-07-18 09:47:04 +01:00

56 lines
1.0 KiB
Go

package accounts
import (
"crypto/ecdsa"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/crypto"
)
const DevAddress = "0x67b1d87101671b127f5f8714789C7192f7ad340e"
type Account struct {
Name string
Address libcommon.Address
sigKey *ecdsa.PrivateKey
}
func init() {
core.DevnetSignKey = SigKey
}
var accountsByAddress = map[libcommon.Address]*Account{}
var accountsByName = map[string]*Account{}
func NewAccount(name string) *Account {
if account, ok := accountsByName[name]; ok {
return account
}
sigKey, _ := crypto.GenerateKey()
account := &Account{
Name: name,
Address: crypto.PubkeyToAddress(sigKey.PublicKey),
sigKey: sigKey,
}
accountsByAddress[account.Address] = account
accountsByName[name] = account
return account
}
func SigKey(address libcommon.Address) *ecdsa.PrivateKey {
if account, ok := accountsByAddress[address]; ok {
return account.sigKey
}
if address == core.DevnetEtherbase {
return core.DevnetSignPrivateKey
}
return nil
}