Skip to content
Closed
40 changes: 16 additions & 24 deletions cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,8 @@ var createAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -535,9 +534,8 @@ var updateAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -605,9 +603,8 @@ var optInAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -675,9 +672,8 @@ var closeOutAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -745,9 +741,8 @@ var clearAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -815,9 +810,8 @@ var callAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -885,9 +879,8 @@ var deleteAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down Expand Up @@ -1376,9 +1369,8 @@ var methodAppCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
appCallTxn.Note = parseNoteField(cmd)
appCallTxn.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&appCallTxn, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down
24 changes: 12 additions & 12 deletions cmd/goal/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ var createAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down Expand Up @@ -367,8 +367,8 @@ var destroyAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

firstValid, lastValid, _, err = client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down Expand Up @@ -460,8 +460,8 @@ var configAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

firstValid, lastValid, _, err = client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down Expand Up @@ -545,8 +545,8 @@ var sendAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

firstValid, lastValid, _, err = client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down Expand Up @@ -616,8 +616,8 @@ var freezeAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

firstValid, lastValid, _, err = client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down Expand Up @@ -703,8 +703,8 @@ var optinAssetCmd = &cobra.Command{
reportErrorf("Cannot construct transaction: %s", err)
}

tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

firstValid, lastValid, _, err = client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func init() {
sendCmd.Flags().StringSliceVar(&argB64Strings, "argb64", nil, "base64 encoded args to pass to transaction logic")
sendCmd.Flags().StringVarP(&logicSigFile, "logic-sig", "L", "", "LogicSig to apply to transaction")
sendCmd.Flags().StringVar(&msigParams, "msig-params", "", "Multisig preimage parameters - [threshold] [Address 1] [Address 2] ...\nUsed to add the necessary fields in case the account was rekeyed to a multisig account")

sendCmd.MarkFlagRequired("to")
sendCmd.MarkFlagRequired("amount")

Expand Down Expand Up @@ -269,6 +270,15 @@ func getProgramArgs() [][]byte {
return getB64Args(argB64Strings)
}

func applyCommonFields(txn *transactions.Transaction, cmd *cobra.Command) {
// Parse notes and lease fields
txn.Note = parseNoteField(cmd)
txn.Lease = parseLease(cmd)
// DevMode fields: the default values would be ignored.
txn.DevMode.SkipValidation = skipValidation
txn.DevMode.SetNextBlockTime = setBlockTime
}

func parseNoteField(cmd *cobra.Command) []byte {
if cmd.Flags().Changed("noteb64") {
noteBytes, err := base64.StdEncoding.DecodeString(noteBase64)
Expand Down Expand Up @@ -361,10 +371,6 @@ var sendCmd = &cobra.Command{
}
toAddressResolved := accountList.getAddressByName(toAddress)

// Parse notes and lease fields
noteBytes := parseNoteField(cmd)
leaseBytes := parseLease(cmd)

// If closing an account, resolve that address as well
var closeToAddressResolved string
if closeToAddress != "" {
Expand All @@ -387,8 +393,8 @@ var sendCmd = &cobra.Command{
reportErrorf(err.Error())
}
payment, err := client.ConstructPayment(
fromAddressResolved, toAddressResolved, fee, amount, noteBytes, closeToAddressResolved,
leaseBytes, basics.Round(firstValid), basics.Round(lastValid),
fromAddressResolved, toAddressResolved, fee, amount, nil, closeToAddressResolved,
[32]byte{}, basics.Round(firstValid), basics.Round(lastValid),
)
if err != nil {
reportErrorf(errorConstructingTX, err)
Expand All @@ -397,6 +403,9 @@ var sendCmd = &cobra.Command{
payment.RekeyTo = rekeyTo
}

// Fill in common fields.
applyCommonFields(&payment, cmd)

// ConstructPayment fills in the suggested fee when fee=0. But if the user actually used --fee=0 on the
// commandline, we ought to do what they asked (especially now that zero or low fees make sense in
// combination with other txns that cover the groups's fee.
Expand Down
8 changes: 8 additions & 0 deletions cmd/goal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ var (
noWaitAfterSend bool
dumpForDryrun bool
dumpForDryrunAccts []string

// devmode txn send options
setBlockTime int64
skipValidation bool
)

var dumpForDryrunFormat cmdutil.CobraStringValue = *cmdutil.MakeCobraStringValue("json", []string{"msgp"})
Expand All @@ -68,4 +72,8 @@ func addTxnFlags(cmd *cobra.Command) {
cmd.Flags().Var(&dumpForDryrunFormat, "dryrun-dump-format", "Dryrun dump format: "+dumpForDryrunFormat.AllowedString())
cmd.Flags().StringSliceVar(&dumpForDryrunAccts, "dryrun-accounts", nil, "additional accounts to include into dryrun request obj")
cmd.Flags().StringVarP(&signerAddress, "signer", "S", "", "Address of key to sign with, if different from transaction \"from\" address due to rekeying")

// devmode options
cmd.Flags().Int64Var(&setBlockTime, "set-block-time", 0, "Add 'set_block_time: <value>' field to the txn.")
cmd.Flags().BoolVar(&skipValidation, "skip-validation", false, "Add 'skip_validation: true' field to the txn.")
}
45 changes: 45 additions & 0 deletions cmd/goal/defaultNetworkTemplate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"Genesis": {
"NetworkName": "",
"FirstPartKeyRound": 0,
"LastPartKeyRound": 30000,
"Wallets": [
{
"Name": "Wallet1",
"Stake": 40,
"Online": true
},
{
"Name": "Wallet2",
"Stake": 40,
"Online": true
},
{
"Name": "Wallet3",
"Stake": 20,
"Online": false
}
]
},
"Nodes": [
{
"Name": "Node",
"IsRelay": false,
"Wallets": [
{
"Name": "Wallet1",
"ParticipationOnly": false
},
{
"Name": "Wallet2",
"ParticipationOnly": false
},
{
"Name": "Wallet3",
"ParticipationOnly": false
}
]
}
]
}

5 changes: 2 additions & 3 deletions cmd/goal/interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,8 @@ var appExecuteCmd = &cobra.Command{
reportErrorf("Cannot create application txn: %v", err)
}

// Fill in note and lease
tx.Note = parseNoteField(cmd)
tx.Lease = parseLease(cmd)
// Fill in common fields.
applyCommonFields(&tx, cmd)

// Fill in rounds, fee, etc.
fv, lv, _, err := client.ComputeValidityRounds(firstValid, lastValid, numValidRounds)
Expand Down
42 changes: 37 additions & 5 deletions cmd/goal/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package main
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this file, these are private network changes from another PR.


import (
_ "embed"
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"

Expand All @@ -35,6 +38,7 @@ var startNode string
var noImportKeys bool
var noClean bool
var devModeOverride bool
var startOnCreation bool

func init() {
networkCmd.AddCommand(networkCreateCmd)
Expand All @@ -43,10 +47,10 @@ func init() {

networkCreateCmd.Flags().StringVarP(&networkName, "network", "n", "", "Specify the name to use for the private network")
networkCreateCmd.Flags().StringVarP(&networkTemplateFile, "template", "t", "", "Specify the path to the template file for the network")
networkCreateCmd.MarkFlagRequired("template")
networkCreateCmd.Flags().BoolVarP(&noImportKeys, "noimportkeys", "K", false, "Do not import root keys when creating the network (by default will import)")
networkCreateCmd.Flags().BoolVar(&noClean, "noclean", false, "Prevents auto-cleanup on error - for diagnosing problems")
networkCreateCmd.Flags().BoolVar(&devModeOverride, "devMode", false, "Forces the configuration to enable DevMode, returns an error if the template is not compatible with DevMode.")
networkCreateCmd.Flags().BoolVarP(&startOnCreation, "start", "s", false, "Automatically start the network after creating it.")

networkStartCmd.Flags().StringVarP(&startNode, "node", "n", "", "Specify the name of a specific node to start")

Expand All @@ -70,6 +74,9 @@ The basic idea is that we create one or more data directories and wallets to for
},
}

//go:embed defaultNetworkTemplate.json
var defaultNetworkTemplate string

var networkCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a private named network from a template",
Expand All @@ -80,10 +87,25 @@ var networkCreateCmd = &cobra.Command{
if err != nil {
panic(err)
}
networkTemplateFile, err := filepath.Abs(networkTemplateFile)
if err != nil {
panic(err)

var templateReader io.Reader

if networkTemplateFile == "" {
templateReader = strings.NewReader(defaultNetworkTemplate)
} else {
networkTemplateFile, err = filepath.Abs(networkTemplateFile)
if err != nil {
panic(err)
}
file, err := os.Open(networkTemplateFile)
if err != nil {
reportErrorf(errorCreateNetwork, err)
}

defer file.Close()
templateReader = file
}

// Make sure target directory does not exist or is empty
if util.FileExists(networkRootDir) && !util.IsEmpty(networkRootDir) {
reportErrorf(infoNetworkAlreadyExists, networkRootDir)
Expand All @@ -101,7 +123,7 @@ var networkCreateCmd = &cobra.Command{
consensus, _ = config.PreloadConfigurableConsensusProtocols(dataDir)
}

network, err := netdeploy.CreateNetworkFromTemplate(networkName, networkRootDir, networkTemplateFile, binDir, !noImportKeys, nil, consensus, devModeOverride)
network, err := netdeploy.CreateNetworkFromTemplate(networkName, networkRootDir, templateReader, binDir, !noImportKeys, nil, consensus, devModeOverride)
if err != nil {
if noClean {
reportInfof(" ** failed ** - Preserving network rootdir '%s'", networkRootDir)
Expand All @@ -112,6 +134,16 @@ var networkCreateCmd = &cobra.Command{
}

reportInfof(infoNetworkCreated, network.Name(), networkRootDir)

if startOnCreation {
fmt.Printf("startOnCreation true\n")
network, binDir := getNetworkAndBinDir()
err := network.Start(binDir, false)
if err != nil {
reportErrorf(errorStartingNetwork, err)
}
reportInfof(infoNetworkStarted, networkRootDir)
}
},
}

Expand Down
Loading