Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update wait interface, Add FetchStakingOperation and ReloadStakingOperation #37

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

drohit-cb
Copy link
Contributor

@drohit-cb drohit-cb commented Sep 23, 2024

What changed? Why?

This PR attempts to expose some helper methods to deal with staking operations that were previously only accessible via a generic helper around waiting for staking operations to complete (Wait).

  1. FetchStakingOperation - a way to fetch a staking operation from backend given a network, address and staking operation id.
  2. ReloadStakingOperation - a way to reload an already existing staking operation with latest state from backend.

Qualified Impact

…n id, and make reload method public to reload a staking operation from backend
@cb-heimdall
Copy link

cb-heimdall commented Sep 23, 2024

✅ Heimdall Review Status

Requirement Status More Info
Reviews 2/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@@ -193,7 +193,7 @@ func (s *StakingOperation) GetSignedVoluntaryExitMessages() ([]string, error) {
return signedVoluntaryExitMessages, nil
}

func (c *Client) Wait(ctx context.Context, stakingOperation *StakingOperation, o ...WaitOption) (*StakingOperation, error) {
func (c *Client) Wait(ctx context.Context, stakingOperation *StakingOperation, o ...WaitOption) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Im okay with this change, but curious as to why?

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 Wait interface attempts to relieve control back to user when the staking operation has terminated along with an up-to-date staking operation object. The options are b/w returning back an updated object vs doing in-place.

Since we pass the staking operation by reference it's possible to do an in-place update. Returning back an explicit staking operation object in response didn't feel the right thing to do. Made it slightly more verbose that what I had imagined it to be.

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like Wait() should be a method on the StakingOperation struct in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

^ Ideally yes - but in the Go SDK all operations are mostly performed directly on the client directly. Doing on wait on staking operation would require access to the client to make backend calls but the SDK is not setup for that (I believe that is intentional)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the "Go" way since the actions are happening on the API (ie Client) not on the structs. Structs have functions for local changes, client has remote change mutations.

}

// FetchStakingOperation fetches a staking operation from the backend given a networkID, addressID, and stakingOperationID.
func (c *Client) FetchStakingOperation(ctx context.Context, networkID, addressID, stakingOperationID string) (*StakingOperation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the same name we use in other SDKs? I thought we included the word external for some reason? (since you can fetch a wallet based op that is slightly different?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In both node and ruby we seem to call it just fetch which takes an optional wallet id as input based on which GetExternalStakingOperation and GetStakingOperation is called.

Since Go SDK is purely external address based for now, I decided not to introduce the wallet id param and simply call GetExternalStakingOperation internally.

@drohit-cb drohit-cb merged commit 25b0cce into master Sep 24, 2024
5 checks passed
@drohit-cb drohit-cb deleted the general_interface_fixes branch September 24, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants