OSDN Git Service

store federation (#83)
[bytom/vapor.git] / config / config.go
index 69b4882..c04662f 100644 (file)
@@ -11,6 +11,7 @@ import (
        log "github.com/sirupsen/logrus"
 
        "github.com/vapor/crypto/ed25519"
+       "github.com/vapor/crypto/ed25519/chainkd"
 )
 
 var (
@@ -22,11 +23,12 @@ type Config struct {
        // Top level options use an anonymous struct
        BaseConfig `mapstructure:",squash"`
        // Options for services
-       P2P       *P2PConfig       `mapstructure:"p2p"`
-       Wallet    *WalletConfig    `mapstructure:"wallet"`
-       Auth      *RPCAuthConfig   `mapstructure:"auth"`
-       Web       *WebConfig       `mapstructure:"web"`
-       Websocket *WebsocketConfig `mapstructure:"ws"`
+       P2P        *P2PConfig        `mapstructure:"p2p"`
+       Wallet     *WalletConfig     `mapstructure:"wallet"`
+       Auth       *RPCAuthConfig    `mapstructure:"auth"`
+       Web        *WebConfig        `mapstructure:"web"`
+       Websocket  *WebsocketConfig  `mapstructure:"ws"`
+       Federation *FederationConfig `mapstructure:"federation"`
 }
 
 // Default configurable parameters.
@@ -38,6 +40,7 @@ func DefaultConfig() *Config {
                Auth:       DefaultRPCAuthConfig(),
                Web:        DefaultWebConfig(),
                Websocket:  DefaultWebsocketConfig(),
+               Federation: DefaultFederationConfig(),
        }
 }
 
@@ -193,6 +196,11 @@ type WebsocketConfig struct {
        MaxNumConcurrentReqs int `mapstructure:"max_num_concurrent_reqs"`
 }
 
+type FederationConfig struct {
+       Xpubs  []chainkd.XPub `json:"xpubs"`
+       Quorum int            `json:"quorum"`
+}
+
 // Default configurable rpc's auth parameters.
 func DefaultRPCAuthConfig() *RPCAuthConfig {
        return &RPCAuthConfig{
@@ -224,6 +232,27 @@ func DefaultWebsocketConfig() *WebsocketConfig {
        }
 }
 
+func DefaultFederationConfig() *FederationConfig {
+       return &FederationConfig{
+               Xpubs: []chainkd.XPub{
+                       xpub("7f23aae65ee4307c38d342699e328f21834488e18191ebd66823d220b5a58303496c9d09731784372bade78d5e9a4a6249b2cfe2e3a85464e5a4017aa5611e47"),
+                       xpub("585e20143db413e45fbc82f03cb61f177e9916ef1df0012daa8cbf6dbb1025ce8f98e51ae319327b63505b64fdbbf6d36ef916d79e6dd67d51b0bfe76fe544c5"),
+                       xpub("b58170b51ca61604028ba1cb412377dfc2bc6567c0afc84c83aae1c0c297d0227ccf568561df70851f4144bbf069b525129f2434133c145e35949375b22a6c9d"),
+                       xpub("983705ae71949c1a5d0fcf953658dd9ecc549f02c63e197b4d087ae31148097ece816bbc60d9012c316139fc550fa0f4b00beb0887f6b152f7a69bc8f392b9fa"),
+                       xpub("d72fb92fa13bf3e0deb39de3a47c8d6eef5584719f7877c82a4c009f78fddf924d9706d48f15b2c782ec80b6bdd621a1f7ba2a0044b0e6f92245de9436885cb9"),
+                       xpub("6798460919e8dc7095ee8b9f9d65033ef3da8c2334813149da5a1e52e9c6da07ba7d0e7379baaa0c8bdcb21890a54e6b7290bee077c645ee4b74b0c1ae9da59a"),
+               },
+               Quorum: 4,
+       }
+}
+
+func xpub(str string) (xpub chainkd.XPub) {
+       if err := xpub.UnmarshalText([]byte(str)); err != nil {
+               log.Panicf("Fail converts a string to xpub")
+       }
+       return xpub
+}
+
 //-----------------------------------------------------------------------------
 // Utils