Skip to content

Commit

Permalink
Added new response classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongph87 committed Feb 2, 2024
1 parent 47b3ec7 commit a3191e1
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 0 deletions.
27 changes: 27 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/GetEventsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetEventsResponse
{
public EventInfo[]? Events;
public long? LatestLedger;

public class EventInfo
{
public string ContractId;

public string Id;

public bool InSuccessfulContractCall;

public int Ledger;

public string LedgerClosedAt;

public string PagingToken;

public string[] Topic;
public string Type;

public string Value;
}
}
6 changes: 6 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/GetHealthResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetHealthResponse
{
public string Status { get; set; }
}
12 changes: 12 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/GetLatestLedgerResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetLatestLedgerResponse
{
public string Id;

public int ProtocolVersion;

public int Sequence;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetLedgerEntriesResponse
{
public LedgerEntryResult?[] Entries;
public long LatestLedger;

public class LedgerEntryResult
{
public string Key;

[JsonProperty(PropertyName = "lastModifiedLedgerSeq")]
public long LastModifiedLedger;

[JsonProperty(PropertyName = "liveUntilLedgerSeq")]
public long LiveUntilLedger;

public string Xdr;
}
}
10 changes: 10 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/GetNetworkResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetNetworkResponse
{
public string FriendbotUrl { get; set; }

public string Passphrase { get; set; }

public int ProtocolVersion { get; set; }
}
70 changes: 70 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/GetTransactionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using stellar_dotnet_sdk.xdr;

namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class GetTransactionResponse
{
public enum GetTransactionStatus
{
NOT_FOUND,
SUCCESS,
FAILED
}

public int ApplicationOrder;

public long CreatedAt;

public string? EnvelopeXdr;

public bool FeeBump;

public long LatestLedger;

public long LatestLedgerCloseTime;

public long Ledger;

public long OldestLedger;

public long OldestLedgerCloseTime;

public string? ResultMetaXdr;

public string? ResultXdr;
public GetTransactionStatus Status;

public SCVal? ResultValue
{
get
{
if (Status != GetTransactionStatus.SUCCESS || ResultMetaXdr == null) return null;

var bytes = Convert.FromBase64String(ResultMetaXdr);
var reader = new XdrDataInputStream(bytes);
var meta = TransactionMeta.Decode(reader);
return meta?.V3?.SorobanMeta?.ReturnValue == null ? null : SCVal.FromXdr(meta.V3.SorobanMeta.ReturnValue);
}
}

public string? WasmId
{
get
{
if (ResultValue is SCBytes bytes) return Convert.ToBase64String(bytes.InnerValue);

return null;
}
}

public string? CreatedContractId
{
get
{
if (ResultValue is SCContractId contract)
return contract.InnerValue;
return null;
}
}
}
21 changes: 21 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/SendTransactionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class SendTransactionResponse
{
public enum SendTransactionStatus
{
PENDING,
DUPLICATE,
TRY_AGAIN_LATER,
ERROR
}

public string ErrorResultXdr;

public string Hash;

public long LatestLedger;

public long LatestLedgerCloseTime;
public SendTransactionStatus Status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Linq;
using Newtonsoft.Json;

namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class SimulateTransactionResponse
{
public SimulateTransactionCost Cost;
public string? Error;

public string[]? Events;
public long LatestLedger;

public uint MinResourceFee;

public RestorePreamble RestorePreambleInfo;

// An array of the individual host function call results.
// This will only contain a single element if present, because only a single
// invokeHostFunctionOperation is supported per transaction.
public SimulateInvokeHostFunctionResult[]? Results;

public string? TransactionData;

public SorobanTransactionData? SorobanTransactionData
{
get
{
if (TransactionData != null) return SorobanTransactionData.FromXdrBase64(TransactionData);

return null;
}
}

public SorobanAuthorizationEntry[]? SorobanAuthorization
{
get
{
if (Results is { Length: > 0 } && Results[0].Auth != null)
return Results[0].Auth.Select(SorobanAuthorizationEntry.FromXdrBase64).ToArray();
return null;
}
}

public class RestorePreamble
{
public long MinResourceFee;
public string TransactionData;
}

public class SimulateTransactionCost
{
[JsonProperty(PropertyName = "cpuInsns")]
public long CpuInstructions;

[JsonProperty(PropertyName = "memBytes")]
public long MemoryBytes;
}

public class SimulateInvokeHostFunctionResult
{
public string[]? Auth;
public string? Xdr;
}
}
14 changes: 14 additions & 0 deletions stellar-dotnet-sdk/responses/sorobanrpc/SorobanRpcResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;

namespace stellar_dotnet_sdk.responses.sorobanrpc;

public class SorobanRpcResponse<T> : Response
{
[JsonProperty(PropertyName = "jsonrpc")]
public string JsonRpc { get; private set; }

[JsonProperty(PropertyName = "id")] public string Id { get; private set; }

[JsonProperty(PropertyName = "result")]
public T Result { get; private set; }
}

0 comments on commit a3191e1

Please sign in to comment.