Skip to content

Commit

Permalink
Allow to select pool config when importing from decrediton on GUI buyer
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusd committed Jul 16, 2018
1 parent d23b597 commit 8a41de4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
32 changes: 28 additions & 4 deletions cmd/splitticketbuyergui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 43 additions & 5 deletions pkg/buyer/config-decrediton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8a41de4

Please sign in to comment.