Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make genesis keys configurable
Browse files Browse the repository at this point in the history
galt-tr committed Feb 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1509a0b commit 81ac76c
Showing 12 changed files with 65 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .goreleaser-for-linux.yml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ changelog:
builds:
- id: linux-build
main: ./cmd/
binary: alert_system
binary: alert-system
goos:
- linux
goarch:
@@ -58,4 +58,4 @@ archives:
- LICENSE
checksum:
name_template: "checksums.txt"
algorithm: sha256
algorithm: sha256
1 change: 1 addition & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ type (
// Config is the global configuration settings
Config struct {
AlertWebhookURL string `json:"alert_webhook_url" mapstructure:"alert_webhook_url"` // AlertWebhookURL is the URL for the alert webhook
GenesisKeys []string `json:"genesis_keys" mapstructure:"genesis_keys"` // GenesisKeys is list of public keys to use for the genesis alert
Datastore DatastoreConfig `json:"datastore" mapstructure:"datastore"` // Datastore's configuration
DisableRPCVerification bool `json:"disable_rpc_verification" mapstructure:"disable_rpc_verification"` // DisableRPCVerification will disable the rpc verification check on startup. Useful if bitcoind isn't running yet
LogOutputFile string `json:"log_output_file" mapstructure:"log_output_file"` // LogOutputFile will set an output file for the logger to write to as opposed to stdout
7 changes: 7 additions & 0 deletions app/config/envs/local.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "",
"bitcoin_config_path": "",
"genesis_keys": [
"027276d234a138415c7d8d61e33ea9c625f0d043fd06f1c863464a58ed7939afe1",
"0254b81f2e1bed83e414970ae7f7e3373014706251efb6990b5292a020e3a1585c",
"03801e7b4077edad7ebb3fa87ced7b126ae8eb2fbcb75821001f84a0374eea4a21",
"03df30507f71d1880888e9e7137280397a4235c2904d4c4e995d4292f00a9257b0",
"03ec55b29332500401336f6e1648d367f4619bedb561fd817d2247d80c4bad236c"
],
"disable_rpc_verification": false,
"log_output_file": "",
"request_logging": true,
9 changes: 8 additions & 1 deletion app/config/envs/mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "",
"bitcoin_config_path": "",
"genesis_keys": [
"02a1589f2c8e1a4e7cbf28d4d6b676aa2f30811277883211027950e82a83eb2768",
"03aec1d40f02ac7f6df701ef8f629515812f1bcd949b6aa6c7a8dd778b748b2433",
"03ddb2806f3cc48aa36bd4aea6b9f1c7ed3ffc8b9302b198ca963f15beff123678",
"036846e3e8f4f944af644b6a6c6243889dd90d7b6c3593abb9ccf2acb8c9e606e2",
"03e45c9dd2b34829c1d27c8b5d16917dd0dc2c88fa0d7bad7bffb9b542229a9304"
],
"log_output_file": "",
"disable_rpc_verification": false,
"request_logging": true,
@@ -67,7 +74,7 @@
{
"user": "your_user",
"password": "",
"host": "http://localhost:8333"
"host": "http://localhost:8332"
}
]
}
7 changes: 7 additions & 0 deletions app/config/envs/production.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "",
"bitcoin_config_path": "",
"genesis_keys": [
"02a1589f2c8e1a4e7cbf28d4d6b676aa2f30811277883211027950e82a83eb2768",
"03aec1d40f02ac7f6df701ef8f629515812f1bcd949b6aa6c7a8dd778b748b2433",
"03ddb2806f3cc48aa36bd4aea6b9f1c7ed3ffc8b9302b198ca963f15beff123678",
"036846e3e8f4f944af644b6a6c6243889dd90d7b6c3593abb9ccf2acb8c9e606e2",
"03e45c9dd2b34829c1d27c8b5d16917dd0dc2c88fa0d7bad7bffb9b542229a9304"
],
"log_output_file": "",
"disable_rpc_verification": false,
"request_logging": true,
7 changes: 7 additions & 0 deletions app/config/envs/stn.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "",
"bitcoin_config_path": "",
"genesis_keys": [
"027276d234a138415c7d8d61e33ea9c625f0d043fd06f1c863464a58ed7939afe1",
"0254b81f2e1bed83e414970ae7f7e3373014706251efb6990b5292a020e3a1585c",
"03801e7b4077edad7ebb3fa87ced7b126ae8eb2fbcb75821001f84a0374eea4a21",
"03df30507f71d1880888e9e7137280397a4235c2904d4c4e995d4292f00a9257b0",
"03ec55b29332500401336f6e1648d367f4619bedb561fd817d2247d80c4bad236c"
],
"log_output_file": "",
"disable_rpc_verification": false,
"request_logging": true,
7 changes: 7 additions & 0 deletions app/config/envs/test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "https://webhook.url",
"bitcoin_config_path": "",
"genesis_keys": [
"027276d234a138415c7d8d61e33ea9c625f0d043fd06f1c863464a58ed7939afe1",
"0254b81f2e1bed83e414970ae7f7e3373014706251efb6990b5292a020e3a1585c",
"03801e7b4077edad7ebb3fa87ced7b126ae8eb2fbcb75821001f84a0374eea4a21",
"03df30507f71d1880888e9e7137280397a4235c2904d4c4e995d4292f00a9257b0",
"03ec55b29332500401336f6e1648d367f4619bedb561fd817d2247d80c4bad236c"
],
"log_output_file": "",
"disable_rpc_verification": false,
"request_logging": true,
7 changes: 7 additions & 0 deletions app/config/envs/testnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"alert_webhook_url": "",
"bitcoin_config_path": "",
"genesis_keys": [
"027276d234a138415c7d8d61e33ea9c625f0d043fd06f1c863464a58ed7939afe1",
"0254b81f2e1bed83e414970ae7f7e3373014706251efb6990b5292a020e3a1585c",
"03801e7b4077edad7ebb3fa87ced7b126ae8eb2fbcb75821001f84a0374eea4a21",
"03df30507f71d1880888e9e7137280397a4235c2904d4c4e995d4292f00a9257b0",
"03ec55b29332500401336f6e1648d367f4619bedb561fd817d2247d80c4bad236c"
],
"log_output_file": "",
"disable_rpc_verification": false,
"request_logging": true,
1 change: 1 addition & 0 deletions app/config/errors.go
Original file line number Diff line number Diff line change
@@ -15,4 +15,5 @@ var (
ErrNoRPCPassword = errors.New("no rpc_password defined")
ErrNoRPCUser = errors.New("no rpc_user defined")
ErrNoRPCConnections = errors.New("no rpc connections configured")
ErrNoGenesisKeys = errors.New("no genesis keys configured")
)
5 changes: 5 additions & 0 deletions app/config/load.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,11 @@ func LoadDependencies(ctx context.Context, models []interface{}, isTesting bool)
return nil, ErrNoRPCConnections
}

