Skip to content

Commit

Permalink
feat(transaction_request): adding fromHTTPRequest method
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 6b30a6b commit 362514f
Show file tree
Hide file tree
Showing 31 changed files with 290 additions and 80 deletions.
4 changes: 2 additions & 2 deletions helpers/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
package helpers

import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"net/http"
)

type TransactionRequest interface {
GetCommonTransactionRequest() CommonTransactionRequest

FromCLI(CLICommand, client.Context) (TransactionRequest, error)
FromJSON(json.RawMessage) (TransactionRequest, error)
FromHTTPRequest(*http.Request) (TransactionRequest, error)
MakeMsg() (sdkTypes.Msg, error)
RegisterLegacyAminoCodec(*codec.LegacyAmino)
Request
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/burn/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -50,8 +52,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.AssetID),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -82,7 +89,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
assetID.(ids.AssetID),
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/define/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/AssetMantle/schema/lists/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -57,8 +59,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.MutableProperties),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -109,7 +116,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
mutableProperties,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/deputize/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/AssetMantle/schema/lists/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -67,8 +69,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadBool(constants.CanMutateMaintainer),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -117,7 +124,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
transactionRequest.CanMutateMaintainer,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/mint/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/AssetMantle/schema/lists/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -61,8 +63,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.MutableProperties),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -125,7 +132,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
mutableProperties,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/mutate/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/AssetMantle/schema/lists/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -55,8 +57,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.MutableProperties),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -100,7 +107,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
mutableProperties,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/renumerate/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -50,8 +52,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.AssetID),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -82,7 +89,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
assetID.(ids.AssetID),
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/revoke/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -52,8 +54,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.ClassificationID),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -90,7 +97,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
classificationID.(ids.ClassificationID),
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/send/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -54,8 +56,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.Value),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -98,7 +105,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
value,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
15 changes: 11 additions & 4 deletions x/assets/transactions/unwrap/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/AssetMantle/schema/ids"
baseIDs "github.com/AssetMantle/schema/ids/base"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -50,8 +52,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.Coins),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down Expand Up @@ -82,7 +89,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
coins,
), nil
}
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) {
func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{})
}
func requestPrototype() helpers.TransactionRequest {
Expand Down
11 changes: 9 additions & 2 deletions x/assets/transactions/wrap/transaction_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/client"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/helpers/constants"
Expand Down Expand Up @@ -50,8 +52,13 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
cliCommand.ReadString(constants.Coins),
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
func (transactionRequest transactionRequest) FromHTTPRequest(httpRequest *http.Request) (helpers.TransactionRequest, error) {
body, err := io.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}

if err := json.Unmarshal(body, &transactionRequest); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 362514f

Please sign in to comment.