Skip to content

Commit

Permalink
Add own node to fixed registry
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Aug 30, 2024
1 parent e7fe0ab commit accf20a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
20 changes: 19 additions & 1 deletion cmd/replication/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/xmtp/xmtpd/pkg/registry"
"github.com/xmtp/xmtpd/pkg/server"
"github.com/xmtp/xmtpd/pkg/tracing"
"github.com/xmtp/xmtpd/pkg/utils"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -46,15 +47,32 @@ func main() {
options.DB.WaitForDB,
options.DB.ReadTimeout,
)

if err != nil {
log.Fatal("initializing database", zap.Error(err))
}

privateKey, err := utils.ParseEcdsaPrivateKey(options.SignerPrivateKey)
if err != nil {
log.Fatal("parsing private key", zap.Error(err))
}

s, err := server.NewReplicationServer(
ctx,
log,
options,
registry.NewFixedNodeRegistry([]registry.Node{}),
// TODO:nm replace with real node registry
registry.NewFixedNodeRegistry(
[]registry.Node{
{
NodeID: 0,
SigningKey: &privateKey.PublicKey,
IsHealthy: true,
HttpAddress: "http://example.com",
IsValidConfig: true,
},
},
),
db,
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/registrant/registrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/ecdsa"
"fmt"
"slices"
"strings"

"github.com/ethereum/go-ethereum/crypto"
"github.com/xmtp/xmtpd/pkg/db/queries"
Expand All @@ -28,7 +27,7 @@ func NewRegistrant(
nodeRegistry registry.NodeRegistry,
privateKeyString string,
) (*Registrant, error) {
privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(privateKeyString, "0x"))
privateKey, err := utils.ParseEcdsaPrivateKey(privateKeyString)
if err != nil {
return nil, fmt.Errorf("unable to parse private key: %v", err)
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/utils/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import (
"crypto/ecdsa"
"strings"

"github.com/ethereum/go-ethereum/crypto"
)

func ParseEcdsaPrivateKey(key string) (*ecdsa.PrivateKey, error) {
return crypto.HexToECDSA(strings.TrimPrefix(key, "0x"))
}

0 comments on commit accf20a

Please sign in to comment.