-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove params from config and introduce app context (#1774)
- Loading branch information
Showing
20 changed files
with
362 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package appcontext | ||
|
||
import ( | ||
"github.com/zeta-chain/zetacore/common" | ||
"github.com/zeta-chain/zetacore/zetaclient/config" | ||
corecontext "github.com/zeta-chain/zetacore/zetaclient/core_context" | ||
) | ||
|
||
// AppContext contains global app structs like config, core context and logger | ||
type AppContext struct { | ||
coreContext *corecontext.ZetaCoreContext | ||
config *config.Config | ||
} | ||
|
||
// NewAppContext creates and returns new AppContext | ||
func NewAppContext( | ||
coreContext *corecontext.ZetaCoreContext, | ||
config *config.Config, | ||
) *AppContext { | ||
return &AppContext{ | ||
coreContext: coreContext, | ||
config: config, | ||
} | ||
} | ||
|
||
func (a *AppContext) Config() *config.Config { | ||
return a.config | ||
} | ||
|
||
func (a *AppContext) ZetaCoreContext() *corecontext.ZetaCoreContext { | ||
return a.coreContext | ||
} | ||
|
||
// GetBTCChainAndConfig returns btc chain and config if enabled | ||
func (a *AppContext) GetBTCChainAndConfig() (common.Chain, config.BTCConfig, bool) { | ||
btcConfig, configEnabled := a.Config().GetBTCConfig() | ||
btcChain, _, paramsEnabled := a.ZetaCoreContext().GetBTCChainParams() | ||
|
||
if !configEnabled || !paramsEnabled { | ||
return common.Chain{}, config.BTCConfig{}, false | ||
} | ||
|
||
return btcChain, btcConfig, true | ||
} |
Oops, something went wrong.