cmd

package
v0.0.0-...-f889647 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Copyright © 2020 Aleksey V. Litvinov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 Alexey V. Litvinov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var SetCandidateOfflineCmd = &cobra.Command{
	Use:   "SetCandidateOffline",
	Short: "Build a transaction for setting candidate into offline mode",

	Run: func(cmd *cobra.Command, args []string) {

		fmt.Print("Seed-phrase of owner wallet (hidden input): ")
		var mnemonic []byte
		var err error
		mnemonic, err = terminal.ReadPassword(int(syscall.Stdin))
		if err != nil {
			fmt.Println("ERROR (", err, ")")
			fmt.Print("Seed-phrase of owner wallet: ")
			reader := bufio.NewReader(os.Stdin)
			text, _ := reader.ReadString('\n')
			text = strings.Replace(text, "\n", "", -1)
			text = strings.Replace(text, "\r", "", -1)
			mnemonic = []byte(text)
		}

		seed, _ := wallet.Seed(string(mnemonic))

		wlt, err := wallet.NewWallet(seed)
		exitIfItIsError(err)

		nonce, err := getNonce(viper.GetStringSlice("common.api_nodes"), wlt.Address())
		exitIfItIsError(err)

		validator_pubkey := viper.GetString("tx_set_candidate_offline.validator_pubkey")

		offData := transaction.NewSetCandidateOffData().MustSetPubKey(validator_pubkey)
		txOff, err := transaction.NewBuilder(getNetworkChain()).NewTransaction(offData)
		exitIfItIsError(err)

		txOff.SetNonce(nonce).SetGasCoin(getCoin()).SetGasPrice(50)
		signedTxOff, err := txOff.Sign(wlt.PrivateKey())
		exitIfItIsError(err)

		tx_enc, _ := signedTxOff.Encode()

		fmt.Println("Validator pubkey:", validator_pubkey)
		fmt.Println("Owner pubkey:", wlt.PublicKey())
		fmt.Println("Owner address:", wlt.Address())
		fmt.Println("TX OFF:", tx_enc)

		f, err := os.Create(fmt.Sprintf("tx_off_%s.yaml", validator_pubkey))
		if err != nil {
			fmt.Println(err)
			return
		}
		defer Close(f)

		_, err = f.WriteString(fmt.Sprintf(
			"validator_pubkey: %s\nowner_pubkey: %s\nowner_address: %s\ntx_off: %s\n",
			validator_pubkey, wlt.PublicKey(), wlt.Address(), tx_enc))
		exitIfItIsError(err)
	},
}

SetCandidateOfflineCmd represents the SetCandidateOffline command

Functions

func Close

func Close(f *os.File)

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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