"github.com/vapor/blockchain/signers"
"github.com/vapor/blockchain/txbuilder"
+ "github.com/vapor/consensus"
"github.com/vapor/crypto/ed25519"
"github.com/vapor/crypto/ed25519/chainkd"
chainjson "github.com/vapor/encoding/json"
bc.AssetAmount
SourceID string `json:"source_id"`
SourcePos uint64 `json:"source_pos"`
- FedXPubs []chainkd.XPub `json:"fed_xpubs"`
- Quorum int `json:"fed_quorum"`
AssetDefinition map[string]interface{} `json:"asset_definition"`
}
// TODO: also need to hard-code mapTx
func (a *crossInAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
var missing []string
- if len(a.FedXPubs) <= 1 {
- missing = append(missing, "fed_xpubs")
- }
- if a.Quorum == 0 {
- missing = append(missing, "fed_quorum")
- }
if a.SourceID == "" {
missing = append(missing, "source_id")
}
a.reg.SaveExtAsset(asset, extAlias)
}
- assetSigner, err := signers.Create("asset", a.FedXPubs, a.Quorum, 1, signers.BIP0032)
+ assetSigner, err := signers.Create("asset", consensus.Federation().XPubs, consensus.Federation().Quorum, 1, signers.BIP0032)
if err != nil {
return err
}
package consensus
import (
- // "encoding/binary"
- // "strings"
+ "encoding/json"
+ "errors"
+
+ log "github.com/sirupsen/logrus"
- // "github.com/vapor/protocol/bc"
"github.com/vapor/crypto/ed25519/chainkd"
)
-type Federation struct {
- XPubs []chainkd.XPub
- Quorum int
+const fedCfgJson = `
+{
+ "fed_xpubs" : [
+ "7f23aae65ee4307c38d342699e328f21834488e18191ebd66823d220b5a58303496c9d09731784372bade78d5e9a4a6249b2cfe2e3a85464e5a4017aa5611e47",
+ "585e20143db413e45fbc82f03cb61f177e9916ef1df0012daa8cbf6dbb1025ce8f98e51ae319327b63505b64fdbbf6d36ef916d79e6dd67d51b0bfe76fe544c5",
+ "b58170b51ca61604028ba1cb412377dfc2bc6567c0afc84c83aae1c0c297d0227ccf568561df70851f4144bbf069b525129f2434133c145e35949375b22a6c9d",
+ "983705ae71949c1a5d0fcf953658dd9ecc549f02c63e197b4d087ae31148097ece816bbc60d9012c316139fc550fa0f4b00beb0887f6b152f7a69bc8f392b9fa",
+ "d72fb92fa13bf3e0deb39de3a47c8d6eef5584719f7877c82a4c009f78fddf924d9706d48f15b2c782ec80b6bdd621a1f7ba2a0044b0e6f92245de9436885cb9",
+ "6798460919e8dc7095ee8b9f9d65033ef3da8c2334813149da5a1e52e9c6da07ba7d0e7379baaa0c8bdcb21890a54e6b7290bee077c645ee4b74b0c1ae9da59a"
+ ],
+ "fed_quorum" : 4
}
+`
-const (
- FedXPubs = ""
- Quorum = 1
-)
+type federation struct {
+ XPubs []chainkd.XPub `json:"fed_xpubs"`
+ Quorum int `json:"fed_quorum"`
+}
+
+func Federation() *federation {
+ fed := &federation{}
+ if err := json.Unmarshal([]byte(fedCfgJson), fed); err != nil {
+ log.Fatalf("invalid federation config json")
+ }
+
+ return fed
+}
+
+func CheckFedConfig() error {
+ fed := Federation()
+ if len(fed.XPubs) <= 1 {
+ return errors.New("federation should have more than 1 member")
+ }
+ if fed.Quorum < 1 {
+ return errors.New("federation quorum should be >= 1")
+ }
+
+ return nil
+}
--- /dev/null
+package main
+
+import (
+ "fmt"
+ "github.com/vapor/consensus"
+)
+
+func main() {
+ for _, x := range consensus.Federation().XPubs {
+ fmt.Printf("%T\n%v\n%s\n\n", x, x, x)
+ }
+}
// NewNode create bytom node
func NewNode(config *cfg.Config) *Node {
ctx := context.Background()
+
+ if err := consensus.CheckFedConfig(); err == nil {
+ log.WithFields(log.Fields{
+ "module": logModule,
+ "fed_xpubs": consensus.Federation().XPubs,
+ "fed_quorum": consensus.Federation().Quorum,
+ }).Info()
+ } else {
+ cmn.Exit("Error: " + err.Error())
+ }
+
if err := lockDataDirectory(config); err != nil {
cmn.Exit("Error: " + err.Error())
}
+
initLogFile(config)
initActiveNetParams(config)
initCommonConfig(config)