// Require list of genesis keys
if len(_appConfig.GenesisKeys) == 0 {
return nil, ErrNoGenesisKeys
}

// Ensure the P2P configuration is valid
if err = requireP2P(_appConfig); err != nil {
return nil, err
21 changes: 4 additions & 17 deletions app/models/genesis_alert.go
Original file line number Diff line number Diff line change
@@ -2,19 +2,16 @@ package models

import (
"context"
"encoding/hex"
"time"

"github.com/bitcoin-sv/alert-system/app/models/model"
"github.com/bitcoin-sv/alert-system/utils"
"github.com/bitcoinschema/go-bitcoin"
"github.com/bitcoinsv/bsvd/bsvec"
)

// CreateGenesisAlert will create the genesis alert if it is not in the database
// If it is in the database, it will do nothing
func CreateGenesisAlert(ctx context.Context, opts ...model.Options) error {

newAlert := NewAlertMessage(opts...)
// Get the alert message by sequence number
m, err := GetAlertMessageBySequenceNumber(ctx, 0, opts...)
if err != nil {
@@ -24,7 +21,7 @@ func CreateGenesisAlert(ctx context.Context, opts ...model.Options) error {
}

// Create the array of keys
keys := []string{utils.Key1, utils.Key2, utils.Key3, utils.Key4, utils.Key5}
keys := newAlert.Config().GenesisKeys
var msg []byte

// Create the array of keys to save
@@ -35,25 +32,15 @@ func CreateGenesisAlert(ctx context.Context, opts ...model.Options) error {

// Loop through the keys
for _, key := range keys {

// Convert the key to a private key
var privateKey *bsvec.PrivateKey
if privateKey, err = bitcoin.PrivateKeyFromString(key); err != nil {
return err
}
pub := privateKey.PubKey()

msg = append(msg, pub.SerializeCompressed()...)

// Create the public key
k := NewPublicKey(opts...)
k.Key = hex.EncodeToString(pub.SerializeCompressed())
k.Key = key
k.Active = true
keysToSave = append(keysToSave, k)
}

// Sync creating a new alert
newAlert := NewAlertMessage(opts...)

newAlert.SetAlertType(AlertTypeSetKeys)
newAlert.message = msg
newAlert.SequenceNumber = 0
9 changes: 9 additions & 0 deletions utils/keys.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,15 @@ const (
Key5 = "161a9d680f1952fef2f2572bfae30e7eda047908a180cbb00a16a4ee270abf62"
)

// Mainnet Keys for the Genesis keys
const (
MainKey1 = "02a1589f2c8e1a4e7cbf28d4d6b676aa2f30811277883211027950e82a83eb2768"
MainKey2 = "03aec1d40f02ac7f6df701ef8f629515812f1bcd949b6aa6c7a8dd778b748b2433"
MainKey3 = "03ddb2806f3cc48aa36bd4aea6b9f1c7ed3ffc8b9302b198ca963f15beff123678"
MainKey4 = "036846e3e8f4f944af644b6a6c6243889dd90d7b6c3593abb9ccf2acb8c9e606e2"
MainKey5 = "03e45c9dd2b34829c1d27c8b5d16917dd0dc2c88fa0d7bad7bffb9b542229a9304"
)

// SignWithGenesis will sign the data with the genesis keys
func SignWithGenesis(data []byte) ([][]byte, error) {
return SignWithKeys(data, []string{Key1, Key2, Key3})

0 comments on commit 81ac76c

Please sign in to comment.