mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 18:31:41 +00:00
Executable
+46
@@ -0,0 +1,46 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
var (
|
||||
amino = codec.NewLegacyAmino()
|
||||
AminoCdc = codec.NewAminoCodec(amino)
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterLegacyAminoCodec(amino)
|
||||
cryptocodec.RegisterCrypto(amino)
|
||||
sdk.RegisterLegacyAminoCodec(amino)
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec
|
||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterConcrete(&MsgRegisterDEXAccount{}, ModuleName+"/MsgRegisterDEXAccount", nil)
|
||||
cdc.RegisterConcrete(&MsgExecuteSwap{}, ModuleName+"/MsgExecuteSwap", nil)
|
||||
cdc.RegisterConcrete(&MsgProvideLiquidity{}, ModuleName+"/MsgProvideLiquidity", nil)
|
||||
cdc.RegisterConcrete(&MsgRemoveLiquidity{}, ModuleName+"/MsgRemoveLiquidity", nil)
|
||||
cdc.RegisterConcrete(&MsgCreateLimitOrder{}, ModuleName+"/MsgCreateLimitOrder", nil)
|
||||
cdc.RegisterConcrete(&MsgCancelOrder{}, ModuleName+"/MsgCancelOrder", nil)
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers the x/dex interfaces types with a given
|
||||
// interface registry
|
||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
registry.RegisterImplementations(
|
||||
(*sdk.Msg)(nil),
|
||||
&MsgRegisterDEXAccount{},
|
||||
&MsgExecuteSwap{},
|
||||
&MsgProvideLiquidity{},
|
||||
&MsgRemoveLiquidity{},
|
||||
&MsgCreateLimitOrder{},
|
||||
&MsgCancelOrder{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package types
|
||||
|
||||
// DIDAccounts wraps a slice of account IDs for use with collections
|
||||
type DIDAccounts struct {
|
||||
Accounts []string `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"`
|
||||
}
|
||||
|
||||
// ProtoMessage implements proto.Message
|
||||
func (DIDAccounts) ProtoMessage() {}
|
||||
|
||||
// Reset implements proto.Message
|
||||
func (m *DIDAccounts) Reset() {
|
||||
*m = DIDAccounts{}
|
||||
}
|
||||
|
||||
// String implements proto.Message
|
||||
func (m DIDAccounts) String() string {
|
||||
return m.Accounts[0] // Simple string representation
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
package types
|
||||
|
||||
import sdkerrors "cosmossdk.io/errors"
|
||||
|
||||
var (
|
||||
ErrInvalidGenesisState = sdkerrors.Register(ModuleName, 1, "invalid genesis state")
|
||||
ErrInvalidActivityType = sdkerrors.Register(ModuleName, 2, "invalid activity type")
|
||||
ErrInvalidDID = sdkerrors.Register(ModuleName, 3, "invalid DID")
|
||||
ErrInvalidConnectionID = sdkerrors.Register(ModuleName, 4, "invalid connection ID")
|
||||
ErrAccountNotFound = sdkerrors.Register(ModuleName, 5, "DEX account not found")
|
||||
ErrAccountNotActive = sdkerrors.Register(ModuleName, 6, "DEX account not active")
|
||||
ErrUnauthorized = sdkerrors.Register(ModuleName, 7, "unauthorized")
|
||||
ErrInvalidSwapParams = sdkerrors.Register(ModuleName, 8, "invalid swap parameters")
|
||||
ErrInvalidLiquidityParams = sdkerrors.Register(ModuleName, 9, "invalid liquidity parameters")
|
||||
ErrInvalidOrderParams = sdkerrors.Register(ModuleName, 10, "invalid order parameters")
|
||||
ErrICAOperationFailed = sdkerrors.Register(ModuleName, 11, "ICA operation failed")
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
Executable
+101
@@ -0,0 +1,101 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
|
||||
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
|
||||
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
|
||||
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
|
||||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
|
||||
|
||||
didtypes "github.com/sonr-io/sonr/x/did/types"
|
||||
)
|
||||
|
||||
// AccountKeeper defines the expected account keeper
|
||||
type AccountKeeper interface {
|
||||
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
|
||||
SetAccount(ctx context.Context, acc sdk.AccountI)
|
||||
GetModuleAddress(name string) sdk.AccAddress
|
||||
GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI
|
||||
}
|
||||
|
||||
// BankKeeper defines the expected bank keeper
|
||||
type BankKeeper interface {
|
||||
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
|
||||
SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
|
||||
}
|
||||
|
||||
// ICAControllerKeeper defines the expected ICA controller keeper
|
||||
type ICAControllerKeeper interface {
|
||||
// RegisterInterchainAccount registers an ICA account
|
||||
RegisterInterchainAccount(
|
||||
ctx sdk.Context,
|
||||
connectionID, owner, version string,
|
||||
) error
|
||||
|
||||
// SendTx sends a transaction to the ICA host
|
||||
SendTx(
|
||||
ctx sdk.Context,
|
||||
chanCap *capabilitytypes.Capability,
|
||||
connectionID, portID string,
|
||||
packetData icatypes.InterchainAccountPacketData,
|
||||
timeoutTimestamp uint64,
|
||||
) (uint64, error)
|
||||
|
||||
// GetActiveChannelID gets the active channel for an ICA
|
||||
GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool)
|
||||
|
||||
// GetInterchainAccountAddress gets the ICA address on the host chain
|
||||
GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool)
|
||||
}
|
||||
|
||||
// ConnectionKeeper defines the expected connection keeper
|
||||
type ConnectionKeeper interface {
|
||||
GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, bool)
|
||||
}
|
||||
|
||||
// ChannelKeeper defines the expected channel keeper
|
||||
type ChannelKeeper interface {
|
||||
GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool)
|
||||
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
|
||||
SendPacket(
|
||||
ctx sdk.Context,
|
||||
chanCap *capabilitytypes.Capability,
|
||||
sourcePort string,
|
||||
sourceChannel string,
|
||||
timeoutHeight clienttypes.Height,
|
||||
timeoutTimestamp uint64,
|
||||
data []byte,
|
||||
) (uint64, error)
|
||||
}
|
||||
|
||||
// PortKeeper defines the expected port keeper
|
||||
type PortKeeper interface {
|
||||
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
|
||||
}
|
||||
|
||||
// ScopedKeeper defines the expected scoped keeper
|
||||
type ScopedKeeper interface {
|
||||
GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool)
|
||||
AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool
|
||||
ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error
|
||||
}
|
||||
|
||||
// DIDKeeper defines the expected DID keeper
|
||||
type DIDKeeper interface {
|
||||
// GetDIDDocument retrieves a DID document
|
||||
GetDIDDocument(ctx context.Context, did string) (*didtypes.DIDDocument, error)
|
||||
}
|
||||
|
||||
// UCANKeeper defines the expected UCAN keeper (placeholder)
|
||||
type UCANKeeper interface {
|
||||
// ValidateCapability validates a UCAN token for a specific capability
|
||||
ValidateCapability(ctx sdk.Context, token string, resource string, ability string) error
|
||||
}
|
||||
|
||||
// DWNKeeper defines the expected DWN keeper
|
||||
type DWNKeeper interface {
|
||||
// Placeholder interface - will be implemented when DWN methods are available
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
package types
|
||||
|
||||
import host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
|
||||
|
||||
// DefaultGenesisState returns the default module GenesisState.
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
PortId: PortID,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGenesisState initializes and returns a new GenesisState.
|
||||
func NewGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
PortId: PortID,
|
||||
}
|
||||
}
|
||||
|
||||
// Validate performs basic validation of the GenesisState.
|
||||
func (gs *GenesisState) Validate() error {
|
||||
if err := host.PortIdentifierValidator(gs.PortId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// UCANCapability represents a UCAN capability for DEX operations
|
||||
type UCANCapability struct {
|
||||
// Resource being accessed (e.g., "dex:swap", "dex:liquidity")
|
||||
Resource string `json:"resource"`
|
||||
|
||||
// Ability being granted (e.g., "execute", "read", "write")
|
||||
Ability string `json:"ability"`
|
||||
|
||||
// Additional constraints (e.g., max amount, specific pools)
|
||||
Constraints map[string]any `json:"constraints,omitempty"`
|
||||
|
||||
// Expiration time
|
||||
Expiration time.Time `json:"expiration"`
|
||||
}
|
||||
|
||||
// DWNRecord represents a record stored in DWN
|
||||
type DWNRecord struct {
|
||||
// Record ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// DID owner
|
||||
DID string `json:"did"`
|
||||
|
||||
// Record type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Record data
|
||||
Data any `json:"data"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
|
||||
// Metadata
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
// ModuleName defines the name of module.
|
||||
ModuleName = "dex"
|
||||
|
||||
// PortID defines the port ID that module module binds to.
|
||||
PortID = ModuleName
|
||||
|
||||
// Version defines the current version the IBC module supports
|
||||
Version = ModuleName + "-1"
|
||||
|
||||
// StoreKey is the store key string for the module.
|
||||
StoreKey = ModuleName
|
||||
|
||||
// RouterKey is the message route for the module.
|
||||
RouterKey = ModuleName
|
||||
|
||||
// QuerierRoute is the querier route for the module.
|
||||
QuerierRoute = ModuleName
|
||||
)
|
||||
|
||||
// Event types
|
||||
const (
|
||||
EventTypeICAPacketAcknowledged = "ica_packet_acknowledged"
|
||||
EventTypeICAPacketTimeout = "ica_packet_timeout"
|
||||
EventTypeDEXAccountRegistered = "dex_account_registered"
|
||||
EventTypeSwapExecuted = "swap_executed"
|
||||
EventTypeLiquidityProvided = "liquidity_provided"
|
||||
EventTypeLiquidityRemoved = "liquidity_removed"
|
||||
EventTypeOrderCreated = "order_created"
|
||||
EventTypeOrderCancelled = "order_cancelled"
|
||||
EventTypeDIDActivity = "did_activity"
|
||||
)
|
||||
Executable
+122
@@ -0,0 +1,122 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
|
||||
// ValidateBasic performs basic validation of MsgRegisterDEXAccount
|
||||
func (msg *MsgRegisterDEXAccount) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation of MsgExecuteSwap
|
||||
func (msg *MsgExecuteSwap) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
if msg.SourceDenom == "" || msg.TargetDenom == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "denoms cannot be empty")
|
||||
}
|
||||
if msg.Amount.IsNil() || !msg.Amount.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive")
|
||||
}
|
||||
if msg.MinAmountOut.IsNil() || !msg.MinAmountOut.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "min amount out must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation of MsgProvideLiquidity
|
||||
func (msg *MsgProvideLiquidity) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
if msg.PoolId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "pool ID cannot be empty")
|
||||
}
|
||||
if len(msg.Assets) == 0 {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "assets cannot be empty")
|
||||
}
|
||||
for _, asset := range msg.Assets {
|
||||
if !asset.IsValid() || !asset.IsPositive() {
|
||||
return errorsmod.Wrap(
|
||||
sdkerrors.ErrInvalidRequest,
|
||||
fmt.Sprintf("invalid asset amount: %s", asset),
|
||||
)
|
||||
}
|
||||
}
|
||||
if msg.MinShares.IsNil() || !msg.MinShares.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "min shares must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation of MsgRemoveLiquidity
|
||||
func (msg *MsgRemoveLiquidity) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
if msg.PoolId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "pool ID cannot be empty")
|
||||
}
|
||||
if msg.Shares.IsNil() || !msg.Shares.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "shares must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation of MsgCreateLimitOrder
|
||||
func (msg *MsgCreateLimitOrder) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
if msg.SellDenom == "" || msg.BuyDenom == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "denoms cannot be empty")
|
||||
}
|
||||
if msg.Amount.IsNil() || !msg.Amount.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "amount must be positive")
|
||||
}
|
||||
if msg.Price.IsNil() || !msg.Price.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "price must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation of MsgCancelOrder
|
||||
func (msg *MsgCancelOrder) ValidateBasic() error {
|
||||
if msg.Did == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "DID cannot be empty")
|
||||
}
|
||||
if msg.ConnectionId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "connection ID cannot be empty")
|
||||
}
|
||||
if msg.OrderId == "" {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "order ID cannot be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,919 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: dex/v1/query.proto
|
||||
|
||||
/*
|
||||
Package types is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = descriptor.ForMessage
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryParamsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryParamsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.Params(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAccountRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
msg, err := client.Account(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Account_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAccountRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
msg, err := server.Account(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_Accounts_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||
)
|
||||
|
||||
func request_Query_Accounts_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAccountsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Accounts_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Accounts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Accounts_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAccountsRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Accounts_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Accounts(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_Balance_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0, "connection_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryBalanceRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Balance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryBalanceRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Balance(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_Pool_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryPoolRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["pool_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id")
|
||||
}
|
||||
|
||||
protoReq.PoolId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err)
|
||||
}
|
||||
|
||||
msg, err := client.Pool(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Pool_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryPoolRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["pool_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "pool_id")
|
||||
}
|
||||
|
||||
protoReq.PoolId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "pool_id", err)
|
||||
}
|
||||
|
||||
msg, err := server.Pool(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_Orders_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0, "connection_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_Query_Orders_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryOrdersRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Orders_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Orders(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Orders_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryOrdersRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["connection_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "connection_id")
|
||||
}
|
||||
|
||||
protoReq.ConnectionId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "connection_id", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Orders_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Orders(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_History_0 = &utilities.DoubleArray{Encoding: map[string]int{"did": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||
)
|
||||
|
||||
func request_Query_History_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryHistoryRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_History_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.History(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_History_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryHistoryRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["did"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "did")
|
||||
}
|
||||
|
||||
protoReq.Did, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "did", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_History_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.History(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
|
||||
// UnaryRPC :call QueryServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
|
||||
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Account_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Account_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Account_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Accounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Accounts_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Accounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Balance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Balance_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Balance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Pool_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Pool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Orders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Orders_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Orders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_History_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_History_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_History_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterQueryHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterQueryHandler registers the http handlers for service Query to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerClient registers the http handlers for service Query
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "QueryClient" to call the correct interceptors.
|
||||
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Account_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Account_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Account_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Accounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Accounts_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Accounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Balance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Balance_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Balance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Pool_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Pool_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Orders_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Orders_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Orders_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_History_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_History_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_History_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sonr", "dex", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Account_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sonr", "dex", "v1", "account", "did", "connection_id"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Accounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sonr", "dex", "v1", "accounts", "did"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Balance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sonr", "dex", "v1", "balance", "did", "connection_id"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Pool_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sonr", "dex", "v1", "pool", "connection_id", "pool_id"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Orders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sonr", "dex", "v1", "orders", "did", "connection_id"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_History_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sonr", "dex", "v1", "history", "did"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_Params_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Account_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Accounts_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Balance_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Pool_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Orders_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_History_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,370 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sonr-io/sonr/crypto/ucan"
|
||||
)
|
||||
|
||||
// UCAN Action Constants for DEX operations
|
||||
const (
|
||||
// Core Trading Actions
|
||||
UCANSwap = "swap" // Execute token swap
|
||||
UCANExecuteSwap = "execute-swap" // Execute a specific swap
|
||||
UCANLimitOrder = "limit-order" // Place limit order
|
||||
UCANMarketOrder = "market-order" // Place market order
|
||||
UCANCancelOrder = "cancel-order" // Cancel order
|
||||
UCANCancelAllOrders = "cancel-all-orders" // Cancel all orders
|
||||
|
||||
// Liquidity Actions
|
||||
UCANProvideLiquidity = "provide-liquidity" // Add liquidity to pool
|
||||
UCANRemoveLiquidity = "remove-liquidity" // Remove liquidity from pool
|
||||
UCANCreatePool = "create-pool" // Create new liquidity pool
|
||||
|
||||
// Portfolio Management Actions
|
||||
UCANRegisterAccount = "register-account" // Register trading account
|
||||
UCANUpdatePortfolio = "update-portfolio" // Update portfolio settings
|
||||
UCANWithdraw = "withdraw" // Withdraw funds
|
||||
UCANDeposit = "deposit" // Deposit funds
|
||||
|
||||
// Query Actions
|
||||
UCANQueryPool = "query-pool" // Query pool details
|
||||
UCANQueryOrders = "query-orders" // Query orders
|
||||
UCANQueryPortfolio = "query-portfolio" // Query portfolio
|
||||
|
||||
// Standard CRUD Actions (for compatibility)
|
||||
UCANCreate = "create" // Create resource
|
||||
UCANRead = "read" // Read resource
|
||||
UCANUpdate = "update" // Update resource
|
||||
UCANDelete = "delete" // Delete resource
|
||||
UCANAdmin = "admin" // Administrative actions
|
||||
UCANAll = "*" // Wildcard for all actions
|
||||
)
|
||||
|
||||
// DEXOperation represents the type of DEX operation being performed
|
||||
type DEXOperation string
|
||||
|
||||
const (
|
||||
DEXOpSwap DEXOperation = "swap"
|
||||
DEXOpExecuteSwap DEXOperation = "execute_swap"
|
||||
DEXOpLimitOrder DEXOperation = "limit_order"
|
||||
DEXOpMarketOrder DEXOperation = "market_order"
|
||||
DEXOpCancelOrder DEXOperation = "cancel_order"
|
||||
DEXOpCancelAllOrders DEXOperation = "cancel_all_orders"
|
||||
DEXOpProvideLiquidity DEXOperation = "provide_liquidity"
|
||||
DEXOpRemoveLiquidity DEXOperation = "remove_liquidity"
|
||||
DEXOpCreatePool DEXOperation = "create_pool"
|
||||
DEXOpRegisterAccount DEXOperation = "register_account"
|
||||
DEXOpUpdatePortfolio DEXOperation = "update_portfolio"
|
||||
DEXOpWithdraw DEXOperation = "withdraw"
|
||||
DEXOpDeposit DEXOperation = "deposit"
|
||||
DEXOpQueryPool DEXOperation = "query_pool"
|
||||
DEXOpQueryOrders DEXOperation = "query_orders"
|
||||
DEXOpQueryPortfolio DEXOperation = "query_portfolio"
|
||||
)
|
||||
|
||||
// String returns the string representation of the DEX operation
|
||||
func (op DEXOperation) String() string {
|
||||
return string(op)
|
||||
}
|
||||
|
||||
// UCANCapabilityMapper provides conversion between DEX operations and UCAN capabilities
|
||||
type UCANCapabilityMapper struct{}
|
||||
|
||||
// NewUCANCapabilityMapper creates a new capability mapper
|
||||
func NewUCANCapabilityMapper() *UCANCapabilityMapper {
|
||||
return &UCANCapabilityMapper{}
|
||||
}
|
||||
|
||||
// GetUCANCapabilitiesForOperation returns UCAN-specific capabilities for a DEX operation
|
||||
func (m *UCANCapabilityMapper) GetUCANCapabilitiesForOperation(operation DEXOperation) []string {
|
||||
switch operation {
|
||||
case DEXOpSwap:
|
||||
return []string{UCANSwap, UCANUpdate}
|
||||
case DEXOpExecuteSwap:
|
||||
return []string{UCANExecuteSwap, UCANUpdate}
|
||||
case DEXOpLimitOrder:
|
||||
return []string{UCANLimitOrder, UCANCreate}
|
||||
case DEXOpMarketOrder:
|
||||
return []string{UCANMarketOrder, UCANCreate}
|
||||
case DEXOpCancelOrder:
|
||||
return []string{UCANCancelOrder, UCANDelete}
|
||||
case DEXOpCancelAllOrders:
|
||||
return []string{UCANCancelAllOrders, UCANDelete, UCANAdmin}
|
||||
case DEXOpProvideLiquidity:
|
||||
return []string{UCANProvideLiquidity, UCANCreate}
|
||||
case DEXOpRemoveLiquidity:
|
||||
return []string{UCANRemoveLiquidity, UCANDelete}
|
||||
case DEXOpCreatePool:
|
||||
return []string{UCANCreatePool, UCANCreate, UCANAdmin}
|
||||
case DEXOpRegisterAccount:
|
||||
return []string{UCANRegisterAccount, UCANCreate}
|
||||
case DEXOpUpdatePortfolio:
|
||||
return []string{UCANUpdatePortfolio, UCANUpdate}
|
||||
case DEXOpWithdraw:
|
||||
return []string{UCANWithdraw, UCANUpdate}
|
||||
case DEXOpDeposit:
|
||||
return []string{UCANDeposit, UCANUpdate}
|
||||
case DEXOpQueryPool:
|
||||
return []string{UCANQueryPool, UCANRead}
|
||||
case DEXOpQueryOrders:
|
||||
return []string{UCANQueryOrders, UCANRead}
|
||||
case DEXOpQueryPortfolio:
|
||||
return []string{UCANQueryPortfolio, UCANRead}
|
||||
default:
|
||||
return []string{UCANRead} // Default to read permission
|
||||
}
|
||||
}
|
||||
|
||||
// CreateDEXResourceURI builds a DEX resource URI for UCAN validation
|
||||
func (m *UCANCapabilityMapper) CreateDEXResourceURI(resourceType, resourceID string) string {
|
||||
return fmt.Sprintf("dex:%s:%s", resourceType, resourceID)
|
||||
}
|
||||
|
||||
// CreatePoolResourceURI builds a pool resource URI for UCAN validation
|
||||
func (m *UCANCapabilityMapper) CreatePoolResourceURI(poolID string) string {
|
||||
return fmt.Sprintf("dex:pool:%s", poolID)
|
||||
}
|
||||
|
||||
// CreateOrderResourceURI builds an order resource URI for UCAN validation
|
||||
func (m *UCANCapabilityMapper) CreateOrderResourceURI(orderID string) string {
|
||||
return fmt.Sprintf("dex:order:%s", orderID)
|
||||
}
|
||||
|
||||
// CreateDEXAttenuation creates a UCAN attenuation for DEX operations
|
||||
func (m *UCANCapabilityMapper) CreateDEXAttenuation(
|
||||
actions []string,
|
||||
resourceType string,
|
||||
resourceID string,
|
||||
) ucan.Attenuation {
|
||||
resourceURI := m.CreateDEXResourceURI(resourceType, resourceID)
|
||||
|
||||
resource := &ucan.SimpleResource{
|
||||
Scheme: "dex",
|
||||
Value: fmt.Sprintf("%s:%s", resourceType, resourceID),
|
||||
URI: resourceURI,
|
||||
}
|
||||
|
||||
// Use MultiCapability for multiple actions
|
||||
var capability ucan.Capability
|
||||
if len(actions) == 1 {
|
||||
capability = &ucan.SimpleCapability{
|
||||
Action: actions[0],
|
||||
}
|
||||
} else {
|
||||
capability = &ucan.MultiCapability{
|
||||
Actions: actions,
|
||||
}
|
||||
}
|
||||
|
||||
return ucan.Attenuation{
|
||||
Capability: capability,
|
||||
Resource: resource,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateAmountLimitedAttenuation creates a UCAN attenuation with amount limits
|
||||
func (m *UCANCapabilityMapper) CreateAmountLimitedAttenuation(
|
||||
actions []string,
|
||||
poolID string,
|
||||
maxAmount string,
|
||||
) ucan.Attenuation {
|
||||
// Create base attenuation
|
||||
baseAttenuation := m.CreateDEXAttenuation(actions, "pool", poolID)
|
||||
|
||||
// For amount limits, we'll need to handle this at validation layer
|
||||
// since the standard capability types don't support custom constraints
|
||||
|
||||
return baseAttenuation
|
||||
}
|
||||
|
||||
// CreatePoolRestrictedAttenuation creates a UCAN attenuation restricted to specific pools
|
||||
func (m *UCANCapabilityMapper) CreatePoolRestrictedAttenuation(
|
||||
actions []string,
|
||||
allowedPools []string,
|
||||
) ucan.Attenuation {
|
||||
// Create resource for multiple pools
|
||||
resourceURI := "dex:pool:*"
|
||||
if len(allowedPools) == 1 {
|
||||
resourceURI = m.CreatePoolResourceURI(allowedPools[0])
|
||||
}
|
||||
|
||||
resource := &ucan.SimpleResource{
|
||||
Scheme: "dex",
|
||||
Value: "pool:*",
|
||||
URI: resourceURI,
|
||||
}
|
||||
|
||||
// Use MultiCapability for multiple actions
|
||||
var capability ucan.Capability
|
||||
if len(actions) == 1 {
|
||||
capability = &ucan.SimpleCapability{
|
||||
Action: actions[0],
|
||||
}
|
||||
} else {
|
||||
capability = &ucan.MultiCapability{
|
||||
Actions: actions,
|
||||
}
|
||||
}
|
||||
|
||||
return ucan.Attenuation{
|
||||
Capability: capability,
|
||||
Resource: resource,
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateUCANCapabilities validates that a UCAN capability grants the required DEX actions
|
||||
func (m *UCANCapabilityMapper) ValidateUCANCapabilities(
|
||||
capability ucan.Capability,
|
||||
requiredActions []string,
|
||||
) bool {
|
||||
return capability.Grants(requiredActions)
|
||||
}
|
||||
|
||||
// IsUCANAction checks if an action string is a valid UCAN action
|
||||
func IsUCANAction(action string) bool {
|
||||
validActions := []string{
|
||||
UCANSwap, UCANExecuteSwap, UCANLimitOrder, UCANMarketOrder,
|
||||
UCANCancelOrder, UCANCancelAllOrders,
|
||||
UCANProvideLiquidity, UCANRemoveLiquidity, UCANCreatePool,
|
||||
UCANRegisterAccount, UCANUpdatePortfolio, UCANWithdraw, UCANDeposit,
|
||||
UCANQueryPool, UCANQueryOrders, UCANQueryPortfolio,
|
||||
UCANCreate, UCANRead, UCANUpdate, UCANDelete, UCANAdmin, UCANAll,
|
||||
}
|
||||
|
||||
for _, validAction := range validActions {
|
||||
if action == validAction {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetDEXCapabilityTemplate returns a preconfigured capability template for DEX
|
||||
func GetDEXCapabilityTemplate() *ucan.CapabilityTemplate {
|
||||
return ucan.StandardServiceTemplate()
|
||||
}
|
||||
|
||||
// UCANPermissionRegistry extends the basic permission registry with UCAN capabilities
|
||||
type UCANPermissionRegistry struct {
|
||||
operationCapabilities map[DEXOperation][]string
|
||||
mapper *UCANCapabilityMapper
|
||||
}
|
||||
|
||||
// NewUCANPermissionRegistry creates a new UCAN-aware permission registry
|
||||
func NewUCANPermissionRegistry() *UCANPermissionRegistry {
|
||||
registry := &UCANPermissionRegistry{
|
||||
operationCapabilities: make(map[DEXOperation][]string),
|
||||
mapper: NewUCANCapabilityMapper(),
|
||||
}
|
||||
|
||||
// Initialize default capabilities
|
||||
registry.initializeDefaultCapabilities()
|
||||
return registry
|
||||
}
|
||||
|
||||
// initializeDefaultCapabilities sets up default capability mappings
|
||||
func (r *UCANPermissionRegistry) initializeDefaultCapabilities() {
|
||||
operations := []DEXOperation{
|
||||
DEXOpSwap, DEXOpExecuteSwap, DEXOpLimitOrder, DEXOpMarketOrder,
|
||||
DEXOpCancelOrder, DEXOpCancelAllOrders,
|
||||
DEXOpProvideLiquidity, DEXOpRemoveLiquidity, DEXOpCreatePool,
|
||||
DEXOpRegisterAccount, DEXOpUpdatePortfolio, DEXOpWithdraw, DEXOpDeposit,
|
||||
DEXOpQueryPool, DEXOpQueryOrders, DEXOpQueryPortfolio,
|
||||
}
|
||||
|
||||
for _, op := range operations {
|
||||
r.operationCapabilities[op] = r.mapper.GetUCANCapabilitiesForOperation(op)
|
||||
}
|
||||
}
|
||||
|
||||
// GetRequiredUCANCapabilities returns UCAN-specific capabilities for a DEX operation
|
||||
func (r *UCANPermissionRegistry) GetRequiredUCANCapabilities(operation DEXOperation) ([]string, error) {
|
||||
capabilities, exists := r.operationCapabilities[operation]
|
||||
if !exists {
|
||||
capabilities = r.mapper.GetUCANCapabilitiesForOperation(operation)
|
||||
}
|
||||
|
||||
if len(capabilities) == 0 {
|
||||
return nil, fmt.Errorf("no UCAN capabilities defined for operation: %s", operation.String())
|
||||
}
|
||||
return capabilities, nil
|
||||
}
|
||||
|
||||
// CreateDEXAttenuation creates a UCAN attenuation for DEX operations
|
||||
func (r *UCANPermissionRegistry) CreateDEXAttenuation(
|
||||
actions []string,
|
||||
resourceType string,
|
||||
resourceID string,
|
||||
) ucan.Attenuation {
|
||||
return r.mapper.CreateDEXAttenuation(actions, resourceType, resourceID)
|
||||
}
|
||||
|
||||
// CreateAmountLimitedAttenuation creates an amount-limited attenuation
|
||||
func (r *UCANPermissionRegistry) CreateAmountLimitedAttenuation(
|
||||
actions []string,
|
||||
poolID string,
|
||||
maxAmount string,
|
||||
) ucan.Attenuation {
|
||||
return r.mapper.CreateAmountLimitedAttenuation(actions, poolID, maxAmount)
|
||||
}
|
||||
|
||||
// CreatePoolRestrictedAttenuation creates a pool-restricted attenuation
|
||||
func (r *UCANPermissionRegistry) CreatePoolRestrictedAttenuation(
|
||||
actions []string,
|
||||
allowedPools []string,
|
||||
) ucan.Attenuation {
|
||||
return r.mapper.CreatePoolRestrictedAttenuation(actions, allowedPools)
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
// CreateGaslessDEXAttenuation creates a UCAN attenuation that supports gasless transactions
|
||||
func CreateGaslessDEXAttenuation(
|
||||
actions []string,
|
||||
resourceType string,
|
||||
resourceID string,
|
||||
gasLimit uint64,
|
||||
) ucan.Attenuation {
|
||||
mapper := NewUCANCapabilityMapper()
|
||||
baseAttenuation := mapper.CreateDEXAttenuation(actions, resourceType, resourceID)
|
||||
|
||||
// Wrap capability with gasless support
|
||||
gaslessCapability := &ucan.GaslessCapability{
|
||||
Capability: baseAttenuation.Capability,
|
||||
AllowGasless: true,
|
||||
GasLimit: gasLimit,
|
||||
}
|
||||
|
||||
return ucan.Attenuation{
|
||||
Capability: gaslessCapability,
|
||||
Resource: baseAttenuation.Resource,
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateAmountConstraint validates amount constraints for DEX operations
|
||||
func ValidateAmountConstraint(
|
||||
capability ucan.Capability,
|
||||
amount string,
|
||||
maxAmount string,
|
||||
) error {
|
||||
// Amount validation would be handled at a higher level
|
||||
// This is a placeholder for the actual implementation
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidatePoolConstraint validates pool constraints for DEX operations
|
||||
func ValidatePoolConstraint(
|
||||
capability ucan.Capability,
|
||||
poolID string,
|
||||
allowedPools []string,
|
||||
) error {
|
||||
// Check if pool is in allowed list
|
||||
for _, allowed := range allowedPools {
|
||||
if poolID == allowed {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("pool %s not in allowed list", poolID)
|
||||
}
|
||||
Reference in New Issue
Block a user