Skip to content

Conversation

@winder
Copy link
Contributor

@winder winder commented Nov 12, 2021

Summary

Add a simple compatibility mode to give a buffer for migration to new REST APIs.

Test Plan

Manual testing:

~$ goal account listpartkeys -d /tmp/private_network/Node/
Registered  Account      ParticipationID   Last Used  First round  Last round
yes         MWGK...HZ4M  PCGXDSAH...               6            0     3000000

~$ goal account listpartkeys -d /tmp/private_network/Node/ -c
Registered	Filename                                                                        	Parent address                                              	 First round	  Last round	   First key
yes       	Wallet2.0.3000000.partkey                                                       	MWGKAWMI2BWYPXVWXKO5FBJVIXE6L4FCMCMBUSNXWCH3JXUOAHOUPSHZ4M  	           0	     3000000	         1.8

@winder winder requested a review from tsachiherman November 12, 2021 19:26
Comment on lines +1069 to +1113
// legacyListParticipationKeysCommand prints key information in the same
// format as earlier versions of goal. Some users are using this information
// in scripts and need some extra time to migrate to the REST API.
func legacyListParticipationKeysCommand() {
dataDir := ensureSingleDataDir()

client := ensureGoalClient(dataDir, libgoal.DynamicClient)
parts, err := client.ListParticipationKeyFiles()
if err != nil {
reportErrorf(errorRequestFail, err)
}

var filenames []string
for fn := range parts {
filenames = append(filenames, fn)
}
sort.Strings(filenames)

rowFormat := "%-10s\t%-80s\t%-60s\t%12s\t%12s\t%12s\n"
fmt.Printf(rowFormat, "Registered", "Filename", "Parent address", "First round", "Last round", "First key")
for _, fn := range filenames {
onlineInfoStr := "unknown"
onlineAccountInfo, err := client.AccountInformation(parts[fn].Address().GetUserAddress())
if err == nil {
votingBytes := parts[fn].Voting.OneTimeSignatureVerifier
vrfBytes := parts[fn].VRF.PK
if onlineAccountInfo.Participation != nil &&
(string(onlineAccountInfo.Participation.ParticipationPK) == string(votingBytes[:])) &&
(string(onlineAccountInfo.Participation.VRFPK) == string(vrfBytes[:])) &&
(onlineAccountInfo.Participation.VoteFirst == uint64(parts[fn].FirstValid)) &&
(onlineAccountInfo.Participation.VoteLast == uint64(parts[fn].LastValid)) &&
(onlineAccountInfo.Participation.VoteKeyDilution == parts[fn].KeyDilution) {
onlineInfoStr = "yes"
} else {
onlineInfoStr = "no"
}
}
// it's okay to proceed without algod info
first, last := parts[fn].ValidInterval()
fmt.Printf(rowFormat, onlineInfoStr, fn, parts[fn].Address().GetUserAddress(),
fmt.Sprintf("%d", first),
fmt.Sprintf("%d", last),
fmt.Sprintf("%d.%d", parts[fn].Voting.FirstBatch, parts[fn].Voting.FirstOffset))
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only difference between this function and the previous version of the cobra command is to rename ListParticipationKey to ListParticipationKeyFiles.

Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

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

looks great.

@winder winder merged commit 25425d1 into algorand:feature/partkey Nov 12, 2021
@winder winder deleted the will/list-partkey-compatibility branch November 12, 2021 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants