Skip to content

Commit

Permalink
Merge pull request #134 from eoscanada/feature/rex
Browse files Browse the repository at this point in the history
Feature/rex
  • Loading branch information
Matthieu Vachon authored May 17, 2019
2 parents 8f2dc93 + 6b48284 commit 83d2353
Show file tree
Hide file tree
Showing 23 changed files with 608 additions and 71 deletions.
6 changes: 6 additions & 0 deletions cli/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func ToAccountName(in string) (out eos.AccountName, err error) {
return eos.AccountName(in), nil
}

// ToAsset converts a eos valid asset string (in) into an eos-go
// Asset struct
func ToAsset(in string) (out eos.Asset, err error) {
return eos.NewAsset(in)
}

// ToName converts a valid eos name string (in) into an eos-go
// Name struct
func ToName(in string) (out eos.Name, err error) {
Expand Down
41 changes: 41 additions & 0 deletions eosc/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -95,6 +96,11 @@ func errorCheck(prefix string, err error) {
}
}

func exitWitMessage(message string) {
fmt.Printf("ERROR: %s\n", message)
os.Exit(1)
}

func permissionToPermissionLevel(in string) (out eos.PermissionLevel, err error) {
return eos.NewPermissionLevel(in)
}
Expand Down Expand Up @@ -313,6 +319,27 @@ func toAccount(in, field string) eos.AccountName {
return acct
}

func toAsset(symbol eos.Symbol, in, field string) eos.Asset {
asset, err := eos.NewAssetFromString(symbol, in)
errorCheck(fmt.Sprintf("invalid %s asset for %q", symbol.String(), field), err)

return asset
}

func toEOSAsset(in, field string) eos.Asset {
asset, err := eos.NewEOSAssetFromString(in)
errorCheck(fmt.Sprintf("invalid %s asset for %q", eos.EOSSymbol, field), err)

return asset
}

func toREXAsset(in, field string) eos.Asset {
asset, err := eos.NewREXAssetFromString(in)
errorCheck(fmt.Sprintf("invalid %s asset for %q", eos.REXSymbol, field), err)

return asset
}

func toName(in, field string) eos.Name {
name, err := cli.ToName(in)
if err != nil {
Expand All @@ -334,6 +361,20 @@ func toActionName(in, field string) eos.ActionName {
return eos.ActionName(toName(in, field))
}

func toUint16(in, field string) uint16 {
value, err := strconv.ParseUint(in, 10, 16)
errorCheck(fmt.Sprintf("invalid uint16 number for %q", field), err)

return uint16(value)
}

func toUint64(in, field string) uint64 {
value, err := strconv.ParseUint(in, 10, 64)
errorCheck(fmt.Sprintf("invalid uint64 number for %q", field), err)

return value
}

func toSHA256Bytes(in, field string) eos.SHA256Bytes {
if len(in) != 64 {
errorCheck(fmt.Sprintf("%q invalid", field), errors.New("should be 64 hexadecimal characters"))
Expand Down
16 changes: 16 additions & 0 deletions eosc/cmd/rex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/spf13/cobra"
)

var rexCmd = &cobra.Command{
Use: "rex",
Short: "EOS REX interactions",
}

func init() {
RootCmd.AddCommand(rexCmd)
}
28 changes: 28 additions & 0 deletions eosc/cmd/rexBuy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexBuy = &cobra.Command{
Use: "buy [account] [quantity]",
Short: "Buy REX tokens using EOS tokens.",
Long: "Buy REX tokens using EOS tokens within your REX fund.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
quantity := toEOSAsset(args[1], "quantity")

pushEOSCActions(getAPI(), rex.NewBuyREX(
account,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexBuy)
}
26 changes: 26 additions & 0 deletions eosc/cmd/rexCancel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexCancel = &cobra.Command{
Use: "cancel [account]",
Short: "Cancels any unfilled sell orders.",
Long: "Cancels any unfilled sell orders for REX tokens.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")

pushEOSCActions(getAPI(), rex.NewCancelREXOrder(
account,
))
},
}

func init() {
rexCmd.AddCommand(rexCancel)
}
26 changes: 26 additions & 0 deletions eosc/cmd/rexClose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexClose = &cobra.Command{
Use: "close [account]",
Short: "Removes all REX related entries from table.",
Long: "Free RAM from an account by removing its entry in the REX table. This action will fail if the account has any pending loans, refunds, or REX tokens.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")

pushEOSCActions(getAPI(), rex.NewCloseREX(
account,
))
},
}

