-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc15ffa
commit b272e3b
Showing
8 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters