forked from ondoprotocol/usdy-noble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: John Letey <[email protected]>
- Loading branch information
Showing
27 changed files
with
4,583 additions
and
1,981 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
go 1.21 | ||
go 1.22.2 | ||
|
||
toolchain go1.23.0 | ||
|
||
use ( | ||
. | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,84 @@ | ||
package simapp | ||
|
||
import ( | ||
"bytes" | ||
"crypto/rand" | ||
"encoding/json" | ||
"fmt" | ||
|
||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type ( | ||
// VoteExtensionHandler defines a dummy vote extension handler for SimApp. | ||
// | ||
// NOTE: This implementation is solely used for testing purposes. DO NOT use | ||
// in a production application! | ||
VoteExtensionHandler struct{} | ||
|
||
// VoteExtension defines the structure used to create a dummy vote extension. | ||
VoteExtension struct { | ||
Hash []byte | ||
Height int64 | ||
Data []byte | ||
} | ||
) | ||
|
||
func NewVoteExtensionHandler() *VoteExtensionHandler { | ||
return &VoteExtensionHandler{} | ||
} | ||
|
||
func (h *VoteExtensionHandler) SetHandlers(bApp *baseapp.BaseApp) { | ||
bApp.SetExtendVoteHandler(h.ExtendVote()) | ||
bApp.SetVerifyVoteExtensionHandler(h.VerifyVoteExtension()) | ||
} | ||
|
||
func (h *VoteExtensionHandler) ExtendVote() sdk.ExtendVoteHandler { | ||
return func(_ sdk.Context, req *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) { | ||
buf := make([]byte, 1024) | ||
|
||
_, err := rand.Read(buf) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to generate random vote extension data: %w", err) | ||
} | ||
|
||
ve := VoteExtension{ | ||
Hash: req.Hash, | ||
Height: req.Height, | ||
Data: buf, | ||
} | ||
|
||
bz, err := json.Marshal(ve) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to encode vote extension: %w", err) | ||
} | ||
|
||
return &abci.ExtendVoteResponse{VoteExtension: bz}, nil | ||
} | ||
} | ||
|
||
func (h *VoteExtensionHandler) VerifyVoteExtension() sdk.VerifyVoteExtensionHandler { | ||
return func(ctx sdk.Context, req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) { | ||
var ve VoteExtension | ||
|
||
if err := json.Unmarshal(req.VoteExtension, &ve); err != nil { | ||
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_REJECT}, nil | ||
} | ||
|
||
switch { | ||
case req.Height != ve.Height: | ||
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_REJECT}, nil | ||
|
||
case !bytes.Equal(req.Hash, ve.Hash): | ||
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_REJECT}, nil | ||
|
||
case len(ve.Data) != 1024: | ||
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_REJECT}, nil | ||
} | ||
|
||
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_ACCEPT}, nil | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,16 @@ | ||
package simapp | ||
|
||
import ( | ||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params" | ||
"github.com/cosmos/cosmos-sdk/std" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
) | ||
|
||
// MakeTestEncodingConfig creates an EncodingConfig for testing. This function | ||
// should be used only in tests or when creating a new app instance (NewApp*()). | ||
// App user shouldn't create new codecs - use the app.AppCodec instead. | ||
// [DEPRECATED] | ||
func MakeTestEncodingConfig() simappparams.EncodingConfig { | ||
encodingConfig := simappparams.MakeTestEncodingConfig() | ||
std.RegisterLegacyAminoCodec(encodingConfig.Amino) | ||
std.RegisterInterfaces(encodingConfig.InterfaceRegistry) | ||
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) | ||
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) | ||
return encodingConfig | ||
// 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 types.InterfaceRegistry | ||
Codec codec.Codec | ||
TxConfig client.TxConfig | ||
Amino *codec.LegacyAmino | ||
} |
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,21 @@ | ||
package simapp | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
) | ||
|
||
// GenesisState The genesis state of the blockchain is represented here as a map of raw json | ||
// messages key'd by a identifier string. | ||
// The identifier is used to determine which module genesis information belongs | ||
// to so it may be appropriately routed during init chain. | ||
// Within this application default genesis information is retrieved from | ||
// the ModuleBasicManager which populates json from each BasicModule | ||
// object provided to it during init. | ||
type GenesisState map[string]json.RawMessage | ||
|
||
// NewDefaultGenesisState generates the default state for the application. | ||
func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { | ||
return ModuleBasics.DefaultGenesis(cdc) | ||
} |
Oops, something went wrong.