diff --git a/app/app.go b/app/app.go index a1a44d15f9..077483dd05 100644 --- a/app/app.go +++ b/app/app.go @@ -498,6 +498,7 @@ func NewEthermintApp( appCodec, keys[bitcoincommitertypes.MemStoreKey], app.GetSubspace(bitcoincommitertypes.ModuleName), + homePath, ) /**** Module Options ****/ diff --git a/testutil/keeper/bitcoincommiter.go b/testutil/keeper/bitcoincommiter.go index b1f0ee6dbb..b5ad4203e8 100644 --- a/testutil/keeper/bitcoincommiter.go +++ b/testutil/keeper/bitcoincommiter.go @@ -40,6 +40,7 @@ func BitcoincommiterKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { cdc, memStoreKey, paramsSubspace, + "", ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/bitcoincommiter/keeper/config.go b/x/bitcoincommiter/keeper/config.go new file mode 100644 index 0000000000..83c9470b36 --- /dev/null +++ b/x/bitcoincommiter/keeper/config.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "log" + "os" + + "gopkg.in/yaml.v3" +) + +type BITCOINConfig struct { + // NetworkName defines the bitcoin network name + NetworkName string `yaml:"network-name"` + RPCHost string `yaml:"rpc-host"` + RPCPort string `yaml:"rpc-port"` + RPCUser string `yaml:"rpc-user"` + RPCPass string `yaml:"rpc-pass"` + WalletName string `yaml:"wallet-name"` + // Destination defines the taproot transaction destination address + Destination string `yaml:"destination"` +} + +const ( + BitcoinRPCConfigFileName = "bitcoin.yaml" +) + +func DefaultBITCOINConfig(homePath string) (*BITCOINConfig, error) { + data, err := os.ReadFile(homePath + "/" + BitcoinRPCConfigFileName) + if err != nil { + log.Fatalf("can not read rpc config file: %v", err) + } + config := BITCOINConfig{} + err = yaml.Unmarshal(data, &config) + return &config, err +} diff --git a/x/bitcoincommiter/keeper/connfig_test.go b/x/bitcoincommiter/keeper/connfig_test.go new file mode 100644 index 0000000000..5a3687e796 --- /dev/null +++ b/x/bitcoincommiter/keeper/connfig_test.go @@ -0,0 +1,19 @@ +package keeper_test + +import ( + "testing" + + "github.com/evmos/ethermint/x/bitcoincommiter/keeper" + "github.com/stretchr/testify/require" +) + +func TestConfig(t *testing.T) { + config, _ := keeper.DefaultBITCOINConfig("../test/source") + require.Equal(t, "signet", config.NetworkName) + require.Equal(t, "localhost", config.RPCHost) + require.Equal(t, "8332", config.RPCPort) + require.Equal(t, "b2node", config.RPCUser) + require.Equal(t, "b2node", config.RPCPass) + require.Equal(t, "b2node", config.WalletName) + require.Equal(t, "tb1qgm39cu009lyvq93afx47pp4h9wxq5x92lxxgnz", config.Destination) +} diff --git a/x/bitcoincommiter/keeper/keeper.go b/x/bitcoincommiter/keeper/keeper.go index c206b5d43b..b262f4e243 100644 --- a/x/bitcoincommiter/keeper/keeper.go +++ b/x/bitcoincommiter/keeper/keeper.go @@ -7,9 +7,8 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/tendermint/tendermint/libs/log" - "github.com/evmos/ethermint/x/bitcoincommiter/types" + "github.com/tendermint/tendermint/libs/log" ) type ( @@ -17,6 +16,7 @@ type ( cdc codec.BinaryCodec memKey storetypes.StoreKey paramstore paramtypes.Subspace + config *BITCOINConfig } ) @@ -24,16 +24,14 @@ func NewKeeper( cdc codec.BinaryCodec, memKey storetypes.StoreKey, ps paramtypes.Subspace, + homePath string, ) *Keeper { - // set KeyTable if it has not already been set - if !ps.HasKeyTable() { - ps = ps.WithKeyTable(types.ParamKeyTable()) - } - + bitcoinConfig, _ := DefaultBITCOINConfig(homePath) return &Keeper{ cdc: cdc, memKey: memKey, paramstore: ps, + config: bitcoinConfig, } } diff --git a/x/bitcoincommiter/keeper/keeper_test.go b/x/bitcoincommiter/keeper/keeper_test.go new file mode 100644 index 0000000000..db72d21bbe --- /dev/null +++ b/x/bitcoincommiter/keeper/keeper_test.go @@ -0,0 +1,31 @@ +package keeper + +import ( + "testing" + + codecc "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + bitcoincommitertypes "github.com/evmos/ethermint/x/bitcoincommiter/types" + "github.com/stretchr/testify/require" +) + +func TestInitKeeper(t *testing.T) { + amino := codecc.NewLegacyAmino() + interfaceRegistry := codectypes.NewInterfaceRegistry() + marshaler := codecc.NewProtoCodec(interfaceRegistry) + key := sdk.NewKVStoreKey("key") + tkey := sdk.NewTransientStoreKey("tkey") + paramsKeeper := paramskeeper.NewKeeper(marshaler, amino, key, tkey) + space := paramsKeeper.Subspace(bitcoincommitertypes.ModuleName) + commiterKey := sdk.NewKVStoreKey(bitcoincommitertypes.ModuleName) + keeper := NewKeeper(marshaler, commiterKey, space, "../test/source") + require.Equal(t, "signet", keeper.config.NetworkName) + require.Equal(t, "localhost", keeper.config.RPCHost) + require.Equal(t, "8332", keeper.config.RPCPort) + require.Equal(t, "b2node", keeper.config.RPCUser) + require.Equal(t, "b2node", keeper.config.RPCPass) + require.Equal(t, "b2node", keeper.config.WalletName) + require.Equal(t, "tb1qgm39cu009lyvq93afx47pp4h9wxq5x92lxxgnz", keeper.config.Destination) +} diff --git a/x/bitcoincommiter/test/source/bitcoin.yaml b/x/bitcoincommiter/test/source/bitcoin.yaml new file mode 100644 index 0000000000..67b36d8426 --- /dev/null +++ b/x/bitcoincommiter/test/source/bitcoin.yaml @@ -0,0 +1,7 @@ +network-name: signet +rpc-host: localhost +rpc-port: 8332 +rpc-user: b2node +rpc-pass: b2node +wallet-name: b2node +destination: tb1qgm39cu009lyvq93afx47pp4h9wxq5x92lxxgnz