Cli: Create working group commands related to openings and applications#707
Conversation
d479798 to
98b059f
Compare
|
Fixed the conflicts and changed the CLI dependency from |
|
Updated the PR to include new commands based on issue #600:
|
|
Updated to include commands from #601:
|
cli/src/Api.ts
Outdated
| stageBlock: number | undefined, | ||
| stageDate: Date | undefined; | ||
|
|
||
| if (stage.type === OpeningStageKeys.WaitingToBegin) { |
There was a problem hiding this comment.
I think a better typesafe way of doing the comparison would be by using a helper methods or getters on the OpeningStage type to look something like:
## bool property
stage.isWaitingToBegin
or
# I think the Enum type has an eq method
stage.eq(OpeningStage.WaitingToBeing)
# WaitingToBeing would be a static method on OpeningStage:
static WaitingToBeing() : OpeningStage {
return new OpeningStage('WaitingToBeing')
}
I've seen multiple instances where the comparison of the enum variant is done in this way.
There was a problem hiding this comment.
of course I'm simplifying here to express the idea, clearly the variant has encapsulated data as well which I'm disregarding
There was a problem hiding this comment.
if I remember correctly, we might even get some of these helper properties as part of the Enum type. I've seen some use of it in the polkadot-js/apps code base.
cli/src/Api.ts
Outdated
| async groupOpening(group: WorkingGroups, workerOpeningId: number): Promise<GroupOpening> { | ||
| const nextId = ((await this.workingGroupApiQuery(group).nextWorkerOpeningId()) as WorkerOpeningId).toNumber(); | ||
|
|
||
| if (workerOpeningId < 0 || workerOpeningId >= nextId) { |
There was a problem hiding this comment.
I've used this strategy as well and as a guard it works well as longs as the map has all keys in the range.
This is not the case for the WorkerById map for example. For that map I had to deal with it differently in the storage-node package
Basically we need a way to check if a key exists in a map.
I've seen you in pioneer code base rely on .isEmpty property for example for a linked value to determine if the value actually existed in the map. That works perfectly for the value type in that case, but it can't really work in general if indeed a struct type will all fields with the "zero" value is actually a valid value.
So we should probably have a common interface/helper methods for reading map, linked_map, double_map state
cli/src/base/ApiCommandBase.ts
Outdated
| default: defaultValue ? entries.length < defaultValue.length : false | ||
| }); | ||
| const defaultEntryValue = defaultValue && defaultValue[entries.length]; | ||
| if (addAnother) entries.push(await this.promptForParam(subtype.type, subtype.name, defaultEntryValue)); |
There was a problem hiding this comment.
Its good defensive style to always use curly braces with if else statemetns
cli/src/base/ApiCommandBase.ts
Outdated
| typeDef.name = forcedName; | ||
| } | ||
|
|
||
| if (rawTypeDef.info === TypeDefInfo.Option) return await this.promptForOption(typeDef, defaultValue as Option<Codec>); |
There was a problem hiding this comment.
I highly recommend using curly braces to avoid future bugs when editing this code, or even using a switch statement if possible?
44f83f5 to
37266eb
Compare
|
Added fixes based on review comments. Introduced new The only minor difference is that instead of getters like |
|
When prompted for exact block I just pressed enter without entering a value. It wasn't clear to me what value was used. So it would be good to show what actual value will be used in the transaction. I see that happens for Similarly for entering an amount for stake amount: Last suggestion would be to add a final summary of the values that will be sent in the transaction and prompting user to confirm. I have to say creating the opening is really nice through the command line now, really nice job. |
|
Please include those UX/Feedback suggestions in upcoming cli PRs, |
Implements #599 - the functionality to create a working group opening and save it as a reusable draft.
Examples:
./cli/bin/run working-groups:createOpening --help./cli/bin/run working-groups:createOpening- create an opening from scratch (requires lead account to be selected viaaccount:choose). User will be asked to provide alladdWorkerOpeningextrinsic parameters along withhuman_readable_textparameters (based on schema), for which I created approperiateStructs to "simulate" identical behavior that is implemented when asking for normal struct parameters (likeOpeningPolicyCommitment) that may have nestedVec,Optionor otherStructs inside. Opening created this way can be saved as draft after for later reuse../cli/bin/run working-groups:createOpening -d- when providing-dor--useDraftflag without-n, the user is prompted to choose one of the previosly created drafts. When creating opening from draft, all the prompts will have default values equal to those provided when the draft was created, but all values can still be overriden along the way if needed../cli/bin/run working-groups:createOpening -d -n="Some draft name"- in this example the draft name is provided using-nor--draftNameflag (it's case insensitive)../cli/bin/run working-groups:createOpening -c- using-cor--createDraftOnlyflag allows creating an opening draft without executing the actual extrinsic. This flag can also be specified with-dflag to create a draft based on an existing draft, but it's exculsive with-s(described below)./cli/bin/run working-groups:createOpening -d -s- when-sor--skipPromptsflag is provided (which also requires-d), all the extrinsic parameters' prompts will be skipped and the extrinsic will be sent with the exact same parameters as provided in a draft. This basically equals to executing./cli/bin/run working-groups:createOpening -dand pressing[Enter]all the way until the extrinsic is sent (which would cause all prompts to "assume" the values provided as defaults). The-sflag is exclusive with-cfor obvious reasons.While implementing this functionality I was trying to do it in the most reusable way possible. Thanks to the fact that prompting for all (or almost all?) possible types of substrate arguments is now implemented (along with the functionality to fetch arguments' types based on extrinsic module and method), this can be easily re-used to handle input for any extrinsic. That will allow us to later implement commands like
api:extrinsic(similar to Pioneer'sExtrinsicstab) and greatly simplify the creation of future commands that will at least partially rely on extrinsics.Prompting for JSON values that are provided to the extrinsic as
Bytes, but "backed" by an existing schema (likehuman_readable_text) is also something that was implemented in a pretty reusable way. The only thing that's required in order to handle those correctly is creating approperiateStructs based on the schema. If needed in the future - some script may be created that will convert schemas intoStructs (it's a pretty mindless process)