Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
PrathyushaLakkireddy committed Sep 20, 2024
1 parent bbb9818 commit f9ad6fe
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 201 deletions.
26 changes: 13 additions & 13 deletions relayer/availclient.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package relayer

import "github.com/vitwit/avail-da-module/types"
// import "github.com/vitwit/avail-da-module/types"

// AvailClient is the client that handles data submission
type AvailClient struct {
config types.AvailConfiguration
}
// // AvailClient is the client that handles data submission
// type AvailClient struct {
// config types.AvailConfiguration
// }

// NewAvailClient initializes a new AvailClient
func NewAvailClient(config types.AvailConfiguration) (*AvailClient, error) {
// api, err := gsrpc.NewSubstrateAPI(config.AppRpcURL)
// if err != nil {
// return nil, fmt.Errorf("cannot create api:%w", err)
// }
// // NewAvailClient initializes a new AvailClient
// func NewAvailClient(config types.AvailConfiguration) (*AvailClient, error) {
// // api, err := gsrpc.NewSubstrateAPI(config.AppRpcURL)
// // if err != nil {
// // return nil, fmt.Errorf("cannot create api:%w", err)
// // }

return &AvailClient{config: config}, nil
}
// return &AvailClient{config: config}, nil
// }
298 changes: 149 additions & 149 deletions relayer/client.go
Original file line number Diff line number Diff line change
@@ -1,151 +1,151 @@
package relayer

import (
"fmt"

cometrpc "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/go-bip39"
)

const (
defaultGasAdjustment = 1.0
defaultGasLimit = 300000
)

// var availdHomePath = xfilepath.JoinFromHome(xfilepath.Path("availsdk"))

func NewClientCtx(kr keyring.Keyring, c *cometrpc.HTTP, chainID string,
cdc codec.BinaryCodec, homepath string, fromAddress sdk.AccAddress,
) client.Context {
encodingConfig := MakeEncodingConfig()

broadcastMode := flags.BroadcastSync

return client.Context{}.
WithCodec(cdc.(codec.Codec)).
WithChainID(chainID).
WithFromAddress(fromAddress).
WithFromName("testkey").
WithKeyringDir(homepath).
WithBroadcastMode(broadcastMode).
WithTxConfig(authTx.NewTxConfig(cdc.(codec.Codec), authTx.DefaultSignModes)).
WithKeyring(kr).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithClient(c).WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithSkipConfirmation(true)
}

// NewFactory creates a new Factory.
func NewFactory(clientCtx client.Context) tx.Factory {
return tx.Factory{}.
WithChainID(clientCtx.ChainID).
WithKeybase(clientCtx.Keyring).
WithGas(defaultGasLimit).
WithGasAdjustment(defaultGasAdjustment).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
WithAccountRetriever(clientCtx.AccountRetriever).
WithTxConfig(clientCtx.TxConfig)
}

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig(modules ...module.AppModuleBasic) EncodingConfig {
aminoCodec := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
txCfg := authTx.NewTxConfig(codec, authTx.DefaultSignModes)

encCfg := EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: txCfg,
Amino: aminoCodec,
}

mb := module.NewBasicManager(modules...)

std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)
mb.RegisterInterfaces(encCfg.InterfaceRegistry)

return encCfg
}

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry codectypes.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// ImportMnemonic is to import existing account mnemonic in keyring
func ImportMnemonic(keyName, mnemonic, hdPath string, c client.Context) (*keyring.Record, error) {
info, err := AccountCreate(keyName, mnemonic, hdPath, c) // return account also
if err != nil {
return nil, err
}

return info, nil
}

// AccountCreate creates an account by name and mnemonic (optional) in the keyring.
func AccountCreate(accountName, mnemonic, _ string, c client.Context) (*keyring.Record, error) {
if mnemonic == "" {
entropySeed, err := bip39.NewEntropy(256)
if err != nil {
return nil, err
}
mnemonic, err = bip39.NewMnemonic(entropySeed)
if err != nil {
return nil, err
}
}

algos, _ := c.Keyring.SupportedAlgorithms()
algo, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), algos)
if err != nil {
return nil, err
}

path := hd.CreateHDPath(118, 0, 0).String()
// fmt.Println("pathhh......", path)

// record, str, err := c.Keyring.NewMnemonic("test_key1", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
// fmt.Println("recorddddd.......", err, str, record)

// k, _, err = kb.NewMnemonic("test", English, types.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1)
info, err := c.Keyring.NewAccount(accountName, mnemonic, keyring.DefaultBIP39Passphrase, path, algo)
fmt.Println("after creationnnn.........", info, err)
if err != nil {
return nil, err
}
// pk, err := info.GetPubKey()
// if err != nil {
// return nil, err
// }

// addr := sdk.AccAddress(pk.Address())
// fmt.Println("address hereee...", addr)

// aa, err := info.GetAddress()
// fmt.Println("here aa and err.......", aa, err)

// account := c.ToAccount(info)
// account.Mnemonic = mnemonic
return info, nil
}
// import (
// "fmt"

// cometrpc "github.com/cometbft/cometbft/rpc/client/http"
// "github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// "github.com/cosmos/cosmos-sdk/client/tx"
// "github.com/cosmos/cosmos-sdk/codec"
// codectypes "github.com/cosmos/cosmos-sdk/codec/types"
// "github.com/cosmos/cosmos-sdk/crypto/hd"
// "github.com/cosmos/cosmos-sdk/crypto/keyring"
// "github.com/cosmos/cosmos-sdk/std"
// sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/cosmos/cosmos-sdk/types/module"
// "github.com/cosmos/cosmos-sdk/types/tx/signing"
// authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
// authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
// "github.com/cosmos/go-bip39"
// )

