create

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "create",
	Short: "Create a new account",
	Run: func(cmd *cobra.Command, args []string) {
		projectConf := cli.LoadConfig()

		signerAccount := projectConf.Accounts[conf.Signer]

		accountKeys := make([]*flow.AccountKey, len(conf.Keys))

		sigAlgo := crypto.StringToSignatureAlgorithm(conf.SigAlgo)
		if sigAlgo == crypto.UnknownSignatureAlgorithm {
			cli.Exitf(1, "Failed to determine signature algorithm from %s", conf.SigAlgo)
		}
		hashAlgo := crypto.StringToHashAlgorithm(conf.HashAlgo)
		if hashAlgo == crypto.UnknownHashAlgorithm {
			cli.Exitf(1, "Failed to determine hash algorithm from %s", conf.HashAlgo)
		}

		for i, publicKeyHex := range conf.Keys {
			publicKey := cli.MustDecodePublicKeyHex(cli.DefaultSigAlgo, publicKeyHex)
			accountKeys[i] = &flow.AccountKey{
				PublicKey: publicKey,
				SigAlgo:   sigAlgo,
				HashAlgo:  hashAlgo,
				Weight:    flow.AccountKeyWeightThreshold,
			}
		}

		contracts := []templates.Contract{}

		for _, contract := range conf.Contracts {
			contractFlagContent := strings.SplitN(contract, ":", 2)
			if len(contractFlagContent) != 2 {
				cli.Exitf(1, "Failed to read contract name and path from flag. Ensure you're providing a contract name and a file path. %s", contract)
			}
			contractName := contractFlagContent[0]
			contractPath := contractFlagContent[1]
			contractSource, err := ioutil.ReadFile(contractPath)
			if err != nil {
				cli.Exitf(1, "Failed to read contract from source file %s", contractPath)
			}
			contracts = append(contracts,
				templates.Contract{
					Name:   contractName,
					Source: string(contractSource),
				},
			)
		}

		tx := templates.CreateAccount(accountKeys, contracts, signerAccount.Address)

		cli.SendTransaction(projectConf.HostWithOverride(conf.Host), signerAccount, tx, conf.Results)
	},
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Signer    string   `default:"service" flag:"signer,s"`
	Keys      []string `flag:"key,k" info:"Public keys to attach to account"`
	SigAlgo   string   `default:"ECDSA_P256" flag:"sig-algo" info:"Signature algorithm used to generate the keys"`
	HashAlgo  string   `default:"SHA3_256" flag:"hash-algo" info:"Hash used for the digest"`
	Host      string   `flag:"host" info:"Flow Access API host address"`
	Results   bool     `default:"false" flag:"results" info:"Display the results of the transaction"`
	Contracts []string `flag:"contract,c" info:"Contract to be deployed during account creation. <name:path>"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL