func run(cmd *cobra.Command, args []string) { log.Print("Reading config.toml file") err := viper.ReadInConfig() if err != nil { log.Fatal("Error reading config file: ", err) } var config config.Config err = viper.Unmarshal(&config) err = config.Validate() if err != nil { log.Fatal(err.Error()) return } if migrateFlag { migrate(config) return } app, err = gateway.NewApp(config) if err != nil { log.Fatal(err.Error()) return } app.Serve() }
// NewApp constructs an new App instance from the provided config. func NewApp(config config.Config) (app *App, err error) { entityManager, err := db.NewEntityManager(config.Database.Type, config.Database.Url) if err != nil { return } repository, err := db.NewRepository(config.Database.Type, config.Database.Url) if err != nil { return } h := horizon.New(*config.Horizon) if config.NetworkPassphrase == "" { config.NetworkPassphrase = "Test SDF Network ; September 2015" } log.Print("Creating and initializing TransactionSubmitter") ts := submitter.NewTransactionSubmitter(&h, &entityManager, config.NetworkPassphrase) if err != nil { return } log.Print("Initializing Authorizing account") if config.Accounts.AuthorizingSeed == nil { log.Warning("No accounts.authorizing_seed param. Skipping...") } else { err = ts.InitAccount(*config.Accounts.AuthorizingSeed) if err != nil { return } } if config.Accounts.IssuingSeed == nil { log.Warning("No accounts.issuing_seed param. Skipping...") } else { log.Print("Initializing Issuing account") err = ts.InitAccount(*config.Accounts.IssuingSeed) if err != nil { return } } log.Print("TransactionSubmitter created") log.Print("Creating and starting PaymentListener") if config.Accounts.ReceivingAccountId == nil { log.Warning("No accounts.receiving_account_id param. Skipping...") } else if config.Hooks.Receive == nil { log.Warning("No hooks.receive param. Skipping...") } else { var paymentListener listener.PaymentListener paymentListener, err = listener.NewPaymentListener(&config, &entityManager, &h, &repository, time.Now) if err != nil { return } err = paymentListener.Listen() if err != nil { return } log.Print("PaymentListener created") } if len(config.ApiKey) > 0 && len(config.ApiKey) < 15 { err = errors.New("api-key have to be at least 15 chars long.") return } app = &App{ config: config, entityManager: &entityManager, horizon: &h, repository: &repository, transactionSubmitter: &ts, } return }