From d929f2ecb8dc920852fc47ba0c7d9b4a01889533 Mon Sep 17 00:00:00 2001 From: interro Date: Tue, 26 Mar 2019 01:17:15 +0200 Subject: [PATCH 1/3] added payout set command to cli --- cmd/commands/cli/command.go | 62 +++++++++++++++++++++++++++++++++++-- tequilapi/client/client.go | 18 +++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/cmd/commands/cli/command.go b/cmd/commands/cli/command.go index 02ed22bc05..bcf3fe4e53 100644 --- a/cmd/commands/cli/command.go +++ b/cmd/commands/cli/command.go @@ -150,6 +150,7 @@ func (c *cliApp) handleActions(line string) { {command: "connect", handler: c.connect}, {command: "unlock", handler: c.unlock}, {command: "identities", handler: c.identities}, + {command: "payout", handler: c.payout}, {command: "version", handler: c.version}, {command: "license", handler: c.license}, {command: "registration", handler: c.registration}, @@ -328,9 +329,9 @@ func (c *cliApp) connect(argsString string) { } func (c *cliApp) unlock(argsString string) { - unlockSignature := "Unlock [passphrase]" + unlockSignature := "unlock [passphrase]" if len(argsString) == 0 { - info("Press tab to select identity.", unlockSignature) + info("Press tab to select identity.\n", unlockSignature) return } @@ -342,7 +343,7 @@ func (c *cliApp) unlock(argsString string) { } else if len(args) == 2 { identity, passphrase = args[0], args[1] } else { - info("Please type in identity and optional passphrase.", unlockSignature) + info("Please type in identity and optional passphrase.\n", unlockSignature) return } @@ -356,6 +357,53 @@ func (c *cliApp) unlock(argsString string) { success(fmt.Sprintf("Identity %s unlocked.", identity)) } +func (c *cliApp) payout(argsString string) { + const usage = "payout command:\n set" + if len(argsString) == 0 { + info(usage) + return + } + + args := strings.Fields(argsString) + if len(args) < 1 { + info(usage) + return + } + + action := args[0] + switch action { + case "set": // Known sub-commands. + default: + warnf("Unknown sub-command '%s'\n", action) + fmt.Println(usage) + return + } + + if action == "set" { + payoutSignature := "payout set " + if len(args) < 2 { + info("Press tab to select identity.\n", payoutSignature) + return + } + + var identity, ethAddress string + if len(args) == 3 { + identity, ethAddress = args[1], args[2] + } else { + info("Please type in identity and Ethereum address.\n", payoutSignature) + return + } + + err := c.tequilapi.Payout(identity, ethAddress) + if err != nil { + warn(err) + return + } + + success(fmt.Sprintf("Payout address %s registered.", ethAddress)) + } +} + func (c *cliApp) disconnect() { err := c.tequilapi.Disconnect() if err != nil { @@ -638,6 +686,14 @@ func newAutocompleter(tequilapi *tequilapi_client.Client, proposals []tequilapi_ getIdentityOptionList(tequilapi), ), ), + readline.PcItem( + "payout", + readline.PcItem("set", + readline.PcItemDynamic( + getIdentityOptionList(tequilapi), + ), + ), + ), readline.PcItem( "license", readline.PcItem("warranty"), diff --git a/tequilapi/client/client.go b/tequilapi/client/client.go index 200ec7d3bd..c6f4b8203c 100644 --- a/tequilapi/client/client.go +++ b/tequilapi/client/client.go @@ -228,6 +228,24 @@ func (client *Client) Unlock(identity, passphrase string) error { return nil } +// Payout registers payout address for identity +func (client *Client) Payout(identity, ethAddress string) error { + path := fmt.Sprintf("identities/%s/payout", identity) + payload := struct { + EthAddress string `json:"ethAddress"` + }{ + ethAddress, + } + + response, err := client.http.Put(path, payload) + if err != nil { + return err + } + defer response.Body.Close() + + return nil +} + // Stop kills mysterium client func (client *Client) Stop() error { emptyPayload := struct{}{} From 520e89280246832dc50adbb91c03c0037b3fc080 Mon Sep 17 00:00:00 2001 From: interro Date: Tue, 26 Mar 2019 11:32:58 +0200 Subject: [PATCH 2/3] reduced checks --- cmd/commands/cli/command.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/cmd/commands/cli/command.go b/cmd/commands/cli/command.go index bcf3fe4e53..acaebc122a 100644 --- a/cmd/commands/cli/command.go +++ b/cmd/commands/cli/command.go @@ -358,13 +358,9 @@ func (c *cliApp) unlock(argsString string) { } func (c *cliApp) payout(argsString string) { - const usage = "payout command:\n set" - if len(argsString) == 0 { - info(usage) - return - } - args := strings.Fields(argsString) + + const usage = "payout command:\n set" if len(args) < 1 { info(usage) return @@ -372,14 +368,7 @@ func (c *cliApp) payout(argsString string) { action := args[0] switch action { - case "set": // Known sub-commands. - default: - warnf("Unknown sub-command '%s'\n", action) - fmt.Println(usage) - return - } - - if action == "set" { + case "set": payoutSignature := "payout set " if len(args) < 2 { info("Press tab to select identity.\n", payoutSignature) @@ -401,6 +390,11 @@ func (c *cliApp) payout(argsString string) { } success(fmt.Sprintf("Payout address %s registered.", ethAddress)) + + default: + warnf("Unknown sub-command '%s'\n", action) + fmt.Println(usage) + return } } From c9d4adb562fb8fa4fb8c1020ef975cc08f044710 Mon Sep 17 00:00:00 2001 From: interro Date: Tue, 26 Mar 2019 14:55:48 +0200 Subject: [PATCH 3/3] more informative CLI message --- cmd/commands/cli/command.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/commands/cli/command.go b/cmd/commands/cli/command.go index acaebc122a..01c4666955 100644 --- a/cmd/commands/cli/command.go +++ b/cmd/commands/cli/command.go @@ -361,7 +361,7 @@ func (c *cliApp) payout(argsString string) { args := strings.Fields(argsString) const usage = "payout command:\n set" - if len(args) < 1 { + if len(args) == 0 { info(usage) return } @@ -371,7 +371,7 @@ func (c *cliApp) payout(argsString string) { case "set": payoutSignature := "payout set " if len(args) < 2 { - info("Press tab to select identity.\n", payoutSignature) + info("Please provide identity. You can select one by pressing tab.\n", payoutSignature) return } @@ -390,7 +390,6 @@ func (c *cliApp) payout(argsString string) { } success(fmt.Sprintf("Payout address %s registered.", ethAddress)) - default: warnf("Unknown sub-command '%s'\n", action) fmt.Println(usage)