diff --git a/schema/helpers/base/transaction.go b/schema/helpers/base/transaction.go index 8aff01df0..59c797774 100644 --- a/schema/helpers/base/transaction.go +++ b/schema/helpers/base/transaction.go @@ -105,6 +105,12 @@ func (transaction transaction) RESTRequestHandler(cliContext context.CLIContext) baseReq := transactionRequest.GetBaseReq() + baseReq = baseReq.Sanitize() + if !baseReq.ValidateBasic(responseWriter) { + rest.WriteErrorResponse(responseWriter, http.StatusBadRequest, "") + return + } + var msg sdkTypes.Msg msg, err = transactionRequest.MakeMsg() if err != nil { @@ -112,12 +118,6 @@ func (transaction transaction) RESTRequestHandler(cliContext context.CLIContext) return } - baseReq = baseReq.Sanitize() - if !baseReq.ValidateBasic(responseWriter) { - rest.WriteErrorResponse(responseWriter, http.StatusBadRequest, "") - return - } - if err = msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(responseWriter, http.StatusBadRequest, err.Error()) return diff --git a/schema/lists/base/dataList.go b/schema/lists/base/dataList.go index 03f2e09c6..70926d412 100644 --- a/schema/lists/base/dataList.go +++ b/schema/lists/base/dataList.go @@ -19,7 +19,9 @@ func (dataList dataList) GetList() []data.Data { DataList := make([]data.Data, dataList.List.Size()) for i, listable := range dataList.List.Get() { - DataList[i] = listable.(data.Data) + if listable != nil { + DataList[i] = listable.(data.Data) + } } return DataList diff --git a/schema/lists/base/dataList_test.go b/schema/lists/base/dataList_test.go index 4b86f7649..ac0f535a2 100644 --- a/schema/lists/base/dataList_test.go +++ b/schema/lists/base/dataList_test.go @@ -73,7 +73,8 @@ func Test_dataList_GetList(t *testing.T) { fields fields want []data.Data }{ - {"+ve with empty struct", fields{list{}}, []data.Data{}}, // TODO: issue Panic for nil + {"+ve with empty struct", fields{list{}}, []data.Data{}}, + {"+ve with empty struct", fields{list{nil}}, []data.Data{nil}}, {"+ve", fields{NewList(dataToListables([]data.Data{NewStringData("Data")}...)...)}, []data.Data{NewStringData("Data")}}, } for _, tt := range tests {