Skip to content

Chain config can have multiple functions and events. #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions api/ue/v1/types.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions proto/ue/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ message AccountId {

// MethodConfig defines the configuration for a method that can be used for cross-chain operations
message MethodConfig {
option (amino.name) = "ue/method_config";
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

string name = 1; // Name of the method
string selector = 2; // Selector is the method selector (first 4 bytes of the keccak256 hash of the method signature)
string event_topic = 3; // event_topic is the topic of the event emitted by the method
Expand Down
18 changes: 13 additions & 5 deletions x/ue/types/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ func (p ChainConfig) ValidateBasic() error {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "locker_contract_address cannot be empty")
}

// Validate fundsAddedEventTopic is non-empty
if len(p.FundsAddedEventTopic) == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "funds_added_event_topic cannot be empty")
}

// Ensure vm_type is within the known enum range
if p.VmType < 0 || int(p.VmType) > int(VM_TYPE_OTHER_VM) {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "invalid vm_type")
}

// Validate gateway_methods is not empty
if len(p.GatewayMethods) == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "gateway_methods cannot be empty")
}

// Validate each method in gateway_methods
for _, method := range p.GatewayMethods {
err := method.ValidateBasic()
if err != nil {
return errors.Wrapf(err, "invalid method in gateway_methods: %s", method.Name)
}
}

return nil
}
35 changes: 35 additions & 0 deletions x/ue/types/method_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package types

import (
"encoding/json"

"cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// Stringer method for Params.
func (p MethodConfig) String() string {
bz, err := json.Marshal(p)
if err != nil {
panic(err)
}

return string(bz)
}

// Validate does the sanity check on the params.
func (p MethodConfig) ValidateBasic() error {

// Validate method name, selector, and event topic are non-empty
if len(p.Name) == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "method name cannot be empty")
}
if len(p.Selector) == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "method selector cannot be empty")
}
if len(p.EventTopic) == 0 {
return errors.Wrap(sdkerrors.ErrInvalidRequest, "method event_topic cannot be empty")
}

return nil
}
2 changes: 1 addition & 1 deletion x/ue/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// DefaultParams returns default module parameters.
func DefaultParams() Params {
return Params{
Admin: "push10wqxnvqj9q56jtspzg3kcxsuju2ga3lrjcqurc", // added acc1 as default admin for now
Admin: "push1gjaw568e35hjc8udhat0xnsxxmkm2snrexxz20", // added acc1 as default admin for now
}
}

Expand Down
Loading
Loading