diff --git a/stellarsdk/stellarsdk.xcodeproj/project.pbxproj b/stellarsdk/stellarsdk.xcodeproj/project.pbxproj index 6e433439..aa6a28b9 100644 --- a/stellarsdk/stellarsdk.xcodeproj/project.pbxproj +++ b/stellarsdk/stellarsdk.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -1585,7 +1581,6 @@ 830DAB3F29AD50FA00ED4E66 /* PaginationOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationOptions.swift; sourceTree = ""; }; 830DAB4229AD540200ED4E66 /* GetEventsResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetEventsResponse.swift; sourceTree = ""; }; 830DAB4529AD545600ED4E66 /* EventInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventInfo.swift; sourceTree = ""; }; - 830DAB4829AD56F300ED4E66 /* EventInfoValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventInfoValue.swift; sourceTree = ""; }; 830DAB4B29AD59DE00ED4E66 /* SimulateTransactionResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionResult.swift; sourceTree = ""; }; 830DAB4E29AD60E100ED4E66 /* GetNetworkResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetNetworkResponse.swift; sourceTree = ""; }; 830DAB5D29AE5AD400ED4E66 /* SorobanAuthTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanAuthTest.swift; sourceTree = ""; }; @@ -1771,7 +1766,6 @@ 835F0CE2297613EF00793708 /* SorobanTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanTest.swift; sourceTree = ""; }; 835F0CE529770B8B00793708 /* SorobanRpcRequestError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SorobanRpcRequestError.swift; sourceTree = ""; }; 835F0CE829770BB100793708 /* GetHealthResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetHealthResponse.swift; sourceTree = ""; }; - 835F0CEB29770BD000793708 /* GetAccountResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetAccountResponse.swift; sourceTree = ""; }; 835F0CF129770C0800793708 /* SimulateTransactionResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionResponse.swift; sourceTree = ""; }; 835F0CF729770C3F00793708 /* SimulateTransactionCost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulateTransactionCost.swift; sourceTree = ""; }; 835F0CFA29770C6E00793708 /* Footprint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Footprint.swift; sourceTree = ""; }; @@ -2840,7 +2834,6 @@ isa = PBXGroup; children = ( 835F0CE829770BB100793708 /* GetHealthResponse.swift */, - 835F0CEB29770BD000793708 /* GetAccountResponse.swift */, 835F0D0029770CA700793708 /* GetTransactionResponse.swift */, 835F0D092977F11400793708 /* TransactionStatusError.swift */, 835F0CE529770B8B00793708 /* SorobanRpcRequestError.swift */, @@ -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 */, @@ -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 */, @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/stellarsdk/stellarsdk/responses/xdr/TransactionEnvelopeXDR.swift b/stellarsdk/stellarsdk/responses/xdr/TransactionEnvelopeXDR.swift index 4b1c8de7..e82f5c92 100644 --- a/stellarsdk/stellarsdk/responses/xdr/TransactionEnvelopeXDR.swift +++ b/stellarsdk/stellarsdk/responses/xdr/TransactionEnvelopeXDR.swift @@ -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 @@ -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) - } - -}*/ - diff --git a/stellarsdk/stellarsdk/responses/xdr/TransactionResultXDR.swift b/stellarsdk/stellarsdk/responses/xdr/TransactionResultXDR.swift index 05a798b9..538e0011 100644 --- a/stellarsdk/stellarsdk/responses/xdr/TransactionResultXDR.swift +++ b/stellarsdk/stellarsdk/responses/xdr/TransactionResultXDR.swift @@ -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) diff --git a/stellarsdk/stellarsdk/soroban/EventFilter.swift b/stellarsdk/stellarsdk/soroban/EventFilter.swift index c7591233..8addd252 100644 --- a/stellarsdk/stellarsdk/soroban/EventFilter.swift +++ b/stellarsdk/stellarsdk/soroban/EventFilter.swift @@ -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. diff --git a/stellarsdk/stellarsdk/soroban/TopicFilter.swift b/stellarsdk/stellarsdk/soroban/TopicFilter.swift index b91cda07..7124d36a 100644 --- a/stellarsdk/stellarsdk/soroban/TopicFilter.swift +++ b/stellarsdk/stellarsdk/soroban/TopicFilter.swift @@ -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] diff --git a/stellarsdk/stellarsdk/soroban/responses/EventInfo.swift b/stellarsdk/stellarsdk/soroban/responses/EventInfo.swift index 825aaf04..77697795 100644 --- a/stellarsdk/stellarsdk/soroban/responses/EventInfo.swift +++ b/stellarsdk/stellarsdk/soroban/responses/EventInfo.swift @@ -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. @@ -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 @@ -45,10 +55,12 @@ 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) @@ -56,12 +68,9 @@ public class EventInfo: NSObject, Decodable { 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) } } diff --git a/stellarsdk/stellarsdk/soroban/responses/EventInfoValue.swift b/stellarsdk/stellarsdk/soroban/responses/EventInfoValue.swift deleted file mode 100644 index b66199a4..00000000 --- a/stellarsdk/stellarsdk/soroban/responses/EventInfoValue.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// EventInfoValue.swift -// stellarsdk -// -// Created by Christian Rogobete on 27.02.23. -// Copyright © 2023 Soneso. All rights reserved. -// - -import Foundation - -/// Part of the getEvents request -/// See: https://soroban.stellar.org/api/methods/getEvents -public class EventInfoValue: NSObject, Decodable { - - /// The emitted body value of the event (serialized in a base64 string - XdrSCVal). - public var xdr:String - - private enum CodingKeys: String, CodingKey { - case xdr - } - - public required init(from decoder: Decoder) throws { - let values = try decoder.container(keyedBy: CodingKeys.self) - xdr = try values.decode(String.self, forKey: .xdr) - } - - public var value:SCValXDR? { - try? SCValXDR.fromXdr(base64: xdr) - } -} diff --git a/stellarsdk/stellarsdk/soroban/responses/GetAccountResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetAccountResponse.swift deleted file mode 100644 index d6359a7e..00000000 --- a/stellarsdk/stellarsdk/soroban/responses/GetAccountResponse.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// GetAccountResponse.swift -// stellarsdk -// -// Created by Christian Rogobete. -// Copyright © 2023 Soneso. All rights reserved. -// - -import Foundation - -/// Response for fetching current info about a stellar account. -public class GetAccountResponse: NSObject, Decodable, TransactionAccount { - - /// Account Id of the account - public var id:String - - /// Current sequence number of the account - public var sequenceNumber:Int64 - - // needed for TransactionAccount impl. - public var keyPair:KeyPair - - private enum CodingKeys: String, CodingKey { - case id - case sequence - } - - public required init(from decoder: Decoder) throws { - let values = try decoder.container(keyedBy: CodingKeys.self) - id = try values.decode(String.self, forKey: .id) - do { - keyPair = try KeyPair(accountId: id) - } catch { - throw StellarSDKError.decodingError(message: "invalid account id") - } - - if let val = Int64(try values.decode(String.self, forKey: .sequence)) { - sequenceNumber = val - } else { - throw StellarSDKError.decodingError(message: "invalid sequence id") - } - } - - public func incrementedSequenceNumber() -> Int64 { - return sequenceNumber + 1 - } - - /// Increments sequence number in this object by one. - public func incrementSequenceNumber() { - sequenceNumber += 1 - } - - public func decrementSequenceNumber() { - sequenceNumber -= 1 - } -} diff --git a/stellarsdk/stellarsdk/soroban/responses/GetEventsResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetEventsResponse.swift index 65690fc8..4579b256 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetEventsResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetEventsResponse.swift @@ -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 { diff --git a/stellarsdk/stellarsdk/soroban/responses/GetHealthResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetHealthResponse.swift index 99d35b9f..4d8cd7b9 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetHealthResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetHealthResponse.swift @@ -13,10 +13,20 @@ 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 } @@ -24,6 +34,8 @@ public class GetHealthResponse: NSObject, Decodable { 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) } } diff --git a/stellarsdk/stellarsdk/soroban/responses/GetLatestLedgerResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetLatestLedgerResponse.swift index 37a422fe..c9c5405d 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetLatestLedgerResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetLatestLedgerResponse.swift @@ -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 { diff --git a/stellarsdk/stellarsdk/soroban/responses/GetLedgerEntriesResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetLedgerEntriesResponse.swift index b9ce961a..b63366ff 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetLedgerEntriesResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetLedgerEntriesResponse.swift @@ -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 { diff --git a/stellarsdk/stellarsdk/soroban/responses/GetNetworkResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetNetworkResponse.swift index 2e192654..d64d7d2a 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetNetworkResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetNetworkResponse.swift @@ -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 diff --git a/stellarsdk/stellarsdk/soroban/responses/GetTransactionResponse.swift b/stellarsdk/stellarsdk/soroban/responses/GetTransactionResponse.swift index 90ff9f9c..66e2ba91 100644 --- a/stellarsdk/stellarsdk/soroban/responses/GetTransactionResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/GetTransactionResponse.swift @@ -10,7 +10,7 @@ import Foundation /// Response when polling the rpc server to find out if a transaction has been /// completed. -/// See: https://soroban.stellar.org/api/methods/getTransaction +/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/getTransaction public class GetTransactionResponse: NSObject, Decodable { public static let STATUS_SUCCESS = "SUCCESS" @@ -20,16 +20,16 @@ public class GetTransactionResponse: NSObject, Decodable { /// The current status of the transaction by hash, one of: SUCCESS, NOT_FOUND, FAILED public var status:String - /// The latest ledger known to Soroban-RPC at the time it handled the getTransaction() request. + /// The sequence number of the latest ledger known to Soroban RPC at the time it handled the request. public var latestLedger:Int - /// The unix timestamp of the close time of the latest ledger known to Soroban-RPC at the time it handled the getTransaction() request. + /// The unix timestamp of the close time of the oldest ledger ingested by Soroban RPC at the time it handled the request. public var latestLedgerCloseTime:String - /// The oldest ledger ingested by Soroban-RPC at the time it handled the getTransaction() request. + /// The sequence number of the oldest ledger ingested by Soroban RPC at the time it handled the request. public var oldestLedger:Int - /// (optional) The sequence of the ledger which included the transaction. This field is only present if status is SUCCESS or FAILED. + /// (optional) The sequence number of the ledger which included the transaction. This field is only present if status is SUCCESS or FAILED public var ledger:Int? /// (optional) The unix timestamp of when the transaction was included in the ledger. This field is only present if status is SUCCESS or FAILED. @@ -42,13 +42,13 @@ public class GetTransactionResponse: NSObject, Decodable { public var feeBump:Bool? /// (optional) A base64 encoded string of the raw TransactionEnvelope XDR struct for this transaction. - public var envelopeXdr:String? // TransactionEnvelope + public var envelopeXdr:String? /// (optional) A base64 encoded string of the raw TransactionResult XDR struct for this transaction. This field is only present if status is SUCCESS or FAILED. - public var resultXdr:String? // TransactionResult + public var resultXdr:String? - /// (optional) A base64 encoded string of the raw TransactionResultMeta XDR struct for this transaction. - public var resultMetaXdr:String? // TransactionResultMeta + /// (optional) A base64 encoded string of the raw TransactionMeta XDR struct for this transaction. + public var resultMetaXdr:String? /// (optional) Will be present on failed transactions. public var error:TransactionStatusError? @@ -67,7 +67,7 @@ public class GetTransactionResponse: NSObject, Decodable { case resultMetaXdr case error } - + public required init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) status = try values.decode(String.self, forKey: .status) @@ -93,6 +93,30 @@ public class GetTransactionResponse: NSObject, Decodable { return meta?.transactionMetaV3?.sorobanMeta?.returnValue } + /// Converts the envelopeXdr value to a TransactionEnvelopeXDR if present and valid + public var transactionEnvelope:TransactionEnvelopeXDR? { + if (error != nil || envelopeXdr == nil) { + return nil + } + return try? TransactionEnvelopeXDR(fromBase64: envelopeXdr!) + } + + /// Converts the resultXdr value to a TransactionResultXDR if present and valid + public var transactionResult: TransactionResultXDR? { + if (error != nil || resultXdr == nil) { + return nil + } + return try? TransactionResultXDR.fromXdr(base64: resultXdr!) + } + + /// Converts the resultMetaXdr value to a TransactionMetaXDR if present and valid + public var transactionMeta: TransactionMetaXDR? { + if (error != nil || resultMetaXdr == nil) { + return nil + } + return try? TransactionMetaXDR(fromBase64: resultMetaXdr!) + } + /// Extracts the wasm id from the response if the transaction installed a contract public var wasmId:String? { return binHex diff --git a/stellarsdk/stellarsdk/soroban/responses/LedgerEntry.swift b/stellarsdk/stellarsdk/soroban/responses/LedgerEntry.swift index b8210ea5..e9a635e9 100644 --- a/stellarsdk/stellarsdk/soroban/responses/LedgerEntry.swift +++ b/stellarsdk/stellarsdk/soroban/responses/LedgerEntry.swift @@ -37,4 +37,14 @@ public class LedgerEntry: NSObject, Decodable { lastModifiedLedgerSeq = try values.decode(Int.self, forKey: .lastModifiedLedgerSeq) liveUntilLedgerSeq = try values.decodeIfPresent(Int.self, forKey: .liveUntilLedgerSeq) } + + /// Converst the key to a SCValXDR if valid. + public var keyXdrValue: SCValXDR? { + return try? SCValXDR.fromXdr(base64: key) + } + + /// Converst the valzue to a LedgerEntryDataXDR if valid + public var valueXdr: LedgerEntryDataXDR? { + return try? LedgerEntryDataXDR(fromBase64: xdr) + } } diff --git a/stellarsdk/stellarsdk/soroban/responses/SendTransactionResponse.swift b/stellarsdk/stellarsdk/soroban/responses/SendTransactionResponse.swift index 8065bb1c..5ca036a4 100644 --- a/stellarsdk/stellarsdk/soroban/responses/SendTransactionResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/SendTransactionResponse.swift @@ -9,7 +9,7 @@ import Foundation /// Response when submitting a real transaction to the stellar network. -/// See: https://soroban.stellar.org/api/methods/sendTransaction +/// See: https://developers.stellar.org/network/soroban-rpc/api-reference/methods/sendTransaction public class SendTransactionResponse: NSObject, Decodable { public static let STATUS_PENDING = "PENDING" @@ -32,6 +32,10 @@ public class SendTransactionResponse: NSObject, Decodable { /// (optional) If the transaction was rejected immediately, this will be an error object. public var error:TransactionStatusError? + /// (optional) If the transaction status is ERROR, this will be the raw TransactionResult XDR struct containing details on why stellar-core rejected the transaction. + public var errorResult:TransactionResultXDR? + + /// (optional) If the transaction status is ERROR, this field may be present. Each entry is a raw DiagnosticEvent XDR struct containing details on why stellar-core rejected the transaction. public var diagnosticEvents:[DiagnosticEventXDR]? private enum CodingKeys: String, CodingKey { @@ -40,6 +44,7 @@ public class SendTransactionResponse: NSObject, Decodable { case latestLedger case latestLedgerCloseTime case error + case errorResultXdr case diagnosticEventsXdr } @@ -50,6 +55,9 @@ public class SendTransactionResponse: NSObject, Decodable { latestLedger = try values.decode(Int.self, forKey: .latestLedger) latestLedgerCloseTime = try values.decode(String.self, forKey: .latestLedgerCloseTime) error = try values.decodeIfPresent(TransactionStatusError.self, forKey: .error) + if let errorResultXdrStr = try values.decodeIfPresent(String.self, forKey: .errorResultXdr) { + errorResult = try? TransactionResultXDR.fromXdr(base64: errorResultXdrStr) + } let diagnosticEventsXdr = try values.decodeIfPresent([String].self, forKey: .diagnosticEventsXdr) if let xdrEntries = diagnosticEventsXdr { diff --git a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionCost.swift b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionCost.swift index 78a488f3..cf4ea11e 100644 --- a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionCost.swift +++ b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionCost.swift @@ -8,13 +8,13 @@ import Foundation -/// Information about the fees expected, instructions used, etc. +/// The cost object is legacy, inaccurate, and will be deprecated in future RPC releases. Please decode transactionData XDR to retrieve the correct resources. public class SimulateTransactionCost: NSObject, Decodable { - /// Stringified-number of the total cpu instructions consumed by this transaction + /// Stringified number - Total cpu instructions consumed by this transaction public var cpuInsns:String - /// Stringified-number of the total memory bytes allocated by this transaction + /// Stringified number - Total memory bytes allocated by this transaction public var memBytes:String private enum CodingKeys: String, CodingKey { diff --git a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResponse.swift b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResponse.swift index 5736c428..9bff5cb0 100644 --- a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResponse.swift +++ b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResponse.swift @@ -11,19 +11,19 @@ import Foundation /// Response that will be received when submitting a trial contract invocation. public class SimulateTransactionResponse: NSObject, Decodable { - /// If error is present then results will not be in the response + /// (optional) - This array will only have one element: the result for the Host Function invocation. Only present on successful simulation (i.e. no error) of InvokeHostFunction operations. public var results:[SimulateTransactionResult]? - /// Information about the fees expected, instructions used, etc. - public var cost:SimulateTransactionCost + /// (deprecated, optional) - The cost object is legacy, inaccurate, and will be deprecated in future RPC releases. Please decode transactionData XDR to retrieve the correct resources. + public var cost:SimulateTransactionCost? - /// number of the current latest ledger observed by the node when this response was generated. + /// The sequence number of the latest ledger known to Soroban RPC at the time it handled the request. public var latestLedger:Int - /// The recommended Soroban Transaction Data to use when submitting the simulated transaction. This data contains the refundable fee and resource usage information such as the ledger footprint and IO access data. + /// The recommended Soroban Transaction Data to use when submitting the simulated transaction. This data contains the refundable fee and resource usage information such as the ledger footprint and IO access data. Not present in case of error. public var transactionData:SorobanTransactionDataXDR? - /// Recommended minimum resource fee to add when submitting the transaction. This fee is to be added on top of the Stellar network fee. + /// Recommended minimum resource fee to add when submitting the transaction. This fee is to be added on top of the Stellar network fee. Not present in case of error. public var minResourceFee:UInt32? /// Array of the events emitted during the contract invocation(s). The events are ordered by their emission time. (an array of serialized base64 strings - DiagnosticEventXdr) @@ -39,7 +39,7 @@ public class SimulateTransactionResponse: NSObject, Decodable { public var restorePreamble:RestorePreamble? /// If present, it indicates how the state (ledger entries) will change as a result of the transaction execution. - public var stateChanges:[LedgerEntryChange]? + public var stateChanges:[LedgerEntryChange]? // only available from protocol 21 on private enum CodingKeys: String, CodingKey { case results @@ -56,7 +56,7 @@ public class SimulateTransactionResponse: NSObject, Decodable { public required init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) latestLedger = try values.decode(Int.self, forKey: .latestLedger) - cost = try values.decode(SimulateTransactionCost.self, forKey: .cost) + cost = try values.decodeIfPresent(SimulateTransactionCost.self, forKey: .cost) if let transactionDataXdrString = try values.decodeIfPresent(String.self, forKey: .transactionData) { transactionData = try SorobanTransactionDataXDR(fromBase64: transactionDataXdrString) } @@ -79,18 +79,18 @@ public class SimulateTransactionResponse: NSObject, Decodable { return nil; } + /// The soroban authorization entries if available. public var sorobanAuth:[SorobanAuthorizationEntryXDR]? { if(results != nil && results!.count > 0) { - if let auth = results![0].auth { - do { - var res:[SorobanAuthorizationEntryXDR] = [] - for base64Xdr in auth { - res.append(try SorobanAuthorizationEntryXDR(fromBase64: base64Xdr)) - } - return res - } catch { - return nil + let auth = results![0].auth + do { + var res:[SorobanAuthorizationEntryXDR] = [] + for base64Xdr in auth { + res.append(try SorobanAuthorizationEntryXDR(fromBase64: base64Xdr)) } + return res + } catch { + return nil } } return nil; @@ -104,10 +104,10 @@ public class SimulateTransactionResponse: NSObject, Decodable { public class RestorePreamble: NSObject, Decodable { /// The recommended Soroban Transaction Data to use when submitting the RestoreFootprint operation. - public var transactionData:SorobanTransactionDataXDR? + public var transactionData:SorobanTransactionDataXDR /// Recommended minimum resource fee to add when submitting the RestoreFootprint operation. This fee is to be added on top of the Stellar network fee. - public var minResourceFee:UInt32? + public var minResourceFee:UInt32 private enum CodingKeys: String, CodingKey { case transactionData @@ -119,7 +119,11 @@ public class RestorePreamble: NSObject, Decodable { let transactionDataXdrString = try values.decode(String.self, forKey: .transactionData) transactionData = try SorobanTransactionDataXDR(fromBase64: transactionDataXdrString) let resStr = try values.decode(String.self, forKey: .minResourceFee) - minResourceFee = UInt32(resStr) + if let mrf = UInt32(resStr) { + minResourceFee = mrf + } else { + throw StellarSDKError.decodingError(message: "min ressource fee must be a positive integer") + } } } diff --git a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResult.swift b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResult.swift index 2fbf01c6..4a10535c 100644 --- a/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResult.swift +++ b/stellarsdk/stellarsdk/soroban/responses/SimulateTransactionResult.swift @@ -10,8 +10,11 @@ import Foundation public class SimulateTransactionResult: NSObject, Decodable { - public var auth:[String]? // ContractAuthXdr - public var xdr:String? + /// Array of serialized base64 strings - Per-address authorizations recorded when simulating this Host Function call. + public var auth:[String] // SorobanAuthorizationEntryXDR, see SimulateTransactionResponse.sorobanAuth + + /// Serialized base64 string - return value of the Host Function call. + public var xdr:String private enum CodingKeys: String, CodingKey { case auth @@ -20,14 +23,12 @@ public class SimulateTransactionResult: NSObject, Decodable { public required init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) - auth = try values.decodeIfPresent([String].self, forKey: .auth) - xdr = try values.decodeIfPresent(String.self, forKey: .xdr) + auth = try values.decode([String].self, forKey: .auth) + xdr = try values.decode(String.self, forKey: .xdr) } + /// Converst the return value of the Host Function call to a SCValXDR object public var value:SCValXDR? { - if let xdr = xdr { - return try? SCValXDR.fromXdr(base64: xdr) - } - return nil + return try? SCValXDR.fromXdr(base64: xdr) } } diff --git a/stellarsdk/stellarsdkTests/soroban/SorobanEventsTest.swift b/stellarsdk/stellarsdkTests/soroban/SorobanEventsTest.swift index a131d1a6..8f1025ec 100644 --- a/stellarsdk/stellarsdkTests/soroban/SorobanEventsTest.swift +++ b/stellarsdk/stellarsdkTests/soroban/SorobanEventsTest.swift @@ -12,9 +12,9 @@ import stellarsdk class SorobanEventsTest: XCTestCase { - let sorobanServer = SorobanServer(endpoint: "https://rpc-futurenet.stellar.org") - let sdk = StellarSDK.futureNet() - let network = Network.futurenet + var sorobanServer = SorobanServer(endpoint: "https://soroban-testnet.stellar.org") // SorobanServer(endpoint: "https://rpc-futurenet.stellar.org") + var sdk = StellarSDK.testNet() // StellarSDK.futureNet() + var network = Network.testnet // Network.futurenet let submitterKeyPair = try! KeyPair.generateRandomKeyPair() var uploadTransactionId:String? = nil var wasmId:String? = nil @@ -33,7 +33,8 @@ class SorobanEventsTest: XCTestCase { sorobanServer.enableLogging = true let accountAId = submitterKeyPair.accountId - sdk.accounts.createFutureNetTestAccount(accountId: accountAId) { (response) -> (Void) in + //sdk.accounts.createFutureNetTestAccount(accountId: accountAId) { (response) -> (Void) in + sdk.accounts.createTestAccount(accountId: accountAId) { (response) -> (Void) in switch response { case .success(_): expectation.fulfill() @@ -95,7 +96,7 @@ class SorobanEventsTest: XCTestCase { let transaction = try! Transaction(sourceAccount: submitterAccount!, operations: [installOperation], memo: Memo.none) - var simulateTxRequest = SimulateTransactionRequest(transaction: transaction); + let simulateTxRequest = SimulateTransactionRequest(transaction: transaction); self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): @@ -166,7 +167,7 @@ class SorobanEventsTest: XCTestCase { let transaction = try! Transaction(sourceAccount: submitterAccount!, operations: [createOperation], memo: Memo.none) - var simulateTxRequest = SimulateTransactionRequest(transaction: transaction); + let simulateTxRequest = SimulateTransactionRequest(transaction: transaction); self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): @@ -235,7 +236,7 @@ class SorobanEventsTest: XCTestCase { let transaction = try! Transaction(sourceAccount: submitterAccount!, operations: [invokeOperation], memo: Memo.none) - var simulateTxRequest = SimulateTransactionRequest(transaction: transaction); + let simulateTxRequest = SimulateTransactionRequest(transaction: transaction); self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): @@ -325,10 +326,14 @@ class SorobanEventsTest: XCTestCase { switch response { case .success(let eventsResponse): XCTAssert(eventsResponse.events.count > 0) - let cId = try! eventsResponse.events[0].contractId.decodeContractIdHex() + let event = eventsResponse.events.first! + let cId = try! event.contractId.decodeContractIdHex() XCTAssert(self.contractId! == cId) - XCTAssert("AAAADwAAAAdDT1VOVEVSAA==" == eventsResponse.events[0].topic[0]) - XCTAssert("AAAAAwAAAAE=" == eventsResponse.events[0].value) + XCTAssert("AAAADwAAAAdDT1VOVEVSAA==" == event.topic[0]) + XCTAssert("AAAAAwAAAAE=" == event.value) + XCTAssert("contract" == event.type) + XCTAssert(event.id == event.pagingToken) + XCTAssertTrue(event.inSuccessfulContractCall) expectation.fulfill() case .failure(let error): self.printError(error: error) diff --git a/stellarsdk/stellarsdkTests/soroban/SorobanTest.swift b/stellarsdk/stellarsdkTests/soroban/SorobanTest.swift index 54a47c58..0c1036bd 100644 --- a/stellarsdk/stellarsdkTests/soroban/SorobanTest.swift +++ b/stellarsdk/stellarsdkTests/soroban/SorobanTest.swift @@ -160,12 +160,9 @@ class SorobanTest: XCTestCase { switch response { case .success(let healthResponse): XCTAssertEqual(HealthStatus.HEALTHY, healthResponse.status) - switch self.network { - case.futurenet: - XCTAssertNotNil(healthResponse.ledgerRetentionWindow) - default: - break - } + XCTAssertNotNil(healthResponse.ledgerRetentionWindow) + XCTAssertNotNil(healthResponse.latestLedger) + XCTAssertNotNil(healthResponse.oldestLedger) case .failure(let error): self.printError(error: error) XCTFail() @@ -331,8 +328,11 @@ class SorobanTest: XCTestCase { self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): - XCTAssert(Int(simulateResponse.cost.cpuInsns)! > 0) - XCTAssert(Int(simulateResponse.cost.memBytes)! > 0) + if let cost = simulateResponse.cost { + XCTAssert(Int(cost.cpuInsns)! > 0) + XCTAssert(Int(cost.memBytes)! > 0) + } + XCTAssertNotNil(simulateResponse.results) XCTAssert(simulateResponse.results!.count > 0) XCTAssertNotNil(simulateResponse.footprint) @@ -555,8 +555,10 @@ class SorobanTest: XCTestCase { self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): - XCTAssert(Int(simulateResponse.cost.cpuInsns)! > 0) - XCTAssert(Int(simulateResponse.cost.memBytes)! > 0) + if let cost = simulateResponse.cost { + XCTAssert(Int(cost.cpuInsns)! > 0) + XCTAssert(Int(cost.memBytes)! > 0) + } XCTAssertNotNil(simulateResponse.results) XCTAssert(simulateResponse.results!.count > 0) self.createContractFootprint = simulateResponse.footprint @@ -634,6 +636,8 @@ class SorobanTest: XCTestCase { switch response { case .success(let ledgerResponse): XCTAssert(Int(exactly:ledgerResponse.latestLedger)! > 0) + XCTAssertNotNil(ledgerResponse.entries.first?.keyXdrValue) + XCTAssertNotNil(ledgerResponse.entries.first?.valueXdr) case .failure(let error): self.printError(error: error) XCTFail() @@ -700,8 +704,10 @@ class SorobanTest: XCTestCase { self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): - XCTAssert(Int(simulateResponse.cost.cpuInsns)! > 0) - XCTAssert(Int(simulateResponse.cost.memBytes)! > 0) + if let cost = simulateResponse.cost { + XCTAssert(Int(cost.cpuInsns)! > 0) + XCTAssert(Int(cost.memBytes)! > 0) + } XCTAssertNotNil(simulateResponse.results) XCTAssert(simulateResponse.results!.count > 0) XCTAssertNotNil(simulateResponse.footprint) @@ -789,8 +795,10 @@ class SorobanTest: XCTestCase { self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): - XCTAssert(Int(simulateResponse.cost.cpuInsns)! > 0) - XCTAssert(Int(simulateResponse.cost.memBytes)! > 0) + if let cost = simulateResponse.cost { + XCTAssert(Int(cost.cpuInsns)! > 0) + XCTAssert(Int(cost.memBytes)! > 0) + } XCTAssertNotNil(simulateResponse.results) XCTAssert(simulateResponse.results!.count > 0) XCTAssertNotNil(simulateResponse.footprint) @@ -894,8 +902,10 @@ class SorobanTest: XCTestCase { self.sorobanServer.simulateTransaction(simulateTxRequest: simulateTxRequest) { (response) -> (Void) in switch response { case .success(let simulateResponse): - XCTAssert(Int(simulateResponse.cost.cpuInsns)! > 0) - XCTAssert(Int(simulateResponse.cost.memBytes)! > 0) + if let cost = simulateResponse.cost { + XCTAssert(Int(cost.cpuInsns)! > 0) + XCTAssert(Int(cost.memBytes)! > 0) + } XCTAssertNotNil(simulateResponse.results) XCTAssert(simulateResponse.results!.count > 0) XCTAssertNotNil(simulateResponse.footprint)