// const (
// defaultGasAdjustment = 1.0
// defaultGasLimit = 300000
// )

// // var availdHomePath = xfilepath.JoinFromHome(xfilepath.Path("availsdk"))

// func NewClientCtx(kr keyring.Keyring, c *cometrpc.HTTP, chainID string,
// cdc codec.BinaryCodec, homepath string, fromAddress sdk.AccAddress,
// ) client.Context {
// encodingConfig := MakeEncodingConfig()

// broadcastMode := flags.BroadcastSync

// return client.Context{}.
// WithCodec(cdc.(codec.Codec)).
// WithChainID(chainID).
// WithFromAddress(fromAddress).
// WithFromName("testkey").
// WithKeyringDir(homepath).
// WithBroadcastMode(broadcastMode).
// WithTxConfig(authTx.NewTxConfig(cdc.(codec.Codec), authTx.DefaultSignModes)).
// WithKeyring(kr).
// WithAccountRetriever(authtypes.AccountRetriever{}).
// WithClient(c).WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
// WithSkipConfirmation(true)
// }

// // NewFactory creates a new Factory.
// func NewFactory(clientCtx client.Context) tx.Factory {
// return tx.Factory{}.
// WithChainID(clientCtx.ChainID).
// WithKeybase(clientCtx.Keyring).
// WithGas(defaultGasLimit).
// WithGasAdjustment(defaultGasAdjustment).
// WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
// WithAccountRetriever(clientCtx.AccountRetriever).
// WithTxConfig(clientCtx.TxConfig)
// }

// // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
// func MakeEncodingConfig(modules ...module.AppModuleBasic) EncodingConfig {
// aminoCodec := codec.NewLegacyAmino()
// interfaceRegistry := codectypes.NewInterfaceRegistry()
// codec := codec.NewProtoCodec(interfaceRegistry)
// txCfg := authTx.NewTxConfig(codec, authTx.DefaultSignModes)

// encCfg := EncodingConfig{
// InterfaceRegistry: interfaceRegistry,
// Codec: codec,
// TxConfig: txCfg,
// Amino: aminoCodec,
// }

// mb := module.NewBasicManager(modules...)

// std.RegisterLegacyAminoCodec(encCfg.Amino)
// std.RegisterInterfaces(encCfg.InterfaceRegistry)
// mb.RegisterLegacyAminoCodec(encCfg.Amino)
// mb.RegisterInterfaces(encCfg.InterfaceRegistry)

// return encCfg
// }

// // EncodingConfig specifies the concrete encoding types to use for a given app.
// // This is provided for compatibility between protobuf and amino implementations.
// type EncodingConfig struct {
// InterfaceRegistry codectypes.InterfaceRegistry
// Codec codec.Codec
// TxConfig client.TxConfig
// Amino *codec.LegacyAmino
// }

// // ImportMnemonic is to import existing account mnemonic in keyring
// func ImportMnemonic(keyName, mnemonic, hdPath string, c client.Context) (*keyring.Record, error) {
// info, err := AccountCreate(keyName, mnemonic, hdPath, c) // return account also
// if err != nil {
// return nil, err
// }

// return info, nil
// }

// // AccountCreate creates an account by name and mnemonic (optional) in the keyring.
// func AccountCreate(accountName, mnemonic, _ string, c client.Context) (*keyring.Record, error) {
// if mnemonic == "" {
// entropySeed, err := bip39.NewEntropy(256)
// if err != nil {
// return nil, err
// }
// mnemonic, err = bip39.NewMnemonic(entropySeed)
// if err != nil {
// return nil, err
// }
// }

// algos, _ := c.Keyring.SupportedAlgorithms()
// algo, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), algos)
// if err != nil {
// return nil, err
// }

// path := hd.CreateHDPath(118, 0, 0).String()
// // fmt.Println("pathhh......", path)

// // record, str, err := c.Keyring.NewMnemonic("test_key1", keyring.English, path, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
// // fmt.Println("recorddddd.......", err, str, record)

// // k, _, err = kb.NewMnemonic("test", English, types.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1)
// info, err := c.Keyring.NewAccount(accountName, mnemonic, keyring.DefaultBIP39Passphrase, path, algo)
// fmt.Println("after creationnnn.........", info, err)
// if err != nil {
// return nil, err
// }
// // pk, err := info.GetPubKey()
// // if err != nil {
// // return nil, err
// // }

// // addr := sdk.AccAddress(pk.Address())
// // fmt.Println("address hereee...", addr)

// // aa, err := info.GetAddress()
// // fmt.Println("here aa and err.......", aa, err)

// // account := c.ToAccount(info)
// // account.Mnemonic = mnemonic
// return info, nil
// }
File renamed without changes.
13 changes: 6 additions & 7 deletions relayer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ func (r *Relayer) Start() error {
case height := <-r.provenHeights:
r.updateHeight(height)
case <-timer.C:
// TODO: client update
}
}
}

// NotifyCommitHeight is called by the app to notify the relayer of the latest commit height
func (r *Relayer) NotifyCommitHeight(height int64) {
r.commitHeights <- height
}
// func (r *Relayer) NotifyCommitHeight(height int64) {
// r.commitHeights <- height
// }

// NotifyProvenHeight is called by the app to notify the relayer of the latest proven height
// i.e. the height of the highest incremental block that was proven to be posted to Avail.
func (r *Relayer) NotifyProvenHeight(height int64) {
r.provenHeights <- height
}
// func (r *Relayer) NotifyProvenHeight(height int64) {
// r.provenHeights <- height
// }

// updateHeight is called when the provenHeight has changed
func (r *Relayer) updateHeight(height int64) {
Expand Down
Loading

0 comments on commit f9ad6fe

Please sign in to comment.