func init() {
rexCmd.AddCommand(rexClose)
}
26 changes: 26 additions & 0 deletions eosc/cmd/rexConsolidate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexConsolidate = &cobra.Command{
Use: "consolidate [account]",
Short: "Consolidates any active REX maturity buckets.",
Long: "Consolidates any active REX maturity buckets into a single bucket that will mature in 4 days.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")

pushEOSCActions(getAPI(), rex.NewConsolidate(
account,
))
},
}

func init() {
rexCmd.AddCommand(rexConsolidate)
}
30 changes: 30 additions & 0 deletions eosc/cmd/rexDefundCPU.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexDefundCPU = &cobra.Command{
Use: "defund-cpu [account] [loan number] [quantity]",
Short: "Remove EOS tokens set for renewal of a CPU loan.",
Long: "Remove EOS tokens set for renewal of a CPU loan.",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
loanNumber := toUint64(args[1], "loan number")
quantity := toEOSAsset(args[2], "quantity")

pushEOSCActions(getAPI(), rex.NewDefundCPULoan(
account,
loanNumber,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexDefundCPU)
}
30 changes: 30 additions & 0 deletions eosc/cmd/rexDefundNET.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexDefundNet = &cobra.Command{
Use: "defund-net [account] [loan number] [quantity]",
Short: "Remove EOS tokens set for renewal of a Network loan.",
Long: "Remove EOS tokens set for renewal of a Network loan.",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
loanNumber := toUint64(args[1], "loan number")
quantity := toEOSAsset(args[2], "quantity")

pushEOSCActions(getAPI(), rex.NewDefundNetLoan(
account,
loanNumber,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexDefundNet)
}
28 changes: 28 additions & 0 deletions eosc/cmd/rexDeposit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexDeposit = &cobra.Command{
Use: "deposit [account] [quantity]",
Short: "Deposit EOS tokens into your REX fund.",
Long: "Deposit EOS tokens into your REX fund, to be used to purchase REX tokens.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
quantity := toEOSAsset(args[1], "quantity")

pushEOSCActions(getAPI(), rex.NewDeposit(
account,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexDeposit)
}
28 changes: 28 additions & 0 deletions eosc/cmd/rexExec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexExec = &cobra.Command{
Use: "exec [account] [max count]",
Short: "Perform maintenance on the REX contract.",
Long: "Perform maintenance on the REX contract (process expired loans or pending sell orders). [max count] needs to be low enough to allow the transaction to be executed within a block.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
maxCount := toUint16(args[1], "max count")

pushEOSCActions(getAPI(), rex.NewREXExec(
account,
maxCount,
))
},
}

func init() {
rexCmd.AddCommand(rexExec)
}
28 changes: 28 additions & 0 deletions eosc/cmd/rexFromSavings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexFromSavings = &cobra.Command{
Use: "from-savings [account] [quantity]",
Short: "Withdraw REX tokens from your savings bucket.",
Long: "Withdraw REX tokens from your savings bucket into your REX fund. Those funds will become available in 4 days.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
quantity := toREXAsset(args[1], "quantity")

pushEOSCActions(getAPI(), rex.NewMoveFromSavings(
account,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexFromSavings)
}
30 changes: 30 additions & 0 deletions eosc/cmd/rexFundCPU.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2018 EOS Canada <[email protected]>

package cmd

import (
"github.com/eoscanada/eos-go/rex"
"github.com/spf13/cobra"
)

var rexFundCPU = &cobra.Command{
Use: "fund-cpu [account] [loan number] [quantity]",
Short: "Set EOS tokens to renew a CPU loan upon expiry.",
Long: "Set an amount of EOS tokens from your REX fund to be used to renew a CPU loan upon expiry.",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
account := toAccount(args[0], "account")
loanNumber := toUint64(args[1], "loan number")
quantity := toEOSAsset(args[2], "quantity")

pushEOSCActions(getAPI(), rex.NewFundCPULoan(
account,
loanNumber,
quantity,
))
},
}

func init() {
rexCmd.AddCommand(rexFundCPU)
}
Loading

0 comments on commit 83d2353

Please sign in to comment.