add preliminary command stubs, kill offline bootstrappers (#164)

This commit is contained in:
Cassandra Heart 2024-04-19 00:53:45 -05:00 committed by GitHub
parent 6b5ce992cf
commit a9fac688d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 512 additions and 7 deletions

2
client/Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
go build -o qclient ./main.go

38
client/cmd/accept.go Normal file
View File

@ -0,0 +1,38 @@
package cmd
import (
"fmt"
"math/big"
"os"
"github.com/spf13/cobra"
)
var acceptCmd = &cobra.Command{
Use: "accept",
Short: "Accepts a pending transfer",
Long: `Accepts a pending transfer:
accept <PendingTransaction>
PendingTransaction - the address of the pending transfer
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
fmt.Println("invalid command")
os.Exit(1)
}
_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid PendingTransaction")
os.Exit(1)
}
fmt.Println("25 QUIL (Coin 0x2688997f2776ab5993894ed04fcdac05577cf2494ddfedf356ebf8bd3de464ab)")
},
}
func init() {
tokenCmd.AddCommand(acceptCmd)
}

19
client/cmd/all.go Normal file
View File

@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var allCmd = &cobra.Command{
Use: "all",
Short: "Mints all available token rewards",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1520.381923 QUIL (Coin 0x162ad88c319060b4f5ea6dbf9a0c2cd82d3d70dfc22d5fc99ca5371083d68416)")
},
}
func init() {
mintCmd.AddCommand(allCmd)
}

19
client/cmd/balance.go Normal file
View File

@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var balanceCmd = &cobra.Command{
Use: "balance",
Short: "Lists the total balance of tokens in the managing account",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1545.381923 QUIL")
},
}
func init() {
tokenCmd.AddCommand(balanceCmd)
}

20
client/cmd/coins.go Normal file
View File

@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var coinsCmd = &cobra.Command{
Use: "coins",
Short: "Lists all coins under control of the managing account",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("25.0 QUIL (Coin 0x1148092cdce78c721835601ef39f9c2cd8b48b7787cbea032dd3913a4106a58d)")
fmt.Println("1520.381923 QUIL (Coin 0x162ad88c319060b4f5ea6dbf9a0c2cd82d3d70dfc22d5fc99ca5371083d68416)")
},
}
func init() {
tokenCmd.AddCommand(coinsCmd)
}

45
client/cmd/merge.go Normal file
View File

@ -0,0 +1,45 @@
package cmd
import (
"fmt"
"math/big"
"os"
"github.com/spf13/cobra"
)
var mergeCmd = &cobra.Command{
Use: "merge",
Short: "Merges two coins",
Long: `Merges two coins:
merge <LeftCoin> <RightCoin>
LeftCoin - the first coin address
RightCoin - the second coin address
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Println("invalid command")
os.Exit(1)
}
_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid LeftCoin")
os.Exit(1)
}
_, ok = new(big.Int).SetString(args[1], 0)
if !ok {
fmt.Println("invalid Rightcoin")
os.Exit(1)
}
fmt.Println("1545.381923 QUIL (Coin 0x151f4ae225e20759077e1724e4c5d0feae26c477fd10d728dfea962eec79b83f)")
},
}
func init() {
tokenCmd.AddCommand(mergeCmd)
}

14
client/cmd/mint.go Normal file
View File

@ -0,0 +1,14 @@
package cmd
import (
"github.com/spf13/cobra"
)
var mintCmd = &cobra.Command{
Use: "mint",
Short: "Performs a mint operation",
}
func init() {
tokenCmd.AddCommand(mintCmd)
}

View File

