Skip to content

Commit d25cc69

Browse files
authored
Merge pull request #117 from koinos/public
Add public command, and show public key on generate
2 parents 2d2819d + 5f8984c commit d25cc69

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

internal/cli/commands.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func NewKoinosCommandSet() *CommandSet {
111111
cs.AddCommand(NewCommandDeclaration("open", "Open a wallet file (unlock also works)", false, NewOpenCommand, *NewCommandArg("filename", FileArg), *NewOptionalCommandArg("password", StringArg)))
112112
cs.AddCommand(NewCommandDeclaration("unlock", "Synonym for open", true, NewOpenCommand, *NewCommandArg("filename", FileArg), *NewOptionalCommandArg("password", StringArg)))
113113
cs.AddCommand(NewCommandDeclaration("private", "Show the currently opened wallet's private key", false, NewPrivateCommand))
114+
cs.AddCommand(NewCommandDeclaration("public", "Show the currently opened wallet's public key", false, NewPublicCommand))
114115
cs.AddCommand(NewCommandDeclaration("rclimit", "Set or show the current rc limit. Give no limit to see current value. Give limit as either mana or a percent (i.e. 80%).", false, NewRcLimitCommand, *NewOptionalCommandArg("limit", StringArg)))
115116
cs.AddCommand(NewCommandDeclaration("read", "Read from a smart contract", false, NewReadCommand, *NewCommandArg("contract-id", StringArg), *NewCommandArg("entry-point", StringArg), *NewCommandArg("arguments", StringArg)))
116117
cs.AddCommand(NewCommandDeclaration("register", "Register a smart contract's commands", false, NewRegisterCommand, *NewCommandArg("name", ContractNameArg), *NewCommandArg("address", AddressArg), *NewOptionalCommandArg("abi-filename", FileArg)))
@@ -331,6 +332,7 @@ func (c *GenerateKeyCommand) Execute(ctx context.Context, ee *ExecutionEnvironme
331332
result := NewExecutionResult()
332333
result.AddMessage("New key generated\nThis is only shown once, make sure to record this information\n---")
333334
result.AddMessage(fmt.Sprintf("Address: %s", base58.Encode(k.AddressBytes())))
335+
result.AddMessage(fmt.Sprintf("Public : %s", base64.URLEncoding.EncodeToString(k.PublicBytes())))
334336
result.AddMessage(fmt.Sprintf("Private: %s", k.Private()))
335337

336338
return result, nil
@@ -630,6 +632,31 @@ func (c *PrivateCommand) Execute(ctx context.Context, ee *ExecutionEnvironment)
630632
return result, nil
631633
}
632634

635+
// ----------------------------------------------------------------------------
636+
// Public Command
637+
// ----------------------------------------------------------------------------
638+
639+
// PublicCommand is a command that shows the currently opened wallet's public
640+
type PublicCommand struct {
641+
}
642+
643+
// NewPublicCommand creates a new public command object
644+
func NewPublicCommand(inv *CommandParseResult) Command {
645+
return &PublicCommand{}
646+
}
647+
648+
// Execute shows wallet public key
649+
func (c *PublicCommand) Execute(ctx context.Context, ee *ExecutionEnvironment) (*ExecutionResult, error) {
650+
if !ee.IsWalletOpen() {
651+
return nil, fmt.Errorf("%w: cannot show public key", cliutil.ErrWalletClosed)
652+
}
653+
654+
result := NewExecutionResult()
655+
result.AddMessage(fmt.Sprintf("Public key: %s", base64.URLEncoding.EncodeToString(ee.Key.PublicBytes())))
656+
657+
return result, nil
658+
}
659+
633660
// ----------------------------------------------------------------------------
634661
// Help
635662
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)