Skip to content

Commit

Permalink
retiring(transaction): decode transaction request, used for wasm
Browse files Browse the repository at this point in the history
Signed-off-by: Deepanshu Tripathi <[email protected]>
  • Loading branch information
deepanshutr committed Sep 2, 2024
1 parent 69a4402 commit 12d52ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 7 additions & 17 deletions helpers/base/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package base

import (
"context"
"encoding/json"
"fmt"
"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/utilities/rest"
Expand All @@ -16,12 +15,11 @@ import (
codecTypes "github.com/cosmos/cosmos-sdk/codec/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module"
"net/http"
"strings"

"github.com/spf13/cobra"
"google.golang.org/grpc"
"net/http"
"reflect"
)

type transaction struct {
Expand Down Expand Up @@ -79,13 +77,13 @@ func (transaction transaction) HandleMessage(context context.Context, message he
}
func (transaction transaction) RESTRequestHandler(context client.Context) http.HandlerFunc {
return func(responseWriter http.ResponseWriter, httpRequest *http.Request) {
transactionRequest := transaction.requestPrototype()
if !rest.ReadRESTReq(responseWriter, httpRequest, context.LegacyAmino, &transactionRequest) {
return
} else if reflect.TypeOf(transaction.requestPrototype()) != reflect.TypeOf(transactionRequest) {
rest.CheckBadRequestError(responseWriter, fmt.Errorf("expected %s, got %s", reflect.TypeOf(transaction.requestPrototype()), reflect.TypeOf(transactionRequest)))
transactionRequest, err := transaction.requestPrototype().FromHTTPRequest(httpRequest)
if err != nil {
rest.CheckBadRequestError(responseWriter, err)
return
} else if rest.CheckBadRequestError(responseWriter, transactionRequest.Validate()) {
}

if rest.CheckBadRequestError(responseWriter, transactionRequest.Validate()) {
return
}

Expand Down Expand Up @@ -117,14 +115,6 @@ func (transaction transaction) RegisterService(configurator sdkModuleTypes.Confi
}
transaction.serviceRegistrar(configurator.MsgServer(), transaction.keeper)
}
func (transaction transaction) DecodeTransactionRequest(rawMessage json.RawMessage) (sdkTypes.Msg, error) {
transactionRequest, err := transaction.requestPrototype().FromJSON(rawMessage)
if err != nil {
return nil, err
}

return transactionRequest.MakeMsg()
}
func (transaction transaction) InitializeKeeper(mapper helpers.Mapper, parameterManager helpers.ParameterManager, auxiliaryKeepers ...interface{}) helpers.Transaction {
transaction.keeper = transaction.keeperPrototype().Initialize(mapper, parameterManager, auxiliaryKeepers).(helpers.TransactionKeeper)
return transaction
Expand Down
2 changes: 0 additions & 2 deletions helpers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package helpers

import (
"context"
"encoding/json"
"net/http"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -24,6 +23,5 @@ type Transaction interface {
RegisterLegacyAminoCodec(amino *codec.LegacyAmino)
RegisterInterfaces(types.InterfaceRegistry)
RegisterService(module.Configurator)
DecodeTransactionRequest(json.RawMessage) (sdkTypes.Msg, error)
InitializeKeeper(Mapper, ParameterManager, ...interface{}) Transaction
}

0 comments on commit 12d52ea

Please sign in to comment.