diff --git a/cmd/splitticketbuyergui/ui.go b/cmd/splitticketbuyergui/ui.go index 37d5cb9..903977d 100644 --- a/cmd/splitticketbuyergui/ui.go +++ b/cmd/splitticketbuyergui/ui.go @@ -48,18 +48,42 @@ func getDecreditonWalletName(logf logFunc) { wallets := buyer.ListDecreditonWallets() - combo := gtk.NewComboBoxEntryNewText() + label := gtk.NewLabel("Wallet") + label.ModifyFontEasy("DejaVu Serif 15") + vbox.PackStart(label, false, false, 2) + + combo := gtk.NewComboBoxText() for _, w := range wallets { combo.AppendText(w) } - //combo.Connect("changed", func() {}) vbox.PackStart(combo, false, false, 2) + label = gtk.NewLabel("Voting Pool") + label.ModifyFontEasy("DejaVu Serif 15") + vbox.PackStart(label, false, false, 2) + + comboPool := gtk.NewComboBoxText() + vbox.PackStart(comboPool, false, false, 2) + + combo.Connect("changed", func() { + w := combo.GetActiveText() + fmt.Println("changed combo", w) + walletPools := buyer.ListDecreditonWalletStakepools(w) + for i := 0; i < 100; i++ { + comboPool.RemoveText(0) + } + for _, p := range walletPools { + comboPool.AppendText(p) + } + fmt.Println("added pools", walletPools) + }) + button := gtk.NewButtonWithLabel("select") button.Clicked(func() { w := combo.GetActiveText() - logf("Resetting config to decrediton wallet \"%s\"", w) - err := buyer.InitConfigFromDecrediton(w) + p := comboPool.GetActiveText() + logf("Resetting config to decrediton wallet '%s' pool '%s'", w, p) + err := buyer.InitConfigFromDecrediton(w, p) if err != nil { logf(err.Error()) } else { diff --git a/pkg/buyer/config-decrediton.go b/pkg/buyer/config-decrediton.go index 31f03e6..fb0044c 100644 --- a/pkg/buyer/config-decrediton.go +++ b/pkg/buyer/config-decrediton.go @@ -147,13 +147,51 @@ func ListDecreditonWallets() []string { } +// ListDecreditonWalletStakepools lists the stakepools configured for the given +// decrediton wallet. +func ListDecreditonWalletStakepools(walletName string) []string { + decreditonDir := decreditonConfigDir() + globalCfg, err := getDecreditonGlobalConfig() + if err != nil { + return nil + } + + walletsDir := filepath.Join(decreditonDir, "wallets", globalCfg.Network) + walletDir := filepath.Join(walletsDir, walletName) + + walletCfgJSONFname := filepath.Join(walletDir, "config.json") + walletCfgJSON, err := ioutil.ReadFile(walletCfgJSONFname) + if err != nil { + return nil + } + + walletCfg := &decreditonWalletConfig{} + + err = json.Unmarshal(walletCfgJSON, walletCfg) + if err != nil { + return nil + } + + res := make([]string, 0) + for _, pool := range walletCfg.StakePools { + if (pool.PoolAddress != "") && + (pool.TicketAddress != "") && + (pool.Network == globalCfg.Network) { + + res = append(res, pool.Host) + } + } + + return res +} + // InitConfigFromDecrediton replaces the config with the default one plus // all available entries read from an installed decrediton. Requires a // decrediton version >= 1.2.0. // // The data for the given walletName (of the currently selected network) // will be used. -func InitConfigFromDecrediton(walletName string) error { +func InitConfigFromDecrediton(walletName, poolHost string) error { decreditonDir := decreditonConfigDir() dcrdDir := dcrutil.AppDataDir("dcrd", false) @@ -209,15 +247,12 @@ func InitConfigFromDecrediton(walletName string) error { activeNet := netparams.MainNetParams isTestNet := globalCfg.Network == decreditonTestnet - matcherHost := "mainnet-split-tickets.matheusd.com:8475" testnetVal := "0" if isTestNet { activeNet = netparams.TestNet2Params - matcherHost = "matheusd.com:18475" testnetVal = "1" } - dstSection.Key("MatcherHost").SetValue(matcherHost) dstSection.Key("TestNet").SetValue(testnetVal) dstSection.Key("WalletCertFile").SetValue(filepath.Join(walletDir, "rpc.cert")) @@ -274,10 +309,13 @@ func InitConfigFromDecrediton(walletName string) error { for _, pool := range walletCfg.StakePools { if (pool.PoolAddress != "") && (pool.TicketAddress != "") && - (pool.Network == globalCfg.Network) { + (pool.Network == globalCfg.Network) && + ((poolHost == "") || (poolHost == pool.Host)) { dstSection.Key("VoteAddress").SetValue(pool.TicketAddress) dstSection.Key("PoolAddress").SetValue(pool.PoolAddress) + dstSection.Key("MatcherHost").SetValue(pool.Host) + break } } diff --git a/pkg/version.go b/pkg/version.go index 2d76b83..c0c55b4 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -20,4 +20,4 @@ const ( // Version is the package version. Remember to modify the previous constants as // well on version bumps. -const Version = "0.5.1+dev5" +const Version = "0.5.1+dev6"