-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d28deaf
commit 5d555ee
Showing
30 changed files
with
1,224 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package swap |
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,77 @@ | ||
// nolint | ||
// autogenerated code using github.com/rigelrozanski/multitool | ||
// aliases generated for the following subdirectories: | ||
// ALIASGEN: github.com/sentinel-official/hub/x/swap/types | ||
// ALIASGEN: github.com/sentinel-official/hub/x/swap/keeper | ||
// ALIASGEN: github.com/sentinel-official/hub/x/swap/querier | ||
package swap | ||
|
||
import ( | ||
"github.com/sentinel-official/hub/x/swap/keeper" | ||
"github.com/sentinel-official/hub/x/swap/querier" | ||
"github.com/sentinel-official/hub/x/swap/types" | ||
) | ||
|
||
const ( | ||
EthereumHashLength = types.EthereumHashLength | ||
AttributeKeyTxHash = types.AttributeKeyTxHash | ||
AttributeKeyAddress = types.AttributeKeyAddress | ||
AttributeKeyAmount = types.AttributeKeyAmount | ||
ModuleName = types.ModuleName | ||
QuerierRoute = types.QuerierRoute | ||
DefaultParamspace = types.DefaultParamspace | ||
DefaultSwapEnabled = types.DefaultSwapEnabled | ||
DefaultSwapDenom = types.DefaultSwapDenom | ||
QuerySwap = types.QuerySwap | ||
QuerySwaps = types.QuerySwaps | ||
) | ||
|
||
var ( | ||
// functions aliases | ||
RegisterCodec = types.RegisterCodec | ||
BytesToHash = types.BytesToHash | ||
NewGenesisState = types.NewGenesisState | ||
DefaultGenesisState = types.DefaultGenesisState | ||
SwapKey = types.SwapKey | ||
NewMsgSwap = types.NewMsgSwap | ||
NewParams = types.NewParams | ||
DefaultParams = types.DefaultParams | ||
ParamsKeyTable = types.ParamsKeyTable | ||
NewQuerySwapParams = types.NewQuerySwapParams | ||
NewQuerySwapsParams = types.NewQuerySwapsParams | ||
NewKeeper = keeper.NewKeeper | ||
NewQuerier = querier.NewQuerier | ||
|
||
// variable aliases | ||
ModuleCdc = types.ModuleCdc | ||
ErrorMarshal = types.ErrorMarshal | ||
ErrorUnmarshal = types.ErrorUnmarshal | ||
ErrorUnknownMsgType = types.ErrorUnknownMsgType | ||
ErrorUnknownQueryType = types.ErrorUnknownQueryType | ||
ErrorInvalidField = types.ErrorInvalidField | ||
ErrorSwapIsDisabled = types.ErrorSwapIsDisabled | ||
ErrorUnauthorized = types.ErrorUnauthorized | ||
ErrorDuplicateSwap = types.ErrorDuplicateSwap | ||
EventTypeSet = types.EventTypeSet | ||
ParamsSubspace = types.ParamsSubspace | ||
RouterKey = types.RouterKey | ||
StoreKey = types.StoreKey | ||
EventModuleName = types.EventModuleName | ||
SwapKeyPrefix = types.SwapKeyPrefix | ||
DefaultApproveBy = types.DefaultApproveBy | ||
KeySwapEnabled = types.KeySwapEnabled | ||
KeySwapDenom = types.KeySwapDenom | ||
KeyApproveBy = types.KeyApproveBy | ||
) | ||
|
||
type ( | ||
EthereumHash = types.EthereumHash | ||
GenesisState = types.GenesisState | ||
MsgSwap = types.MsgSwap | ||
Params = types.Params | ||
QuerySwapParams = types.QuerySwapParams | ||
QuerySwapsParams = types.QuerySwapsParams | ||
Swap = types.Swap | ||
Swaps = types.Swaps | ||
Keeper = keeper.Keeper | ||
) |
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,38 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetQueryCmd(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "swap", | ||
Short: "Querying commands for the swap module", | ||
} | ||
|
||
cmd.AddCommand( | ||
flags.GetCommands( | ||
querySwap(cdc), | ||
querySwaps(cdc), | ||
)..., | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func GetTxCmd(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "swap", | ||
Short: "Swap module sub-commands", | ||
} | ||
|
||
cmd.AddCommand( | ||
flags.PostCommands( | ||
txSwap(cdc), | ||
)..., | ||
) | ||
|
||
return cmd | ||
} |
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,6 @@ | ||
package cli | ||
|
||
const ( | ||
flagSkip = "skip" | ||
flagLimit = "limit" | ||
) |
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,73 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/sentinel-official/hub/x/swap/client/common" | ||
"github.com/sentinel-official/hub/x/swap/types" | ||
) | ||
|
||
func querySwap(cdc *codec.Codec) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "swap", | ||
Short: "Query a swap", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.NewCLIContext().WithCodec(cdc) | ||
|
||
txHash, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
swap, err := common.QuerySwap(ctx, types.BytesToHash(txHash)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(swap) | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func querySwaps(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "swaps", | ||
Short: "Query swaps", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := context.NewCLIContext().WithCodec(cdc) | ||
|
||
skip, err := cmd.Flags().GetInt(flagSkip) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
limit, err := cmd.Flags().GetInt(flagLimit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
swaps, err := common.QuerySwaps(ctx, skip, limit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, swap := range swaps { | ||
fmt.Printf("%s\n\n", swap) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().Int(flagSkip, 0, "skip") | ||
cmd.Flags().Int(flagLimit, 25, "limit") | ||
|
||
return cmd | ||
} |
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,53 @@ | ||
package cli | ||
|
||
import ( | ||
"bufio" | ||
"encoding/hex" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth" | ||
"github.com/cosmos/cosmos-sdk/x/auth/client/utils" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/sentinel-official/hub/x/swap/types" | ||
) | ||
|
||
func txSwap(cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "swap [txHash] [receiver] [amount]", | ||
Short: "Swap from SENT to DVPN", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
buffer := bufio.NewReader(cmd.InOrStdin()) | ||
txb := auth.NewTxBuilderFromCLI(buffer).WithTxEncoder(utils.GetTxEncoder(cdc)) | ||
ctx := context.NewCLIContextWithInput(buffer).WithCodec(cdc) | ||
|
||
txHash, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
receiver, err := sdk.AccAddressFromBech32(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
amount, err := strconv.ParseInt(args[2], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgSwap(ctx.FromAddress, types.BytesToHash(txHash), receiver, sdk.NewInt(amount)) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return utils.GenerateOrBroadcastMsgs(ctx, txb, []sdk.Msg{msg}) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,57 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
|
||
"github.com/sentinel-official/hub/x/swap/types" | ||
) | ||
|
||
func QuerySwap(ctx context.CLIContext, txHash types.EthereumHash) (*types.Swap, error) { | ||
params := types.NewQuerySwapParams(txHash) | ||
bytes, err := ctx.Codec.MarshalJSON(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
path := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySwap) | ||
res, _, err := ctx.QueryWithData(path, bytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if res == nil { | ||
return nil, fmt.Errorf("no swap found") | ||
} | ||
|
||
var swap types.Swap | ||
if err = ctx.Codec.UnmarshalJSON(res, &swap); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &swap, nil | ||
} | ||
|
||
func QuerySwaps(ctx context.CLIContext, skip, limit int) (types.Swaps, error) { | ||
params := types.NewQuerySwapsParams(skip, limit) | ||
bytes, err := ctx.Codec.MarshalJSON(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
path := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySwaps) | ||
res, _, err := ctx.QueryWithData(path, bytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if res == nil { | ||
return nil, fmt.Errorf("no swaps found") | ||
} | ||
|
||
var swaps types.Swaps | ||
if err = ctx.Codec.UnmarshalJSON(res, &swaps); err != nil { | ||
return nil, err | ||
} | ||
|
||
return swaps, nil | ||
} |
Oops, something went wrong.