From bc668c56902f1acc37fff98da3f7785f19bb3f95 Mon Sep 17 00:00:00 2001 From: Salvionied Date: Thu, 26 Oct 2023 10:35:39 +0200 Subject: [PATCH] Add: Evaluate Endpoint --- client/transactions.go | 19 +++++++++++++++++++ models/transactions.go | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/client/transactions.go b/client/transactions.go index 3a605e4..52a5b40 100644 --- a/client/transactions.go +++ b/client/transactions.go @@ -110,3 +110,22 @@ func (c *Client) TransactionOutputsFromReferences(references []models.TxoReferen return &transactionOutputsFromReferences, nil } + +func (c *Client) EvaluateTx(txCbor string, AdditionalUtxos ...string) ([]models.RedeemerEvaluation, error) { + url := "/transactions/evaluate" + body := models.EvaluateTx{ + Cbor: txCbor, + AdditionalUtxos: AdditionalUtxos, + } + resp, err := c.post(url, body) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var redeemerEvals []models.RedeemerEvaluation + err = json.NewDecoder(resp.Body).Decode(&redeemerEvals) + if err != nil { + return nil, err + } + return redeemerEvals, nil +} diff --git a/models/transactions.go b/models/transactions.go index 5bde671..35226ab 100644 --- a/models/transactions.go +++ b/models/transactions.go @@ -65,3 +65,21 @@ type TransactionOutputsFromReferences struct { LastUpdated utils.LastUpdated `json:"last_updated"` NextCursor string `json:"next_cursor"` } + +type EvaluateTx struct { + Cbor string `json:"cbor"` + AdditionalUtxos []string `json:"additional_utxos"` +} + +type ExecutionUnits struct { + Mem int64 `json:"Mem"` + Steps int64 `json:"Steps"` +} + +type RedeemerEvaluation struct { + ExUnits ExecutionUnits `json:"ex_units"` + RedeemerIndex int `json:"redeemer_index"` + RedeemerTag string `json:"redeemer_tag"` +} + +type EvaluateTxResponse []RedeemerEvaluation