Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetRewardAddress API #1438

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ type Summary struct {
MinHops uint16 `json:"min_hops"`
PersistentTransports []transport.PersistentTransports `json:"persistent_transports"`
SkybianBuildVersion string `json:"skybian_build_version"`
RewardAddress string `json:"reward_address"`
BuildTag string `json:"build_tag"`
PublicAutoconnect bool `json:"public_autoconnect"`
}
Expand Down Expand Up @@ -266,6 +267,11 @@ func (v *Visor) Summary() (*Summary, error) {
dmsgStatValue = &dmsgTracker
}

rewardAddress, err := v.GetRewardAddress()
if err != nil {
return nil, fmt.Errorf("reward_address")
}
ersonp marked this conversation as resolved.
Show resolved Hide resolved

summary := &Summary{
Overview: overview,
Health: health,
Expand All @@ -275,6 +281,7 @@ func (v *Visor) Summary() (*Summary, error) {
PersistentTransports: pts,
SkybianBuildVersion: skybianBuildVersion,
BuildTag: BuildTag,
RewardAddress: rewardAddress,
PublicAutoconnect: v.conf.Transport.PublicAutoconnect,
DmsgStats: dmsgStatValue,
}
Expand Down Expand Up @@ -350,6 +357,17 @@ func (v *Visor) SetRewardAddress(p string) (string, error) {
// GetRewardAddress implements API.
func (v *Visor) GetRewardAddress() (string, error) {
path := v.conf.LocalPath + "/" + visorconfig.RewardFile
_, err := os.Stat(path)
if os.IsNotExist(err) {
file, err := os.Create(filepath.Clean(path))
if err != nil {
return "", fmt.Errorf("failed to create config file. err=%v", err)
}
err = file.Close()
if err != nil {
return "", fmt.Errorf("failed to close config file. err=%v", err)
}
}
rConfig, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return "", fmt.Errorf("failed to read config file. err=%v", err)
Expand Down