@ -0,0 +1,43 @@
package cmd
import (
"fmt"
"os"
"time"
"github.com/shopspring/decimal"
"github.com/spf13/cobra"
)
var mutualReceiveCmd = &cobra.Command{
Use: "mutual-receive",
Short: "Initiates a mutual receive",
Long: `Initiates a mutual receive:
mutual-receive <ExpectedAmount>
ExpectedAmount - the amount expected in the transfer
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("invalid command")
os.Exit(1)
}
amount := args[len(args)-1]
_, err := decimal.NewFromString(amount)
if err != nil {
fmt.Println("invalid ExpectedAmount")
os.Exit(1)
}
fmt.Println("Rendezvous: 0x2ad567e4fc1ac335a8d3d6077de2ee998aff996b51936da04ee1b0f5dc196a4f")
fmt.Printf("Awaiting sender... ")
time.Sleep(2 * time.Second)
fmt.Println("OK")
fmt.Println(amount + " QUIL (Coin 0x0525c76ecdc6ef21c2eb75df628b52396adcf402ba26a518ac395db8f5874a82)")
},
}
func init() {
tokenCmd.AddCommand(mutualReceiveCmd)
}

View File

@ -0,0 +1,39 @@
package cmd
import (
"fmt"
"os"
"time"
"github.com/spf13/cobra"
)
var mutualTransferCmd = &cobra.Command{
Use: "mutual-transfer",
Short: "Initiates a mutual transfer",
Long: `Initiates a mutual transfer:
mutual-transfer <Rendezvous> (<Amount>|<OfCoin>)
Rendezvous - the rendezvous point to connect to the recipient
Amount the amount to send, splitting/merging and sending as needed
OfCoin the address of the coin to send in whole
Either Amount or OfCoin must be specified
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Println("invalid command")
os.Exit(1)
}
fmt.Printf("Confirming rendezvous... ")
time.Sleep(500 * time.Millisecond)
fmt.Println("OK")
fmt.Println("50 QUIL (Coin [private])")
},
}
func init() {
tokenCmd.AddCommand(mutualTransferCmd)
}

38
client/cmd/reject.go Normal file
View File

@ -0,0 +1,38 @@
package cmd
import (
"fmt"
"math/big"
"os"
"github.com/spf13/cobra"
)
var rejectCmd = &cobra.Command{
Use: "reject",
Short: "Rejects the pending transaction",
Long: `Rejects a pending transfer:
reject <PendingTransaction>
PendingTransaction - the address of the pending transfer
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
fmt.Println("invalid command")
os.Exit(1)
}
_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid PendingTransaction")
os.Exit(1)
}
fmt.Println("25 QUIL (PendingTransaction 0x27fff099dee515ece193d2af09b164864e4bb60c19eb6719b5bc981f92151009)")
},
}
func init() {
tokenCmd.AddCommand(rejectCmd)
}

31
client/cmd/root.go Normal file
View File

@ -0,0 +1,31 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
)
var configDirectory string
var simulateFail bool
var rootCmd = &cobra.Command{
Use: "qclient",
Short: "Quilibrium RPC Client",
}
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().StringVar(
&configDirectory,
"config",
"../node/.config/",
"config directory (default is ../node/.config/)",
)
}

55
client/cmd/split.go Normal file
View File

@ -0,0 +1,55 @@
package cmd
import (
"fmt"
"math/big"
"os"
"github.com/shopspring/decimal"
"github.com/spf13/cobra"
)
var splitCmd = &cobra.Command{
Use: "split",
Short: "Splits a coin into two coins",
Long: `Splits a coin into two coins:
split <OfCoin> <LeftAmount> <RightAmount>
OfCoin - the address of the coin to split
LeftAmount - the first half of the split amount
RightAmount - the second half of the split amount
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 3 {
fmt.Println("invalid command")
os.Exit(1)
}
_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid OfCoin")
os.Exit(1)
}
leftAmount := args[1]
_, err := decimal.NewFromString(leftAmount)
if err != nil {
fmt.Println("invalid LeftAmount")
os.Exit(1)
}
rightAmount := args[2]
_, err = decimal.NewFromString(rightAmount)
if err != nil {
fmt.Println("invalid RightAmount")
os.Exit(1)
}
fmt.Println(leftAmount + " QUIL (Coin 0x024479f49f03dc53fd702198cd9b548c9e96004e19ef6a4e9c5211a9795ba34d)")
fmt.Println(rightAmount + " QUIL (Coin 0x0140e01731256793bba03914f3844d645fbece26553acdea8ac4de4d84f91690)")
},
}
func init() {
tokenCmd.AddCommand(splitCmd)
}

