@@ -11,6 +11,7 @@ import (
1111 "github.com/gin-gonic/gin"
1212 "github.com/multiversx/mx-chain-core-go/core"
1313 "github.com/multiversx/mx-chain-core-go/core/check"
14+ "github.com/multiversx/mx-chain-core-go/data/smartContractResult"
1415 "github.com/multiversx/mx-chain-core-go/data/transaction"
1516 "github.com/multiversx/mx-chain-go/api/errors"
1617 "github.com/multiversx/mx-chain-go/api/middleware"
@@ -24,11 +25,13 @@ import (
2425const (
2526 sendTransactionEndpoint = "/transaction/send"
2627 simulateTransactionEndpoint = "/transaction/simulate"
28+ simulateSCRCostEndpoint = "/transaction/cost-scr"
2729 sendMultipleTransactionsEndpoint = "/transaction/send-multiple"
2830 getTransactionEndpoint = "/transaction/:hash"
2931 getScrsByTxHashEndpoint = "/transaction/scrs-by-tx-hash/:txhash"
3032 sendTransactionPath = "/send"
3133 simulateTransactionPath = "/simulate"
34+ simulateSCRCostPath = "/cost-scr"
3235 costPath = "/cost"
3336 sendMultiplePath = "/send-multiple"
3437 getTransactionPath = "/:txhash"
@@ -51,6 +54,7 @@ type transactionFacadeHandler interface {
5154 ValidateTransactionForSimulation (tx * transaction.Transaction , checkSignature bool ) error
5255 SendBulkTransactions ([]* transaction.Transaction ) (uint64 , error )
5356 SimulateTransactionExecution (tx * transaction.Transaction ) (* txSimData.SimulationResultsWithVMOutput , error )
57+ SimulateSCRExecutionCost (scr * smartContractResult.SmartContractResult ) (* transaction.CostResponse , error )
5458 GetTransaction (hash string , withResults bool ) (* transaction.ApiTransactionResult , error )
5559 GetSCRsByTxHash (txHash string , scrHash string ) ([]* transaction.ApiSmartContractResult , error )
5660 GetTransactionsPool (fields string ) (* common.TransactionsPoolAPIResponse , error )
@@ -103,6 +107,17 @@ func NewTransactionGroup(facade transactionFacadeHandler) (*transactionGroup, er
103107 },
104108 },
105109 },
110+ {
111+ Path : simulateSCRCostPath ,
112+ Method : http .MethodPost ,
113+ Handler : tg .simulateSCR ,
114+ AdditionalMiddlewares : []shared.AdditionalMiddleware {
115+ {
116+ Middleware : middleware .CreateEndpointThrottlerFromFacade (simulateSCRCostEndpoint , facade ),
117+ Position : shared .Before ,
118+ },
119+ },
120+ },
106121 {
107122 Path : costPath ,
108123 Method : http .MethodPost ,
@@ -168,6 +183,46 @@ type TxResponse struct {
168183 Timestamp uint64 `json:"timestamp"`
169184}
170185
186+ func (tg * transactionGroup ) simulateSCR (c * gin.Context ) {
187+ var scr = smartContractResult.SmartContractResult {}
188+ err := c .ShouldBindJSON (& scr )
189+ if err != nil {
190+ c .JSON (
191+ http .StatusBadRequest ,
192+ shared.GenericAPIResponse {
193+ Data : nil ,
194+ Error : fmt .Sprintf ("%s: %s" , errors .ErrValidation .Error (), err .Error ()),
195+ Code : shared .ReturnCodeRequestError ,
196+ },
197+ )
198+ return
199+ }
200+
201+ start := time .Now ()
202+ executionResults , err := tg .getFacade ().SimulateSCRExecutionCost (& scr )
203+ logging .LogAPIActionDurationIfNeeded (start , "API call: SimulateSCRExecution" )
204+ if err != nil {
205+ c .JSON (
206+ http .StatusInternalServerError ,
207+ shared.GenericAPIResponse {
208+ Data : nil ,
209+ Error : err .Error (),
210+ Code : shared .ReturnCodeInternalError ,
211+ },
212+ )
213+ return
214+ }
215+
216+ c .JSON (
217+ http .StatusOK ,
218+ shared.GenericAPIResponse {
219+ Data : executionResults ,
220+ Error : "" ,
221+ Code : shared .ReturnCodeSuccess ,
222+ },
223+ )
224+ }
225+
171226// simulateTransaction will receive a transaction from the client and will simulate its execution and return the results
172227func (tg * transactionGroup ) simulateTransaction (c * gin.Context ) {
173228 var ftx = transaction.FrontendTransaction {}
0 commit comments