From 20e2d200f2c3198b73ff497a09edbb7eb6f7c71f Mon Sep 17 00:00:00 2001 From: David Hernando Date: Mon, 17 Mar 2025 09:44:50 +0100 Subject: [PATCH] Adde refund and current_price parsing. Signed-off-by: David Hernando --- .../RPCResponses/GetTransactionTest.cs | 5 ++++ .../TestData/get-transaction-deploy-v200.json | 2 ++ .../TestData/get-transaction-stored-v200.json | 2 ++ Casper.Network.SDK/Types/ExecutionResult.cs | 30 +++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/Casper.Network.SDK.Test/RPCResponses/GetTransactionTest.cs b/Casper.Network.SDK.Test/RPCResponses/GetTransactionTest.cs index 9983185..f29905e 100644 --- a/Casper.Network.SDK.Test/RPCResponses/GetTransactionTest.cs +++ b/Casper.Network.SDK.Test/RPCResponses/GetTransactionTest.cs @@ -2,6 +2,7 @@ using Casper.Network.SDK.JsonRpc.ResultTypes; using Casper.Network.SDK.Types; using NUnit.Framework; +using Org.BouncyCastle.Math; using Org.BouncyCastle.Utilities.Encoders; namespace NetCasperTest.RPCResponses @@ -36,6 +37,8 @@ public void GetTransactionWithDeployHashTest_v200() AssertExtensions.IsHash(result.ExecutionInfo.BlockHash); Assert.IsTrue(result.ExecutionInfo.BlockHeight > 0); Assert.IsNotNull(result.ExecutionInfo.ExecutionResult); + Assert.AreEqual(1, result.ExecutionInfo.ExecutionResult.CurrentGasPrice); + Assert.AreEqual("30000", result.ExecutionInfo.ExecutionResult.Refund.ToString()); } [Test] @@ -136,6 +139,8 @@ public void GetTransactionWithStoredTransactionTest_v200() AssertExtensions.IsHash(result.ExecutionInfo.BlockHash); Assert.IsTrue(result.ExecutionInfo.BlockHeight > 0); Assert.IsNotNull(result.ExecutionInfo.ExecutionResult); + Assert.AreEqual(2, result.ExecutionInfo.ExecutionResult.CurrentGasPrice); + Assert.AreEqual("2123123123", result.ExecutionInfo.ExecutionResult.Refund.ToString()); } [Test] diff --git a/Casper.Network.SDK.Test/TestData/get-transaction-deploy-v200.json b/Casper.Network.SDK.Test/TestData/get-transaction-deploy-v200.json index 05ef8fc..069c579 100644 --- a/Casper.Network.SDK.Test/TestData/get-transaction-deploy-v200.json +++ b/Casper.Network.SDK.Test/TestData/get-transaction-deploy-v200.json @@ -81,6 +81,8 @@ "limit": "10000", "consumed": "10000", "cost": "10000", + "refund": "30000", + "current_price": 1, "payment": [], "transfers": [ { diff --git a/Casper.Network.SDK.Test/TestData/get-transaction-stored-v200.json b/Casper.Network.SDK.Test/TestData/get-transaction-stored-v200.json index db6c83d..283646a 100644 --- a/Casper.Network.SDK.Test/TestData/get-transaction-stored-v200.json +++ b/Casper.Network.SDK.Test/TestData/get-transaction-stored-v200.json @@ -75,6 +75,8 @@ "limit": "3000000000", "consumed": "1241925", "cost": "3000000000", + "refund": "2123123123", + "current_price": 2, "transfers": [], "size_estimate": 591, "effects": [ diff --git a/Casper.Network.SDK/Types/ExecutionResult.cs b/Casper.Network.SDK/Types/ExecutionResult.cs index 3e8fefd..ea7165b 100644 --- a/Casper.Network.SDK/Types/ExecutionResult.cs +++ b/Casper.Network.SDK/Types/ExecutionResult.cs @@ -53,6 +53,8 @@ public static explicit operator ExecutionResult(ExecutionResultV1 executionResul ErrorMessage = executionResult.ErrorMessage, // Transfers = executionResult.Transfers, Cost = executionResult.Cost, + Refund = 0, + CurrentGasPrice = 1, Limit = 0, Consumed = 0, Effect = v2Effect, @@ -81,6 +83,19 @@ public static explicit operator ExecutionResult(ExecutionResultV1 executionResul [JsonPropertyName("cost")] [JsonConverter(typeof(BigIntegerConverter))] public BigInteger Cost { get; init; } + + /// + /// How much was refunded (if any) + /// + [JsonPropertyName("refund")] + [JsonConverter(typeof(BigIntegerConverter))] + public BigInteger Refund { get; init; } + + /// + /// The gas price of the era. + /// + [JsonPropertyName("current_price")] + public UInt16 CurrentGasPrice { get; init; } /// /// If there is no error message, this execution was processed successfully. If there is an error message, this @@ -150,6 +165,8 @@ public override ExecutionResult Read( ErrorMessage = erv2.ErrorMessage, Transfers = erv2.Transfers, Cost = erv2.Cost, + Refund = erv2.Refund, + CurrentGasPrice = erv2.CurrentGasPrice, Limit = erv2.Limit, Consumed = erv2.Consumed, Effect = erv2.Effect, @@ -342,6 +359,19 @@ internal class ExecutionResultV2 [JsonConverter(typeof(BigIntegerConverter))] public BigInteger Cost { get; init; } + /// + /// How much was refunded (if any) + /// + [JsonPropertyName("refund")] + [JsonConverter(typeof(BigIntegerConverter))] + public BigInteger Refund { get; init; } + + /// + /// The gas price of the era. + /// + [JsonPropertyName("current_price")] + public UInt16 CurrentGasPrice { get; init; } + /// /// If there is no error message, this execution was processed successfully. If there is an error message, this /// execution failed to fully process for the stated reason.