Skip to content

Commit

Permalink
changes to process info from latest xtz.signer
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Oct 19, 2024
1 parent 178d786 commit a41113f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
48 changes: 38 additions & 10 deletions apps/signer/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"os"
"reflect"
"sort"
"strings"

"github.com/samber/lo"
"github.com/tez-capital/tezbake/ami"
"github.com/tez-capital/tezbake/apps/base"

Expand All @@ -16,9 +18,10 @@ import (

type InfoCollectionOptions struct {
//Timeout int
Baking bool
Wallets bool
Simple bool
Services bool
// Sensitive bool // Not needed for now
}

func (infoCollectionOptions *InfoCollectionOptions) toAmiArgs() []string {
Expand All @@ -27,20 +30,23 @@ func (infoCollectionOptions *InfoCollectionOptions) toAmiArgs() []string {
// args = append(args, fmt.Sprintf("--timeout=%d", infoCollectionOptions.Timeout))
// }

if infoCollectionOptions.Baking {
args = append(args, "--baking")
if infoCollectionOptions.Wallets {
args = append(args, "--wallets")
}
if infoCollectionOptions.Simple {
args = append(args, "--simple")
}
if infoCollectionOptions.Services {
args = append(args, "--services")
}
// if infoCollectionOptions.Sensitive {
// args = append(args, "--sensitive")
// }
return args
}

func (sico *InfoCollectionOptions) All() bool {
return !sico.Baking && !sico.Simple && !sico.Services
return !sico.Wallets && !sico.Simple && !sico.Services
}

func (app *Signer) getInfoCollectionOptions(optionsJson []byte) *InfoCollectionOptions {
Expand Down Expand Up @@ -115,15 +121,37 @@ func (app *Signer) PrintInfo(optionsJson []byte) error {
signerTable.AppendRow(table.Row{"Status", fmt.Sprint(signerInfo["status"])})
signerTable.AppendRow(table.Row{"Status Level", fmt.Sprint(signerInfo["level"])})

if infoCollectionOptions.All() || infoCollectionOptions.Simple || infoCollectionOptions.Baking {
if infoCollectionOptions.All() || infoCollectionOptions.Simple || infoCollectionOptions.Wallets {
// Baker Info
signerTable.AppendSeparator()
signerTable.AppendRow(table.Row{"Baking", "Baking"}, table.RowConfig{AutoMerge: true})
signerTable.AppendRow(table.Row{"Wallets", "Wallets"}, table.RowConfig{AutoMerge: true})
signerTable.AppendSeparator()
signerTable.AppendRow(table.Row{"Ledger Id", fmt.Sprint(signerInfo["ledger_id"])})
signerTable.AppendRow(table.Row{"Baking App", fmt.Sprint(signerInfo["baking_app"])})
signerTable.AppendRow(table.Row{"Baking App Status", fmt.Sprint(signerInfo["baking_app_status"])})
signerTable.AppendRow(table.Row{"Baker Address", fmt.Sprint(signerInfo["baker_address"])})
if wallets, ok := signerInfo["wallets"].(map[string]interface{}); ok {
wallet_ids := lo.Keys(wallets)
sort.Strings(wallet_ids)
for _, k := range wallet_ids {
v := wallets[k]
if properties, ok := v.(map[string]interface{}); ok {
kind := fmt.Sprint(properties["kind"])
switch kind {
case "ledger":
status := "error"
if properties["ledger_status"] == "connected" && properties["authorized"] == true {
status = "ok"
}
signerTable.AppendRow(table.Row{k, fmt.Sprintf("%v (%v) - %v", kind, properties["pkh"], status)})
case "soft":
signerTable.AppendRow(table.Row{k, fmt.Sprintf("⚠️ %v ⚠️ (%v)", kind, properties["pkh"])})
case "remote":
signerTable.AppendRow(table.Row{k, fmt.Sprintf("%v (%v)", kind, properties["pkh"])})
}
} else {
signerTable.AppendRow(table.Row{k, "unknown data format"})
}
}
} else {
signerTable.AppendRow(table.Row{"N/A", "N/A"})
}
}

if infoCollectionOptions.All() || infoCollectionOptions.Services {
Expand Down
2 changes: 1 addition & 1 deletion constants/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

const (
VERSION = "0.16.1-alpha.1"
VERSION = "0.16.1-beta"

DefaultBBDirectory string = "/bake-buddy"
DefaultRemoteBBDirectory string = DefaultBBDirectory
Expand Down

0 comments on commit a41113f

Please sign in to comment.