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

chore: add common getter and setter to message types #3565

Closed
wants to merge 5 commits into from

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented May 7, 2023

Description

closes: #3604

support generic unmarshal and exec msg server methods like:


func unmarshalAndExec[T MsgType, U any](
	bc *RelayerContract,
	input []byte,
	msg T,
	callback func(context.Context, T) (U, error),
) error {
	if err := proto.Unmarshal(input, msg); err != nil {
		return fmt.Errorf("fail to Unmarshal %T", msg)
	}

	var anyMsg any = msg
	if clientMsg, ok := anyMsg.(ClientStateMsg); ok {
		clientState := new(tmtypes.ClientState)
		if err := proto.Unmarshal(clientMsg.GetClientState(), clientState); err != nil {
			return errors.New("fail to Unmarshal ClientState")
		}
		value, err := codectypes.NewAnyWithValue(clientState)
		if err != nil {
			return err
		}
		clientMsg.SetClientState(value)
	}

	return bc.stateDB.ExecuteNativeAction(func(ctx sdk.Context) error {
		_, err := callback(ctx, msg)
		return err
	})
}

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@charleenfei
Copy link
Contributor

Hi @mmsqe! thanks for this PR -- could we have a little bit more context on why you need the unmarshalAndExec method in the msg server?

@mmsqe
Copy link
Contributor Author

mmsqe commented May 10, 2023

Hi @mmsqe! thanks for this PR -- could we have a little bit more context on why you need the unmarshalAndExec method in the msg server?

Yes, I find it cleaner with the help of template function like in ethermint and relayer side.

@colin-axner
Copy link
Contributor

Hi @mmsqe, thanks for the contribution! It would help us if you could open an issue for these changes so we could have a discussion there on the context of these changes. Issue writeups are a valuable part of our engineering process as it allows us to gain context on the problem and determine if there's other parts of the codebase that could be improved with a similar solution. It's hard for us to determine whether a solution is sufficient without having a full understanding of the problem

@mmsqe mmsqe changed the title chore: add types for core message server chore: add common getter and setter to message types May 17, 2023
@mmsqe
Copy link
Contributor Author

mmsqe commented May 17, 2023

Hi @colin-axner, just added #3604, see if it's ok.

@damiannolan
Copy link
Contributor

temporarily closing this PR until more feedback is provided in #3604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add common getter and setter to message types
4 participants