mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 16:53:08 +08:00
read private key from file
This commit is contained in:
@@ -90,6 +90,16 @@ func runHandler(opts *runCmdOptions, cmd *cobra.Command, _ []string) error {
|
||||
// Add logger context
|
||||
ctx = logger.WithContext(ctx, slogx.Stringer("network", conf.Network))
|
||||
|
||||
// Load private key
|
||||
privKeyPath := conf.NodeKey.Path
|
||||
if privKeyPath == "" {
|
||||
privKeyPath = "/data/keys/priv.key"
|
||||
}
|
||||
privKeyByte, err := os.ReadFile(privKeyPath)
|
||||
if err != nil {
|
||||
logger.PanicContext(ctx, "Failed to read private key file", slogx.Error(err))
|
||||
}
|
||||
|
||||
// Initialize Bitcoin Core RPC Client
|
||||
client, err := rpcclient.New(&rpcclient.ConnConfig{
|
||||
Host: conf.BitcoinNode.Host,
|
||||
@@ -125,7 +135,7 @@ func runHandler(opts *runCmdOptions, cmd *cobra.Command, _ []string) error {
|
||||
|
||||
var reportingClient *reportingclientv2.ReportingClient
|
||||
if !conf.Reporting.Disabled {
|
||||
reportingClient, err = reportingclientv2.New(conf.Reporting) // TODO: read private key from file
|
||||
reportingClient, err = reportingclientv2.New(conf.Reporting, string(privKeyByte)) // TODO: read private key from file
|
||||
if err != nil {
|
||||
logger.PanicContext(ctx, "Failed to create reporting client", slogx.Error(err))
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ type Config struct {
|
||||
HTTPServer HTTPServerConfig `mapstructure:"http_server"`
|
||||
Modules Modules `mapstructure:"modules"`
|
||||
Reporting reportingclientv2.Config `mapstructure:"reporting"`
|
||||
NodeKey NodeKey `mapstructure:"node_key"`
|
||||
}
|
||||
|
||||
type NodeKey struct {
|
||||
Path string `mapstructure:"path"`
|
||||
}
|
||||
|
||||
type BitcoinNodeClient struct {
|
||||
|
||||
@@ -2,6 +2,7 @@ package reportingclientv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
@@ -11,36 +12,85 @@ import (
|
||||
|
||||
// Key for test only. DO NOT USE IN PRODUCTION
|
||||
const (
|
||||
privateKeyStr = "ce9c2fd75623e82a83ed743518ec7749f6f355f7301dd432400b087717fed2f2"
|
||||
mainnetKey = "L49LKamtrPZxty5TG7jaFPHMRZbrvAr4Dvn5BHGdvmvbcTDNAbZj"
|
||||
pubKeyStr = "0251e2dfcdeea17cc9726e4be0855cd0bae19e64f3e247b10760cd76851e7df47e"
|
||||
privateKeyStrOfficial = "ce9c2fd75623e82a83ed743518ec7749f6f355f7301dd432400b087717fed2f2"
|
||||
mainnetKeyOfficial = "L2hqSEYLjRQHHSiSgfNSFwaZ1dYpwn4PUTt2nQT8AefzYGQCwsGY"
|
||||
pubKeyStrOfficial = "0251e2dfcdeea17cc9726e4be0855cd0bae19e64f3e247b10760cd76851e7df47e"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
config := Config{
|
||||
const (
|
||||
privateKeyStr1 = "a3a7d2c40c8bb7a4b4afa9a6b3ed613da1de233913ed07a017e6dd44ef542d80"
|
||||
mainnetKey1 = "L49LKamtrPZxty5TG7jaFPHMRZbrvAr4Dvn5BHGdvmvbcTDNAbZj"
|
||||
pubKeyStr1 = "02596e11b5a2104533d2732a3df35eadaeb61b189b9069715106e72e27c1de7775"
|
||||
)
|
||||
|
||||
const (
|
||||
privateKeyStr2 = "a3a7d2c40c8bb7a4b4afa9a6b3ed613da1de233913ed07a017e6dd44ef542d81"
|
||||
// mainnetKey1 = "L49LKamtrPZxty5TG7jaFPHMRZbrvAr4Dvn5BHGdvmvbcTDNAbZj"
|
||||
// pubKeyStr1 = "02596e11b5a2104533d2732a3df35eadaeb61b189b9069715106e72e27c1de7775"
|
||||
)
|
||||
|
||||
func TestReport1(t *testing.T) {
|
||||
block := 18
|
||||
hash, err := chainhash.NewHashFromStr(fmt.Sprintf("%d", block))
|
||||
assert.NoError(t, err)
|
||||
|
||||
configOfficial := Config{
|
||||
ReportCenter: ReportCenter{
|
||||
BaseURL: "http://localhost:8000",
|
||||
BaseURL: "https://indexer-dev.api.gaze.network",
|
||||
PublicKey: defaultPublicKey,
|
||||
},
|
||||
NodeInfo: NodeInfo{
|
||||
Name: "tests",
|
||||
Name: "Official Node",
|
||||
APIURL: "http://localhost:2000",
|
||||
},
|
||||
}
|
||||
client, err := New(config, privateKeyStr)
|
||||
config1 := Config{
|
||||
ReportCenter: ReportCenter{
|
||||
BaseURL: "https://indexer-dev.api.gaze.network",
|
||||
PublicKey: defaultPublicKey,
|
||||
},
|
||||
NodeInfo: NodeInfo{
|
||||
Name: "Node 1",
|
||||
APIURL: "http://localhost:2000",
|
||||
},
|
||||
}
|
||||
config2 := Config{
|
||||
ReportCenter: ReportCenter{
|
||||
BaseURL: "https://indexer-dev.api.gaze.network",
|
||||
PublicKey: defaultPublicKey,
|
||||
},
|
||||
NodeInfo: NodeInfo{
|
||||
Name: "Node 2",
|
||||
APIURL: "http://localhost:2000",
|
||||
},
|
||||
}
|
||||
clientOfficial, err := New(configOfficial, privateKeyStrOfficial)
|
||||
assert.NoError(t, err)
|
||||
client1, err := New(config1, privateKeyStr1)
|
||||
assert.NoError(t, err)
|
||||
client2, err := New(config2, privateKeyStr2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = client.SubmitNodeReport(context.Background(), "runes", "mainnet", "v0.0.1")
|
||||
err = clientOfficial.SubmitNodeReport(context.Background(), "runes", "mainnet", "v0.0.1")
|
||||
assert.NoError(t, err)
|
||||
err = client1.SubmitNodeReport(context.Background(), "runes", "mainnet", "v0.0.1")
|
||||
assert.NoError(t, err)
|
||||
err = client2.SubmitNodeReport(context.Background(), "runes", "mainnet", "v0.0.1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = client.SubmitBlockReport(context.Background(), SubmitBlockReportPayloadData{
|
||||
blockReport := SubmitBlockReportPayloadData{
|
||||
Type: "runes",
|
||||
ClientVersion: "v0.0.1",
|
||||
DBVersion: 1,
|
||||
EventHashVersion: 1,
|
||||
Network: common.NetworkMainnet,
|
||||
BlockHeight: 2,
|
||||
BlockHash: chainhash.Hash{},
|
||||
EventHash: chainhash.Hash{},
|
||||
CumulativeEventHash: chainhash.Hash{},
|
||||
})
|
||||
BlockHeight: uint64(block),
|
||||
BlockHash: *hash,
|
||||
EventHash: *hash,
|
||||
CumulativeEventHash: *hash,
|
||||
}
|
||||
|
||||
err = clientOfficial.SubmitBlockReport(context.Background(), blockReport)
|
||||
err = client1.SubmitBlockReport(context.Background(), blockReport)
|
||||
err = client2.SubmitBlockReport(context.Background(), blockReport)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user