14
client/cmd/token.go Normal file
View File

@ -0,0 +1,14 @@
package cmd
import (
"github.com/spf13/cobra"
)
var tokenCmd = &cobra.Command{
Use: "token",
Short: "Performs a token operation",
}
func init() {
rootCmd.AddCommand(tokenCmd)
}

93
client/cmd/transfer.go Normal file
View File

@ -0,0 +1,93 @@
package cmd
import (
"fmt"
"math/big"
"os"
"strconv"
"github.com/shopspring/decimal"
"github.com/spf13/cobra"
)
var transferCmd = &cobra.Command{
Use: "transfer",
Short: "Creates a pending transfer of coin",
Long: `Creates a pending transfer of coin:
transfer <ToAccount> [<RefundAccount>] [<Expiry>] (<Amount>|<OfCoin>)
ToAccount account address, must be specified
RefundAccount - account address to receive coin if rejected (if omitted, uses sender address)
Expiry unix epoch time in seconds where the ToAccount can no longer claim (if omitted, does not expire)
Amount the amount to send, splitting/merging and sending as needed
OfCoin the address of the coin to send in whole
Either Amount or OfCoin must be specified
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 2 {
fmt.Println("invalid command")
os.Exit(1)
}
_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid ToAccount")
os.Exit(1)
}
refundAccount := "0x23c0f371e9faa7be4ffedd616361e0c9aeb776ae4d7f3a37605ecbfa40a55a90"
// expiry := int64(9999999999)
var err error
if len(args) >= 3 {
if len(args[len(args)-2]) != 66 {
_, err = strconv.ParseInt(args[len(args)-2], 10, 0)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
} else {
refundAccount = args[1]
}
}
if refundAccount[0] != '0' || refundAccount[1] != 'x' {
_, ok := new(big.Int).SetString(refundAccount, 0)
if !ok {
fmt.Println("invalid refund account")
os.Exit(1)
}
}
ofCoin := ""
amount := ""
if len(args[len(args)-1]) == 66 {
ofCoin = args[len(args)-1]
_, ok := new(big.Int).SetString(ofCoin, 0)
if !ok {
fmt.Println("invalid OfCoin")
os.Exit(1)
}
switch ofCoin {
case "0x1148092cdce78c721835601ef39f9c2cd8b48b7787cbea032dd3913a4106a58d":
fmt.Println("25.0 QUIL (Pending Transaction 0x0382e4da0c7c0133a1b53453b05096272b80c1575c6828d0211c4e371f7c81bb)")
case "0x162ad88c319060b4f5ea6dbf9a0c2cd82d3d70dfc22d5fc99ca5371083d68416":
fmt.Println("1520.381923 QUIL (Pending Transaction 0x0382e4da0c7c0133a1b53453b05096272b80c1575c6828d0211c4e371f7c81bb)")
}
} else {
amount = args[len(args)-1]
_, err := decimal.NewFromString(amount)
if err != nil {
fmt.Println("invalid Amount")
os.Exit(1)
}
fmt.Println(amount + " QUIL (Pending Transaction 0x0382e4da0c7c0133a1b53453b05096272b80c1575c6828d0211c4e371f7c81bb)")
}
},
}
func init() {
tokenCmd.AddCommand(transferCmd)
}

10
client/go.mod Normal file
View File

@ -0,0 +1,10 @@
module source.quilibrium.com/quilibrium/monorepo/client
go 1.20
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)

12
client/go.sum Normal file
View File

@ -0,0 +1,12 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

12
client/main.go Normal file
View File

@ -0,0 +1,12 @@
package main
import (
"fmt"
"source.quilibrium.com/quilibrium/monorepo/client/cmd"
)
func main() {
fmt.Println("Quilibrium RPC Client Simulation Mode")
cmd.Execute()
}

File diff suppressed because one or more lines are too long