Skip to content

Commit

Permalink
Merge pull request #820 from mysteriumnetwork/cli-payout-set
Browse files Browse the repository at this point in the history
payout set command in cli
  • Loading branch information
zolia authored Mar 28, 2019
2 parents 4e71ca0 + f029b77 commit a1b5668
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
55 changes: 52 additions & 3 deletions cmd/commands/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -328,9 +329,9 @@ func (c *cliApp) connect(argsString string) {
}

func (c *cliApp) unlock(argsString string) {
unlockSignature := "Unlock <identity> [passphrase]"
unlockSignature := "unlock <identity> [passphrase]"
if len(argsString) == 0 {
info("Press tab to select identity.", unlockSignature)
info("Press tab to select identity.\n", unlockSignature)
return
}

Expand All @@ -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
}

Expand All @@ -356,6 +357,46 @@ func (c *cliApp) unlock(argsString string) {
success(fmt.Sprintf("Identity %s unlocked.", identity))
}

func (c *cliApp) payout(argsString string) {
args := strings.Fields(argsString)

const usage = "payout command:\n set"
if len(args) == 0 {
info(usage)
return
}

action := args[0]
switch action {
case "set":
payoutSignature := "payout set <identity> <ethAddress>"
if len(args) < 2 {
info("Please provide identity. You can select one by pressing tab.\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))
default:
warnf("Unknown sub-command '%s'\n", action)
fmt.Println(usage)
return
}
}

func (c *cliApp) disconnect() {
err := c.tequilapi.Disconnect()
if err != nil {
Expand Down Expand Up @@ -638,6 +679,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"),
Expand Down
18 changes: 18 additions & 0 deletions tequilapi/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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{}{}
Expand Down

0 comments on commit a1b5668

Please sign in to comment.