From d52a7c432afa5ea60a879a0f63c840d481c0b141 Mon Sep 17 00:00:00 2001 From: testinginprod <98415576+testinginprod@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:00:13 +0100 Subject: [PATCH] feat(core): add branch service (#18379) Co-authored-by: unknown unknown --- core/CHANGELOG.md | 2 ++ core/branch/branch.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 core/branch/branch.go diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 4098e12dac..3b80170d78 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. + ## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0) :::note diff --git a/core/branch/branch.go b/core/branch/branch.go new file mode 100644 index 0000000000..c5af0087fc --- /dev/null +++ b/core/branch/branch.go @@ -0,0 +1,19 @@ +// Package branch contains the core branch service interface. +package branch + +import "context" + +// Service is the branch service interface. It can be used to execute +// code paths in an isolated execution context that can be reverted. +// A revert typically means a rollback on events and state changes. +type Service interface { + // Execute executes the given function in an isolated context. If the + // `f` function returns an error, the execution is considered failed, + // and every change made affecting the execution context is rolled back. + // If the function returns nil, the execution is considered successful, and + // committed. + // The context.Context passed to the `f` function is a child of the context + // passed to the Execute function, and is what should be used with other + // core services in order to ensure the execution remains isolated. + Execute(ctx context.Context, f func(ctx context.Context) error) error +}