Skip to content

Commit

Permalink
soroban improvements: add missing fields, xdr conversions, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jun 4, 2024
1 parent 0037ab7 commit f26059e
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 214 deletions.
12 changes: 0 additions & 12 deletions stellarsdk/stellarsdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,6 @@
830DAB4429AD540200ED4E66 /* GetEventsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4229AD540200ED4E66 /* GetEventsResponse.swift */; };
830DAB4629AD545600ED4E66 /* EventInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4529AD545600ED4E66 /* EventInfo.swift */; };
830DAB4729AD545600ED4E66 /* EventInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4529AD545600ED4E66 /* EventInfo.swift */; };
830DAB4929AD56F300ED4E66 /* EventInfoValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4829AD56F300ED4E66 /* EventInfoValue.swift */; };
830DAB4A29AD56F300ED4E66 /* EventInfoValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4829AD56F300ED4E66 /* EventInfoValue.swift */; };
830DAB4C29AD59DE00ED4E66 /* SimulateTransactionResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4B29AD59DE00ED4E66 /* SimulateTransactionResult.swift */; };
830DAB4D29AD59DE00ED4E66 /* SimulateTransactionResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4B29AD59DE00ED4E66 /* SimulateTransactionResult.swift */; };
830DAB4F29AD60E100ED4E66 /* GetNetworkResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DAB4E29AD60E100ED4E66 /* GetNetworkResponse.swift */; };
Expand Down Expand Up @@ -922,8 +920,6 @@
835F0CE729770B8B00793708 /* SorobanRpcRequestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CE529770B8B00793708 /* SorobanRpcRequestError.swift */; };
835F0CE929770BB100793708 /* GetHealthResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CE829770BB100793708 /* GetHealthResponse.swift */; };
835F0CEA29770BB100793708 /* GetHealthResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CE829770BB100793708 /* GetHealthResponse.swift */; };
835F0CEC29770BD000793708 /* GetAccountResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CEB29770BD000793708 /* GetAccountResponse.swift */; };
835F0CED29770BD000793708 /* GetAccountResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CEB29770BD000793708 /* GetAccountResponse.swift */; };
835F0CF229770C0800793708 /* SimulateTransactionResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CF129770C0800793708 /* SimulateTransactionResponse.swift */; };
835F0CF329770C0800793708 /* SimulateTransactionResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CF129770C0800793708 /* SimulateTransactionResponse.swift */; };
835F0CF829770C3F00793708 /* SimulateTransactionCost.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835F0CF729770C3F00793708 /* SimulateTransactionCost.swift */; };
Expand Down Expand Up @@ -1585,7 +1581,6 @@
830DAB3F29AD50FA00ED4E66 /* PaginationOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationOptions.swift; sourceTree = "<group>"; };
830DAB4229AD540200ED4E66 /* GetEventsResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetEventsResponse.swift; sourceTree = "<group>"; };
830DAB4529AD545600ED4E66 /* EventInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventInfo.swift; sourceTree = "<group>"; };
830DAB4829AD56F300ED4E66 /* EventInfoValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventInfoValue.swift; sourceTree = "<group>"; };
830DAB4B29AD59DE00ED4E66 /* SimulateTransactionResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionResult.swift; sourceTree = "<group>"; };
830DAB4E29AD60E100ED4E66 /* GetNetworkResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetNetworkResponse.swift; sourceTree = "<group>"; };
830DAB5D29AE5AD400ED4E66 /* SorobanAuthTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanAuthTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1771,7 +1766,6 @@
835F0CE2297613EF00793708 /* SorobanTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanTest.swift; sourceTree = "<group>"; };
835F0CE529770B8B00793708 /* SorobanRpcRequestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanRpcRequestError.swift; sourceTree = "<group>"; };
835F0CE829770BB100793708 /* GetHealthResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetHealthResponse.swift; sourceTree = "<group>"; };
835F0CEB29770BD000793708 /* GetAccountResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetAccountResponse.swift; sourceTree = "<group>"; };
835F0CF129770C0800793708 /* SimulateTransactionResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionResponse.swift; sourceTree = "<group>"; };
835F0CF729770C3F00793708 /* SimulateTransactionCost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionCost.swift; sourceTree = "<group>"; };
835F0CFA29770C6E00793708 /* Footprint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Footprint.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2840,7 +2834,6 @@
isa = PBXGroup;
children = (
835F0CE829770BB100793708 /* GetHealthResponse.swift */,
835F0CEB29770BD000793708 /* GetAccountResponse.swift */,
835F0D0029770CA700793708 /* GetTransactionResponse.swift */,
835F0D092977F11400793708 /* TransactionStatusError.swift */,
835F0CE529770B8B00793708 /* SorobanRpcRequestError.swift */,
Expand All @@ -2851,7 +2844,6 @@
835F0CFD29770C8700793708 /* SendTransactionResponse.swift */,
830DAB4229AD540200ED4E66 /* GetEventsResponse.swift */,
830DAB4529AD545600ED4E66 /* EventInfo.swift */,
830DAB4829AD56F300ED4E66 /* EventInfoValue.swift */,
830DAB4E29AD60E100ED4E66 /* GetNetworkResponse.swift */,
832C2B1B2AE958EE005BB7B8 /* GetLedgerEntriesResponse.swift */,
832C2B1E2AE95926005BB7B8 /* LedgerEntry.swift */,
Expand Down Expand Up @@ -4302,7 +4294,6 @@
834389E826E8C93B009116D0 /* LiquidityPoolDepositResultXDR.swift in Sources */,
83B4CB96252876E900EEE55E /* ClaimableBalanceResponse.swift in Sources */,
830E7D30252930E10059A4B4 /* EndSponsoringFutureReservesOperationResponse.swift in Sources */,
830DAB4A29AD56F300ED4E66 /* EventInfoValue.swift in Sources */,
83F4E6182A1EAAE700DD42A9 /* PutCustomerVerificationRequest.swift in Sources */,
83B4CBAE2528839500EEE55E /* ClaimantResponse.swift in Sources */,
745DF49B2052FF9C000D3660 /* ChangeTrustResultXDR.swift in Sources */,
Expand Down Expand Up @@ -4410,7 +4401,6 @@
8345D411251E1F3400E3F6DA /* ClaimableBalanceEntryXDR.swift in Sources */,
745DF4D72052FF9C000D3660 /* Array+Foundation.swift in Sources */,
835F0CE02976017A00793708 /* SorobanServer.swift in Sources */,
835F0CED29770BD000793708 /* GetAccountResponse.swift in Sources */,
836658F82A6ECB9700E8B8D9 /* ExtendFootprintTTLOperation.swift in Sources */,
744FC6EB212D3CCC00ADFC88 /* Evaluator.swift in Sources */,
830DAB5029AD60E100ED4E66 /* GetNetworkResponse.swift in Sources */,
Expand Down Expand Up @@ -4984,7 +4974,6 @@
834389E726E8C93B009116D0 /* LiquidityPoolDepositResultXDR.swift in Sources */,
83B4CB95252876E900EEE55E /* ClaimableBalanceResponse.swift in Sources */,
830E7D2F252930E10059A4B4 /* EndSponsoringFutureReservesOperationResponse.swift in Sources */,
830DAB4929AD56F300ED4E66 /* EventInfoValue.swift in Sources */,
83F4E6172A1EAAE700DD42A9 /* PutCustomerVerificationRequest.swift in Sources */,
83B4CBAD2528839500EEE55E /* ClaimantResponse.swift in Sources */,
743DF5672020530A00713DE7 /* add_scalar.c in Sources */,
Expand Down Expand Up @@ -5093,7 +5082,6 @@
8345D410251E1F3400E3F6DA /* ClaimableBalanceEntryXDR.swift in Sources */,
437D8A8D202F0B980024D031 /* TradesService.swift in Sources */,
835F0CDF2976017A00793708 /* SorobanServer.swift in Sources */,
835F0CEC29770BD000793708 /* GetAccountResponse.swift in Sources */,
836658F72A6ECB9700E8B8D9 /* ExtendFootprintTTLOperation.swift in Sources */,
743DF582202053B100713DE7 /* Seed.swift in Sources */,
830DAB4F29AD60E100ED4E66 /* GetNetworkResponse.swift in Sources */,
Expand Down
36 changes: 5 additions & 31 deletions stellarsdk/stellarsdk/responses/xdr/TransactionEnvelopeXDR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public enum TransactionEnvelopeXDR: XDRCodable {
}
}

