+
+type calculateTxGasResp struct {
+ LeftBTM int64 `json:"left_btm"`
+ ConsumedBTM int64 `json:"consumed_btm"`
+ LeftGas int64 `json:"left_gas"`
+ ConsumedGas int64 `json:"consumed_gas"`
+ StorageGas int64 `json:"storage_gas"`
+ VMGas int64 `json:"vm_gas"`
+}
+
+// POST /calculate-transaction-gas
+func (a *API) calculateGas(ctx context.Context, ins struct {
+ Tx types.Tx `json:"raw_transaction"`
+}) Response {
+ gasState, err := txbuilder.CalculateTxGas(a.chain, &ins.Tx)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
+ btmLeft, ok := checked.MulInt64(gasState.GasLeft, consensus.VMGasRate)
+ if !ok {
+ return NewErrorResponse(errors.New("calculate btmleft got a math error"))
+ }
+
+ txGasResp := &calculateTxGasResp{
+ LeftBTM: btmLeft,
+ ConsumedBTM: int64(gasState.BTMValue) - btmLeft,
+ LeftGas: gasState.GasLeft,
+ ConsumedGas: gasState.GasUsed,
+ StorageGas: gasState.StorageGas,
+ VMGas: gasState.GasUsed - gasState.StorageGas,
+ }
+
+ return NewSuccessResponse(txGasResp)
+}