Skip to content

Commit

Permalink
Fix cmd name + add genesis command
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Dec 26, 2022
1 parent dc15ffa commit b272e3b
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ref. https://goreleaser.com/customization/build/
builds:
- id: xsvm
main: ./cmd
main: ./cmd/xsvm
binary: xsvm
flags:
- -v
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ Currently there are no fees enforced in the XSVM.
```bash
git clone https://github.com/ava-labs/xsvm.git;
cd xsvm;
go install -v ./cmd;
go install -v ./cmd/xsvm;
```

#### Usage

```
XSVM agent
Runs an XSVM plugin
Usage:
xsvm [flags]
xsvm [command]
Available Commands:
account Displays the state of the requested account
chain Manages XS chains
completion Generate the autocompletion script for the specified shell
help Help about any command
issue Issues transactions
version Prints out the version
Flags:
Expand Down
2 changes: 2 additions & 0 deletions cmd/chain/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"

"github.com/ava-labs/xsvm/cmd/chain/create"
"github.com/ava-labs/xsvm/cmd/chain/genesis"
)

func Command() *cobra.Command {
Expand All @@ -16,6 +17,7 @@ func Command() *cobra.Command {
}
c.AddCommand(
create.Command(),
genesis.Command(),
)
return c
}
38 changes: 38 additions & 0 deletions cmd/chain/genesis/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package genesis

import (
"os"

"github.com/ava-labs/xsvm/genesis"
"github.com/spf13/cobra"
)

func Command() *cobra.Command {
c := &cobra.Command{
Use: "genesis",
Short: "Creates a chain's genesis and prints it to stdout",
RunE: genesisFunc,
}
flags := c.Flags()
AddFlags(flags)
return c
}

func genesisFunc(c *cobra.Command, args []string) error {
flags := c.Flags()
g, err := ParseFlags(flags, args)
if err != nil {
return err
}

genesisBytes, err := genesis.Codec.Marshal(genesis.Version, g)
if err != nil {
return err
}

_, err = os.Stdout.Write(genesisBytes)
return err
}
68 changes: 68 additions & 0 deletions cmd/chain/genesis/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package genesis

import (
"math"
"time"

"github.com/spf13/pflag"

"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"

xsgenesis "github.com/ava-labs/xsvm/genesis"
)

const (
TimeKey = "time"
AddressKey = "address"
BalanceKey = "balance"
)

func AddFlags(flags *pflag.FlagSet) {
flags.Int64(TimeKey, time.Now().Unix(), "Unix timestamp to include in the genesis")
flags.String(AddressKey, genesis.EWOQKey.Address().String(), "Address to fund in the genesis")
flags.Uint64(BalanceKey, math.MaxUint64, "Amount to provide the funded address in the genesis")
}

func ParseFlags(flags *pflag.FlagSet, args []string) (*xsgenesis.Genesis, error) {
if err := flags.Parse(args); err != nil {
return nil, err
}

if err := flags.Parse(args); err != nil {
return nil, err
}

timestamp, err := flags.GetInt64(TimeKey)
if err != nil {
return nil, err
}

addrStr, err := flags.GetString(AddressKey)
if err != nil {
return nil, err
}

addr, err := ids.ShortFromString(addrStr)
if err != nil {
return nil, err
}

balance, err := flags.GetUint64(BalanceKey)
if err != nil {
return nil, err
}

return &xsgenesis.Genesis{
Timestamp: timestamp,
Allocations: []xsgenesis.Allocation{
{
Address: addr,
Balance: balance,
},
},
}, nil
}
2 changes: 1 addition & 1 deletion cmd/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func Command() *cobra.Command {
return &cobra.Command{
Use: "run",
Use: "xsvm",
Short: "Runs an XSVM plugin",
RunE: runFunc,
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ name="v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH"
mkdir -p ./build

echo "Building xsvm into ./build/"
go build -o ./build/$name ./cmd/
go build -o ./build/xsvm ./cmd/
go build -o ./build/$name ./cmd/xsvm/
go build -o ./build/xsvm ./cmd/xsvm/

0 comments on commit b272e3b

Please sign in to comment.