public init(fromBase64 xdr:String) throws {
let xdrDecoder = XDRDecoder.init(data: [UInt8].init(base64: xdr))
self = try TransactionEnvelopeXDR(from: xdrDecoder)
}

public func type() -> Int32 {
switch self {
case .v0: return EnvelopeType.ENVELOPE_TYPE_TX_V0
Expand Down Expand Up @@ -268,34 +273,3 @@ public enum TransactionEnvelopeXDR: XDRCodable {
}
}

/*public enum EnvelopeType: Int32 {
case typeSCP = 1
case typeTX = 2
case typeAUTH = 3
}
public class TransactionEnvelopeXDR: NSObject, XDRCodable {
public let tx: TransactionXDR
public var signatures: [DecoratedSignatureXDR]
public init(tx: TransactionXDR, signatures: [DecoratedSignatureXDR]) {
self.tx = tx
self.signatures = signatures
}
public required init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
tx = try container.decode(TransactionXDR.self)
signatures = try decodeArray(type: DecoratedSignatureXDR.self, dec: decoder)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(tx)
try container.encode(signatures)
}
}*/

Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public struct TransactionResultXDR: XDRCodable {

}

public static func fromXdr(base64:String) throws -> TransactionResultXDR {
let xdrDecoder = XDRDecoder.init(data: [UInt8].init(base64: base64))
return try TransactionResultXDR(from: xdrDecoder)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(feeCharged)
Expand Down
2 changes: 1 addition & 1 deletion stellarsdk/stellarsdk/soroban/EventFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Part of the getEvents request
/// See: https://soroban.stellar.org/api/methods/getEvents
/// https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getEvents
public class EventFilter {

/// (optional) A comma separated list of event types (system, contract, or diagnostic) used to filter events. If omitted, all event types are included.
Expand Down
2 changes: 1 addition & 1 deletion stellarsdk/stellarsdk/soroban/TopicFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// part of the get Events request
/// See: https://soroban.stellar.org/api/methods/getEvents
/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getEvents
public class TopicFilter {

public let segmentMatchers: [String]
Expand Down
29 changes: 19 additions & 10 deletions stellarsdk/stellarsdk/soroban/responses/EventInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
import Foundation

/// Part of the getEvents respopnse
/// See https://soroban.stellar.org/api/methods/getEvents
/// See https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getEvents
public class EventInfo: NSObject, Decodable {

/// String-ified sequence number of the ledger.
/// The type of event emission. Possible values: contract, diagnostic, system
public var type:String

/// Sequence number of the ledger in which this event was emitted.
public var ledger:Int

/// ISO8601 timestamp of the ledger closing time.
public var ledgerClosedAt:String

/// ID of the emitting contract.
/// StrKey representation of the contract address that emitted this event.
public var contractId:String

/// Unique identifier for this event.
public var id:String

/// Duplicate of id field, but in the standard place for pagination tokens.
/// Duplicate of id field, but in the standard place for pagination tokens.
public var pagingToken:String

/// If true the event was emitted during a successful contract call.
Expand All @@ -36,7 +39,14 @@ public class EventInfo: NSObject, Decodable {
/// The emitted body value of the event (serialized in a base64 string - XdrSCVal).
public var value:String

/// The emitted body value of the event as XdrSCVal
public var valueXdr:SCValXDR

/// The transaction which triggered this event.
public var txHash:String

private enum CodingKeys: String, CodingKey {
case type
case ledger
case ledgerClosedAt
case contractId
Expand All @@ -45,23 +55,22 @@ public class EventInfo: NSObject, Decodable {
case inSuccessfulContractCall
case topic
case value
case txHash
}

public required init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
type = try values.decode(String.self, forKey: .type)
ledger = try values.decode(Int.self, forKey: .ledger)
ledgerClosedAt = try values.decode(String.self, forKey: .ledgerClosedAt)
contractId = try values.decode(String.self, forKey: .contractId)
id = try values.decode(String.self, forKey: .id)
inSuccessfulContractCall = try values.decode(Bool.self, forKey: .inSuccessfulContractCall)
pagingToken = try values.decode(String.self, forKey: .pagingToken)
topic = try values.decode([String].self, forKey: .topic)
if let val = try? values.decodeIfPresent(String.self, forKey: .value) {
value = val
} else {
let valueXdr = try values.decode(EventInfoValue.self, forKey: .value)
value = valueXdr.xdr
}
value = try values.decode(String.self, forKey: .value)
valueXdr = try SCValXDR.fromXdr(base64: value)
txHash = try values.decode(String.self, forKey: .txHash)
}
}

30 changes: 0 additions & 30 deletions stellarsdk/stellarsdk/soroban/responses/EventInfoValue.swift

This file was deleted.

56 changes: 0 additions & 56 deletions stellarsdk/stellarsdk/soroban/responses/GetAccountResponse.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Foundation
public class GetEventsResponse: NSObject, Decodable {

public var events:[EventInfo]
/// The ledger number of the last time this entry was updated (optional)

/// The sequence number of the latest ledger known to Soroban RPC at the time it handled the request.
public var latestLedger:Int

private enum CodingKeys: String, CodingKey {
Expand Down
14 changes: 13 additions & 1 deletion stellarsdk/stellarsdk/soroban/responses/GetHealthResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ public class GetHealthResponse: NSObject, Decodable {

/// Health status e.g. "healthy"
public var status:String
public var ledgerRetentionWindow:Int?

/// Most recent known ledger sequence
public var latestLedger:Int? // only available from protocol 21

/// Oldest ledger sequence kept in history
public var oldestLedger:Int? // only available from protocol 21

/// Maximum retention window configured. A full window state can be determined via: ledgerRetentionWindow = latestLedger - oldestLedger + 1
public var ledgerRetentionWindow:Int? // only available from protocol 21

private enum CodingKeys: String, CodingKey {
case status
case latestLedger
case oldestLedger
case ledgerRetentionWindow

}

public required init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
status = try values.decode(String.self, forKey: .status)
latestLedger = try values.decodeIfPresent(Int.self, forKey: .latestLedger)
oldestLedger = try values.decodeIfPresent(Int.self, forKey: .oldestLedger)
ledgerRetentionWindow = try values.decodeIfPresent(Int.self, forKey: .ledgerRetentionWindow)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Response for the getLatestLedger request
/// See: https://soroban.stellar.org/api/methods/getLatestLedger
/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getLatestLedger
///
public class GetLatestLedgerResponse: NSObject, Decodable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation


/// Response for the getLedgerEntry request
/// See: https://soroban.stellar.org/api/methods/getLedgerEntry
/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getLedgerEntries
///
public class GetLedgerEntriesResponse: NSObject, Decodable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// General info about the currently configured network.
/// See: https://soroban.stellar.org/api/methods/getNetwork
/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getNetwork
public class GetNetworkResponse: NSObject, Decodable {

/// (optional) - The URL of this network's "friendbot" faucet
Expand Down
Loading

0 comments on commit f26059e

Please sign in to comment.