diff --git a/Example/Tests/XDREncodingTests.swift b/Example/Tests/XDREncodingTests.swift index 7ba31fc..8614bec 100644 --- a/Example/Tests/XDREncodingTests.swift +++ b/Example/Tests/XDREncodingTests.swift @@ -104,6 +104,23 @@ class XDREncodingTests: XCTestCase { return xdr } + + init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case 0: + let data = try Int64(xdrData: &xdrData) + self = .a(data) + case 1: + let data = try Int32(xdrData: &xdrData) + self = .b(data) + case 2: + self = .c + default: + throw XDRErrors.unknownEnumCase + } + } } XCTAssertEqual(TestDescriminatedUnion.a(1).toXDR().base64, "AAAAAAAAAAAAAAAB") diff --git a/Example/Tests/XDRTypesTests.swift b/Example/Tests/XDRTypesTests.swift index fffc3da..c04e023 100644 --- a/Example/Tests/XDRTypesTests.swift +++ b/Example/Tests/XDRTypesTests.swift @@ -27,6 +27,8 @@ class XDRTypesTests: XCTestCase { let op = Operation(sourceAccount: nil, body: Operation.OperationBody.manageBalance(manageBalanceOp)) XCTAssertEqual(op.toXDR().base64, "AAAAAAAAAAkAAAAAAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA") + // Decoding + XCTAssertEqual(try! Operation(xdrBase64: "AAAAAAAAAAkAAAAAAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA").toXdrBase64String(), "AAAAAAAAAAkAAAAAAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA") } func testDeleteBalanceOp() { @@ -37,6 +39,8 @@ class XDRTypesTests: XCTestCase { let op = Operation(sourceAccount: nil, body: Operation.OperationBody.manageBalance(manageBalanceOp)) XCTAssertEqual(op.toXDR().base64, "AAAAAAAAAAkAAAABAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA") + // Decoding + XCTAssertEqual(try! Operation(xdrBase64: "AAAAAAAAAAkAAAABAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA").toXdrBase64String(), "AAAAAAAAAAkAAAABAAAAAHteR0/xHy/UY52BNKpS2XhbRQ9sVCsVfrSwiwW7X7B9AAAAA09MRwAAAAAA") } } diff --git a/Sources/TokenDWallet/Xdr/AMLAlertDetails.swift b/Sources/TokenDWallet/Xdr/AMLAlertDetails.swift index 87a8eac..1d1cdd4 100644 --- a/Sources/TokenDWallet/Xdr/AMLAlertDetails.swift +++ b/Sources/TokenDWallet/Xdr/AMLAlertDetails.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct AMLAlertDetails: XDREncodable { +public struct AMLAlertDetails: XDRCodable { public var comment: String public var ext: AMLAlertDetailsExt @@ -40,6 +40,11 @@ public struct AMLAlertDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.comment = try String(xdrData: &xdrData) + self.ext = try AMLAlertDetailsExt(xdrData: &xdrData) + } + public enum AMLAlertDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -61,5 +66,15 @@ public struct AMLAlertDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AMLAlertRequest.swift b/Sources/TokenDWallet/Xdr/AMLAlertRequest.swift index 1054331..d3cb011 100644 --- a/Sources/TokenDWallet/Xdr/AMLAlertRequest.swift +++ b/Sources/TokenDWallet/Xdr/AMLAlertRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct AMLAlertRequest: XDREncodable { +public struct AMLAlertRequest: XDRCodable { public var balanceID: BalanceID public var amount: Uint64 public var creatorDetails: Longstring @@ -55,6 +55,13 @@ public struct AMLAlertRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.balanceID = try BalanceID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try AMLAlertRequestExt(xdrData: &xdrData) + } + public enum AMLAlertRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -76,5 +83,15 @@ public struct AMLAlertRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ASwapBidCreationRequest.swift b/Sources/TokenDWallet/Xdr/ASwapBidCreationRequest.swift deleted file mode 100644 index 941eccf..0000000 --- a/Sources/TokenDWallet/Xdr/ASwapBidCreationRequest.swift +++ /dev/null @@ -1,80 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct ASwapBidCreationRequest -// { -// BalanceID baseBalance; -// uint64 amount; -// longstring creatorDetails; // details set by requester -// -// ASwapBidQuoteAsset quoteAssets<>; -// -// // reserved for future use -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct ASwapBidCreationRequest: XDREncodable { - public var baseBalance: BalanceID - public var amount: Uint64 - public var creatorDetails: Longstring - public var quoteAssets: [ASwapBidQuoteAsset] - public var ext: ASwapBidCreationRequestExt - - public init( - baseBalance: BalanceID, - amount: Uint64, - creatorDetails: Longstring, - quoteAssets: [ASwapBidQuoteAsset], - ext: ASwapBidCreationRequestExt) { - - self.baseBalance = baseBalance - self.amount = amount - self.creatorDetails = creatorDetails - self.quoteAssets = quoteAssets - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.baseBalance.toXDR()) - xdr.append(self.amount.toXDR()) - xdr.append(self.creatorDetails.toXDR()) - xdr.append(self.quoteAssets.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum ASwapBidCreationRequestExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/ASwapBidQuoteAsset.swift b/Sources/TokenDWallet/Xdr/ASwapBidQuoteAsset.swift deleted file mode 100644 index e9a31cd..0000000 --- a/Sources/TokenDWallet/Xdr/ASwapBidQuoteAsset.swift +++ /dev/null @@ -1,69 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct ASwapBidQuoteAsset -// { -// AssetCode quoteAsset; -// uint64 price; -// -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } -// ext; -// }; - -// =========================================================================== -public struct ASwapBidQuoteAsset: XDREncodable { - public var quoteAsset: AssetCode - public var price: Uint64 - public var ext: ASwapBidQuoteAssetExt - - public init( - quoteAsset: AssetCode, - price: Uint64, - ext: ASwapBidQuoteAssetExt) { - - self.quoteAsset = quoteAsset - self.price = price - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.quoteAsset.toXDR()) - xdr.append(self.price.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum ASwapBidQuoteAssetExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/ASwapExtended.swift b/Sources/TokenDWallet/Xdr/ASwapExtended.swift deleted file mode 100644 index b3b9821..0000000 --- a/Sources/TokenDWallet/Xdr/ASwapExtended.swift +++ /dev/null @@ -1,120 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct ASwapExtended -// { -// //: ID of the bid to apply atomic swap to -// uint64 bidID; -// //: AccountID of the bid owner -// AccountID bidOwnerID; -// //: Account id of the atomic swap source -// AccountID purchaserID; -// //: Base asset for the atomic swap -// AssetCode baseAsset; -// //: Quote asset for the atomic swap -// AssetCode quoteAsset; -// //: Amount in base asset to exchange -// uint64 baseAmount; -// //: Amount in quote asset to exchange -// uint64 quoteAmount; -// //: Price of base asset in terms of quote -// uint64 price; -// //: Balance in base asset of bid owner -// BalanceID bidOwnerBaseBalanceID; -// //: Balance in quote asset of atomic swap source -// BalanceID purchaserBaseBalanceID; -// -// //: Reserved for future use -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } -// ext; -// }; - -// =========================================================================== -public struct ASwapExtended: XDREncodable { - public var bidID: Uint64 - public var bidOwnerID: AccountID - public var purchaserID: AccountID - public var baseAsset: AssetCode - public var quoteAsset: AssetCode - public var baseAmount: Uint64 - public var quoteAmount: Uint64 - public var price: Uint64 - public var bidOwnerBaseBalanceID: BalanceID - public var purchaserBaseBalanceID: BalanceID - public var ext: ASwapExtendedExt - - public init( - bidID: Uint64, - bidOwnerID: AccountID, - purchaserID: AccountID, - baseAsset: AssetCode, - quoteAsset: AssetCode, - baseAmount: Uint64, - quoteAmount: Uint64, - price: Uint64, - bidOwnerBaseBalanceID: BalanceID, - purchaserBaseBalanceID: BalanceID, - ext: ASwapExtendedExt) { - - self.bidID = bidID - self.bidOwnerID = bidOwnerID - self.purchaserID = purchaserID - self.baseAsset = baseAsset - self.quoteAsset = quoteAsset - self.baseAmount = baseAmount - self.quoteAmount = quoteAmount - self.price = price - self.bidOwnerBaseBalanceID = bidOwnerBaseBalanceID - self.purchaserBaseBalanceID = purchaserBaseBalanceID - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.bidID.toXDR()) - xdr.append(self.bidOwnerID.toXDR()) - xdr.append(self.purchaserID.toXDR()) - xdr.append(self.baseAsset.toXDR()) - xdr.append(self.quoteAsset.toXDR()) - xdr.append(self.baseAmount.toXDR()) - xdr.append(self.quoteAmount.toXDR()) - xdr.append(self.price.toXDR()) - xdr.append(self.bidOwnerBaseBalanceID.toXDR()) - xdr.append(self.purchaserBaseBalanceID.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum ASwapExtendedExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/ASwapRequest.swift b/Sources/TokenDWallet/Xdr/ASwapRequest.swift deleted file mode 100644 index 4bd76a8..0000000 --- a/Sources/TokenDWallet/Xdr/ASwapRequest.swift +++ /dev/null @@ -1,78 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct ASwapRequest -// { -// uint64 bidID; -// uint64 baseAmount; -// AssetCode quoteAsset; -// longstring creatorDetails; // details set by requester -// -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct ASwapRequest: XDREncodable { - public var bidID: Uint64 - public var baseAmount: Uint64 - public var quoteAsset: AssetCode - public var creatorDetails: Longstring - public var ext: ASwapRequestExt - - public init( - bidID: Uint64, - baseAmount: Uint64, - quoteAsset: AssetCode, - creatorDetails: Longstring, - ext: ASwapRequestExt) { - - self.bidID = bidID - self.baseAmount = baseAmount - self.quoteAsset = quoteAsset - self.creatorDetails = creatorDetails - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.bidID.toXDR()) - xdr.append(self.baseAmount.toXDR()) - xdr.append(self.quoteAsset.toXDR()) - xdr.append(self.creatorDetails.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum ASwapRequestExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/AccountEntry.swift b/Sources/TokenDWallet/Xdr/AccountEntry.swift index d906c0c..6fd1a12 100644 --- a/Sources/TokenDWallet/Xdr/AccountEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountEntry.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct AccountEntry: XDREncodable { +public struct AccountEntry: XDRCodable { public var accountID: AccountID public var referrer: AccountID? public var sequentialID: Uint64 @@ -61,6 +61,18 @@ public struct AccountEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.referrer = try AccountID(xdrData: &xdrData) + } else { + self.referrer = nil + } + self.sequentialID = try Uint64(xdrData: &xdrData) + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try AccountEntryExt(xdrData: &xdrData) + } + public enum AccountEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -82,5 +94,15 @@ public struct AccountEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountKYCEntry.swift b/Sources/TokenDWallet/Xdr/AccountKYCEntry.swift index b819885..eaed237 100644 --- a/Sources/TokenDWallet/Xdr/AccountKYCEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountKYCEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct AccountKYCEntry: XDREncodable { +public struct AccountKYCEntry: XDRCodable { public var accountID: AccountID public var KYCData: Longstring public var ext: AccountKYCEntryExt @@ -45,6 +45,12 @@ public struct AccountKYCEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.KYCData = try Longstring(xdrData: &xdrData) + self.ext = try AccountKYCEntryExt(xdrData: &xdrData) + } + public enum AccountKYCEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct AccountKYCEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountLimitsEntry.swift b/Sources/TokenDWallet/Xdr/AccountLimitsEntry.swift index bd79073..6183c2a 100644 --- a/Sources/TokenDWallet/Xdr/AccountLimitsEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountLimitsEntry.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct AccountLimitsEntry: XDREncodable { +public struct AccountLimitsEntry: XDRCodable { public var accountID: AccountID public var limits: Limits public var ext: AccountLimitsEntryExt @@ -44,6 +44,12 @@ public struct AccountLimitsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.limits = try Limits(xdrData: &xdrData) + self.ext = try AccountLimitsEntryExt(xdrData: &xdrData) + } + public enum AccountLimitsEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -65,5 +71,15 @@ public struct AccountLimitsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountRoleEntry.swift b/Sources/TokenDWallet/Xdr/AccountRoleEntry.swift index 0bbc210..9131529 100644 --- a/Sources/TokenDWallet/Xdr/AccountRoleEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountRoleEntry.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct AccountRoleEntry: XDREncodable { +public struct AccountRoleEntry: XDRCodable { public var id: Uint64 public var ruleIDs: [Uint64] public var details: Longstring @@ -52,6 +52,17 @@ public struct AccountRoleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.details = try Longstring(xdrData: &xdrData) + self.ext = try AccountRoleEntryExt(xdrData: &xdrData) + } + public enum AccountRoleEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +84,15 @@ public struct AccountRoleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountRuleAction.swift b/Sources/TokenDWallet/Xdr/AccountRuleAction.swift index 94dcc42..57cb34f 100644 --- a/Sources/TokenDWallet/Xdr/AccountRuleAction.swift +++ b/Sources/TokenDWallet/Xdr/AccountRuleAction.swift @@ -26,7 +26,10 @@ import Foundation // CLOSE = 16, // REMOVE = 17, // UPDATE_END_TIME = 18, -// CREATE_FOR_OTHER_WITH_TASKS = 19 +// CREATE_FOR_OTHER_WITH_TASKS = 19, +// REMOVE_FOR_OTHER = 20, +// EXCHANGE = 21, +// RECEIVE_REDEMPTION = 22 // }; // =========================================================================== @@ -50,4 +53,7 @@ public enum AccountRuleAction: Int32, XDREnum { case remove = 17 case updateEndTime = 18 case createForOtherWithTasks = 19 + case removeForOther = 20 + case exchange = 21 + case receiveRedemption = 22 } diff --git a/Sources/TokenDWallet/Xdr/AccountRuleEntry.swift b/Sources/TokenDWallet/Xdr/AccountRuleEntry.swift index 7377be3..537b20b 100644 --- a/Sources/TokenDWallet/Xdr/AccountRuleEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountRuleEntry.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct AccountRuleEntry: XDREncodable { +public struct AccountRuleEntry: XDRCodable { public var id: Uint64 public var resource: AccountRuleResource public var action: AccountRuleAction @@ -63,6 +63,15 @@ public struct AccountRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.resource = try AccountRuleResource(xdrData: &xdrData) + self.action = try AccountRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try AccountRuleEntryExt(xdrData: &xdrData) + } + public enum AccountRuleEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -84,5 +93,15 @@ public struct AccountRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountRuleRequirement.swift b/Sources/TokenDWallet/Xdr/AccountRuleRequirement.swift index dd6b0f3..e2b6bda 100644 --- a/Sources/TokenDWallet/Xdr/AccountRuleRequirement.swift +++ b/Sources/TokenDWallet/Xdr/AccountRuleRequirement.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct AccountRuleRequirement: XDREncodable { +public struct AccountRuleRequirement: XDRCodable { public var resource: AccountRuleResource public var action: AccountRuleAction public var account: AccountID @@ -48,4 +48,11 @@ public struct AccountRuleRequirement: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.resource = try AccountRuleResource(xdrData: &xdrData) + self.action = try AccountRuleAction(xdrData: &xdrData) + self.account = try AccountID(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/AccountRuleResource.swift b/Sources/TokenDWallet/Xdr/AccountRuleResource.swift index 1b2e3d4..b770a2f 100644 --- a/Sources/TokenDWallet/Xdr/AccountRuleResource.swift +++ b/Sources/TokenDWallet/Xdr/AccountRuleResource.swift @@ -125,6 +125,17 @@ import Foundation // EmptyExt ext; // } accountSpecificRule; // } accountSpecificRuleExt; +// case SWAP: +// struct +// { +// //: code of the asset +// AssetCode assetCode; +// //: type of asset +// uint64 assetType; +// +// //: reserved for future extension +// EmptyExt ext; +// } swap; // default: // //: reserved for future extension // EmptyExt ext; @@ -143,6 +154,7 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { case vote(AccountRuleResourceVote) case initiateKycRecovery(AccountRuleResourceInitiateKYCRecovery) case accountSpecificRule(AccountRuleResourceAccountSpecificRuleExt) + case swap(AccountRuleResourceSwap) public var discriminant: Int32 { switch self { @@ -157,6 +169,7 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { case .vote: return LedgerEntryType.vote.rawValue case .initiateKycRecovery: return LedgerEntryType.initiateKycRecovery.rawValue case .accountSpecificRule: return LedgerEntryType.accountSpecificRule.rawValue + case .swap: return LedgerEntryType.swap.rawValue } } @@ -177,11 +190,55 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { case .vote(let data): xdr.append(data.toXDR()) case .initiateKycRecovery(let data): xdr.append(data.toXDR()) case .accountSpecificRule(let data): xdr.append(data.toXDR()) + case .swap(let data): xdr.append(data.toXDR()) } return xdr } - public struct AccountRuleResourceAsset: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerEntryType.asset.rawValue: + let data = try AccountRuleResourceAsset(xdrData: &xdrData) + self = .asset(data) + case LedgerEntryType.reviewableRequest.rawValue: + let data = try AccountRuleResourceReviewableRequest(xdrData: &xdrData) + self = .reviewableRequest(data) + case LedgerEntryType.any.rawValue: self = .any() + case LedgerEntryType.offerEntry.rawValue: + let data = try AccountRuleResourceOffer(xdrData: &xdrData) + self = .offerEntry(data) + case LedgerEntryType.sale.rawValue: + let data = try AccountRuleResourceSale(xdrData: &xdrData) + self = .sale(data) + case LedgerEntryType.atomicSwapAsk.rawValue: + let data = try AccountRuleResourceAtomicSwapAsk(xdrData: &xdrData) + self = .atomicSwapAsk(data) + case LedgerEntryType.keyValue.rawValue: + let data = try AccountRuleResourceKeyValue(xdrData: &xdrData) + self = .keyValue(data) + case LedgerEntryType.poll.rawValue: + let data = try AccountRuleResourcePoll(xdrData: &xdrData) + self = .poll(data) + case LedgerEntryType.vote.rawValue: + let data = try AccountRuleResourceVote(xdrData: &xdrData) + self = .vote(data) + case LedgerEntryType.initiateKycRecovery.rawValue: + let data = try AccountRuleResourceInitiateKYCRecovery(xdrData: &xdrData) + self = .initiateKycRecovery(data) + case LedgerEntryType.accountSpecificRule.rawValue: + let data = try AccountRuleResourceAccountSpecificRuleExt(xdrData: &xdrData) + self = .accountSpecificRule(data) + case LedgerEntryType.swap.rawValue: + let data = try AccountRuleResourceSwap(xdrData: &xdrData) + self = .swap(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct AccountRuleResourceAsset: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -206,8 +263,14 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceReviewableRequest: XDREncodable { + public struct AccountRuleResourceReviewableRequest: XDRCodable { public var details: ReviewableRequestResource public var ext: EmptyExt @@ -228,8 +291,13 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ReviewableRequestResource(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceOffer: XDREncodable { + public struct AccountRuleResourceOffer: XDRCodable { public var baseAssetType: Uint64 public var quoteAssetType: Uint64 public var baseAssetCode: AssetCode @@ -266,8 +334,17 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.baseAssetType = try Uint64(xdrData: &xdrData) + self.quoteAssetType = try Uint64(xdrData: &xdrData) + self.baseAssetCode = try AssetCode(xdrData: &xdrData) + self.quoteAssetCode = try AssetCode(xdrData: &xdrData) + self.isBuy = try Bool(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceSale: XDREncodable { + public struct AccountRuleResourceSale: XDRCodable { public var saleID: Uint64 public var saleType: Uint64 public var ext: EmptyExt @@ -292,8 +369,14 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.saleType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceAtomicSwapAsk: XDREncodable { + public struct AccountRuleResourceAtomicSwapAsk: XDRCodable { public var assetType: Uint64 public var assetCode: AssetCode public var ext: EmptyExt @@ -318,8 +401,14 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetType = try Uint64(xdrData: &xdrData) + self.assetCode = try AssetCode(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceKeyValue: XDREncodable { + public struct AccountRuleResourceKeyValue: XDRCodable { public var keyPrefix: Longstring public var ext: EmptyExt @@ -340,8 +429,13 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.keyPrefix = try Longstring(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourcePoll: XDREncodable { + public struct AccountRuleResourcePoll: XDRCodable { public var pollID: Uint64 public var permissionType: Uint32 public var ext: EmptyExt @@ -366,8 +460,14 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.permissionType = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceVote: XDREncodable { + public struct AccountRuleResourceVote: XDRCodable { public var pollID: Uint64 public var permissionType: Uint32 public var ext: EmptyExt @@ -392,8 +492,14 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.permissionType = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct AccountRuleResourceInitiateKYCRecovery: XDREncodable { + public struct AccountRuleResourceInitiateKYCRecovery: XDRCodable { public var roleID: Uint64 public var ext: EmptyExt @@ -414,6 +520,11 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } public enum AccountRuleResourceAccountSpecificRuleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -439,7 +550,20 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } - public struct AccountRuleResourceAccountSpecificRuleExtAccountSpecificRule: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.addAccSpecificRuleResource.rawValue: + let data = try AccountRuleResourceAccountSpecificRuleExtAccountSpecificRule(xdrData: &xdrData) + self = .addAccSpecificRuleResource(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct AccountRuleResourceAccountSpecificRuleExtAccountSpecificRule: XDRCodable { public var ledgerKey: LedgerKey public var ext: EmptyExt @@ -460,6 +584,43 @@ public enum AccountRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerKey = try LedgerKey(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } + } + public struct AccountRuleResourceSwap: XDRCodable { + public var assetCode: AssetCode + public var assetType: Uint64 + public var ext: EmptyExt + + public init( + assetCode: AssetCode, + assetType: Uint64, + ext: EmptyExt) { + + self.assetCode = assetCode + self.assetType = assetType + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.assetCode.toXDR()) + xdr.append(self.assetType.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr } + + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } diff --git a/Sources/TokenDWallet/Xdr/AccountSpecificRuleEntry.swift b/Sources/TokenDWallet/Xdr/AccountSpecificRuleEntry.swift index bd761e3..d5d9d22 100644 --- a/Sources/TokenDWallet/Xdr/AccountSpecificRuleEntry.swift +++ b/Sources/TokenDWallet/Xdr/AccountSpecificRuleEntry.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct AccountSpecificRuleEntry: XDREncodable { +public struct AccountSpecificRuleEntry: XDRCodable { public var id: Uint64 public var ledgerKey: LedgerKey public var accountID: AccountID? @@ -56,6 +56,18 @@ public struct AccountSpecificRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ledgerKey = try LedgerKey(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.forbids = try Bool(xdrData: &xdrData) + self.ext = try AccountSpecificRuleEntryExt(xdrData: &xdrData) + } + public enum AccountSpecificRuleEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -77,5 +89,15 @@ public struct AccountSpecificRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AssetChangePreissuedSigner.swift b/Sources/TokenDWallet/Xdr/AssetChangePreissuedSigner.swift index 6f1ec3c..a47d963 100644 --- a/Sources/TokenDWallet/Xdr/AssetChangePreissuedSigner.swift +++ b/Sources/TokenDWallet/Xdr/AssetChangePreissuedSigner.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct AssetChangePreissuedSigner: XDREncodable { +public struct AssetChangePreissuedSigner: XDRCodable { public var code: AssetCode public var accountID: AccountID public var signature: DecoratedSignature @@ -55,6 +55,13 @@ public struct AssetChangePreissuedSigner: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.accountID = try AccountID(xdrData: &xdrData) + self.signature = try DecoratedSignature(xdrData: &xdrData) + self.ext = try AssetChangePreissuedSignerExt(xdrData: &xdrData) + } + public enum AssetChangePreissuedSignerExt: XDRDiscriminatedUnion { case emptyVersion() @@ -76,5 +83,15 @@ public struct AssetChangePreissuedSigner: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AssetCreationRequest.swift b/Sources/TokenDWallet/Xdr/AssetCreationRequest.swift index cec422d..7b914bb 100644 --- a/Sources/TokenDWallet/Xdr/AssetCreationRequest.swift +++ b/Sources/TokenDWallet/Xdr/AssetCreationRequest.swift @@ -36,7 +36,7 @@ import Foundation // }; // =========================================================================== -public struct AssetCreationRequest: XDREncodable { +public struct AssetCreationRequest: XDRCodable { public var code: AssetCode public var preissuedAssetSigner: AccountID public var maxIssuanceAmount: Uint64 @@ -89,6 +89,19 @@ public struct AssetCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.preissuedAssetSigner = try AccountID(xdrData: &xdrData) + self.maxIssuanceAmount = try Uint64(xdrData: &xdrData) + self.initialPreissuedAmount = try Uint64(xdrData: &xdrData) + self.policies = try Uint32(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.type = try Uint64(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + self.trailingDigitsCount = try Uint32(xdrData: &xdrData) + self.ext = try AssetCreationRequestExt(xdrData: &xdrData) + } + public enum AssetCreationRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -110,5 +123,15 @@ public struct AssetCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AssetEntry.swift b/Sources/TokenDWallet/Xdr/AssetEntry.swift index 85b0162..3f424a3 100644 --- a/Sources/TokenDWallet/Xdr/AssetEntry.swift +++ b/Sources/TokenDWallet/Xdr/AssetEntry.swift @@ -7,29 +7,35 @@ import Foundation // struct AssetEntry // { +// //: Code of the asset // AssetCode code; +// //: Owner(creator) of the asset // AccountID owner; -// AccountID preissuedAssetSigner; // signer of pre issuance tokens +// //: Account responsible for preissuance of the asset +// AccountID preissuedAssetSigner; +// //: Arbitrary stringified JSON object that can be used to attach data to asset // longstring details; -// uint64 maxIssuanceAmount; // max number of tokens to be issued -// uint64 availableForIssueance; // pre issued tokens available for issuance -// uint64 issued; // number of issued tokens -// uint64 pendingIssuance; // number of tokens locked for entries like token sale. lockedIssuance + issued can not be > maxIssuanceAmount +// //: Maximal amount of tokens that can be issued +// uint64 maxIssuanceAmount; +// //: Amount of tokens available for issuance +// uint64 availableForIssueance; +// //: Amount of tokens issued already +// uint64 issued; +// //: Amount of tokens to be issued which is locked. `pendingIssuance+issued <= maxIssuanceAmount` +// uint64 pendingIssuance; +// //: Policies of the asset // uint32 policies; -// uint64 type; // use instead policies that limit usage, use in account rules +// //: Used to restrict usage. Used in account rules +// uint64 type; +// //: Number of decimal places. Must be <= 6 // uint32 trailingDigitsCount; // -// // reserved for future use -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } -// ext; +// //: Reserved for future use +// EmptyExt ext; // }; // =========================================================================== -public struct AssetEntry: XDREncodable { +public struct AssetEntry: XDRCodable { public var code: AssetCode public var owner: AccountID public var preissuedAssetSigner: AccountID @@ -41,7 +47,7 @@ public struct AssetEntry: XDREncodable { public var policies: Uint32 public var type: Uint64 public var trailingDigitsCount: Uint32 - public var ext: AssetEntryExt + public var ext: EmptyExt public init( code: AssetCode, @@ -55,7 +61,7 @@ public struct AssetEntry: XDREncodable { policies: Uint32, type: Uint64, trailingDigitsCount: Uint32, - ext: AssetEntryExt) { + ext: EmptyExt) { self.code = code self.owner = owner @@ -90,26 +96,18 @@ public struct AssetEntry: XDREncodable { return xdr } - public enum AssetEntryExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.owner = try AccountID(xdrData: &xdrData) + self.preissuedAssetSigner = try AccountID(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.maxIssuanceAmount = try Uint64(xdrData: &xdrData) + self.availableForIssueance = try Uint64(xdrData: &xdrData) + self.issued = try Uint64(xdrData: &xdrData) + self.pendingIssuance = try Uint64(xdrData: &xdrData) + self.policies = try Uint32(xdrData: &xdrData) + self.type = try Uint64(xdrData: &xdrData) + self.trailingDigitsCount = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) } } diff --git a/Sources/TokenDWallet/Xdr/AssetPairEntry.swift b/Sources/TokenDWallet/Xdr/AssetPairEntry.swift index dc8b882..d40c9b6 100644 --- a/Sources/TokenDWallet/Xdr/AssetPairEntry.swift +++ b/Sources/TokenDWallet/Xdr/AssetPairEntry.swift @@ -40,7 +40,7 @@ import Foundation // }; // =========================================================================== -public struct AssetPairEntry: XDREncodable { +public struct AssetPairEntry: XDRCodable { public var base: AssetCode public var quote: AssetCode public var currentPrice: Int64 @@ -85,6 +85,17 @@ public struct AssetPairEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.base = try AssetCode(xdrData: &xdrData) + self.quote = try AssetCode(xdrData: &xdrData) + self.currentPrice = try Int64(xdrData: &xdrData) + self.physicalPrice = try Int64(xdrData: &xdrData) + self.physicalPriceCorrection = try Int64(xdrData: &xdrData) + self.maxPriceStep = try Int64(xdrData: &xdrData) + self.policies = try Int32(xdrData: &xdrData) + self.ext = try AssetPairEntryExt(xdrData: &xdrData) + } + public enum AssetPairEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -106,5 +117,15 @@ public struct AssetPairEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AssetPolicy.swift b/Sources/TokenDWallet/Xdr/AssetPolicy.swift index 603ad16..6413cd1 100644 --- a/Sources/TokenDWallet/Xdr/AssetPolicy.swift +++ b/Sources/TokenDWallet/Xdr/AssetPolicy.swift @@ -7,13 +7,21 @@ import Foundation // enum AssetPolicy // { +// //: Defines whether or not asset can be transfered using payments // TRANSFERABLE = 1, +// //: Defines whether or not asset is considered base // BASE_ASSET = 2, +// //: [[Deprecated]] // STATS_QUOTE_ASSET = 4, +// //: Defines whether or not asset can be withdrawed from the system // WITHDRAWABLE = 8, +// //: Defines whether or not manual review for issuance of asset is required // ISSUANCE_MANUAL_REVIEW_REQUIRED = 16, +// //: Defines whether or not asset can be base in atomic swap // CAN_BE_BASE_IN_ATOMIC_SWAP = 32, -// CAN_BE_QUOTE_IN_ATOMIC_SWAP = 64 +// //: Defines whether or not asset can be quote in atomic swap +// CAN_BE_QUOTE_IN_ATOMIC_SWAP = 64, +// SWAPPABLE = 128 // }; // =========================================================================== @@ -25,4 +33,5 @@ public enum AssetPolicy: Int32, XDREnum { case issuanceManualReviewRequired = 16 case canBeBaseInAtomicSwap = 32 case canBeQuoteInAtomicSwap = 64 + case swappable = 128 } diff --git a/Sources/TokenDWallet/Xdr/AssetUpdateRequest.swift b/Sources/TokenDWallet/Xdr/AssetUpdateRequest.swift index 826bea0..c670f41 100644 --- a/Sources/TokenDWallet/Xdr/AssetUpdateRequest.swift +++ b/Sources/TokenDWallet/Xdr/AssetUpdateRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct AssetUpdateRequest: XDREncodable { +public struct AssetUpdateRequest: XDRCodable { public var code: AssetCode public var creatorDetails: Longstring public var policies: Uint32 @@ -59,6 +59,14 @@ public struct AssetUpdateRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.policies = try Uint32(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + self.ext = try AssetUpdateRequestExt(xdrData: &xdrData) + } + public enum AssetUpdateRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -80,5 +88,15 @@ public struct AssetUpdateRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AtomicSwapAskEntry.swift b/Sources/TokenDWallet/Xdr/AtomicSwapAskEntry.swift index 4aeb234..4460969 100644 --- a/Sources/TokenDWallet/Xdr/AtomicSwapAskEntry.swift +++ b/Sources/TokenDWallet/Xdr/AtomicSwapAskEntry.swift @@ -31,7 +31,7 @@ import Foundation // }; // =========================================================================== -public struct AtomicSwapAskEntry: XDREncodable { +public struct AtomicSwapAskEntry: XDRCodable { public var id: Uint64 public var ownerID: AccountID public var baseAsset: AssetCode @@ -88,6 +88,24 @@ public struct AtomicSwapAskEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + self.baseAsset = try AssetCode(xdrData: &xdrData) + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.lockedAmount = try Uint64(xdrData: &xdrData) + self.createdAt = try Uint64(xdrData: &xdrData) + self.isCancelled = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + let lengthquoteAssets = try Int32(xdrData: &xdrData) + self.quoteAssets = [AtomicSwapAskQuoteAsset]() + for _ in 1...lengthquoteAssets { + self.quoteAssets.append(try AtomicSwapAskQuoteAsset(xdrData: &xdrData)) + } + self.ext = try AtomicSwapAskEntryExt(xdrData: &xdrData) + } + public enum AtomicSwapAskEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -109,5 +127,15 @@ public struct AtomicSwapAskEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AtomicSwapAskExtended.swift b/Sources/TokenDWallet/Xdr/AtomicSwapAskExtended.swift index 468fea7..cf935e8 100644 --- a/Sources/TokenDWallet/Xdr/AtomicSwapAskExtended.swift +++ b/Sources/TokenDWallet/Xdr/AtomicSwapAskExtended.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct AtomicSwapAskExtended: XDREncodable { +public struct AtomicSwapAskExtended: XDRCodable { public var askID: Uint64 public var ext: AtomicSwapAskExtendedExt @@ -42,6 +42,11 @@ public struct AtomicSwapAskExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.askID = try Uint64(xdrData: &xdrData) + self.ext = try AtomicSwapAskExtendedExt(xdrData: &xdrData) + } + public enum AtomicSwapAskExtendedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct AtomicSwapAskExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AtomicSwapAskQuoteAsset.swift b/Sources/TokenDWallet/Xdr/AtomicSwapAskQuoteAsset.swift index 55d679a..2858081 100644 --- a/Sources/TokenDWallet/Xdr/AtomicSwapAskQuoteAsset.swift +++ b/Sources/TokenDWallet/Xdr/AtomicSwapAskQuoteAsset.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct AtomicSwapAskQuoteAsset: XDREncodable { +public struct AtomicSwapAskQuoteAsset: XDRCodable { public var quoteAsset: AssetCode public var price: Uint64 public var ext: AtomicSwapAskQuoteAssetExt @@ -47,6 +47,12 @@ public struct AtomicSwapAskQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.price = try Uint64(xdrData: &xdrData) + self.ext = try AtomicSwapAskQuoteAssetExt(xdrData: &xdrData) + } + public enum AtomicSwapAskQuoteAssetExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +74,15 @@ public struct AtomicSwapAskQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/AtomicSwapBidEntry.swift b/Sources/TokenDWallet/Xdr/AtomicSwapBidEntry.swift deleted file mode 100644 index b263fa7..0000000 --- a/Sources/TokenDWallet/Xdr/AtomicSwapBidEntry.swift +++ /dev/null @@ -1,113 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct AtomicSwapBidEntry -// { -// uint64 bidID; -// AccountID ownerID; -// AssetCode baseAsset; -// BalanceID baseBalance; -// uint64 amount; -// uint64 lockedAmount; -// uint64 createdAt; -// -// bool isCancelled; -// -// longstring details; -// -// ASwapBidQuoteAsset quoteAssets<>; -// -// // reserved for future use -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } -// ext; -// }; - -// =========================================================================== -public struct AtomicSwapBidEntry: XDREncodable { - public var bidID: Uint64 - public var ownerID: AccountID - public var baseAsset: AssetCode - public var baseBalance: BalanceID - public var amount: Uint64 - public var lockedAmount: Uint64 - public var createdAt: Uint64 - public var isCancelled: Bool - public var details: Longstring - public var quoteAssets: [ASwapBidQuoteAsset] - public var ext: AtomicSwapBidEntryExt - - public init( - bidID: Uint64, - ownerID: AccountID, - baseAsset: AssetCode, - baseBalance: BalanceID, - amount: Uint64, - lockedAmount: Uint64, - createdAt: Uint64, - isCancelled: Bool, - details: Longstring, - quoteAssets: [ASwapBidQuoteAsset], - ext: AtomicSwapBidEntryExt) { - - self.bidID = bidID - self.ownerID = ownerID - self.baseAsset = baseAsset - self.baseBalance = baseBalance - self.amount = amount - self.lockedAmount = lockedAmount - self.createdAt = createdAt - self.isCancelled = isCancelled - self.details = details - self.quoteAssets = quoteAssets - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.bidID.toXDR()) - xdr.append(self.ownerID.toXDR()) - xdr.append(self.baseAsset.toXDR()) - xdr.append(self.baseBalance.toXDR()) - xdr.append(self.amount.toXDR()) - xdr.append(self.lockedAmount.toXDR()) - xdr.append(self.createdAt.toXDR()) - xdr.append(self.isCancelled.toXDR()) - xdr.append(self.details.toXDR()) - xdr.append(self.quoteAssets.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum AtomicSwapBidEntryExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/AtomicSwapBidExtended.swift b/Sources/TokenDWallet/Xdr/AtomicSwapBidExtended.swift index 247d3c8..5de573e 100644 --- a/Sources/TokenDWallet/Xdr/AtomicSwapBidExtended.swift +++ b/Sources/TokenDWallet/Xdr/AtomicSwapBidExtended.swift @@ -41,7 +41,7 @@ import Foundation // }; // =========================================================================== -public struct AtomicSwapBidExtended: XDREncodable { +public struct AtomicSwapBidExtended: XDRCodable { public var askID: Uint64 public var askOwnerID: AccountID public var bidOwnerID: AccountID @@ -102,6 +102,21 @@ public struct AtomicSwapBidExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.askID = try Uint64(xdrData: &xdrData) + self.askOwnerID = try AccountID(xdrData: &xdrData) + self.bidOwnerID = try AccountID(xdrData: &xdrData) + self.baseAsset = try AssetCode(xdrData: &xdrData) + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.baseAmount = try Uint64(xdrData: &xdrData) + self.quoteAmount = try Uint64(xdrData: &xdrData) + self.price = try Uint64(xdrData: &xdrData) + self.askOwnerBaseBalanceID = try BalanceID(xdrData: &xdrData) + self.bidOwnerBaseBalanceID = try BalanceID(xdrData: &xdrData) + self.unlockedAmount = try Uint64(xdrData: &xdrData) + self.ext = try AtomicSwapBidExtendedExt(xdrData: &xdrData) + } + public enum AtomicSwapBidExtendedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -123,5 +138,15 @@ public struct AtomicSwapBidExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/Auth.swift b/Sources/TokenDWallet/Xdr/Auth.swift index 40b5ddc..fa9c13e 100644 --- a/Sources/TokenDWallet/Xdr/Auth.swift +++ b/Sources/TokenDWallet/Xdr/Auth.swift @@ -13,7 +13,7 @@ import Foundation // }; // =========================================================================== -public struct Auth: XDREncodable { +public struct Auth: XDRCodable { public var unused: Int32 public init( @@ -29,4 +29,8 @@ public struct Auth: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.unused = try Int32(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/AuthCert.swift b/Sources/TokenDWallet/Xdr/AuthCert.swift index d57ecbc..e38a2c2 100644 --- a/Sources/TokenDWallet/Xdr/AuthCert.swift +++ b/Sources/TokenDWallet/Xdr/AuthCert.swift @@ -13,7 +13,7 @@ import Foundation // }; // =========================================================================== -public struct AuthCert: XDREncodable { +public struct AuthCert: XDRCodable { public var pubkey: Curve25519Public public var expiration: Uint64 public var sig: Signature @@ -37,4 +37,10 @@ public struct AuthCert: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.pubkey = try Curve25519Public(xdrData: &xdrData) + self.expiration = try Uint64(xdrData: &xdrData) + self.sig = try Signature(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/AuthenticatedMessage.swift b/Sources/TokenDWallet/Xdr/AuthenticatedMessage.swift index 24d66dd..30fbdb3 100644 --- a/Sources/TokenDWallet/Xdr/AuthenticatedMessage.swift +++ b/Sources/TokenDWallet/Xdr/AuthenticatedMessage.swift @@ -37,7 +37,19 @@ public enum AuthenticatedMessage: XDRDiscriminatedUnion { return xdr } - public struct AuthenticatedMessageV0: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: + let data = try AuthenticatedMessageV0(xdrData: &xdrData) + self = .emptyVersion(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct AuthenticatedMessageV0: XDRCodable { public var sequence: Uint64 public var message: StellarMessage public var mac: HmacSha256Mac @@ -62,5 +74,11 @@ public enum AuthenticatedMessage: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.sequence = try Uint64(xdrData: &xdrData) + self.message = try StellarMessage(xdrData: &xdrData) + self.mac = try HmacSha256Mac(xdrData: &xdrData) + } + } } diff --git a/Sources/TokenDWallet/Xdr/BalanceEntry.swift b/Sources/TokenDWallet/Xdr/BalanceEntry.swift index a326a1c..614b5cd 100644 --- a/Sources/TokenDWallet/Xdr/BalanceEntry.swift +++ b/Sources/TokenDWallet/Xdr/BalanceEntry.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct BalanceEntry: XDREncodable { +public struct BalanceEntry: XDRCodable { public var balanceID: BalanceID public var sequentialID: Uint64 public var asset: AssetCode @@ -67,6 +67,16 @@ public struct BalanceEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.balanceID = try BalanceID(xdrData: &xdrData) + self.sequentialID = try Uint64(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.accountID = try AccountID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.locked = try Uint64(xdrData: &xdrData) + self.ext = try BalanceEntryExt(xdrData: &xdrData) + } + public enum BalanceEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -88,5 +98,15 @@ public struct BalanceEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/BasicSale.swift b/Sources/TokenDWallet/Xdr/BasicSale.swift index cd4696c..81ead83 100644 --- a/Sources/TokenDWallet/Xdr/BasicSale.swift +++ b/Sources/TokenDWallet/Xdr/BasicSale.swift @@ -15,7 +15,7 @@ import Foundation // }; // =========================================================================== -public struct BasicSale: XDREncodable { +public struct BasicSale: XDRCodable { public var ext: BasicSaleExt public init( @@ -32,6 +32,10 @@ public struct BasicSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try BasicSaleExt(xdrData: &xdrData) + } + public enum BasicSaleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -53,5 +57,15 @@ public struct BasicSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/BillPayDetails.swift b/Sources/TokenDWallet/Xdr/BillPayDetails.swift index fcb91fd..7286f3b 100644 --- a/Sources/TokenDWallet/Xdr/BillPayDetails.swift +++ b/Sources/TokenDWallet/Xdr/BillPayDetails.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct BillPayDetails: XDREncodable { +public struct BillPayDetails: XDRCodable { public var paymentDetails: PaymentOp public var ext: BillPayDetailsExt @@ -41,6 +41,11 @@ public struct BillPayDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.paymentDetails = try PaymentOp(xdrData: &xdrData) + self.ext = try BillPayDetailsExt(xdrData: &xdrData) + } + public enum BillPayDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct BillPayDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdOp.swift b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdOp.swift index 06317e5..cb41621 100644 --- a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdOp.swift +++ b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdOp.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct BindExternalSystemAccountIdOp: XDREncodable { +public struct BindExternalSystemAccountIdOp: XDRCodable { public var externalSystemType: Int32 public var ext: BindExternalSystemAccountIdOpExt @@ -42,6 +42,11 @@ public struct BindExternalSystemAccountIdOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.externalSystemType = try Int32(xdrData: &xdrData) + self.ext = try BindExternalSystemAccountIdOpExt(xdrData: &xdrData) + } + public enum BindExternalSystemAccountIdOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct BindExternalSystemAccountIdOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdResult.swift b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdResult.swift index fe1b8b1..5e237b2 100644 --- a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdResult.swift +++ b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdResult.swift @@ -36,4 +36,16 @@ public enum BindExternalSystemAccountIdResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case BindExternalSystemAccountIdResultCode.success.rawValue: + let data = try BindExternalSystemAccountIdSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdSuccess.swift b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdSuccess.swift index 890b806..e7acd68 100644 --- a/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdSuccess.swift +++ b/Sources/TokenDWallet/Xdr/BindExternalSystemAccountIdSuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct BindExternalSystemAccountIdSuccess: XDREncodable { +public struct BindExternalSystemAccountIdSuccess: XDRCodable { public var data: Longstring public var ext: BindExternalSystemAccountIdSuccessExt @@ -42,6 +42,11 @@ public struct BindExternalSystemAccountIdSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try Longstring(xdrData: &xdrData) + self.ext = try BindExternalSystemAccountIdSuccessExt(xdrData: &xdrData) + } + public enum BindExternalSystemAccountIdSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct BindExternalSystemAccountIdSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/BucketEntry.swift b/Sources/TokenDWallet/Xdr/BucketEntry.swift index adbf22b..c8d232e 100644 --- a/Sources/TokenDWallet/Xdr/BucketEntry.swift +++ b/Sources/TokenDWallet/Xdr/BucketEntry.swift @@ -38,4 +38,19 @@ public enum BucketEntry: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case BucketEntryType.liveentry.rawValue: + let data = try LedgerEntry(xdrData: &xdrData) + self = .liveentry(data) + case BucketEntryType.deadentry.rawValue: + let data = try LedgerKey(xdrData: &xdrData) + self = .deadentry(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelASwapBidOp.swift b/Sources/TokenDWallet/Xdr/CancelASwapBidOp.swift deleted file mode 100644 index 18ffb7b..0000000 --- a/Sources/TokenDWallet/Xdr/CancelASwapBidOp.swift +++ /dev/null @@ -1,64 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct CancelASwapBidOp -// { -// uint64 bidID; -// -// // reserved for future use -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct CancelASwapBidOp: XDREncodable { - public var bidID: Uint64 - public var ext: CancelASwapBidOpExt - - public init( - bidID: Uint64, - ext: CancelASwapBidOpExt) { - - self.bidID = bidID - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.bidID.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum CancelASwapBidOpExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/CancelASwapBidResult.swift b/Sources/TokenDWallet/Xdr/CancelASwapBidResult.swift deleted file mode 100644 index 45d21ed..0000000 --- a/Sources/TokenDWallet/Xdr/CancelASwapBidResult.swift +++ /dev/null @@ -1,37 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// union CancelASwapBidResult switch (CancelASwapBidResultCode code) -// { -// case SUCCESS: -// CancelASwapBidResultSuccess success; -// default: -// void; -// }; - -// =========================================================================== -public enum CancelASwapBidResult: XDRDiscriminatedUnion { - case success(CancelASwapBidResultSuccess) - - public var discriminant: Int32 { - switch self { - case .success: return CancelASwapBidResultCode.success.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .success(let data): xdr.append(data.toXDR()) - } - - return xdr - } -} diff --git a/Sources/TokenDWallet/Xdr/CancelASwapBidResultCode.swift b/Sources/TokenDWallet/Xdr/CancelASwapBidResultCode.swift deleted file mode 100644 index 4b38074..0000000 --- a/Sources/TokenDWallet/Xdr/CancelASwapBidResultCode.swift +++ /dev/null @@ -1,23 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// enum CancelASwapBidResultCode -// { -// // codes considered as "success" for the operation -// SUCCESS = 0, -// -// // codes considered as "failure" for the operation -// NOT_FOUND = -1, // atomic swap bid does not exist -// ALREADY_CANCELLED = -2 // atomic swap bid already cancelled -// }; - -// =========================================================================== -public enum CancelASwapBidResultCode: Int32, XDREnum { - case success = 0 - case notFound = -1 - case alreadyCancelled = -2 -} diff --git a/Sources/TokenDWallet/Xdr/CancelASwapBidResultSuccess.swift b/Sources/TokenDWallet/Xdr/CancelASwapBidResultSuccess.swift deleted file mode 100644 index 9044c14..0000000 --- a/Sources/TokenDWallet/Xdr/CancelASwapBidResultSuccess.swift +++ /dev/null @@ -1,57 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct CancelASwapBidResultSuccess -// { -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct CancelASwapBidResultSuccess: XDREncodable { - public var ext: CancelASwapBidResultSuccessExt - - public init( - ext: CancelASwapBidResultSuccessExt) { - - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum CancelASwapBidResultSuccessExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/CancelAssetRequest.swift b/Sources/TokenDWallet/Xdr/CancelAssetRequest.swift index 690e553..eea8c5a 100644 --- a/Sources/TokenDWallet/Xdr/CancelAssetRequest.swift +++ b/Sources/TokenDWallet/Xdr/CancelAssetRequest.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct CancelAssetRequest: XDREncodable { +public struct CancelAssetRequest: XDRCodable { public var ext: CancelAssetRequestExt public init( @@ -35,6 +35,10 @@ public struct CancelAssetRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try CancelAssetRequestExt(xdrData: &xdrData) + } + public enum CancelAssetRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct CancelAssetRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskOp.swift b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskOp.swift index b57dc9f..1ee4a71 100644 --- a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskOp.swift +++ b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskOp.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct CancelAtomicSwapAskOp: XDREncodable { +public struct CancelAtomicSwapAskOp: XDRCodable { public var askID: Uint64 public var ext: CancelAtomicSwapAskOpExt @@ -41,6 +41,11 @@ public struct CancelAtomicSwapAskOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.askID = try Uint64(xdrData: &xdrData) + self.ext = try CancelAtomicSwapAskOpExt(xdrData: &xdrData) + } + public enum CancelAtomicSwapAskOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct CancelAtomicSwapAskOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResult.swift b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResult.swift index c20beac..95e2a32 100644 --- a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResult.swift +++ b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResult.swift @@ -36,4 +36,16 @@ public enum CancelAtomicSwapAskResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CancelAtomicSwapAskResultCode.success.rawValue: + let data = try CancelAtomicSwapAskResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResultSuccess.swift b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResultSuccess.swift index 4d64c2b..d1beef6 100644 --- a/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResultSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CancelAtomicSwapAskResultSuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CancelAtomicSwapAskResultSuccess: XDREncodable { +public struct CancelAtomicSwapAskResultSuccess: XDRCodable { public var lockedAmount: Uint64 public var ext: CancelAtomicSwapAskResultSuccessExt @@ -42,6 +42,11 @@ public struct CancelAtomicSwapAskResultSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.lockedAmount = try Uint64(xdrData: &xdrData) + self.ext = try CancelAtomicSwapAskResultSuccessExt(xdrData: &xdrData) + } + public enum CancelAtomicSwapAskResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct CancelAtomicSwapAskResultSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestOp.swift b/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestOp.swift index 49ed87a..6052966 100644 --- a/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestOp.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct CancelChangeRoleRequestOp: XDREncodable { +public struct CancelChangeRoleRequestOp: XDRCodable { public var requestID: Uint64 public var ext: CancelChangeRoleRequestOpExt @@ -44,6 +44,11 @@ public struct CancelChangeRoleRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try CancelChangeRoleRequestOpExt(xdrData: &xdrData) + } + public enum CancelChangeRoleRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -65,5 +70,15 @@ public struct CancelChangeRoleRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestResult.swift b/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestResult.swift index 5b8c219..86350ee 100644 --- a/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CancelChangeRoleRequestResult.swift @@ -9,14 +9,14 @@ import Foundation // union CancelChangeRoleRequestResult switch (CancelChangeRoleRequestResultCode code) // { // case SUCCESS: -// CancelSaleCreationSuccess success; +// CancelChangeRoleSuccess success; // default: // void; // }; // =========================================================================== public enum CancelChangeRoleRequestResult: XDRDiscriminatedUnion { - case success(CancelSaleCreationSuccess) + case success(CancelChangeRoleSuccess) public var discriminant: Int32 { switch self { @@ -35,4 +35,16 @@ public enum CancelChangeRoleRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CancelChangeRoleRequestResultCode.success.rawValue: + let data = try CancelChangeRoleSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelChangeRoleSuccess.swift b/Sources/TokenDWallet/Xdr/CancelChangeRoleSuccess.swift index 26369ae..5c6bf53 100644 --- a/Sources/TokenDWallet/Xdr/CancelChangeRoleSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CancelChangeRoleSuccess.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct CancelChangeRoleSuccess: XDREncodable { +public struct CancelChangeRoleSuccess: XDRCodable { public var ext: CancelChangeRoleSuccessExt public init( @@ -35,6 +35,10 @@ public struct CancelChangeRoleSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try CancelChangeRoleSuccessExt(xdrData: &xdrData) + } + public enum CancelChangeRoleSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct CancelChangeRoleSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelPollRequestData.swift b/Sources/TokenDWallet/Xdr/CancelPollRequestData.swift index bb148f8..adbe4f0 100644 --- a/Sources/TokenDWallet/Xdr/CancelPollRequestData.swift +++ b/Sources/TokenDWallet/Xdr/CancelPollRequestData.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CancelPollRequestData: XDREncodable { +public struct CancelPollRequestData: XDRCodable { public var requestID: Uint64 public var ext: CancelPollRequestDataExt @@ -42,6 +42,11 @@ public struct CancelPollRequestData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try CancelPollRequestDataExt(xdrData: &xdrData) + } + public enum CancelPollRequestDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct CancelPollRequestData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestOp.swift b/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestOp.swift index e762acf..2747d5d 100644 --- a/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestOp.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CancelSaleCreationRequestOp: XDREncodable { +public struct CancelSaleCreationRequestOp: XDRCodable { public var requestID: Uint64 public var ext: CancelSaleCreationRequestOpExt @@ -45,6 +45,11 @@ public struct CancelSaleCreationRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try CancelSaleCreationRequestOpExt(xdrData: &xdrData) + } + public enum CancelSaleCreationRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +71,15 @@ public struct CancelSaleCreationRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestResult.swift b/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestResult.swift index a4c7846..aed265a 100644 --- a/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CancelSaleCreationRequestResult.swift @@ -35,4 +35,16 @@ public enum CancelSaleCreationRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CancelSaleCreationRequestResultCode.success.rawValue: + let data = try CancelSaleCreationSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CancelSaleCreationSuccess.swift b/Sources/TokenDWallet/Xdr/CancelSaleCreationSuccess.swift index 3efc453..95e76b6 100644 --- a/Sources/TokenDWallet/Xdr/CancelSaleCreationSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CancelSaleCreationSuccess.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct CancelSaleCreationSuccess: XDREncodable { +public struct CancelSaleCreationSuccess: XDRCodable { public var ext: CancelSaleCreationSuccessExt public init( @@ -35,6 +35,10 @@ public struct CancelSaleCreationSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try CancelSaleCreationSuccessExt(xdrData: &xdrData) + } + public enum CancelSaleCreationSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct CancelSaleCreationSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ChangeRoleRequest.swift b/Sources/TokenDWallet/Xdr/ChangeRoleRequest.swift index 0da5490..f9563d6 100644 --- a/Sources/TokenDWallet/Xdr/ChangeRoleRequest.swift +++ b/Sources/TokenDWallet/Xdr/ChangeRoleRequest.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct ChangeRoleRequest: XDREncodable { +public struct ChangeRoleRequest: XDRCodable { public var destinationAccount: AccountID public var accountRoleToSet: Uint64 public var sequenceNumber: Uint32 @@ -58,6 +58,14 @@ public struct ChangeRoleRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.destinationAccount = try AccountID(xdrData: &xdrData) + self.accountRoleToSet = try Uint64(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try ChangeRoleRequestExt(xdrData: &xdrData) + } + public enum ChangeRoleRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -79,5 +87,15 @@ public struct ChangeRoleRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CheckSaleClosedResult.swift b/Sources/TokenDWallet/Xdr/CheckSaleClosedResult.swift index 8f2f1ff..cad9db9 100644 --- a/Sources/TokenDWallet/Xdr/CheckSaleClosedResult.swift +++ b/Sources/TokenDWallet/Xdr/CheckSaleClosedResult.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CheckSaleClosedResult: XDREncodable { +public struct CheckSaleClosedResult: XDRCodable { public var saleOwner: AccountID public var results: [CheckSubSaleClosedResult] public var ext: CheckSaleClosedResultExt @@ -46,6 +46,16 @@ public struct CheckSaleClosedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleOwner = try AccountID(xdrData: &xdrData) + let lengthresults = try Int32(xdrData: &xdrData) + self.results = [CheckSubSaleClosedResult]() + for _ in 1...lengthresults { + self.results.append(try CheckSubSaleClosedResult(xdrData: &xdrData)) + } + self.ext = try CheckSaleClosedResultExt(xdrData: &xdrData) + } + public enum CheckSaleClosedResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -67,5 +77,15 @@ public struct CheckSaleClosedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CheckSaleStateOp.swift b/Sources/TokenDWallet/Xdr/CheckSaleStateOp.swift index 192fcf5..1757e24 100644 --- a/Sources/TokenDWallet/Xdr/CheckSaleStateOp.swift +++ b/Sources/TokenDWallet/Xdr/CheckSaleStateOp.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct CheckSaleStateOp: XDREncodable { +public struct CheckSaleStateOp: XDRCodable { public var saleID: Uint64 public var ext: CheckSaleStateOpExt @@ -41,6 +41,11 @@ public struct CheckSaleStateOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.ext = try CheckSaleStateOpExt(xdrData: &xdrData) + } + public enum CheckSaleStateOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct CheckSaleStateOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CheckSaleStateResult.swift b/Sources/TokenDWallet/Xdr/CheckSaleStateResult.swift index a61637d..eb2ffbc 100644 --- a/Sources/TokenDWallet/Xdr/CheckSaleStateResult.swift +++ b/Sources/TokenDWallet/Xdr/CheckSaleStateResult.swift @@ -35,4 +35,16 @@ public enum CheckSaleStateResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CheckSaleStateResultCode.success.rawValue: + let data = try CheckSaleStateSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CheckSaleStateSuccess.swift b/Sources/TokenDWallet/Xdr/CheckSaleStateSuccess.swift index 51fff07..bad8755 100644 --- a/Sources/TokenDWallet/Xdr/CheckSaleStateSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CheckSaleStateSuccess.swift @@ -31,7 +31,7 @@ import Foundation // }; // =========================================================================== -public struct CheckSaleStateSuccess: XDREncodable { +public struct CheckSaleStateSuccess: XDRCodable { public var saleID: Uint64 public var effect: CheckSaleStateSuccessEffect public var ext: CheckSaleStateSuccessExt @@ -56,6 +56,12 @@ public struct CheckSaleStateSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.effect = try CheckSaleStateSuccessEffect(xdrData: &xdrData) + self.ext = try CheckSaleStateSuccessExt(xdrData: &xdrData) + } + public enum CheckSaleStateSuccessEffect: XDRDiscriminatedUnion { case canceled(SaleCanceled) case closed(CheckSaleClosedResult) @@ -83,6 +89,24 @@ public struct CheckSaleStateSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CheckSaleStateEffect.canceled.rawValue: + let data = try SaleCanceled(xdrData: &xdrData) + self = .canceled(data) + case CheckSaleStateEffect.closed.rawValue: + let data = try CheckSaleClosedResult(xdrData: &xdrData) + self = .closed(data) + case CheckSaleStateEffect.updated.rawValue: + let data = try SaleUpdated(xdrData: &xdrData) + self = .updated(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum CheckSaleStateSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -105,5 +129,15 @@ public struct CheckSaleStateSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CheckSubSaleClosedResult.swift b/Sources/TokenDWallet/Xdr/CheckSubSaleClosedResult.swift index 41fe76a..0c02dda 100644 --- a/Sources/TokenDWallet/Xdr/CheckSubSaleClosedResult.swift +++ b/Sources/TokenDWallet/Xdr/CheckSubSaleClosedResult.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct CheckSubSaleClosedResult: XDREncodable { +public struct CheckSubSaleClosedResult: XDRCodable { public var saleBaseBalance: BalanceID public var saleQuoteBalance: BalanceID public var saleDetails: ManageOfferSuccessResult @@ -52,6 +52,13 @@ public struct CheckSubSaleClosedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleBaseBalance = try BalanceID(xdrData: &xdrData) + self.saleQuoteBalance = try BalanceID(xdrData: &xdrData) + self.saleDetails = try ManageOfferSuccessResult(xdrData: &xdrData) + self.ext = try CheckSubSaleClosedResultExt(xdrData: &xdrData) + } + public enum CheckSubSaleClosedResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +80,15 @@ public struct CheckSubSaleClosedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ClaimOfferAtom.swift b/Sources/TokenDWallet/Xdr/ClaimOfferAtom.swift index 218a08a..ae04eae 100644 --- a/Sources/TokenDWallet/Xdr/ClaimOfferAtom.swift +++ b/Sources/TokenDWallet/Xdr/ClaimOfferAtom.swift @@ -37,7 +37,7 @@ import Foundation // }; // =========================================================================== -public struct ClaimOfferAtom: XDREncodable { +public struct ClaimOfferAtom: XDRCodable { public var bAccountID: AccountID public var offerID: Uint64 public var baseAmount: Int64 @@ -90,6 +90,19 @@ public struct ClaimOfferAtom: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.bAccountID = try AccountID(xdrData: &xdrData) + self.offerID = try Uint64(xdrData: &xdrData) + self.baseAmount = try Int64(xdrData: &xdrData) + self.quoteAmount = try Int64(xdrData: &xdrData) + self.bFeePaid = try Int64(xdrData: &xdrData) + self.aFeePaid = try Int64(xdrData: &xdrData) + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.quoteBalance = try BalanceID(xdrData: &xdrData) + self.currentPrice = try Int64(xdrData: &xdrData) + self.ext = try ClaimOfferAtomExt(xdrData: &xdrData) + } + public enum ClaimOfferAtomExt: XDRDiscriminatedUnion { case emptyVersion() @@ -111,5 +124,15 @@ public struct ClaimOfferAtom: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ClosePollData.swift b/Sources/TokenDWallet/Xdr/ClosePollData.swift index 695a3dc..8a295c8 100644 --- a/Sources/TokenDWallet/Xdr/ClosePollData.swift +++ b/Sources/TokenDWallet/Xdr/ClosePollData.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct ClosePollData: XDREncodable { +public struct ClosePollData: XDRCodable { public var result: PollResult public var details: Longstring public var ext: ClosePollDataExt @@ -49,6 +49,12 @@ public struct ClosePollData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.result = try PollResult(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try ClosePollDataExt(xdrData: &xdrData) + } + public enum ClosePollDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -70,5 +76,15 @@ public struct ClosePollData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CloseSwapEffect.swift b/Sources/TokenDWallet/Xdr/CloseSwapEffect.swift new file mode 100644 index 0000000..7e5164b --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CloseSwapEffect.swift @@ -0,0 +1,20 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// enum CloseSwapEffect +// { +// //: Swap closed +// CLOSED = 0, +// //: Swap cancelled +// CANCELLED = 1 +// }; + +// =========================================================================== +public enum CloseSwapEffect: Int32, XDREnum { + case closed = 0 + case cancelled = 1 +} diff --git a/Sources/TokenDWallet/Xdr/CloseSwapOp.swift b/Sources/TokenDWallet/Xdr/CloseSwapOp.swift new file mode 100644 index 0000000..15834fa --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CloseSwapOp.swift @@ -0,0 +1,54 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct CloseSwapOp +// { +// //: ID of the swap to close +// uint64 swapID; +// //: (optional) Secret of the swap. Must be provided in order for destination of the swap to receive funds +// Hash* secret; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CloseSwapOp: XDRCodable { + public var swapID: Uint64 + public var secret: Hash? + public var ext: EmptyExt + + public init( + swapID: Uint64, + secret: Hash?, + ext: EmptyExt) { + + self.swapID = swapID + self.secret = secret + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.swapID.toXDR()) + xdr.append(self.secret.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.swapID = try Uint64(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.secret = try Hash(xdrData: &xdrData) + } else { + self.secret = nil + } + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/CloseSwapResult.swift b/Sources/TokenDWallet/Xdr/CloseSwapResult.swift new file mode 100644 index 0000000..6264135 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CloseSwapResult.swift @@ -0,0 +1,50 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: CloseSwapResult is a result of CloseSwap operation application +// union CloseSwapResult switch (CloseSwapResultCode code) +// { +// case SUCCESS: +// CloseSwapSuccess success; +// default: +// void; +// }; + +// =========================================================================== +public enum CloseSwapResult: XDRDiscriminatedUnion { + case success(CloseSwapSuccess) + + public var discriminant: Int32 { + switch self { + case .success: return CloseSwapResultCode.success.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CloseSwapResultCode.success.rawValue: + let data = try CloseSwapSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/CloseSwapResultCode.swift b/Sources/TokenDWallet/Xdr/CloseSwapResultCode.swift new file mode 100644 index 0000000..313cb09 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CloseSwapResultCode.swift @@ -0,0 +1,29 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// enum CloseSwapResultCode +// { +// //: CloseSwap was successful +// SUCCESS = 0, +// //: Too late to close swap +// SWAP_EXPIRED = -1, +// //: Provided secret is invalid +// INVALID_SECRET = -2, +// //: After the swap fulfillment, the destination balance will exceed the limit (total amount on the balance will be greater than UINT64_MAX) +// LINE_FULL = -3, +// //: Source account is not authorized to close swap +// NOT_AUTHORIZED = -4 +// }; + +// =========================================================================== +public enum CloseSwapResultCode: Int32, XDREnum { + case success = 0 + case swapExpired = -1 + case invalidSecret = -2 + case lineFull = -3 + case notAuthorized = -4 +} diff --git a/Sources/TokenDWallet/Xdr/CloseSwapSuccess.swift b/Sources/TokenDWallet/Xdr/CloseSwapSuccess.swift new file mode 100644 index 0000000..8896300 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CloseSwapSuccess.swift @@ -0,0 +1,42 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: CloseSwapSuccess is used to pass saved ledger hash and license hash +// struct CloseSwapSuccess { +// //: Effect of CloseSwap application +// CloseSwapEffect effect; +// +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CloseSwapSuccess: XDRCodable { + public var effect: CloseSwapEffect + public var ext: EmptyExt + + public init( + effect: CloseSwapEffect, + ext: EmptyExt) { + + self.effect = effect + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.effect.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.effect = try CloseSwapEffect(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/ContractDetails.swift b/Sources/TokenDWallet/Xdr/ContractDetails.swift index 9a957df..c57d1c2 100644 --- a/Sources/TokenDWallet/Xdr/ContractDetails.swift +++ b/Sources/TokenDWallet/Xdr/ContractDetails.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct ContractDetails: XDREncodable { +public struct ContractDetails: XDRCodable { public var details: Longstring public var ext: ContractDetailsExt @@ -39,6 +39,11 @@ public struct ContractDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try Longstring(xdrData: &xdrData) + self.ext = try ContractDetailsExt(xdrData: &xdrData) + } + public enum ContractDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -60,5 +65,15 @@ public struct ContractDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ContractEntry.swift b/Sources/TokenDWallet/Xdr/ContractEntry.swift index 8bd2046..a979ff8 100644 --- a/Sources/TokenDWallet/Xdr/ContractEntry.swift +++ b/Sources/TokenDWallet/Xdr/ContractEntry.swift @@ -30,7 +30,7 @@ import Foundation // }; // =========================================================================== -public struct ContractEntry: XDREncodable { +public struct ContractEntry: XDRCodable { public var contractID: Uint64 public var contractor: AccountID public var customer: AccountID @@ -87,6 +87,24 @@ public struct ContractEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.contractID = try Uint64(xdrData: &xdrData) + self.contractor = try AccountID(xdrData: &xdrData) + self.customer = try AccountID(xdrData: &xdrData) + self.escrow = try AccountID(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + let lengthinvoiceRequestsIDs = try Int32(xdrData: &xdrData) + self.invoiceRequestsIDs = [Uint64]() + for _ in 1...lengthinvoiceRequestsIDs { + self.invoiceRequestsIDs.append(try Uint64(xdrData: &xdrData)) + } + self.initialDetails = try Longstring(xdrData: &xdrData) + self.state = try Uint32(xdrData: &xdrData) + self.customerDetails = try Longstring(xdrData: &xdrData) + self.ext = try ContractEntryExt(xdrData: &xdrData) + } + public enum ContractEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -108,5 +126,15 @@ public struct ContractEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ContractRequest.swift b/Sources/TokenDWallet/Xdr/ContractRequest.swift index 60e137d..c5f0f12 100644 --- a/Sources/TokenDWallet/Xdr/ContractRequest.swift +++ b/Sources/TokenDWallet/Xdr/ContractRequest.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct ContractRequest: XDREncodable { +public struct ContractRequest: XDRCodable { public var customer: AccountID public var escrow: AccountID public var creatorDetails: Longstring @@ -61,6 +61,15 @@ public struct ContractRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.customer = try AccountID(xdrData: &xdrData) + self.escrow = try AccountID(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + self.ext = try ContractRequestExt(xdrData: &xdrData) + } + public enum ContractRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -82,5 +91,15 @@ public struct ContractRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestOp.swift index 953ea38..6e880fc 100644 --- a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestOp.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAMLAlertRequestOp: XDREncodable { +public struct CreateAMLAlertRequestOp: XDRCodable { public var reference: String64 public var amlAlertRequest: AMLAlertRequest public var allTasks: Uint32? @@ -57,6 +57,17 @@ public struct CreateAMLAlertRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.reference = try String64(xdrData: &xdrData) + self.amlAlertRequest = try AMLAlertRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateAMLAlertRequestOpExt(xdrData: &xdrData) + } + public enum CreateAMLAlertRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -78,5 +89,15 @@ public struct CreateAMLAlertRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestResult.swift index 10f1f2c..34ca6a4 100644 --- a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestResult.swift @@ -35,4 +35,16 @@ public enum CreateAMLAlertRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateAMLAlertRequestResultCode.success.rawValue: + let data = try CreateAMLAlertRequestSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestSuccess.swift index a4e6a5e..45ce283 100644 --- a/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateAMLAlertRequestSuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAMLAlertRequestSuccess: XDREncodable { +public struct CreateAMLAlertRequestSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreateAMLAlertRequestSuccessExt @@ -46,6 +46,12 @@ public struct CreateAMLAlertRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateAMLAlertRequestSuccessExt(xdrData: &xdrData) + } + public enum CreateAMLAlertRequestSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -67,5 +73,15 @@ public struct CreateAMLAlertRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResult.swift deleted file mode 100644 index 81f3ecf..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResult.swift +++ /dev/null @@ -1,37 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// union CreateASwapBidCreationRequestResult switch (CreateASwapBidCreationRequestResultCode code) -// { -// case SUCCESS: -// CreateASwapBidCreationRequestSuccess success; -// default: -// void; -// }; - -// =========================================================================== -public enum CreateASwapBidCreationRequestResult: XDRDiscriminatedUnion { - case success(CreateASwapBidCreationRequestSuccess) - - public var discriminant: Int32 { - switch self { - case .success: return CreateASwapBidCreationRequestResultCode.success.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .success(let data): xdr.append(data.toXDR()) - } - - return xdr - } -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResultCode.swift b/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResultCode.swift deleted file mode 100644 index 8e1bb80..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestResultCode.swift +++ /dev/null @@ -1,45 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// enum CreateASwapBidCreationRequestResultCode -// { -// // codes considered as "success" for the operation -// SUCCESS = 0, -// -// // codes considered as "failure" for the operation -// INVALID_AMOUNT = -1, // amount is equal to 0 -// INVALID_PRICE = -2, // price is equal to 0 -// INVALID_DETAILS = -3, -// ATOMIC_SWAP_BID_OVERFLOW = -4, -// BASE_ASSET_NOT_FOUND = -5, // base asset does not exist -// BASE_ASSET_CANNOT_BE_SWAPPED = -6, -// QUOTE_ASSET_NOT_FOUND = -7, // quote asset does not exist -// QUOTE_ASSET_CANNOT_BE_SWAPPED = -8, -// BASE_BALANCE_NOT_FOUND = -9, -// ASSETS_ARE_EQUAL = -10, // base and quote assets are the same -// BASE_BALANCE_UNDERFUNDED = -11, -// INVALID_QUOTE_ASSET = -12, // one of the quote assets is invalid -// NOT_ALLOWED_BY_ASSET_POLICY = -13 -// }; - -// =========================================================================== -public enum CreateASwapBidCreationRequestResultCode: Int32, XDREnum { - case success = 0 - case invalidAmount = -1 - case invalidPrice = -2 - case invalidDetails = -3 - case atomicSwapBidOverflow = -4 - case baseAssetNotFound = -5 - case baseAssetCannotBeSwapped = -6 - case quoteAssetNotFound = -7 - case quoteAssetCannotBeSwapped = -8 - case baseBalanceNotFound = -9 - case assetsAreEqual = -10 - case baseBalanceUnderfunded = -11 - case invalidQuoteAsset = -12 - case notAllowedByAssetPolicy = -13 -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestSuccess.swift deleted file mode 100644 index 2f3ad37..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestSuccess.swift +++ /dev/null @@ -1,68 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct CreateASwapBidCreationRequestSuccess -// { -// uint64 requestID; -// bool fulfilled; -// -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct CreateASwapBidCreationRequestSuccess: XDREncodable { - public var requestID: Uint64 - public var fulfilled: Bool - public var ext: CreateASwapBidCreationRequestSuccessExt - - public init( - requestID: Uint64, - fulfilled: Bool, - ext: CreateASwapBidCreationRequestSuccessExt) { - - self.requestID = requestID - self.fulfilled = fulfilled - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.requestID.toXDR()) - xdr.append(self.fulfilled.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum CreateASwapBidCreationRequestSuccessExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateASwapRequestOp.swift deleted file mode 100644 index d7187c6..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapRequestOp.swift +++ /dev/null @@ -1,63 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct CreateASwapRequestOp -// { -// ASwapRequest request; -// -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct CreateASwapRequestOp: XDREncodable { - public var request: ASwapRequest - public var ext: CreateASwapRequestOpExt - - public init( - request: ASwapRequest, - ext: CreateASwapRequestOpExt) { - - self.request = request - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.request.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum CreateASwapRequestOpExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateASwapRequestResult.swift deleted file mode 100644 index aa5361c..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapRequestResult.swift +++ /dev/null @@ -1,37 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// union CreateASwapRequestResult switch (CreateASwapRequestResultCode code) -// { -// case SUCCESS: -// CreateASwapRequestSuccess success; -// default: -// void; -// }; - -// =========================================================================== -public enum CreateASwapRequestResult: XDRDiscriminatedUnion { - case success(CreateASwapRequestSuccess) - - public var discriminant: Int32 { - switch self { - case .success: return CreateASwapRequestResultCode.success.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .success(let data): xdr.append(data.toXDR()) - } - - return xdr - } -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapRequestResultCode.swift b/Sources/TokenDWallet/Xdr/CreateASwapRequestResultCode.swift deleted file mode 100644 index 2484d60..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapRequestResultCode.swift +++ /dev/null @@ -1,37 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// enum CreateASwapRequestResultCode -// { -// // codes considered as "success" for the operation -// SUCCESS = 0, -// -// // codes considered as "failure" for the operation -// INVALID_BASE_AMOUNT = -1, -// INVALID_QUOTE_ASSET = -2, -// BID_NOT_FOUND = -3, -// QUOTE_ASSET_NOT_FOUND = -4, -// BID_UNDERFUNDED = -5, // bid has not enough base amount available for lock -// ATOMIC_SWAP_TASKS_NOT_FOUND = -6, -// NOT_ALLOWED_BY_ASSET_POLICY = -7, -// BID_IS_CANCELLED = -8, -// CANNOT_CREATE_ASWAP_REQUEST_FOR_OWN_BID = -9 -// }; - -// =========================================================================== -public enum CreateASwapRequestResultCode: Int32, XDREnum { - case success = 0 - case invalidBaseAmount = -1 - case invalidQuoteAsset = -2 - case bidNotFound = -3 - case quoteAssetNotFound = -4 - case bidUnderfunded = -5 - case atomicSwapTasksNotFound = -6 - case notAllowedByAssetPolicy = -7 - case bidIsCancelled = -8 - case cannotCreateAswapRequestForOwnBid = -9 -} diff --git a/Sources/TokenDWallet/Xdr/CreateASwapRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateASwapRequestSuccess.swift deleted file mode 100644 index 7ed62a8..0000000 --- a/Sources/TokenDWallet/Xdr/CreateASwapRequestSuccess.swift +++ /dev/null @@ -1,68 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// struct CreateASwapRequestSuccess -// { -// uint64 requestID; -// AccountID bidOwnerID; -// -// union switch (LedgerVersion v) -// { -// case EMPTY_VERSION: -// void; -// } ext; -// }; - -// =========================================================================== -public struct CreateASwapRequestSuccess: XDREncodable { - public var requestID: Uint64 - public var bidOwnerID: AccountID - public var ext: CreateASwapRequestSuccessExt - - public init( - requestID: Uint64, - bidOwnerID: AccountID, - ext: CreateASwapRequestSuccessExt) { - - self.requestID = requestID - self.bidOwnerID = bidOwnerID - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.requestID.toXDR()) - xdr.append(self.bidOwnerID.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - public enum CreateASwapRequestSuccessExt: XDRDiscriminatedUnion { - case emptyVersion() - - public var discriminant: Int32 { - switch self { - case .emptyVersion: return LedgerVersion.emptyVersion.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .emptyVersion(): xdr.append(Data()) - } - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/CreateAccountOp.swift b/Sources/TokenDWallet/Xdr/CreateAccountOp.swift index 57c96ed..29224bc 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountOp: XDREncodable { +public struct CreateAccountOp: XDRCodable { public var destination: AccountID public var referrer: AccountID? public var roleID: Uint64 @@ -62,6 +62,22 @@ public struct CreateAccountOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.destination = try AccountID(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.referrer = try AccountID(xdrData: &xdrData) + } else { + self.referrer = nil + } + self.roleID = try Uint64(xdrData: &xdrData) + let lengthsignersData = try Int32(xdrData: &xdrData) + self.signersData = [UpdateSignerData]() + for _ in 1...lengthsignersData { + self.signersData.append(try UpdateSignerData(xdrData: &xdrData)) + } + self.ext = try CreateAccountOpExt(xdrData: &xdrData) + } + public enum CreateAccountOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -83,5 +99,15 @@ public struct CreateAccountOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountResult.swift b/Sources/TokenDWallet/Xdr/CreateAccountResult.swift index 44cdbee..56548de 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountResult.swift @@ -41,4 +41,19 @@ public enum CreateAccountResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateAccountResultCode.success.rawValue: + let data = try CreateAccountSuccess(xdrData: &xdrData) + self = .success(data) + case CreateAccountResultCode.invalidSignerData.rawValue: + let data = try ManageSignerResultCode(xdrData: &xdrData) + self = .invalidSignerData(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountRoleData.swift b/Sources/TokenDWallet/Xdr/CreateAccountRoleData.swift index 50ec4b7..78f5fc4 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountRoleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountRoleData.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountRoleData: XDREncodable { +public struct CreateAccountRoleData: XDRCodable { public var details: Longstring public var ruleIDs: [Uint64] public var ext: CreateAccountRoleDataExt @@ -47,6 +47,16 @@ public struct CreateAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try Longstring(xdrData: &xdrData) + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.ext = try CreateAccountRoleDataExt(xdrData: &xdrData) + } + public enum CreateAccountRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +78,15 @@ public struct CreateAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountRuleData.swift b/Sources/TokenDWallet/Xdr/CreateAccountRuleData.swift index 74211ac..dcb360c 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountRuleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountRuleData.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountRuleData: XDREncodable { +public struct CreateAccountRuleData: XDRCodable { public var resource: AccountRuleResource public var action: AccountRuleAction public var forbids: Bool @@ -59,6 +59,14 @@ public struct CreateAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.resource = try AccountRuleResource(xdrData: &xdrData) + self.action = try AccountRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try CreateAccountRuleDataExt(xdrData: &xdrData) + } + public enum CreateAccountRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -80,5 +88,15 @@ public struct CreateAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountSaleRuleData.swift b/Sources/TokenDWallet/Xdr/CreateAccountSaleRuleData.swift index 2c090bc..3794486 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountSaleRuleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountSaleRuleData.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountSaleRuleData: XDREncodable { +public struct CreateAccountSaleRuleData: XDRCodable { public var accountID: AccountID? public var forbids: Bool public var ext: CreateAccountSaleRuleDataExt @@ -47,6 +47,16 @@ public struct CreateAccountSaleRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.forbids = try Bool(xdrData: &xdrData) + self.ext = try CreateAccountSaleRuleDataExt(xdrData: &xdrData) + } + public enum CreateAccountSaleRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +78,15 @@ public struct CreateAccountSaleRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountSpecificRuleData.swift b/Sources/TokenDWallet/Xdr/CreateAccountSpecificRuleData.swift index a7cfc38..b09285f 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountSpecificRuleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountSpecificRuleData.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountSpecificRuleData: XDREncodable { +public struct CreateAccountSpecificRuleData: XDRCodable { public var ledgerKey: LedgerKey public var accountID: AccountID? public var forbids: Bool @@ -53,6 +53,17 @@ public struct CreateAccountSpecificRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerKey = try LedgerKey(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.forbids = try Bool(xdrData: &xdrData) + self.ext = try CreateAccountSpecificRuleDataExt(xdrData: &xdrData) + } + public enum CreateAccountSpecificRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +85,15 @@ public struct CreateAccountSpecificRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAccountSuccess.swift b/Sources/TokenDWallet/Xdr/CreateAccountSuccess.swift index 0e58b09..e02ecdf 100644 --- a/Sources/TokenDWallet/Xdr/CreateAccountSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateAccountSuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAccountSuccess: XDREncodable { +public struct CreateAccountSuccess: XDRCodable { public var sequentialID: Uint64 public var ext: CreateAccountSuccessExt @@ -42,6 +42,11 @@ public struct CreateAccountSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.sequentialID = try Uint64(xdrData: &xdrData) + self.ext = try CreateAccountSuccessExt(xdrData: &xdrData) + } + public enum CreateAccountSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct CreateAccountSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequest.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequest.swift index 2bc255a..96b4491 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequest.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapAskRequest: XDREncodable { +public struct CreateAtomicSwapAskRequest: XDRCodable { public var baseBalance: BalanceID public var amount: Uint64 public var creatorDetails: Longstring @@ -59,6 +59,18 @@ public struct CreateAtomicSwapAskRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + let lengthquoteAssets = try Int32(xdrData: &xdrData) + self.quoteAssets = [AtomicSwapAskQuoteAsset]() + for _ in 1...lengthquoteAssets { + self.quoteAssets.append(try AtomicSwapAskQuoteAsset(xdrData: &xdrData)) + } + self.ext = try CreateAtomicSwapAskRequestExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapAskRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -80,5 +92,15 @@ public struct CreateAtomicSwapAskRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestOp.swift index 81625e7..654d494 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestOp.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapAskRequestOp: XDREncodable { +public struct CreateAtomicSwapAskRequestOp: XDRCodable { public var request: CreateAtomicSwapAskRequest public var allTasks: Uint32? public var ext: CreateAtomicSwapAskRequestOpExt @@ -49,6 +49,16 @@ public struct CreateAtomicSwapAskRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try CreateAtomicSwapAskRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateAtomicSwapAskRequestOpExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapAskRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -70,5 +80,15 @@ public struct CreateAtomicSwapAskRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestResult.swift index 619663f..6cdca6d 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestResult.swift @@ -36,4 +36,16 @@ public enum CreateAtomicSwapAskRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateAtomicSwapAskRequestResultCode.success.rawValue: + let data = try CreateAtomicSwapAskRequestSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestSuccess.swift index 390167e..417a1bb 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapAskRequestSuccess.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapAskRequestSuccess: XDREncodable { +public struct CreateAtomicSwapAskRequestSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var askID: Uint64 @@ -53,6 +53,13 @@ public struct CreateAtomicSwapAskRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.askID = try Uint64(xdrData: &xdrData) + self.ext = try CreateAtomicSwapAskRequestSuccessExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapAskRequestSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +81,15 @@ public struct CreateAtomicSwapAskRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequest.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequest.swift index a856912..fe234cf 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequest.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapBidRequest: XDREncodable { +public struct CreateAtomicSwapBidRequest: XDRCodable { public var askID: Uint64 public var baseAmount: Uint64 public var quoteAsset: AssetCode @@ -59,6 +59,14 @@ public struct CreateAtomicSwapBidRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.askID = try Uint64(xdrData: &xdrData) + self.baseAmount = try Uint64(xdrData: &xdrData) + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try CreateAtomicSwapBidRequestExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapBidRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -80,5 +88,15 @@ public struct CreateAtomicSwapBidRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestOp.swift index bd0fa01..d538701 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestOp.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapBidRequestOp: XDREncodable { +public struct CreateAtomicSwapBidRequestOp: XDRCodable { public var request: CreateAtomicSwapBidRequest public var ext: CreateAtomicSwapBidRequestOpExt @@ -41,6 +41,11 @@ public struct CreateAtomicSwapBidRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try CreateAtomicSwapBidRequest(xdrData: &xdrData) + self.ext = try CreateAtomicSwapBidRequestOpExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapBidRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct CreateAtomicSwapBidRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestResult.swift index fa83d22..a9c2931 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestResult.swift @@ -36,4 +36,16 @@ public enum CreateAtomicSwapBidRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateAtomicSwapBidRequestResultCode.success.rawValue: + let data = try CreateAtomicSwapBidRequestSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestSuccess.swift index 4f93baa..1d17c94 100644 --- a/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateAtomicSwapBidRequestSuccess.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CreateAtomicSwapBidRequestSuccess: XDREncodable { +public struct CreateAtomicSwapBidRequestSuccess: XDRCodable { public var requestID: Uint64 public var askOwnerID: AccountID public var quoteAmount: Uint64 @@ -53,6 +53,13 @@ public struct CreateAtomicSwapBidRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.askOwnerID = try AccountID(xdrData: &xdrData) + self.quoteAmount = try Uint64(xdrData: &xdrData) + self.ext = try CreateAtomicSwapBidRequestSuccessExt(xdrData: &xdrData) + } + public enum CreateAtomicSwapBidRequestSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +81,15 @@ public struct CreateAtomicSwapBidRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestOp.swift index 35a3274..54271f2 100644 --- a/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestOp.swift @@ -33,7 +33,7 @@ import Foundation // }; // =========================================================================== -public struct CreateChangeRoleRequestOp: XDREncodable { +public struct CreateChangeRoleRequestOp: XDRCodable { public var requestID: Uint64 public var destinationAccount: AccountID public var accountRoleToSet: Uint64 @@ -70,6 +70,19 @@ public struct CreateChangeRoleRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.destinationAccount = try AccountID(xdrData: &xdrData) + self.accountRoleToSet = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateChangeRoleRequestOpExt(xdrData: &xdrData) + } + public enum CreateChangeRoleRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -91,5 +104,15 @@ public struct CreateChangeRoleRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestResult.swift index 78d7b78..a476bda 100644 --- a/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateChangeRoleRequestResult.swift @@ -48,7 +48,19 @@ public enum CreateChangeRoleRequestResult: XDRDiscriminatedUnion { return xdr } - public struct CreateChangeRoleRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateChangeRoleRequestResultCode.success.rawValue: + let data = try CreateChangeRoleRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct CreateChangeRoleRequestResultSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreateChangeRoleRequestResultSuccessExt @@ -73,6 +85,12 @@ public enum CreateChangeRoleRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateChangeRoleRequestResultSuccessExt(xdrData: &xdrData) + } + public enum CreateChangeRoleRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,6 +112,16 @@ public enum CreateChangeRoleRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/CreateContractRequest.swift b/Sources/TokenDWallet/Xdr/CreateContractRequest.swift index 627acaf..45e41e4 100644 --- a/Sources/TokenDWallet/Xdr/CreateContractRequest.swift +++ b/Sources/TokenDWallet/Xdr/CreateContractRequest.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct CreateContractRequest: XDREncodable { +public struct CreateContractRequest: XDRCodable { public var contractRequest: ContractRequest public var allTasks: Uint32? public var ext: CreateContractRequestExt @@ -45,6 +45,16 @@ public struct CreateContractRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.contractRequest = try ContractRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateContractRequestExt(xdrData: &xdrData) + } + public enum CreateContractRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +76,15 @@ public struct CreateContractRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateContractRequestResponse.swift b/Sources/TokenDWallet/Xdr/CreateContractRequestResponse.swift index 941a8d1..d7d24e6 100644 --- a/Sources/TokenDWallet/Xdr/CreateContractRequestResponse.swift +++ b/Sources/TokenDWallet/Xdr/CreateContractRequestResponse.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct CreateContractRequestResponse: XDREncodable { +public struct CreateContractRequestResponse: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreateContractRequestResponseExt @@ -44,6 +44,12 @@ public struct CreateContractRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateContractRequestResponseExt(xdrData: &xdrData) + } + public enum CreateContractRequestResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -65,5 +71,15 @@ public struct CreateContractRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateExternalSystemAccountIdPoolEntryActionInput.swift b/Sources/TokenDWallet/Xdr/CreateExternalSystemAccountIdPoolEntryActionInput.swift index 646a523..e006f3a 100644 --- a/Sources/TokenDWallet/Xdr/CreateExternalSystemAccountIdPoolEntryActionInput.swift +++ b/Sources/TokenDWallet/Xdr/CreateExternalSystemAccountIdPoolEntryActionInput.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct CreateExternalSystemAccountIdPoolEntryActionInput: XDREncodable { +public struct CreateExternalSystemAccountIdPoolEntryActionInput: XDRCodable { public var externalSystemType: Int32 public var data: Longstring public var parent: Uint64 @@ -55,6 +55,13 @@ public struct CreateExternalSystemAccountIdPoolEntryActionInput: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.externalSystemType = try Int32(xdrData: &xdrData) + self.data = try Longstring(xdrData: &xdrData) + self.parent = try Uint64(xdrData: &xdrData) + self.ext = try CreateExternalSystemAccountIdPoolEntryActionInputExt(xdrData: &xdrData) + } + public enum CreateExternalSystemAccountIdPoolEntryActionInputExt: XDRDiscriminatedUnion { case emptyVersion() @@ -76,5 +83,15 @@ public struct CreateExternalSystemAccountIdPoolEntryActionInput: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateInvoiceRequestResponse.swift b/Sources/TokenDWallet/Xdr/CreateInvoiceRequestResponse.swift index 506222c..1908a19 100644 --- a/Sources/TokenDWallet/Xdr/CreateInvoiceRequestResponse.swift +++ b/Sources/TokenDWallet/Xdr/CreateInvoiceRequestResponse.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CreateInvoiceRequestResponse: XDREncodable { +public struct CreateInvoiceRequestResponse: XDRCodable { public var receiverBalance: BalanceID public var senderBalance: BalanceID public var requestID: Uint64 @@ -50,6 +50,13 @@ public struct CreateInvoiceRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.receiverBalance = try BalanceID(xdrData: &xdrData) + self.senderBalance = try BalanceID(xdrData: &xdrData) + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try CreateInvoiceRequestResponseExt(xdrData: &xdrData) + } + public enum CreateInvoiceRequestResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +78,15 @@ public struct CreateInvoiceRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestOp.swift index 2a98687..aec3345 100644 --- a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestOp.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct CreateIssuanceRequestOp: XDREncodable { +public struct CreateIssuanceRequestOp: XDRCodable { public var request: IssuanceRequest public var reference: String64 public var allTasks: Uint32? @@ -55,6 +55,17 @@ public struct CreateIssuanceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try IssuanceRequest(xdrData: &xdrData) + self.reference = try String64(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateIssuanceRequestOpExt(xdrData: &xdrData) + } + public enum CreateIssuanceRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -76,5 +87,15 @@ public struct CreateIssuanceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestResult.swift index 5a07cd1..ecd9ab2 100644 --- a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestResult.swift @@ -35,4 +35,16 @@ public enum CreateIssuanceRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateIssuanceRequestResultCode.success.rawValue: + let data = try CreateIssuanceRequestSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestSuccess.swift b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestSuccess.swift index 2fc11a9..c2cab85 100644 --- a/Sources/TokenDWallet/Xdr/CreateIssuanceRequestSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateIssuanceRequestSuccess.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct CreateIssuanceRequestSuccess: XDREncodable { +public struct CreateIssuanceRequestSuccess: XDRCodable { public var requestID: Uint64 public var receiver: AccountID public var fulfilled: Bool @@ -58,6 +58,14 @@ public struct CreateIssuanceRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.receiver = try AccountID(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.fee = try Fee(xdrData: &xdrData) + self.ext = try CreateIssuanceRequestSuccessExt(xdrData: &xdrData) + } + public enum CreateIssuanceRequestSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -79,5 +87,15 @@ public struct CreateIssuanceRequestSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestOp.swift index 2dddb35..56cd93b 100644 --- a/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestOp.swift @@ -31,7 +31,7 @@ import Foundation // }; // =========================================================================== -public struct CreateKYCRecoveryRequestOp: XDREncodable { +public struct CreateKYCRecoveryRequestOp: XDRCodable { public var requestID: Uint64 public var targetAccount: AccountID public var signersData: [UpdateSignerData] @@ -68,6 +68,23 @@ public struct CreateKYCRecoveryRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.targetAccount = try AccountID(xdrData: &xdrData) + let lengthsignersData = try Int32(xdrData: &xdrData) + self.signersData = [UpdateSignerData]() + for _ in 1...lengthsignersData { + self.signersData.append(try UpdateSignerData(xdrData: &xdrData)) + } + self.creatorDetails = try Longstring(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateKYCRecoveryRequestOpExt(xdrData: &xdrData) + } + public enum CreateKYCRecoveryRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -89,5 +106,15 @@ public struct CreateKYCRecoveryRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestResult.swift index a887810..3242068 100644 --- a/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateKYCRecoveryRequestResult.swift @@ -50,7 +50,19 @@ public enum CreateKYCRecoveryRequestResult: XDRDiscriminatedUnion { return xdr } - public struct CreateKYCRecoveryRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateKYCRecoveryRequestResultCode.success.rawValue: + let data = try CreateKYCRecoveryRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct CreateKYCRecoveryRequestResultSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreateKYCRecoveryRequestResultSuccessExt @@ -75,6 +87,12 @@ public enum CreateKYCRecoveryRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateKYCRecoveryRequestResultSuccessExt(xdrData: &xdrData) + } + public enum CreateKYCRecoveryRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -96,6 +114,16 @@ public enum CreateKYCRecoveryRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestOp.swift index a6256a5..f3db1d1 100644 --- a/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct CreateManageLimitsRequestOp: XDREncodable { +public struct CreateManageLimitsRequestOp: XDRCodable { public var manageLimitsRequest: LimitsUpdateRequest public var allTasks: Uint32? public var requestID: Uint64 @@ -56,6 +56,17 @@ public struct CreateManageLimitsRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.manageLimitsRequest = try LimitsUpdateRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try CreateManageLimitsRequestOpExt(xdrData: &xdrData) + } + public enum CreateManageLimitsRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -77,5 +88,15 @@ public struct CreateManageLimitsRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestResult.swift index d1ced0a..0e8e609 100644 --- a/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateManageLimitsRequestResult.swift @@ -47,7 +47,19 @@ public enum CreateManageLimitsRequestResult: XDRDiscriminatedUnion { return xdr } - public struct CreateManageLimitsRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateManageLimitsRequestResultCode.success.rawValue: + let data = try CreateManageLimitsRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct CreateManageLimitsRequestResultSuccess: XDRCodable { public var manageLimitsRequestID: Uint64 public var fulfilled: Bool public var ext: CreateManageLimitsRequestResultSuccessExt @@ -72,6 +84,12 @@ public enum CreateManageLimitsRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.manageLimitsRequestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateManageLimitsRequestResultSuccessExt(xdrData: &xdrData) + } + public enum CreateManageLimitsRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -93,6 +111,16 @@ public enum CreateManageLimitsRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/CreateManageOfferRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestOp.swift new file mode 100644 index 0000000..c807dac --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestOp.swift @@ -0,0 +1,56 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct CreateManageOfferRequestOp +// { +// //: ManageOfferRequest details +// ManageOfferRequest request; +// +// //: (optional) Bit mask whose flags must be cleared in order for CreateSale request to be approved, which will be used by key sale_create_tasks: +// //: instead of key-value +// uint32* allTasks; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CreateManageOfferRequestOp: XDRCodable { + public var request: ManageOfferRequest + public var allTasks: Uint32? + public var ext: EmptyExt + + public init( + request: ManageOfferRequest, + allTasks: Uint32?, + ext: EmptyExt) { + + self.request = request + self.allTasks = allTasks + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.request.toXDR()) + xdr.append(self.allTasks.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.request = try ManageOfferRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResult.swift new file mode 100644 index 0000000..1d196f9 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResult.swift @@ -0,0 +1,57 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// union CreateManageOfferRequestResult switch (CreateManageOfferRequestResultCode code) +// { +// case SUCCESS: +// CreateManagerOfferRequestSuccessResult success; +// case INVALID_OFFER: +// ManageOfferResultCode manageOfferCode; +// default: +// void; +// }; + +// =========================================================================== +public enum CreateManageOfferRequestResult: XDRDiscriminatedUnion { + case success(CreateManagerOfferRequestSuccessResult) + case invalidOffer(ManageOfferResultCode) + + public var discriminant: Int32 { + switch self { + case .success: return CreateManageOfferRequestResultCode.success.rawValue + case .invalidOffer: return CreateManageOfferRequestResultCode.invalidOffer.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + case .invalidOffer(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateManageOfferRequestResultCode.success.rawValue: + let data = try CreateManagerOfferRequestSuccessResult(xdrData: &xdrData) + self = .success(data) + case CreateManageOfferRequestResultCode.invalidOffer.rawValue: + let data = try ManageOfferResultCode(xdrData: &xdrData) + self = .invalidOffer(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResultCode.swift b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResultCode.swift new file mode 100644 index 0000000..838bd8c --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateManageOfferRequestResultCode.swift @@ -0,0 +1,27 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// enum CreateManageOfferRequestResultCode +// { +// //: CreateManageOfferRequestOp was successfully applied +// SUCCESS = 0, +// +// //: Offer is invalid +// INVALID_OFFER = -1, +// //: Tasks for the manage offer request were neither provided in the request nor loaded through KeyValue +// MANAGE_OFFER_TASKS_NOT_FOUND = -2, +// //: Creator details are not in a valid JSON format +// INVALID_CREATOR_DETAILS = -3 +// }; + +// =========================================================================== +public enum CreateManageOfferRequestResultCode: Int32, XDREnum { + case success = 0 + case invalidOffer = -1 + case manageOfferTasksNotFound = -2 + case invalidCreatorDetails = -3 +} diff --git a/Sources/TokenDWallet/Xdr/CreateManagerOfferRequestSuccessResult.swift b/Sources/TokenDWallet/Xdr/CreateManagerOfferRequestSuccessResult.swift new file mode 100644 index 0000000..a6daae9 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateManagerOfferRequestSuccessResult.swift @@ -0,0 +1,62 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct CreateManagerOfferRequestSuccessResult +// { +// //: ID of the ManageOfferRequest +// uint64 requestID; +// //: Indicates whether or not the manage offer request was auto approved +// bool fulfilled; +// +// //: Result of manage offer application +// ManageOfferResult* manageOfferResult; +// +// //: Reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CreateManagerOfferRequestSuccessResult: XDRCodable { + public var requestID: Uint64 + public var fulfilled: Bool + public var manageOfferResult: ManageOfferResult? + public var ext: EmptyExt + + public init( + requestID: Uint64, + fulfilled: Bool, + manageOfferResult: ManageOfferResult?, + ext: EmptyExt) { + + self.requestID = requestID + self.fulfilled = fulfilled + self.manageOfferResult = manageOfferResult + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.requestID.toXDR()) + xdr.append(self.fulfilled.toXDR()) + xdr.append(self.manageOfferResult.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.manageOfferResult = try ManageOfferResult(xdrData: &xdrData) + } else { + self.manageOfferResult = nil + } + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/CreatePaymentRequest.swift b/Sources/TokenDWallet/Xdr/CreatePaymentRequest.swift new file mode 100644 index 0000000..616e7fc --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreatePaymentRequest.swift @@ -0,0 +1,86 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct CreatePaymentRequest +// { +// PaymentOp paymentOp; +// +// union switch (LedgerVersion v) +// { +// case EMPTY_VERSION: +// void; +// case MOVEMENT_REQUESTS_DETAILS: +// longstring creatorDetails; +// } ext; +// }; + +// =========================================================================== +public struct CreatePaymentRequest: XDRCodable { + public var paymentOp: PaymentOp + public var ext: CreatePaymentRequestExt + + public init( + paymentOp: PaymentOp, + ext: CreatePaymentRequestExt) { + + self.paymentOp = paymentOp + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.paymentOp.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.paymentOp = try PaymentOp(xdrData: &xdrData) + self.ext = try CreatePaymentRequestExt(xdrData: &xdrData) + } + + public enum CreatePaymentRequestExt: XDRDiscriminatedUnion { + case emptyVersion() + case movementRequestsDetails(Longstring) + + public var discriminant: Int32 { + switch self { + case .emptyVersion: return LedgerVersion.emptyVersion.rawValue + case .movementRequestsDetails: return LedgerVersion.movementRequestsDetails.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .emptyVersion(): xdr.append(Data()) + case .movementRequestsDetails(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.movementRequestsDetails.rawValue: + let data = try Longstring(xdrData: &xdrData) + self = .movementRequestsDetails(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/CreatePaymentRequestOp.swift b/Sources/TokenDWallet/Xdr/CreatePaymentRequestOp.swift new file mode 100644 index 0000000..cb3167e --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreatePaymentRequestOp.swift @@ -0,0 +1,56 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct CreatePaymentRequestOp +// { +// //: Payment request details +// CreatePaymentRequest request; +// +// //: (optional) Bit mask whose flags must be cleared in order for CreateSale request to be approved, which will be used by key sale_create_tasks: +// //: instead of key-value +// uint32* allTasks; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CreatePaymentRequestOp: XDRCodable { + public var request: CreatePaymentRequest + public var allTasks: Uint32? + public var ext: EmptyExt + + public init( + request: CreatePaymentRequest, + allTasks: Uint32?, + ext: EmptyExt) { + + self.request = request + self.allTasks = allTasks + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.request.toXDR()) + xdr.append(self.allTasks.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.request = try CreatePaymentRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/CreatePaymentRequestResult.swift b/Sources/TokenDWallet/Xdr/CreatePaymentRequestResult.swift new file mode 100644 index 0000000..9e69e9c --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreatePaymentRequestResult.swift @@ -0,0 +1,58 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result of CreatePaymentRequestOp application +// union CreatePaymentRequestResult switch (CreatePaymentRequestResultCode code) +// { +// case SUCCESS: +// CreatePaymentRequestSuccessResult success; +// case INVALID_PAYMENT: +// PaymentResultCode paymentCode; +// default: +// void; +// }; + +// =========================================================================== +public enum CreatePaymentRequestResult: XDRDiscriminatedUnion { + case success(CreatePaymentRequestSuccessResult) + case invalidPayment(PaymentResultCode) + + public var discriminant: Int32 { + switch self { + case .success: return CreatePaymentRequestResultCode.success.rawValue + case .invalidPayment: return CreatePaymentRequestResultCode.invalidPayment.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + case .invalidPayment(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreatePaymentRequestResultCode.success.rawValue: + let data = try CreatePaymentRequestSuccessResult(xdrData: &xdrData) + self = .success(data) + case CreatePaymentRequestResultCode.invalidPayment.rawValue: + let data = try PaymentResultCode(xdrData: &xdrData) + self = .invalidPayment(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/CreatePaymentRequestResultCode.swift b/Sources/TokenDWallet/Xdr/CreatePaymentRequestResultCode.swift new file mode 100644 index 0000000..6c13f7e --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreatePaymentRequestResultCode.swift @@ -0,0 +1,27 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// enum CreatePaymentRequestResultCode +// { +// //: CreatePaymentRequestOp was successfully applied +// SUCCESS = 0, +// +// //: Payment is invalid +// INVALID_PAYMENT = -1, +// //: Tasks for the payment request were neither provided in the request nor loaded through KeyValue +// PAYMENT_TASKS_NOT_FOUND = -2, +// //: Creator details are not in a valid JSON format +// INVALID_CREATOR_DETAILS = -3 +// }; + +// =========================================================================== +public enum CreatePaymentRequestResultCode: Int32, XDREnum { + case success = 0 + case invalidPayment = -1 + case paymentTasksNotFound = -2 + case invalidCreatorDetails = -3 +} diff --git a/Sources/TokenDWallet/Xdr/CreatePaymentRequestSuccessResult.swift b/Sources/TokenDWallet/Xdr/CreatePaymentRequestSuccessResult.swift new file mode 100644 index 0000000..417d0c2 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreatePaymentRequestSuccessResult.swift @@ -0,0 +1,63 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result of the successful payment request creation +// struct CreatePaymentRequestSuccessResult +// { +// //: ID of the Payment request +// uint64 requestID; +// //: Indicates whether or not the payment request was auto approved +// bool fulfilled; +// +// //: Result of the payment application +// PaymentResult* paymentResult; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct CreatePaymentRequestSuccessResult: XDRCodable { + public var requestID: Uint64 + public var fulfilled: Bool + public var paymentResult: PaymentResult? + public var ext: EmptyExt + + public init( + requestID: Uint64, + fulfilled: Bool, + paymentResult: PaymentResult?, + ext: EmptyExt) { + + self.requestID = requestID + self.fulfilled = fulfilled + self.paymentResult = paymentResult + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.requestID.toXDR()) + xdr.append(self.fulfilled.toXDR()) + xdr.append(self.paymentResult.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.paymentResult = try PaymentResult(xdrData: &xdrData) + } else { + self.paymentResult = nil + } + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/CreatePollExtended.swift b/Sources/TokenDWallet/Xdr/CreatePollExtended.swift index 351b572..dc87e58 100644 --- a/Sources/TokenDWallet/Xdr/CreatePollExtended.swift +++ b/Sources/TokenDWallet/Xdr/CreatePollExtended.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CreatePollExtended: XDREncodable { +public struct CreatePollExtended: XDRCodable { public var pollID: Uint64 public var ext: CreatePollExtendedExt @@ -42,6 +42,11 @@ public struct CreatePollExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.ext = try CreatePollExtendedExt(xdrData: &xdrData) + } + public enum CreatePollExtendedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct CreatePollExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreatePollRequest.swift b/Sources/TokenDWallet/Xdr/CreatePollRequest.swift index ab8775d..0b1441c 100644 --- a/Sources/TokenDWallet/Xdr/CreatePollRequest.swift +++ b/Sources/TokenDWallet/Xdr/CreatePollRequest.swift @@ -42,7 +42,7 @@ import Foundation // }; // =========================================================================== -public struct CreatePollRequest: XDREncodable { +public struct CreatePollRequest: XDRCodable { public var permissionType: Uint32 public var numberOfChoices: Uint32 public var data: PollData @@ -91,6 +91,18 @@ public struct CreatePollRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.permissionType = try Uint32(xdrData: &xdrData) + self.numberOfChoices = try Uint32(xdrData: &xdrData) + self.data = try PollData(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + self.resultProviderID = try AccountID(xdrData: &xdrData) + self.voteConfirmationRequired = try Bool(xdrData: &xdrData) + self.ext = try CreatePollRequestExt(xdrData: &xdrData) + } + public enum CreatePollRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -112,5 +124,15 @@ public struct CreatePollRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreatePollRequestData.swift b/Sources/TokenDWallet/Xdr/CreatePollRequestData.swift index 0faa807..4cce682 100644 --- a/Sources/TokenDWallet/Xdr/CreatePollRequestData.swift +++ b/Sources/TokenDWallet/Xdr/CreatePollRequestData.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct CreatePollRequestData: XDREncodable { +public struct CreatePollRequestData: XDRCodable { public var request: CreatePollRequest public var allTasks: Uint32? public var ext: CreatePollRequestDataExt @@ -50,6 +50,16 @@ public struct CreatePollRequestData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try CreatePollRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreatePollRequestDataExt(xdrData: &xdrData) + } + public enum CreatePollRequestDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +81,15 @@ public struct CreatePollRequestData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreatePollRequestResponse.swift b/Sources/TokenDWallet/Xdr/CreatePollRequestResponse.swift index 3988a58..772b5a4 100644 --- a/Sources/TokenDWallet/Xdr/CreatePollRequestResponse.swift +++ b/Sources/TokenDWallet/Xdr/CreatePollRequestResponse.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct CreatePollRequestResponse: XDREncodable { +public struct CreatePollRequestResponse: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var pollID: Uint64? @@ -57,6 +57,17 @@ public struct CreatePollRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.pollID = try Uint64(xdrData: &xdrData) + } else { + self.pollID = nil + } + self.ext = try CreatePollRequestResponseExt(xdrData: &xdrData) + } + public enum CreatePollRequestResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -78,5 +89,15 @@ public struct CreatePollRequestResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestOp.swift b/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestOp.swift index 83a991c..db105d8 100644 --- a/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestOp.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct CreatePreIssuanceRequestOp: XDREncodable { +public struct CreatePreIssuanceRequestOp: XDRCodable { public var request: PreIssuanceRequest public var allTasks: Uint32? public var ext: CreatePreIssuanceRequestOpExt @@ -50,6 +50,16 @@ public struct CreatePreIssuanceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try PreIssuanceRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreatePreIssuanceRequestOpExt(xdrData: &xdrData) + } + public enum CreatePreIssuanceRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +81,15 @@ public struct CreatePreIssuanceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestResult.swift b/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestResult.swift index 7b29d82..4feff4a 100644 --- a/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreatePreIssuanceRequestResult.swift @@ -49,7 +49,19 @@ public enum CreatePreIssuanceRequestResult: XDRDiscriminatedUnion { return xdr } - public struct CreatePreIssuanceRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreatePreIssuanceRequestResultCode.success.rawValue: + let data = try CreatePreIssuanceRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct CreatePreIssuanceRequestResultSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreatePreIssuanceRequestResultSuccessExt @@ -74,6 +86,12 @@ public enum CreatePreIssuanceRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreatePreIssuanceRequestResultSuccessExt(xdrData: &xdrData) + } + public enum CreatePreIssuanceRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -95,6 +113,16 @@ public enum CreatePreIssuanceRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/CreateRedemptionRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestOp.swift new file mode 100644 index 0000000..9375c83 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestOp.swift @@ -0,0 +1,103 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: CreateRedemptionRequest operation creates a reviewable request +// //: that will transfer the specified amount from current holder's balance to destination balance after the reviewer's approval +// struct CreateRedemptionRequestOp +// { +// //: Reference of RedemptionRequest +// string64 reference; // TODO longstring ? +// //: Parameters of RedemptionRequest +// RedemptionRequest redemptionRequest; +// //: (optional) Bit mask whose flags must be cleared in order for RedemptionRequest to be approved, which will be used by key redemption_tasks +// //: instead of key-value +// uint32* allTasks; +// +// //: Reserved for future use +// union switch (LedgerVersion v) +// { +// case EMPTY_VERSION: +// void; +// } +// ext; +// +// }; + +// =========================================================================== +public struct CreateRedemptionRequestOp: XDRCodable { + public var reference: String64 + public var redemptionRequest: RedemptionRequest + public var allTasks: Uint32? + public var ext: CreateRedemptionRequestOpExt + + public init( + reference: String64, + redemptionRequest: RedemptionRequest, + allTasks: Uint32?, + ext: CreateRedemptionRequestOpExt) { + + self.reference = reference + self.redemptionRequest = redemptionRequest + self.allTasks = allTasks + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.reference.toXDR()) + xdr.append(self.redemptionRequest.toXDR()) + xdr.append(self.allTasks.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.reference = try String64(xdrData: &xdrData) + self.redemptionRequest = try RedemptionRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateRedemptionRequestOpExt(xdrData: &xdrData) + } + + public enum CreateRedemptionRequestOpExt: XDRDiscriminatedUnion { + case emptyVersion() + + public var discriminant: Int32 { + switch self { + case .emptyVersion: return LedgerVersion.emptyVersion.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .emptyVersion(): xdr.append(Data()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResult.swift new file mode 100644 index 0000000..c126c5c --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResult.swift @@ -0,0 +1,50 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result of `CreateRedemptionRequest` operation application along with the result code +// union CreateRedemptionRequestResult switch (CreateRedemptionRequestResultCode code) +// { +// case SUCCESS: +// RedemptionRequestResponse redemptionResponse; +// default: +// void; +// }; + +// =========================================================================== +public enum CreateRedemptionRequestResult: XDRDiscriminatedUnion { + case success(RedemptionRequestResponse) + + public var discriminant: Int32 { + switch self { + case .success: return CreateRedemptionRequestResultCode.success.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateRedemptionRequestResultCode.success.rawValue: + let data = try RedemptionRequestResponse(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResultCode.swift b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResultCode.swift new file mode 100644 index 0000000..4f49b3b --- /dev/null +++ b/Sources/TokenDWallet/Xdr/CreateRedemptionRequestResultCode.swift @@ -0,0 +1,57 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result codes for CreateRedemption operation +// enum CreateRedemptionRequestResultCode +// { +// // codes considered as "success" for the operation +// //: Operation has been successfully performed +// SUCCESS = 0, +// +// //codes considered as "failure" for the operation +// //: Redemption is invalid +// INVALID_REDEMPTION = -1, +// //: Tasks for the redemption request were neither provided in the request nor loaded through KeyValue +// REDEMPTION_TASKS_NOT_FOUND = -2, +// //: Creator details must not be empty +// INVALID_CREATOR_DETAILS = -3, +// //: Amount must be greater then 0 +// INVALID_AMOUNT = -4, +// //: Reference must not be longer then 64 bytes +// INVALID_REFERENCE = -5, +// //: Source balance with provided balance ID does not exist +// SOURCE_BALANCE_NOT_EXIST = -6, // balance doesn't exist +// //: Amount has incorrect precision +// INCORRECT_PRECISION = -7, +// //: Balance underfunded +// UNDERFUNDED = -8, +// //: Duplicated references are not allowed +// REFERENCE_DUPLICATION = -9, +// //: No destination with provided account ID +// DST_ACCOUNT_NOT_FOUND = -10, +// //: Not allowed to set zero tasks for request +// REDEMPTION_ZERO_TASKS_NOT_ALLOWED = -11, +// //: Not allowed to redeem non-owned asset +// REDEMPTION_NON_OWNED_ASSET_FORBIDDEN = -12 +// }; + +// =========================================================================== +public enum CreateRedemptionRequestResultCode: Int32, XDREnum { + case success = 0 + case invalidRedemption = -1 + case redemptionTasksNotFound = -2 + case invalidCreatorDetails = -3 + case invalidAmount = -4 + case invalidReference = -5 + case sourceBalanceNotExist = -6 + case incorrectPrecision = -7 + case underfunded = -8 + case referenceDuplication = -9 + case dstAccountNotFound = -10 + case redemptionZeroTasksNotAllowed = -11 + case redemptionNonOwnedAssetForbidden = -12 +} diff --git a/Sources/TokenDWallet/Xdr/CreateSaleCreationAutoReviewFailed.swift b/Sources/TokenDWallet/Xdr/CreateSaleCreationAutoReviewFailed.swift index 4ef8906..009dbf1 100644 --- a/Sources/TokenDWallet/Xdr/CreateSaleCreationAutoReviewFailed.swift +++ b/Sources/TokenDWallet/Xdr/CreateSaleCreationAutoReviewFailed.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct CreateSaleCreationAutoReviewFailed: XDREncodable { +public struct CreateSaleCreationAutoReviewFailed: XDRCodable { public var reviewRequestRequest: ReviewRequestResult public var ext: CreateSaleCreationAutoReviewFailedExt @@ -40,6 +40,11 @@ public struct CreateSaleCreationAutoReviewFailed: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.reviewRequestRequest = try ReviewRequestResult(xdrData: &xdrData) + self.ext = try CreateSaleCreationAutoReviewFailedExt(xdrData: &xdrData) + } + public enum CreateSaleCreationAutoReviewFailedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -61,5 +66,15 @@ public struct CreateSaleCreationAutoReviewFailed: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestOp.swift index 250f425..913404f 100644 --- a/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct CreateSaleCreationRequestOp: XDREncodable { +public struct CreateSaleCreationRequestOp: XDRCodable { public var requestID: Uint64 public var request: SaleCreationRequest public var allTasks: Uint32? @@ -56,6 +56,17 @@ public struct CreateSaleCreationRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.request = try SaleCreationRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateSaleCreationRequestOpExt(xdrData: &xdrData) + } + public enum CreateSaleCreationRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -77,5 +88,15 @@ public struct CreateSaleCreationRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestResult.swift index 624b8eb..33223de 100644 --- a/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateSaleCreationRequestResult.swift @@ -40,4 +40,19 @@ public enum CreateSaleCreationRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateSaleCreationRequestResultCode.success.rawValue: + let data = try CreateSaleCreationSuccess(xdrData: &xdrData) + self = .success(data) + case CreateSaleCreationRequestResultCode.autoReviewFailed.rawValue: + let data = try CreateSaleCreationAutoReviewFailed(xdrData: &xdrData) + self = .autoReviewFailed(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateSaleCreationSuccess.swift b/Sources/TokenDWallet/Xdr/CreateSaleCreationSuccess.swift index e5a8691..43bc6a5 100644 --- a/Sources/TokenDWallet/Xdr/CreateSaleCreationSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateSaleCreationSuccess.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct CreateSaleCreationSuccess: XDREncodable { +public struct CreateSaleCreationSuccess: XDRCodable { public var requestID: Uint64 public var saleID: Uint64 public var fulfilled: Bool @@ -51,6 +51,13 @@ public struct CreateSaleCreationSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.saleID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateSaleCreationSuccessExt(xdrData: &xdrData) + } + public enum CreateSaleCreationSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -72,5 +79,15 @@ public struct CreateSaleCreationSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateSignerRoleData.swift b/Sources/TokenDWallet/Xdr/CreateSignerRoleData.swift index 66e0c12..a1f1686 100644 --- a/Sources/TokenDWallet/Xdr/CreateSignerRoleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateSignerRoleData.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct CreateSignerRoleData: XDREncodable { +public struct CreateSignerRoleData: XDRCodable { public var ruleIDs: [Uint64] public var isReadOnly: Bool public var details: Longstring @@ -53,6 +53,17 @@ public struct CreateSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.isReadOnly = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try CreateSignerRoleDataExt(xdrData: &xdrData) + } + public enum CreateSignerRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +85,15 @@ public struct CreateSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateSignerRuleData.swift b/Sources/TokenDWallet/Xdr/CreateSignerRuleData.swift index 70eace1..3b214f1 100644 --- a/Sources/TokenDWallet/Xdr/CreateSignerRuleData.swift +++ b/Sources/TokenDWallet/Xdr/CreateSignerRuleData.swift @@ -30,7 +30,7 @@ import Foundation // }; // =========================================================================== -public struct CreateSignerRuleData: XDREncodable { +public struct CreateSignerRuleData: XDRCodable { public var resource: SignerRuleResource public var action: SignerRuleAction public var forbids: Bool @@ -71,6 +71,16 @@ public struct CreateSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.resource = try SignerRuleResource(xdrData: &xdrData) + self.action = try SignerRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.isDefault = try Bool(xdrData: &xdrData) + self.isReadOnly = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try CreateSignerRuleDataExt(xdrData: &xdrData) + } + public enum CreateSignerRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -92,5 +102,15 @@ public struct CreateSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateVoteData.swift b/Sources/TokenDWallet/Xdr/CreateVoteData.swift index 7f3baa4..90d2ba6 100644 --- a/Sources/TokenDWallet/Xdr/CreateVoteData.swift +++ b/Sources/TokenDWallet/Xdr/CreateVoteData.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct CreateVoteData: XDREncodable { +public struct CreateVoteData: XDRCodable { public var pollID: Uint64 public var data: VoteData public var ext: CreateVoteDataExt @@ -48,6 +48,12 @@ public struct CreateVoteData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.data = try VoteData(xdrData: &xdrData) + self.ext = try CreateVoteDataExt(xdrData: &xdrData) + } + public enum CreateVoteDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -69,5 +75,15 @@ public struct CreateVoteData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestOp.swift b/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestOp.swift index 6f1b2a7..f8c5596 100644 --- a/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestOp.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct CreateWithdrawalRequestOp: XDREncodable { +public struct CreateWithdrawalRequestOp: XDRCodable { public var request: WithdrawalRequest public var allTasks: Uint32? public var ext: CreateWithdrawalRequestOpExt @@ -50,6 +50,16 @@ public struct CreateWithdrawalRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.request = try WithdrawalRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try CreateWithdrawalRequestOpExt(xdrData: &xdrData) + } + public enum CreateWithdrawalRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +81,15 @@ public struct CreateWithdrawalRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestResult.swift b/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestResult.swift index e47fc6d..50555b9 100644 --- a/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/CreateWithdrawalRequestResult.swift @@ -35,4 +35,16 @@ public enum CreateWithdrawalRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CreateWithdrawalRequestResultCode.success.rawValue: + let data = try CreateWithdrawalSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateWithdrawalSuccess.swift b/Sources/TokenDWallet/Xdr/CreateWithdrawalSuccess.swift index b1fdaa9..53b916b 100644 --- a/Sources/TokenDWallet/Xdr/CreateWithdrawalSuccess.swift +++ b/Sources/TokenDWallet/Xdr/CreateWithdrawalSuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct CreateWithdrawalSuccess: XDREncodable { +public struct CreateWithdrawalSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: CreateWithdrawalSuccessExt @@ -46,6 +46,12 @@ public struct CreateWithdrawalSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try CreateWithdrawalSuccessExt(xdrData: &xdrData) + } + public enum CreateWithdrawalSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -67,5 +73,15 @@ public struct CreateWithdrawalSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CrowdFundingSale.swift b/Sources/TokenDWallet/Xdr/CrowdFundingSale.swift index 084e39d..5b5279e 100644 --- a/Sources/TokenDWallet/Xdr/CrowdFundingSale.swift +++ b/Sources/TokenDWallet/Xdr/CrowdFundingSale.swift @@ -15,7 +15,7 @@ import Foundation // }; // =========================================================================== -public struct CrowdFundingSale: XDREncodable { +public struct CrowdFundingSale: XDRCodable { public var ext: CrowdFundingSaleExt public init( @@ -32,6 +32,10 @@ public struct CrowdFundingSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try CrowdFundingSaleExt(xdrData: &xdrData) + } + public enum CrowdFundingSaleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -53,5 +57,15 @@ public struct CrowdFundingSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/Curve25519Public.swift b/Sources/TokenDWallet/Xdr/Curve25519Public.swift index e5421e0..da32a91 100644 --- a/Sources/TokenDWallet/Xdr/Curve25519Public.swift +++ b/Sources/TokenDWallet/Xdr/Curve25519Public.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct Curve25519Public: XDREncodable { +public struct Curve25519Public: XDRCodable { public var key: XDRDataFixed32 public init( @@ -27,4 +27,8 @@ public struct Curve25519Public: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.key = try XDRDataFixed32(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/Curve25519Secret.swift b/Sources/TokenDWallet/Xdr/Curve25519Secret.swift index a74d037..1aa3f42 100644 --- a/Sources/TokenDWallet/Xdr/Curve25519Secret.swift +++ b/Sources/TokenDWallet/Xdr/Curve25519Secret.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct Curve25519Secret: XDREncodable { +public struct Curve25519Secret: XDRCodable { public var key: XDRDataFixed32 public init( @@ -27,4 +27,8 @@ public struct Curve25519Secret: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.key = try XDRDataFixed32(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/DecoratedSignature.swift b/Sources/TokenDWallet/Xdr/DecoratedSignature.swift index d9f9208..36994b8 100644 --- a/Sources/TokenDWallet/Xdr/DecoratedSignature.swift +++ b/Sources/TokenDWallet/Xdr/DecoratedSignature.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct DecoratedSignature: XDREncodable { +public struct DecoratedSignature: XDRCodable { public var hint: SignatureHint public var signature: Signature @@ -32,4 +32,9 @@ public struct DecoratedSignature: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.hint = try SignatureHint(xdrData: &xdrData) + self.signature = try Signature(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/DeleteExternalSystemAccountIdPoolEntryActionInput.swift b/Sources/TokenDWallet/Xdr/DeleteExternalSystemAccountIdPoolEntryActionInput.swift index 60159fb..baf87b9 100644 --- a/Sources/TokenDWallet/Xdr/DeleteExternalSystemAccountIdPoolEntryActionInput.swift +++ b/Sources/TokenDWallet/Xdr/DeleteExternalSystemAccountIdPoolEntryActionInput.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct DeleteExternalSystemAccountIdPoolEntryActionInput: XDREncodable { +public struct DeleteExternalSystemAccountIdPoolEntryActionInput: XDRCodable { public var poolEntryID: Uint64 public var ext: DeleteExternalSystemAccountIdPoolEntryActionInputExt @@ -43,6 +43,11 @@ public struct DeleteExternalSystemAccountIdPoolEntryActionInput: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.poolEntryID = try Uint64(xdrData: &xdrData) + self.ext = try DeleteExternalSystemAccountIdPoolEntryActionInputExt(xdrData: &xdrData) + } + public enum DeleteExternalSystemAccountIdPoolEntryActionInputExt: XDRDiscriminatedUnion { case emptyVersion() @@ -64,5 +69,15 @@ public struct DeleteExternalSystemAccountIdPoolEntryActionInput: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/DontHave.swift b/Sources/TokenDWallet/Xdr/DontHave.swift index de5f961..baa10da 100644 --- a/Sources/TokenDWallet/Xdr/DontHave.swift +++ b/Sources/TokenDWallet/Xdr/DontHave.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct DontHave: XDREncodable { +public struct DontHave: XDRCodable { public var type: MessageType public var reqHash: Uint256 @@ -32,4 +32,9 @@ public struct DontHave: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.type = try MessageType(xdrData: &xdrData) + self.reqHash = try Uint256(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/EmptyExt.swift b/Sources/TokenDWallet/Xdr/EmptyExt.swift index 47aa289..34470b7 100644 --- a/Sources/TokenDWallet/Xdr/EmptyExt.swift +++ b/Sources/TokenDWallet/Xdr/EmptyExt.swift @@ -32,4 +32,14 @@ public enum EmptyExt: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/Error.swift b/Sources/TokenDWallet/Xdr/Error.swift index 182c29e..52a92b1 100644 --- a/Sources/TokenDWallet/Xdr/Error.swift +++ b/Sources/TokenDWallet/Xdr/Error.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct Error: XDREncodable { +public struct Error: XDRCodable { public var code: ErrorCode public var msg: String @@ -32,4 +32,9 @@ public struct Error: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.code = try ErrorCode(xdrData: &xdrData) + self.msg = try String(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/ExtendedResult.swift b/Sources/TokenDWallet/Xdr/ExtendedResult.swift index 4527d5e..f702171 100644 --- a/Sources/TokenDWallet/Xdr/ExtendedResult.swift +++ b/Sources/TokenDWallet/Xdr/ExtendedResult.swift @@ -21,6 +21,12 @@ import Foundation // AtomicSwapAskExtended atomicSwapAskExtended; // case CREATE_POLL: // CreatePollExtended createPoll; +// case MANAGE_OFFER: +// ManageOfferResult manageOfferResult; +// case CREATE_PAYMENT: +// PaymentResult paymentResult; +// case PERFORM_REDEMPTION: +// CreateRedemptionRequestResult createRedemptionResult; // } typeExt; // // //: Reserved for future use @@ -33,7 +39,7 @@ import Foundation // }; // =========================================================================== -public struct ExtendedResult: XDREncodable { +public struct ExtendedResult: XDRCodable { public var fulfilled: Bool public var typeExt: ExtendedResultTypeExt public var ext: ExtendedResultExt @@ -58,12 +64,21 @@ public struct ExtendedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.fulfilled = try Bool(xdrData: &xdrData) + self.typeExt = try ExtendedResultTypeExt(xdrData: &xdrData) + self.ext = try ExtendedResultExt(xdrData: &xdrData) + } + public enum ExtendedResultTypeExt: XDRDiscriminatedUnion { case createSale(SaleExtended) case none() case createAtomicSwapBid(AtomicSwapBidExtended) case createAtomicSwapAsk(AtomicSwapAskExtended) case createPoll(CreatePollExtended) + case manageOffer(ManageOfferResult) + case createPayment(PaymentResult) + case performRedemption(CreateRedemptionRequestResult) public var discriminant: Int32 { switch self { @@ -72,6 +87,9 @@ public struct ExtendedResult: XDREncodable { case .createAtomicSwapBid: return ReviewableRequestType.createAtomicSwapBid.rawValue case .createAtomicSwapAsk: return ReviewableRequestType.createAtomicSwapAsk.rawValue case .createPoll: return ReviewableRequestType.createPoll.rawValue + case .manageOffer: return ReviewableRequestType.manageOffer.rawValue + case .createPayment: return ReviewableRequestType.createPayment.rawValue + case .performRedemption: return ReviewableRequestType.performRedemption.rawValue } } @@ -86,11 +104,45 @@ public struct ExtendedResult: XDREncodable { case .createAtomicSwapBid(let data): xdr.append(data.toXDR()) case .createAtomicSwapAsk(let data): xdr.append(data.toXDR()) case .createPoll(let data): xdr.append(data.toXDR()) + case .manageOffer(let data): xdr.append(data.toXDR()) + case .createPayment(let data): xdr.append(data.toXDR()) + case .performRedemption(let data): xdr.append(data.toXDR()) } return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ReviewableRequestType.createSale.rawValue: + let data = try SaleExtended(xdrData: &xdrData) + self = .createSale(data) + case ReviewableRequestType.none.rawValue: self = .none() + case ReviewableRequestType.createAtomicSwapBid.rawValue: + let data = try AtomicSwapBidExtended(xdrData: &xdrData) + self = .createAtomicSwapBid(data) + case ReviewableRequestType.createAtomicSwapAsk.rawValue: + let data = try AtomicSwapAskExtended(xdrData: &xdrData) + self = .createAtomicSwapAsk(data) + case ReviewableRequestType.createPoll.rawValue: + let data = try CreatePollExtended(xdrData: &xdrData) + self = .createPoll(data) + case ReviewableRequestType.manageOffer.rawValue: + let data = try ManageOfferResult(xdrData: &xdrData) + self = .manageOffer(data) + case ReviewableRequestType.createPayment.rawValue: + let data = try PaymentResult(xdrData: &xdrData) + self = .createPayment(data) + case ReviewableRequestType.performRedemption.rawValue: + let data = try CreateRedemptionRequestResult(xdrData: &xdrData) + self = .performRedemption(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ExtendedResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -113,5 +165,15 @@ public struct ExtendedResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ExternalSystemAccountID.swift b/Sources/TokenDWallet/Xdr/ExternalSystemAccountID.swift index 0fcc7c8..747c73c 100644 --- a/Sources/TokenDWallet/Xdr/ExternalSystemAccountID.swift +++ b/Sources/TokenDWallet/Xdr/ExternalSystemAccountID.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct ExternalSystemAccountID: XDREncodable { +public struct ExternalSystemAccountID: XDRCodable { public var accountID: AccountID public var externalSystemType: Int32 public var data: Longstring @@ -50,6 +50,13 @@ public struct ExternalSystemAccountID: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.externalSystemType = try Int32(xdrData: &xdrData) + self.data = try Longstring(xdrData: &xdrData) + self.ext = try ExternalSystemAccountIDExt(xdrData: &xdrData) + } + public enum ExternalSystemAccountIDExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +78,15 @@ public struct ExternalSystemAccountID: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ExternalSystemAccountIDPoolEntry.swift b/Sources/TokenDWallet/Xdr/ExternalSystemAccountIDPoolEntry.swift index 40c207d..353c24a 100644 --- a/Sources/TokenDWallet/Xdr/ExternalSystemAccountIDPoolEntry.swift +++ b/Sources/TokenDWallet/Xdr/ExternalSystemAccountIDPoolEntry.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ExternalSystemAccountIDPoolEntry: XDREncodable { +public struct ExternalSystemAccountIDPoolEntry: XDRCodable { public var poolEntryID: Uint64 public var externalSystemType: Int32 public var data: Longstring @@ -76,6 +76,22 @@ public struct ExternalSystemAccountIDPoolEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.poolEntryID = try Uint64(xdrData: &xdrData) + self.externalSystemType = try Int32(xdrData: &xdrData) + self.data = try Longstring(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.expiresAt = try Uint64(xdrData: &xdrData) + self.bindedAt = try Uint64(xdrData: &xdrData) + self.parent = try Uint64(xdrData: &xdrData) + self.isDeleted = try Bool(xdrData: &xdrData) + self.ext = try ExternalSystemAccountIDPoolEntryExt(xdrData: &xdrData) + } + public enum ExternalSystemAccountIDPoolEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -97,5 +113,15 @@ public struct ExternalSystemAccountIDPoolEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/Fee.swift b/Sources/TokenDWallet/Xdr/Fee.swift index eeda603..8c8bcb1 100644 --- a/Sources/TokenDWallet/Xdr/Fee.swift +++ b/Sources/TokenDWallet/Xdr/Fee.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct Fee: XDREncodable { +public struct Fee: XDRCodable { public var fixed: Uint64 public var percent: Uint64 public var ext: FeeExt @@ -47,6 +47,12 @@ public struct Fee: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.fixed = try Uint64(xdrData: &xdrData) + self.percent = try Uint64(xdrData: &xdrData) + self.ext = try FeeExt(xdrData: &xdrData) + } + public enum FeeExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +74,15 @@ public struct Fee: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/FeeEntry.swift b/Sources/TokenDWallet/Xdr/FeeEntry.swift index 8c4590a..9b9dc9e 100644 --- a/Sources/TokenDWallet/Xdr/FeeEntry.swift +++ b/Sources/TokenDWallet/Xdr/FeeEntry.swift @@ -45,7 +45,7 @@ import Foundation // }; // =========================================================================== -public struct FeeEntry: XDREncodable { +public struct FeeEntry: XDRCodable { public var feeType: FeeType public var asset: AssetCode public var fixedFee: Int64 @@ -102,6 +102,28 @@ public struct FeeEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.feeType = try FeeType(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.fixedFee = try Int64(xdrData: &xdrData) + self.percentFee = try Int64(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + if (try Bool(xdrData: &xdrData)) { + self.accountRole = try Uint64(xdrData: &xdrData) + } else { + self.accountRole = nil + } + self.subtype = try Int64(xdrData: &xdrData) + self.lowerBound = try Int64(xdrData: &xdrData) + self.upperBound = try Int64(xdrData: &xdrData) + self.hash = try Hash(xdrData: &xdrData) + self.ext = try FeeEntryExt(xdrData: &xdrData) + } + public enum FeeEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -123,5 +145,15 @@ public struct FeeEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/FeeType.swift b/Sources/TokenDWallet/Xdr/FeeType.swift index 51a4c58..afee12f 100644 --- a/Sources/TokenDWallet/Xdr/FeeType.swift +++ b/Sources/TokenDWallet/Xdr/FeeType.swift @@ -17,7 +17,8 @@ import Foundation // OPERATION_FEE = 6, // PAYOUT_FEE = 7, // ATOMIC_SWAP_SALE_FEE = 8, -// ATOMIC_SWAP_PURCHASE_FEE = 9 +// ATOMIC_SWAP_PURCHASE_FEE = 9, +// SWAP_FEE = 10 // }; // =========================================================================== @@ -32,4 +33,5 @@ public enum FeeType: Int32, XDREnum { case payoutFee = 7 case atomicSwapSaleFee = 8 case atomicSwapPurchaseFee = 9 + case swapFee = 10 } diff --git a/Sources/TokenDWallet/Xdr/FixedPriceSale.swift b/Sources/TokenDWallet/Xdr/FixedPriceSale.swift index dbb7901..529fec0 100644 --- a/Sources/TokenDWallet/Xdr/FixedPriceSale.swift +++ b/Sources/TokenDWallet/Xdr/FixedPriceSale.swift @@ -15,7 +15,7 @@ import Foundation // }; // =========================================================================== -public struct FixedPriceSale: XDREncodable { +public struct FixedPriceSale: XDRCodable { public var ext: FixedPriceSaleExt public init( @@ -32,6 +32,10 @@ public struct FixedPriceSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try FixedPriceSaleExt(xdrData: &xdrData) + } + public enum FixedPriceSaleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -53,5 +57,15 @@ public struct FixedPriceSale: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/Hello.swift b/Sources/TokenDWallet/Xdr/Hello.swift index 236edc8..74161ce 100644 --- a/Sources/TokenDWallet/Xdr/Hello.swift +++ b/Sources/TokenDWallet/Xdr/Hello.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct Hello: XDREncodable { +public struct Hello: XDRCodable { public var ledgerVersion: Uint32 public var overlayVersion: Uint32 public var overlayMinVersion: Uint32 @@ -67,4 +67,16 @@ public struct Hello: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.ledgerVersion = try Uint32(xdrData: &xdrData) + self.overlayVersion = try Uint32(xdrData: &xdrData) + self.overlayMinVersion = try Uint32(xdrData: &xdrData) + self.networkID = try Hash(xdrData: &xdrData) + self.versionStr = try String(xdrData: &xdrData) + self.listeningPort = try Int32(xdrData: &xdrData) + self.peerID = try NodeID(xdrData: &xdrData) + self.cert = try AuthCert(xdrData: &xdrData) + self.nonce = try Uint256(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/HmacSha256Key.swift b/Sources/TokenDWallet/Xdr/HmacSha256Key.swift index a2ad88c..37e5448 100644 --- a/Sources/TokenDWallet/Xdr/HmacSha256Key.swift +++ b/Sources/TokenDWallet/Xdr/HmacSha256Key.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct HmacSha256Key: XDREncodable { +public struct HmacSha256Key: XDRCodable { public var key: XDRDataFixed32 public init( @@ -27,4 +27,8 @@ public struct HmacSha256Key: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.key = try XDRDataFixed32(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/HmacSha256Mac.swift b/Sources/TokenDWallet/Xdr/HmacSha256Mac.swift index 395f81f..1a1eaf7 100644 --- a/Sources/TokenDWallet/Xdr/HmacSha256Mac.swift +++ b/Sources/TokenDWallet/Xdr/HmacSha256Mac.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct HmacSha256Mac: XDREncodable { +public struct HmacSha256Mac: XDRCodable { public var mac: XDRDataFixed32 public init( @@ -27,4 +27,8 @@ public struct HmacSha256Mac: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.mac = try XDRDataFixed32(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/IdGenerator.swift b/Sources/TokenDWallet/Xdr/IdGenerator.swift index 414645d..5f4f7be 100644 --- a/Sources/TokenDWallet/Xdr/IdGenerator.swift +++ b/Sources/TokenDWallet/Xdr/IdGenerator.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct IdGenerator: XDREncodable { +public struct IdGenerator: XDRCodable { public var entryType: LedgerEntryType public var idPool: Uint64 @@ -31,4 +31,9 @@ public struct IdGenerator: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.entryType = try LedgerEntryType(xdrData: &xdrData) + self.idPool = try Uint64(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/ImmediateSale.swift b/Sources/TokenDWallet/Xdr/ImmediateSale.swift new file mode 100644 index 0000000..a588132 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/ImmediateSale.swift @@ -0,0 +1,33 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct ImmediateSale { +// EmptyExt ext; +// }; + +// =========================================================================== +public struct ImmediateSale: XDRCodable { + public var ext: EmptyExt + + public init( + ext: EmptyExt) { + + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryOp.swift b/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryOp.swift index 62641f8..09443bb 100644 --- a/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryOp.swift +++ b/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryOp.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct InitiateKYCRecoveryOp: XDREncodable { +public struct InitiateKYCRecoveryOp: XDRCodable { public var account: AccountID public var signer: PublicKey public var ext: InitiateKYCRecoveryOpExt @@ -47,6 +47,12 @@ public struct InitiateKYCRecoveryOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.account = try AccountID(xdrData: &xdrData) + self.signer = try PublicKey(xdrData: &xdrData) + self.ext = try InitiateKYCRecoveryOpExt(xdrData: &xdrData) + } + public enum InitiateKYCRecoveryOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +74,15 @@ public struct InitiateKYCRecoveryOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryResult.swift b/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryResult.swift index 982c7d2..d820931 100644 --- a/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryResult.swift +++ b/Sources/TokenDWallet/Xdr/InitiateKYCRecoveryResult.swift @@ -43,7 +43,19 @@ public enum InitiateKYCRecoveryResult: XDRDiscriminatedUnion { return xdr } - public struct InitiateKYCRecoveryResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case InitiateKYCRecoveryResultCode.success.rawValue: + let data = try InitiateKYCRecoveryResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct InitiateKYCRecoveryResultSuccess: XDRCodable { public var ext: InitiateKYCRecoveryResultSuccessExt public init( @@ -60,6 +72,10 @@ public enum InitiateKYCRecoveryResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try InitiateKYCRecoveryResultSuccessExt(xdrData: &xdrData) + } + public enum InitiateKYCRecoveryResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -81,6 +97,16 @@ public enum InitiateKYCRecoveryResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/InvoiceCreationRequest.swift b/Sources/TokenDWallet/Xdr/InvoiceCreationRequest.swift index 1cfad1d..75cecf7 100644 --- a/Sources/TokenDWallet/Xdr/InvoiceCreationRequest.swift +++ b/Sources/TokenDWallet/Xdr/InvoiceCreationRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct InvoiceCreationRequest: XDREncodable { +public struct InvoiceCreationRequest: XDRCodable { public var asset: AssetCode public var sender: AccountID public var amount: Uint64 @@ -67,6 +67,24 @@ public struct InvoiceCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.asset = try AssetCode(xdrData: &xdrData) + self.sender = try AccountID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.contractID = try Uint64(xdrData: &xdrData) + } else { + self.contractID = nil + } + self.details = try Longstring(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try InvoiceCreationRequestExt(xdrData: &xdrData) + } + public enum InvoiceCreationRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -88,5 +106,15 @@ public struct InvoiceCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/InvoiceRequest.swift b/Sources/TokenDWallet/Xdr/InvoiceRequest.swift index b5488ac..93c05f4 100644 --- a/Sources/TokenDWallet/Xdr/InvoiceRequest.swift +++ b/Sources/TokenDWallet/Xdr/InvoiceRequest.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct InvoiceRequest: XDREncodable { +public struct InvoiceRequest: XDRCodable { public var asset: AssetCode public var amount: Uint64 public var senderBalance: BalanceID @@ -71,6 +71,21 @@ public struct InvoiceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.asset = try AssetCode(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.senderBalance = try BalanceID(xdrData: &xdrData) + self.receiverBalance = try BalanceID(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.contractID = try Uint64(xdrData: &xdrData) + } else { + self.contractID = nil + } + self.isApproved = try Bool(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try InvoiceRequestExt(xdrData: &xdrData) + } + public enum InvoiceRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -92,5 +107,15 @@ public struct InvoiceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/IssuanceRequest.swift b/Sources/TokenDWallet/Xdr/IssuanceRequest.swift index 4523992..d9c1606 100644 --- a/Sources/TokenDWallet/Xdr/IssuanceRequest.swift +++ b/Sources/TokenDWallet/Xdr/IssuanceRequest.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct IssuanceRequest: XDREncodable { +public struct IssuanceRequest: XDRCodable { public var asset: AssetCode public var amount: Uint64 public var receiver: BalanceID @@ -64,6 +64,15 @@ public struct IssuanceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.asset = try AssetCode(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.receiver = try BalanceID(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.fee = try Fee(xdrData: &xdrData) + self.ext = try IssuanceRequestExt(xdrData: &xdrData) + } + public enum IssuanceRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -85,5 +94,15 @@ public struct IssuanceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/KYCRecoveryRequest.swift b/Sources/TokenDWallet/Xdr/KYCRecoveryRequest.swift index 9197909..90b9e63 100644 --- a/Sources/TokenDWallet/Xdr/KYCRecoveryRequest.swift +++ b/Sources/TokenDWallet/Xdr/KYCRecoveryRequest.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct KYCRecoveryRequest: XDREncodable { +public struct KYCRecoveryRequest: XDRCodable { public var targetAccount: AccountID public var signersData: [UpdateSignerData] public var creatorDetails: Longstring @@ -60,6 +60,18 @@ public struct KYCRecoveryRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.targetAccount = try AccountID(xdrData: &xdrData) + let lengthsignersData = try Int32(xdrData: &xdrData) + self.signersData = [UpdateSignerData]() + for _ in 1...lengthsignersData { + self.signersData.append(try UpdateSignerData(xdrData: &xdrData)) + } + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + self.ext = try KYCRecoveryRequestExt(xdrData: &xdrData) + } + public enum KYCRecoveryRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -81,5 +93,15 @@ public struct KYCRecoveryRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/KeyValueEntry.swift b/Sources/TokenDWallet/Xdr/KeyValueEntry.swift index f4a908a..14dca3c 100644 --- a/Sources/TokenDWallet/Xdr/KeyValueEntry.swift +++ b/Sources/TokenDWallet/Xdr/KeyValueEntry.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct KeyValueEntry: XDREncodable { +public struct KeyValueEntry: XDRCodable { public var key: Longstring public var value: KeyValueEntryValue public var ext: KeyValueEntryExt @@ -50,6 +50,12 @@ public struct KeyValueEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.key = try Longstring(xdrData: &xdrData) + self.value = try KeyValueEntryValue(xdrData: &xdrData) + self.ext = try KeyValueEntryExt(xdrData: &xdrData) + } + public enum KeyValueEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +77,15 @@ public struct KeyValueEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/KeyValueEntryValue.swift b/Sources/TokenDWallet/Xdr/KeyValueEntryValue.swift index 9b6246e..4d34c76 100644 --- a/Sources/TokenDWallet/Xdr/KeyValueEntryValue.swift +++ b/Sources/TokenDWallet/Xdr/KeyValueEntryValue.swift @@ -43,4 +43,22 @@ public enum KeyValueEntryValue: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case KeyValueEntryType.uint32.rawValue: + let data = try Uint32(xdrData: &xdrData) + self = .uint32(data) + case KeyValueEntryType.string.rawValue: + let data = try String(xdrData: &xdrData) + self = .string(data) + case KeyValueEntryType.uint64.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .uint64(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerEntry.swift b/Sources/TokenDWallet/Xdr/LedgerEntry.swift index b24769b..d6d1041 100644 --- a/Sources/TokenDWallet/Xdr/LedgerEntry.swift +++ b/Sources/TokenDWallet/Xdr/LedgerEntry.swift @@ -71,6 +71,8 @@ import Foundation // VoteEntry vote; // case ACCOUNT_SPECIFIC_RULE: // AccountSpecificRuleEntry accountSpecificRule; +// case SWAP: +// SwapEntry swap; // } // data; // @@ -84,7 +86,7 @@ import Foundation // }; // =========================================================================== -public struct LedgerEntry: XDREncodable { +public struct LedgerEntry: XDRCodable { public var lastModifiedLedgerSeq: Uint32 public var data: LedgerEntryData public var ext: LedgerEntryExt @@ -109,6 +111,12 @@ public struct LedgerEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.lastModifiedLedgerSeq = try Uint32(xdrData: &xdrData) + self.data = try LedgerEntryData(xdrData: &xdrData) + self.ext = try LedgerEntryExt(xdrData: &xdrData) + } + public enum LedgerEntryData: XDRDiscriminatedUnion { case account(AccountEntry) case signer(SignerEntry) @@ -140,6 +148,7 @@ public struct LedgerEntry: XDREncodable { case poll(PollEntry) case vote(VoteEntry) case accountSpecificRule(AccountSpecificRuleEntry) + case swap(SwapEntry) public var discriminant: Int32 { switch self { @@ -173,6 +182,7 @@ public struct LedgerEntry: XDREncodable { case .poll: return LedgerEntryType.poll.rawValue case .vote: return LedgerEntryType.vote.rawValue case .accountSpecificRule: return LedgerEntryType.accountSpecificRule.rawValue + case .swap: return LedgerEntryType.swap.rawValue } } @@ -212,11 +222,114 @@ public struct LedgerEntry: XDREncodable { case .poll(let data): xdr.append(data.toXDR()) case .vote(let data): xdr.append(data.toXDR()) case .accountSpecificRule(let data): xdr.append(data.toXDR()) + case .swap(let data): xdr.append(data.toXDR()) } return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerEntryType.account.rawValue: + let data = try AccountEntry(xdrData: &xdrData) + self = .account(data) + case LedgerEntryType.signer.rawValue: + let data = try SignerEntry(xdrData: &xdrData) + self = .signer(data) + case LedgerEntryType.fee.rawValue: + let data = try FeeEntry(xdrData: &xdrData) + self = .fee(data) + case LedgerEntryType.balance.rawValue: + let data = try BalanceEntry(xdrData: &xdrData) + self = .balance(data) + case LedgerEntryType.asset.rawValue: + let data = try AssetEntry(xdrData: &xdrData) + self = .asset(data) + case LedgerEntryType.referenceEntry.rawValue: + let data = try ReferenceEntry(xdrData: &xdrData) + self = .referenceEntry(data) + case LedgerEntryType.statistics.rawValue: + let data = try StatisticsEntry(xdrData: &xdrData) + self = .statistics(data) + case LedgerEntryType.accountLimits.rawValue: + let data = try AccountLimitsEntry(xdrData: &xdrData) + self = .accountLimits(data) + case LedgerEntryType.assetPair.rawValue: + let data = try AssetPairEntry(xdrData: &xdrData) + self = .assetPair(data) + case LedgerEntryType.offerEntry.rawValue: + let data = try OfferEntry(xdrData: &xdrData) + self = .offerEntry(data) + case LedgerEntryType.reviewableRequest.rawValue: + let data = try ReviewableRequestEntry(xdrData: &xdrData) + self = .reviewableRequest(data) + case LedgerEntryType.externalSystemAccountId.rawValue: + let data = try ExternalSystemAccountID(xdrData: &xdrData) + self = .externalSystemAccountId(data) + case LedgerEntryType.sale.rawValue: + let data = try SaleEntry(xdrData: &xdrData) + self = .sale(data) + case LedgerEntryType.keyValue.rawValue: + let data = try KeyValueEntry(xdrData: &xdrData) + self = .keyValue(data) + case LedgerEntryType.accountKyc.rawValue: + let data = try AccountKYCEntry(xdrData: &xdrData) + self = .accountKyc(data) + case LedgerEntryType.externalSystemAccountIdPoolEntry.rawValue: + let data = try ExternalSystemAccountIDPoolEntry(xdrData: &xdrData) + self = .externalSystemAccountIdPoolEntry(data) + case LedgerEntryType.limitsV2.rawValue: + let data = try LimitsV2Entry(xdrData: &xdrData) + self = .limitsV2(data) + case LedgerEntryType.statisticsV2.rawValue: + let data = try StatisticsV2Entry(xdrData: &xdrData) + self = .statisticsV2(data) + case LedgerEntryType.pendingStatistics.rawValue: + let data = try PendingStatisticsEntry(xdrData: &xdrData) + self = .pendingStatistics(data) + case LedgerEntryType.contract.rawValue: + let data = try ContractEntry(xdrData: &xdrData) + self = .contract(data) + case LedgerEntryType.atomicSwapAsk.rawValue: + let data = try AtomicSwapAskEntry(xdrData: &xdrData) + self = .atomicSwapAsk(data) + case LedgerEntryType.accountRole.rawValue: + let data = try AccountRoleEntry(xdrData: &xdrData) + self = .accountRole(data) + case LedgerEntryType.accountRule.rawValue: + let data = try AccountRuleEntry(xdrData: &xdrData) + self = .accountRule(data) + case LedgerEntryType.signerRule.rawValue: + let data = try SignerRuleEntry(xdrData: &xdrData) + self = .signerRule(data) + case LedgerEntryType.signerRole.rawValue: + let data = try SignerRoleEntry(xdrData: &xdrData) + self = .signerRole(data) + case LedgerEntryType.license.rawValue: + let data = try LicenseEntry(xdrData: &xdrData) + self = .license(data) + case LedgerEntryType.stamp.rawValue: + let data = try StampEntry(xdrData: &xdrData) + self = .stamp(data) + case LedgerEntryType.poll.rawValue: + let data = try PollEntry(xdrData: &xdrData) + self = .poll(data) + case LedgerEntryType.vote.rawValue: + let data = try VoteEntry(xdrData: &xdrData) + self = .vote(data) + case LedgerEntryType.accountSpecificRule.rawValue: + let data = try AccountSpecificRuleEntry(xdrData: &xdrData) + self = .accountSpecificRule(data) + case LedgerEntryType.swap.rawValue: + let data = try SwapEntry(xdrData: &xdrData) + self = .swap(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum LedgerEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -239,5 +352,15 @@ public struct LedgerEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerEntryChange.swift b/Sources/TokenDWallet/Xdr/LedgerEntryChange.swift index 78cdd46..3d4967e 100644 --- a/Sources/TokenDWallet/Xdr/LedgerEntryChange.swift +++ b/Sources/TokenDWallet/Xdr/LedgerEntryChange.swift @@ -47,4 +47,25 @@ public enum LedgerEntryChange: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerEntryChangeType.created.rawValue: + let data = try LedgerEntry(xdrData: &xdrData) + self = .created(data) + case LedgerEntryChangeType.updated.rawValue: + let data = try LedgerEntry(xdrData: &xdrData) + self = .updated(data) + case LedgerEntryChangeType.removed.rawValue: + let data = try LedgerKey(xdrData: &xdrData) + self = .removed(data) + case LedgerEntryChangeType.state.rawValue: + let data = try LedgerEntry(xdrData: &xdrData) + self = .state(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerEntryType.swift b/Sources/TokenDWallet/Xdr/LedgerEntryType.swift index 1830f87..4436575 100644 --- a/Sources/TokenDWallet/Xdr/LedgerEntryType.swift +++ b/Sources/TokenDWallet/Xdr/LedgerEntryType.swift @@ -41,7 +41,8 @@ import Foundation // POLL = 34, // VOTE = 35, // ACCOUNT_SPECIFIC_RULE = 36, -// INITIATE_KYC_RECOVERY = 37 +// INITIATE_KYC_RECOVERY = 37, +// SWAP = 38 // }; // =========================================================================== @@ -81,4 +82,5 @@ public enum LedgerEntryType: Int32, XDREnum { case vote = 35 case accountSpecificRule = 36 case initiateKycRecovery = 37 + case swap = 38 } diff --git a/Sources/TokenDWallet/Xdr/LedgerHeader.swift b/Sources/TokenDWallet/Xdr/LedgerHeader.swift index c4e983d..228479c 100644 --- a/Sources/TokenDWallet/Xdr/LedgerHeader.swift +++ b/Sources/TokenDWallet/Xdr/LedgerHeader.swift @@ -40,7 +40,7 @@ import Foundation // }; // =========================================================================== -public struct LedgerHeader: XDREncodable { +public struct LedgerHeader: XDRCodable { public var ledgerVersion: Uint32 public var previousLedgerHash: Hash public var scpValue: StellarValue @@ -52,7 +52,7 @@ public struct LedgerHeader: XDREncodable { public var baseReserve: Uint32 public var maxTxSetSize: Uint32 public var txExpirationPeriod: Int64 -// public var skipList: XDRArrayFixed + public var skipList: XDRArrayFixed4 public var ext: LedgerHeaderExt public init( @@ -67,7 +67,7 @@ public struct LedgerHeader: XDREncodable { baseReserve: Uint32, maxTxSetSize: Uint32, txExpirationPeriod: Int64, -// skipList: XDRArrayFixed, + skipList: XDRArrayFixed4, ext: LedgerHeaderExt) { self.ledgerVersion = ledgerVersion @@ -81,7 +81,7 @@ public struct LedgerHeader: XDREncodable { self.baseReserve = baseReserve self.maxTxSetSize = maxTxSetSize self.txExpirationPeriod = txExpirationPeriod -// self.skipList = skipList + self.skipList = skipList self.ext = ext } @@ -99,12 +99,32 @@ public struct LedgerHeader: XDREncodable { xdr.append(self.baseReserve.toXDR()) xdr.append(self.maxTxSetSize.toXDR()) xdr.append(self.txExpirationPeriod.toXDR()) -// xdr.append(self.skipList.toXDR()) + xdr.append(self.skipList.toXDR()) xdr.append(self.ext.toXDR()) return xdr } + public init(xdrData: inout Data) throws { + self.ledgerVersion = try Uint32(xdrData: &xdrData) + self.previousLedgerHash = try Hash(xdrData: &xdrData) + self.scpValue = try StellarValue(xdrData: &xdrData) + self.txSetResultHash = try Hash(xdrData: &xdrData) + self.bucketListHash = try Hash(xdrData: &xdrData) + self.ledgerSeq = try Uint32(xdrData: &xdrData) + let lengthidGenerators = try Int32(xdrData: &xdrData) + self.idGenerators = [IdGenerator]() + for _ in 1...lengthidGenerators { + self.idGenerators.append(try IdGenerator(xdrData: &xdrData)) + } + self.baseFee = try Uint32(xdrData: &xdrData) + self.baseReserve = try Uint32(xdrData: &xdrData) + self.maxTxSetSize = try Uint32(xdrData: &xdrData) + self.txExpirationPeriod = try Int64(xdrData: &xdrData) + self.skipList = try XDRArrayFixed4(xdrData: &xdrData) + self.ext = try LedgerHeaderExt(xdrData: &xdrData) + } + public enum LedgerHeaderExt: XDRDiscriminatedUnion { case emptyVersion() @@ -126,5 +146,15 @@ public struct LedgerHeader: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerHeaderHistoryEntry.swift b/Sources/TokenDWallet/Xdr/LedgerHeaderHistoryEntry.swift index 64e7bc5..5e9688a 100644 --- a/Sources/TokenDWallet/Xdr/LedgerHeaderHistoryEntry.swift +++ b/Sources/TokenDWallet/Xdr/LedgerHeaderHistoryEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct LedgerHeaderHistoryEntry: XDREncodable { +public struct LedgerHeaderHistoryEntry: XDRCodable { public var hash: Hash public var header: LedgerHeader public var ext: LedgerHeaderHistoryEntryExt @@ -45,6 +45,12 @@ public struct LedgerHeaderHistoryEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.hash = try Hash(xdrData: &xdrData) + self.header = try LedgerHeader(xdrData: &xdrData) + self.ext = try LedgerHeaderHistoryEntryExt(xdrData: &xdrData) + } + public enum LedgerHeaderHistoryEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct LedgerHeaderHistoryEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerKey.swift b/Sources/TokenDWallet/Xdr/LedgerKey.swift index f123b13..9f10d8f 100644 --- a/Sources/TokenDWallet/Xdr/LedgerKey.swift +++ b/Sources/TokenDWallet/Xdr/LedgerKey.swift @@ -303,6 +303,13 @@ import Foundation // // EmptyExt ext; // } accountSpecificRule; +// case SWAP: +// struct +// { +// uint64 id; +// +// EmptyExt ext; +// } swap; // }; // =========================================================================== @@ -337,6 +344,7 @@ public enum LedgerKey: XDRDiscriminatedUnion { case poll(LedgerKeyPoll) case vote(LedgerKeyVote) case accountSpecificRule(LedgerKeyAccountSpecificRule) + case swap(LedgerKeySwap) public var discriminant: Int32 { switch self { @@ -370,6 +378,7 @@ public enum LedgerKey: XDRDiscriminatedUnion { case .poll: return LedgerEntryType.poll.rawValue case .vote: return LedgerEntryType.vote.rawValue case .accountSpecificRule: return LedgerEntryType.accountSpecificRule.rawValue + case .swap: return LedgerEntryType.swap.rawValue } } @@ -409,11 +418,114 @@ public enum LedgerKey: XDRDiscriminatedUnion { case .poll(let data): xdr.append(data.toXDR()) case .vote(let data): xdr.append(data.toXDR()) case .accountSpecificRule(let data): xdr.append(data.toXDR()) + case .swap(let data): xdr.append(data.toXDR()) } return xdr } - public struct LedgerKeyAccount: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerEntryType.account.rawValue: + let data = try LedgerKeyAccount(xdrData: &xdrData) + self = .account(data) + case LedgerEntryType.signer.rawValue: + let data = try LedgerKeySigner(xdrData: &xdrData) + self = .signer(data) + case LedgerEntryType.fee.rawValue: + let data = try LedgerKeyFeeState(xdrData: &xdrData) + self = .fee(data) + case LedgerEntryType.balance.rawValue: + let data = try LedgerKeyBalance(xdrData: &xdrData) + self = .balance(data) + case LedgerEntryType.asset.rawValue: + let data = try LedgerKeyAsset(xdrData: &xdrData) + self = .asset(data) + case LedgerEntryType.referenceEntry.rawValue: + let data = try LedgerKeyReference(xdrData: &xdrData) + self = .referenceEntry(data) + case LedgerEntryType.statistics.rawValue: + let data = try LedgerKeyStats(xdrData: &xdrData) + self = .statistics(data) + case LedgerEntryType.accountLimits.rawValue: + let data = try LedgerKeyAccountLimits(xdrData: &xdrData) + self = .accountLimits(data) + case LedgerEntryType.assetPair.rawValue: + let data = try LedgerKeyAssetPair(xdrData: &xdrData) + self = .assetPair(data) + case LedgerEntryType.offerEntry.rawValue: + let data = try LedgerKeyOffer(xdrData: &xdrData) + self = .offerEntry(data) + case LedgerEntryType.reviewableRequest.rawValue: + let data = try LedgerKeyReviewableRequest(xdrData: &xdrData) + self = .reviewableRequest(data) + case LedgerEntryType.externalSystemAccountId.rawValue: + let data = try LedgerKeyExternalSystemAccountID(xdrData: &xdrData) + self = .externalSystemAccountId(data) + case LedgerEntryType.sale.rawValue: + let data = try LedgerKeySale(xdrData: &xdrData) + self = .sale(data) + case LedgerEntryType.keyValue.rawValue: + let data = try LedgerKeyKeyValue(xdrData: &xdrData) + self = .keyValue(data) + case LedgerEntryType.accountKyc.rawValue: + let data = try LedgerKeyAccountKYC(xdrData: &xdrData) + self = .accountKyc(data) + case LedgerEntryType.externalSystemAccountIdPoolEntry.rawValue: + let data = try LedgerKeyExternalSystemAccountIDPoolEntry(xdrData: &xdrData) + self = .externalSystemAccountIdPoolEntry(data) + case LedgerEntryType.limitsV2.rawValue: + let data = try LedgerKeyLimitsV2(xdrData: &xdrData) + self = .limitsV2(data) + case LedgerEntryType.statisticsV2.rawValue: + let data = try LedgerKeyStatisticsV2(xdrData: &xdrData) + self = .statisticsV2(data) + case LedgerEntryType.pendingStatistics.rawValue: + let data = try LedgerKeyPendingStatistics(xdrData: &xdrData) + self = .pendingStatistics(data) + case LedgerEntryType.contract.rawValue: + let data = try LedgerKeyContract(xdrData: &xdrData) + self = .contract(data) + case LedgerEntryType.atomicSwapAsk.rawValue: + let data = try LedgerKeyAtomicSwapAsk(xdrData: &xdrData) + self = .atomicSwapAsk(data) + case LedgerEntryType.accountRole.rawValue: + let data = try LedgerKeyAccountRole(xdrData: &xdrData) + self = .accountRole(data) + case LedgerEntryType.accountRule.rawValue: + let data = try LedgerKeyAccountRule(xdrData: &xdrData) + self = .accountRule(data) + case LedgerEntryType.signerRole.rawValue: + let data = try LedgerKeySignerRole(xdrData: &xdrData) + self = .signerRole(data) + case LedgerEntryType.signerRule.rawValue: + let data = try LedgerKeySignerRule(xdrData: &xdrData) + self = .signerRule(data) + case LedgerEntryType.stamp.rawValue: + let data = try LedgerKeyStamp(xdrData: &xdrData) + self = .stamp(data) + case LedgerEntryType.license.rawValue: + let data = try LedgerKeyLicense(xdrData: &xdrData) + self = .license(data) + case LedgerEntryType.poll.rawValue: + let data = try LedgerKeyPoll(xdrData: &xdrData) + self = .poll(data) + case LedgerEntryType.vote.rawValue: + let data = try LedgerKeyVote(xdrData: &xdrData) + self = .vote(data) + case LedgerEntryType.accountSpecificRule.rawValue: + let data = try LedgerKeyAccountSpecificRule(xdrData: &xdrData) + self = .accountSpecificRule(data) + case LedgerEntryType.swap.rawValue: + let data = try LedgerKeySwap(xdrData: &xdrData) + self = .swap(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct LedgerKeyAccount: XDRCodable { public var accountID: AccountID public var ext: LedgerKeyAccountExt @@ -434,6 +546,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.ext = try LedgerKeyAccountExt(xdrData: &xdrData) + } + public enum LedgerKeyAccountExt: XDRDiscriminatedUnion { case emptyVersion() @@ -455,9 +572,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeySigner: XDREncodable { + public struct LedgerKeySigner: XDRCodable { public var pubKey: PublicKey public var accountID: AccountID public var ext: LedgerKeySignerExt @@ -482,6 +609,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pubKey = try PublicKey(xdrData: &xdrData) + self.accountID = try AccountID(xdrData: &xdrData) + self.ext = try LedgerKeySignerExt(xdrData: &xdrData) + } + public enum LedgerKeySignerExt: XDRDiscriminatedUnion { case emptyVersion() @@ -503,9 +636,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyFeeState: XDREncodable { + public struct LedgerKeyFeeState: XDRCodable { public var hash: Hash public var lowerBound: Int64 public var upperBound: Int64 @@ -534,6 +677,13 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.hash = try Hash(xdrData: &xdrData) + self.lowerBound = try Int64(xdrData: &xdrData) + self.upperBound = try Int64(xdrData: &xdrData) + self.ext = try LedgerKeyFeeStateExt(xdrData: &xdrData) + } + public enum LedgerKeyFeeStateExt: XDRDiscriminatedUnion { case emptyVersion() @@ -555,9 +705,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyBalance: XDREncodable { + public struct LedgerKeyBalance: XDRCodable { public var balanceID: BalanceID public var ext: LedgerKeyBalanceExt @@ -578,6 +738,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.balanceID = try BalanceID(xdrData: &xdrData) + self.ext = try LedgerKeyBalanceExt(xdrData: &xdrData) + } + public enum LedgerKeyBalanceExt: XDRDiscriminatedUnion { case emptyVersion() @@ -599,9 +764,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAsset: XDREncodable { + public struct LedgerKeyAsset: XDRCodable { public var code: AssetCode public var ext: LedgerKeyAssetExt @@ -622,6 +797,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.ext = try LedgerKeyAssetExt(xdrData: &xdrData) + } + public enum LedgerKeyAssetExt: XDRDiscriminatedUnion { case emptyVersion() @@ -643,9 +823,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyReference: XDREncodable { + public struct LedgerKeyReference: XDRCodable { public var sender: AccountID public var reference: String64 public var ext: LedgerKeyReferenceExt @@ -670,6 +860,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.sender = try AccountID(xdrData: &xdrData) + self.reference = try String64(xdrData: &xdrData) + self.ext = try LedgerKeyReferenceExt(xdrData: &xdrData) + } + public enum LedgerKeyReferenceExt: XDRDiscriminatedUnion { case emptyVersion() @@ -691,9 +887,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyStats: XDREncodable { + public struct LedgerKeyStats: XDRCodable { public var accountID: AccountID public var ext: LedgerKeyStatsExt @@ -714,6 +920,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.ext = try LedgerKeyStatsExt(xdrData: &xdrData) + } + public enum LedgerKeyStatsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -735,9 +946,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAccountLimits: XDREncodable { + public struct LedgerKeyAccountLimits: XDRCodable { public var accountID: AccountID public var ext: LedgerKeyAccountLimitsExt @@ -758,6 +979,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.ext = try LedgerKeyAccountLimitsExt(xdrData: &xdrData) + } + public enum LedgerKeyAccountLimitsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -779,9 +1005,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAssetPair: XDREncodable { + public struct LedgerKeyAssetPair: XDRCodable { public var base: AssetCode public var quote: AssetCode public var ext: LedgerKeyAssetPairExt @@ -806,6 +1042,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.base = try AssetCode(xdrData: &xdrData) + self.quote = try AssetCode(xdrData: &xdrData) + self.ext = try LedgerKeyAssetPairExt(xdrData: &xdrData) + } + public enum LedgerKeyAssetPairExt: XDRDiscriminatedUnion { case emptyVersion() @@ -827,9 +1069,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyOffer: XDREncodable { + public struct LedgerKeyOffer: XDRCodable { public var offerID: Uint64 public var ownerID: AccountID @@ -850,8 +1102,13 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.offerID = try Uint64(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + } + } - public struct LedgerKeyReviewableRequest: XDREncodable { + public struct LedgerKeyReviewableRequest: XDRCodable { public var requestID: Uint64 public var ext: LedgerKeyReviewableRequestExt @@ -872,6 +1129,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyReviewableRequestExt(xdrData: &xdrData) + } + public enum LedgerKeyReviewableRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -893,9 +1155,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyExternalSystemAccountID: XDREncodable { + public struct LedgerKeyExternalSystemAccountID: XDRCodable { public var accountID: AccountID public var externalSystemType: Int32 public var ext: LedgerKeyExternalSystemAccountIDExt @@ -920,6 +1192,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.externalSystemType = try Int32(xdrData: &xdrData) + self.ext = try LedgerKeyExternalSystemAccountIDExt(xdrData: &xdrData) + } + public enum LedgerKeyExternalSystemAccountIDExt: XDRDiscriminatedUnion { case emptyVersion() @@ -941,9 +1219,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeySale: XDREncodable { + public struct LedgerKeySale: XDRCodable { public var saleID: Uint64 public var ext: LedgerKeySaleExt @@ -964,6 +1252,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeySaleExt(xdrData: &xdrData) + } + public enum LedgerKeySaleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -985,9 +1278,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyKeyValue: XDREncodable { + public struct LedgerKeyKeyValue: XDRCodable { public var key: Longstring public var ext: LedgerKeyKeyValueExt @@ -1008,6 +1311,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.key = try Longstring(xdrData: &xdrData) + self.ext = try LedgerKeyKeyValueExt(xdrData: &xdrData) + } + public enum LedgerKeyKeyValueExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1029,9 +1337,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAccountKYC: XDREncodable { + public struct LedgerKeyAccountKYC: XDRCodable { public var accountID: AccountID public var ext: LedgerKeyAccountKYCExt @@ -1052,6 +1370,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.ext = try LedgerKeyAccountKYCExt(xdrData: &xdrData) + } + public enum LedgerKeyAccountKYCExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1073,9 +1396,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyExternalSystemAccountIDPoolEntry: XDREncodable { + public struct LedgerKeyExternalSystemAccountIDPoolEntry: XDRCodable { public var poolEntryID: Uint64 public var ext: LedgerKeyExternalSystemAccountIDPoolEntryExt @@ -1096,6 +1429,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.poolEntryID = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyExternalSystemAccountIDPoolEntryExt(xdrData: &xdrData) + } + public enum LedgerKeyExternalSystemAccountIDPoolEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1117,9 +1455,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyLimitsV2: XDREncodable { + public struct LedgerKeyLimitsV2: XDRCodable { public var id: Uint64 public var ext: LedgerKeyLimitsV2Ext @@ -1140,6 +1488,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyLimitsV2Ext(xdrData: &xdrData) + } + public enum LedgerKeyLimitsV2Ext: XDRDiscriminatedUnion { case emptyVersion() @@ -1161,9 +1514,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyStatisticsV2: XDREncodable { + public struct LedgerKeyStatisticsV2: XDRCodable { public var id: Uint64 public var ext: LedgerKeyStatisticsV2Ext @@ -1184,6 +1547,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyStatisticsV2Ext(xdrData: &xdrData) + } + public enum LedgerKeyStatisticsV2Ext: XDRDiscriminatedUnion { case emptyVersion() @@ -1205,9 +1573,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyPendingStatistics: XDREncodable { + public struct LedgerKeyPendingStatistics: XDRCodable { public var statisticsID: Uint64 public var requestID: Uint64 public var ext: LedgerKeyPendingStatisticsExt @@ -1232,6 +1610,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.statisticsID = try Uint64(xdrData: &xdrData) + self.requestID = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyPendingStatisticsExt(xdrData: &xdrData) + } + public enum LedgerKeyPendingStatisticsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1253,9 +1637,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyContract: XDREncodable { + public struct LedgerKeyContract: XDRCodable { public var contractID: Uint64 public var ext: LedgerKeyContractExt @@ -1276,6 +1670,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.contractID = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyContractExt(xdrData: &xdrData) + } + public enum LedgerKeyContractExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1297,9 +1696,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAtomicSwapAsk: XDREncodable { + public struct LedgerKeyAtomicSwapAsk: XDRCodable { public var id: Uint64 public var ext: LedgerKeyAtomicSwapAskExt @@ -1320,6 +1729,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyAtomicSwapAskExt(xdrData: &xdrData) + } + public enum LedgerKeyAtomicSwapAskExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1341,9 +1755,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAccountRole: XDREncodable { + public struct LedgerKeyAccountRole: XDRCodable { public var id: Uint64 public var ext: LedgerKeyAccountRoleExt @@ -1364,6 +1788,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyAccountRoleExt(xdrData: &xdrData) + } + public enum LedgerKeyAccountRoleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1385,9 +1814,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyAccountRule: XDREncodable { + public struct LedgerKeyAccountRule: XDRCodable { public var id: Uint64 public var ext: LedgerKeyAccountRuleExt @@ -1408,6 +1847,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeyAccountRuleExt(xdrData: &xdrData) + } + public enum LedgerKeyAccountRuleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1429,9 +1873,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeySignerRole: XDREncodable { + public struct LedgerKeySignerRole: XDRCodable { public var id: Uint64 public var ext: LedgerKeySignerRoleExt @@ -1452,6 +1906,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeySignerRoleExt(xdrData: &xdrData) + } + public enum LedgerKeySignerRoleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1473,9 +1932,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeySignerRule: XDREncodable { + public struct LedgerKeySignerRule: XDRCodable { public var id: Uint64 public var ext: LedgerKeySignerRuleExt @@ -1496,6 +1965,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try LedgerKeySignerRuleExt(xdrData: &xdrData) + } + public enum LedgerKeySignerRuleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1517,9 +1991,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyStamp: XDREncodable { + public struct LedgerKeyStamp: XDRCodable { public var ledgerHash: Hash public var licenseHash: Hash public var ext: LedgerKeyStampExt @@ -1544,6 +2028,12 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerHash = try Hash(xdrData: &xdrData) + self.licenseHash = try Hash(xdrData: &xdrData) + self.ext = try LedgerKeyStampExt(xdrData: &xdrData) + } + public enum LedgerKeyStampExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1565,9 +2055,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyLicense: XDREncodable { + public struct LedgerKeyLicense: XDRCodable { public var licenseHash: Hash public var ext: LedgerKeyLicenseExt @@ -1588,6 +2088,11 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.licenseHash = try Hash(xdrData: &xdrData) + self.ext = try LedgerKeyLicenseExt(xdrData: &xdrData) + } + public enum LedgerKeyLicenseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -1609,9 +2114,19 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct LedgerKeyPoll: XDREncodable { + public struct LedgerKeyPoll: XDRCodable { public var id: Uint64 public var ext: EmptyExt @@ -1632,8 +2147,13 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct LedgerKeyVote: XDREncodable { + public struct LedgerKeyVote: XDRCodable { public var pollID: Uint64 public var voterID: AccountID public var ext: EmptyExt @@ -1658,8 +2178,41 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.voterID = try AccountID(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } + public struct LedgerKeyAccountSpecificRule: XDRCodable { + public var id: Uint64 + public var ext: EmptyExt + + public init( + id: Uint64, + ext: EmptyExt) { + + self.id = id + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.id.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct LedgerKeyAccountSpecificRule: XDREncodable { + public struct LedgerKeySwap: XDRCodable { public var id: Uint64 public var ext: EmptyExt @@ -1680,5 +2233,10 @@ public enum LedgerKey: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerSCPMessages.swift b/Sources/TokenDWallet/Xdr/LedgerSCPMessages.swift index 7029974..46ae76d 100644 --- a/Sources/TokenDWallet/Xdr/LedgerSCPMessages.swift +++ b/Sources/TokenDWallet/Xdr/LedgerSCPMessages.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct LedgerSCPMessages: XDREncodable { +public struct LedgerSCPMessages: XDRCodable { public var ledgerSeq: Uint32 public var messages: [SCPEnvelope] @@ -32,4 +32,13 @@ public struct LedgerSCPMessages: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.ledgerSeq = try Uint32(xdrData: &xdrData) + let lengthmessages = try Int32(xdrData: &xdrData) + self.messages = [SCPEnvelope]() + for _ in 1...lengthmessages { + self.messages.append(try SCPEnvelope(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerUpgrade.swift b/Sources/TokenDWallet/Xdr/LedgerUpgrade.swift index 10a9f45..27df105 100644 --- a/Sources/TokenDWallet/Xdr/LedgerUpgrade.swift +++ b/Sources/TokenDWallet/Xdr/LedgerUpgrade.swift @@ -42,4 +42,22 @@ public enum LedgerUpgrade: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerUpgradeType.version.rawValue: + let data = try Uint32(xdrData: &xdrData) + self = .version(data) + case LedgerUpgradeType.maxTxSetSize.rawValue: + let data = try Uint32(xdrData: &xdrData) + self = .maxTxSetSize(data) + case LedgerUpgradeType.txExpirationPeriod.rawValue: + let data = try Int64(xdrData: &xdrData) + self = .txExpirationPeriod(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/LedgerVersion.swift b/Sources/TokenDWallet/Xdr/LedgerVersion.swift index 365f752..b99055a 100644 --- a/Sources/TokenDWallet/Xdr/LedgerVersion.swift +++ b/Sources/TokenDWallet/Xdr/LedgerVersion.swift @@ -26,7 +26,15 @@ import Foundation // ADD_ACC_SPECIFIC_RULE_RESOURCE = 16, // FIX_SIGNER_CHANGES_REMOVE = 17, // FIX_DEPOSIT_STATS = 18, -// FIX_CREATE_KYC_RECOVERY_PERMISSIONS = 19 +// FIX_CREATE_KYC_RECOVERY_PERMISSIONS = 19, +// CLEAR_DATABASE_CACHE = 20, +// FIX_ISSUANCE_REVIEWER = 21, +// MARK_ASSET_AS_DELETED = 22, +// FIX_MAX_SUBJECT_SIZE = 23, +// FIX_MOVEMENT_REVIEW = 24, +// FIX_SIGNATURE_CHECK = 25, +// FIX_AUTOREVIEW = 26, +// MOVEMENT_REQUESTS_DETAILS = 27 // }; // =========================================================================== @@ -51,4 +59,12 @@ public enum LedgerVersion: Int32, XDREnum { case fixSignerChangesRemove = 17 case fixDepositStats = 18 case fixCreateKycRecoveryPermissions = 19 + case clearDatabaseCache = 20 + case fixIssuanceReviewer = 21 + case markAssetAsDeleted = 22 + case fixMaxSubjectSize = 23 + case fixMovementReview = 24 + case fixSignatureCheck = 25 + case fixAutoreview = 26 + case movementRequestsDetails = 27 } diff --git a/Sources/TokenDWallet/Xdr/LicenseEntry.swift b/Sources/TokenDWallet/Xdr/LicenseEntry.swift index 3a87183..286c38f 100644 --- a/Sources/TokenDWallet/Xdr/LicenseEntry.swift +++ b/Sources/TokenDWallet/Xdr/LicenseEntry.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct LicenseEntry: XDREncodable { +public struct LicenseEntry: XDRCodable { public var adminCount: Uint64 public var dueDate: Uint64 public var ledgerHash: Hash @@ -60,6 +60,19 @@ public struct LicenseEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.adminCount = try Uint64(xdrData: &xdrData) + self.dueDate = try Uint64(xdrData: &xdrData) + self.ledgerHash = try Hash(xdrData: &xdrData) + self.prevLicenseHash = try Hash(xdrData: &xdrData) + let lengthsignatures = try Int32(xdrData: &xdrData) + self.signatures = [DecoratedSignature]() + for _ in 1...lengthsignatures { + self.signatures.append(try DecoratedSignature(xdrData: &xdrData)) + } + self.ext = try LicenseEntryExt(xdrData: &xdrData) + } + public enum LicenseEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -81,5 +94,15 @@ public struct LicenseEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LicenseOp.swift b/Sources/TokenDWallet/Xdr/LicenseOp.swift index d0534d7..78c75c1 100644 --- a/Sources/TokenDWallet/Xdr/LicenseOp.swift +++ b/Sources/TokenDWallet/Xdr/LicenseOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct LicenseOp: XDREncodable { +public struct LicenseOp: XDRCodable { public var adminCount: Uint64 public var dueDate: Uint64 public var ledgerHash: Hash @@ -66,6 +66,19 @@ public struct LicenseOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.adminCount = try Uint64(xdrData: &xdrData) + self.dueDate = try Uint64(xdrData: &xdrData) + self.ledgerHash = try Hash(xdrData: &xdrData) + self.prevLicenseHash = try Hash(xdrData: &xdrData) + let lengthsignatures = try Int32(xdrData: &xdrData) + self.signatures = [DecoratedSignature]() + for _ in 1...lengthsignatures { + self.signatures.append(try DecoratedSignature(xdrData: &xdrData)) + } + self.ext = try LicenseOpExt(xdrData: &xdrData) + } + public enum LicenseOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -87,5 +100,15 @@ public struct LicenseOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LicenseResult.swift b/Sources/TokenDWallet/Xdr/LicenseResult.swift index 2db5f90..13bb264 100644 --- a/Sources/TokenDWallet/Xdr/LicenseResult.swift +++ b/Sources/TokenDWallet/Xdr/LicenseResult.swift @@ -35,4 +35,16 @@ public enum LicenseResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LicenseResultCode.success.rawValue: + let data = try LicenseSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/LicenseResultCode.swift b/Sources/TokenDWallet/Xdr/LicenseResultCode.swift index 4992516..75138f2 100644 --- a/Sources/TokenDWallet/Xdr/LicenseResultCode.swift +++ b/Sources/TokenDWallet/Xdr/LicenseResultCode.swift @@ -17,7 +17,8 @@ import Foundation // //: Provided due date is in the past. // INVALID_DUE_DATE = -2, // //: Not enough valid signatures to submit a license (at least one valid signature is required) -// INVALID_SIGNATURE = -3 +// INVALID_SIGNATURE = -3, +// EXTRA_SIGNATURES = -4 // }; // =========================================================================== @@ -26,4 +27,5 @@ public enum LicenseResultCode: Int32, XDREnum { case invalidStamp = -1 case invalidDueDate = -2 case invalidSignature = -3 + case extraSignatures = -4 } diff --git a/Sources/TokenDWallet/Xdr/LicenseSuccess.swift b/Sources/TokenDWallet/Xdr/LicenseSuccess.swift index cef30c8..88cbb03 100644 --- a/Sources/TokenDWallet/Xdr/LicenseSuccess.swift +++ b/Sources/TokenDWallet/Xdr/LicenseSuccess.swift @@ -17,7 +17,7 @@ import Foundation // }; // =========================================================================== -public struct LicenseSuccess: XDREncodable { +public struct LicenseSuccess: XDRCodable { public var ext: LicenseSuccessExt public init( @@ -34,6 +34,10 @@ public struct LicenseSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try LicenseSuccessExt(xdrData: &xdrData) + } + public enum LicenseSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -55,5 +59,15 @@ public struct LicenseSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/Limits.swift b/Sources/TokenDWallet/Xdr/Limits.swift index 6a4cb6f..a115306 100644 --- a/Sources/TokenDWallet/Xdr/Limits.swift +++ b/Sources/TokenDWallet/Xdr/Limits.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct Limits: XDREncodable { +public struct Limits: XDRCodable { public var dailyOut: Int64 public var weeklyOut: Int64 public var monthlyOut: Int64 @@ -55,6 +55,14 @@ public struct Limits: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.dailyOut = try Int64(xdrData: &xdrData) + self.weeklyOut = try Int64(xdrData: &xdrData) + self.monthlyOut = try Int64(xdrData: &xdrData) + self.annualOut = try Int64(xdrData: &xdrData) + self.ext = try LimitsExt(xdrData: &xdrData) + } + public enum LimitsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -76,5 +84,15 @@ public struct Limits: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LimitsCreateDetails.swift b/Sources/TokenDWallet/Xdr/LimitsCreateDetails.swift index a904e60..39b4ba9 100644 --- a/Sources/TokenDWallet/Xdr/LimitsCreateDetails.swift +++ b/Sources/TokenDWallet/Xdr/LimitsCreateDetails.swift @@ -42,7 +42,7 @@ import Foundation // }; // =========================================================================== -public struct LimitsCreateDetails: XDREncodable { +public struct LimitsCreateDetails: XDRCodable { public var accountRole: Uint64? public var accountID: AccountID? public var statsOpType: StatsOpType @@ -95,6 +95,27 @@ public struct LimitsCreateDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + if (try Bool(xdrData: &xdrData)) { + self.accountRole = try Uint64(xdrData: &xdrData) + } else { + self.accountRole = nil + } + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.statsOpType = try StatsOpType(xdrData: &xdrData) + self.assetCode = try AssetCode(xdrData: &xdrData) + self.isConvertNeeded = try Bool(xdrData: &xdrData) + self.dailyOut = try Uint64(xdrData: &xdrData) + self.weeklyOut = try Uint64(xdrData: &xdrData) + self.monthlyOut = try Uint64(xdrData: &xdrData) + self.annualOut = try Uint64(xdrData: &xdrData) + self.ext = try LimitsCreateDetailsExt(xdrData: &xdrData) + } + public enum LimitsCreateDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -116,5 +137,15 @@ public struct LimitsCreateDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LimitsUpdateDetails.swift b/Sources/TokenDWallet/Xdr/LimitsUpdateDetails.swift index 172d77d..28e4477 100644 --- a/Sources/TokenDWallet/Xdr/LimitsUpdateDetails.swift +++ b/Sources/TokenDWallet/Xdr/LimitsUpdateDetails.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct LimitsUpdateDetails: XDREncodable { +public struct LimitsUpdateDetails: XDRCodable { public var newLimitsV2: LimitsV2Entry public var ext: LimitsUpdateDetailsExt @@ -41,6 +41,11 @@ public struct LimitsUpdateDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.newLimitsV2 = try LimitsV2Entry(xdrData: &xdrData) + self.ext = try LimitsUpdateDetailsExt(xdrData: &xdrData) + } + public enum LimitsUpdateDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct LimitsUpdateDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LimitsUpdateRequest.swift b/Sources/TokenDWallet/Xdr/LimitsUpdateRequest.swift index 4e32cca..560aa6f 100644 --- a/Sources/TokenDWallet/Xdr/LimitsUpdateRequest.swift +++ b/Sources/TokenDWallet/Xdr/LimitsUpdateRequest.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct LimitsUpdateRequest: XDREncodable { +public struct LimitsUpdateRequest: XDRCodable { public var creatorDetails: Longstring public var ext: LimitsUpdateRequestExt @@ -42,6 +42,11 @@ public struct LimitsUpdateRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try LimitsUpdateRequestExt(xdrData: &xdrData) + } + public enum LimitsUpdateRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct LimitsUpdateRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/LimitsV2Entry.swift b/Sources/TokenDWallet/Xdr/LimitsV2Entry.swift index 2fa14e6..b242a69 100644 --- a/Sources/TokenDWallet/Xdr/LimitsV2Entry.swift +++ b/Sources/TokenDWallet/Xdr/LimitsV2Entry.swift @@ -44,7 +44,7 @@ import Foundation // }; // =========================================================================== -public struct LimitsV2Entry: XDREncodable { +public struct LimitsV2Entry: XDRCodable { public var id: Uint64 public var accountRole: Uint64? public var accountID: AccountID? @@ -101,6 +101,28 @@ public struct LimitsV2Entry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.accountRole = try Uint64(xdrData: &xdrData) + } else { + self.accountRole = nil + } + if (try Bool(xdrData: &xdrData)) { + self.accountID = try AccountID(xdrData: &xdrData) + } else { + self.accountID = nil + } + self.statsOpType = try StatsOpType(xdrData: &xdrData) + self.assetCode = try AssetCode(xdrData: &xdrData) + self.isConvertNeeded = try Bool(xdrData: &xdrData) + self.dailyOut = try Uint64(xdrData: &xdrData) + self.weeklyOut = try Uint64(xdrData: &xdrData) + self.monthlyOut = try Uint64(xdrData: &xdrData) + self.annualOut = try Uint64(xdrData: &xdrData) + self.ext = try LimitsV2EntryExt(xdrData: &xdrData) + } + public enum LimitsV2EntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -122,5 +144,15 @@ public struct LimitsV2Entry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountRoleOp.swift b/Sources/TokenDWallet/Xdr/ManageAccountRoleOp.swift index 7ca295c..20f6ea0 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountRoleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountRoleOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAccountRoleOp: XDREncodable { +public struct ManageAccountRoleOp: XDRCodable { public var data: ManageAccountRoleOpData public var ext: ManageAccountRoleOpExt @@ -50,6 +50,11 @@ public struct ManageAccountRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageAccountRoleOpData(xdrData: &xdrData) + self.ext = try ManageAccountRoleOpExt(xdrData: &xdrData) + } + public enum ManageAccountRoleOpData: XDRDiscriminatedUnion { case create(CreateAccountRoleData) case update(UpdateAccountRoleData) @@ -77,6 +82,24 @@ public struct ManageAccountRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountRoleAction.create.rawValue: + let data = try CreateAccountRoleData(xdrData: &xdrData) + self = .create(data) + case ManageAccountRoleAction.update.rawValue: + let data = try UpdateAccountRoleData(xdrData: &xdrData) + self = .update(data) + case ManageAccountRoleAction.remove.rawValue: + let data = try RemoveAccountRoleData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageAccountRoleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -99,5 +122,15 @@ public struct ManageAccountRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountRoleResult.swift b/Sources/TokenDWallet/Xdr/ManageAccountRoleResult.swift index d70e56e..e0e51fe 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountRoleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountRoleResult.swift @@ -57,7 +57,25 @@ public enum ManageAccountRoleResult: XDRDiscriminatedUnion { return xdr } - public struct ManageAccountRoleResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountRoleResultCode.success.rawValue: + let data = try ManageAccountRoleResultSuccess(xdrData: &xdrData) + self = .success(data) + case ManageAccountRoleResultCode.ruleIdDuplication.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .ruleIdDuplication(data) + case ManageAccountRoleResultCode.noSuchRule.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .noSuchRule(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageAccountRoleResultSuccess: XDRCodable { public var roleID: Uint64 public var ext: ManageAccountRoleResultSuccessExt @@ -78,6 +96,11 @@ public enum ManageAccountRoleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try ManageAccountRoleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageAccountRoleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -99,6 +122,16 @@ public enum ManageAccountRoleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountRuleOp.swift b/Sources/TokenDWallet/Xdr/ManageAccountRuleOp.swift index 28cea26..f92e967 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountRuleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountRuleOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAccountRuleOp: XDREncodable { +public struct ManageAccountRuleOp: XDRCodable { public var data: ManageAccountRuleOpData public var ext: ManageAccountRuleOpExt @@ -50,6 +50,11 @@ public struct ManageAccountRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageAccountRuleOpData(xdrData: &xdrData) + self.ext = try ManageAccountRuleOpExt(xdrData: &xdrData) + } + public enum ManageAccountRuleOpData: XDRDiscriminatedUnion { case create(CreateAccountRuleData) case update(UpdateAccountRuleData) @@ -77,6 +82,24 @@ public struct ManageAccountRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountRuleAction.create.rawValue: + let data = try CreateAccountRuleData(xdrData: &xdrData) + self = .create(data) + case ManageAccountRuleAction.update.rawValue: + let data = try UpdateAccountRuleData(xdrData: &xdrData) + self = .update(data) + case ManageAccountRuleAction.remove.rawValue: + let data = try RemoveAccountRuleData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageAccountRuleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -99,5 +122,15 @@ public struct ManageAccountRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountRuleResult.swift b/Sources/TokenDWallet/Xdr/ManageAccountRuleResult.swift index dc194cc..2c094e8 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountRuleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountRuleResult.swift @@ -53,7 +53,26 @@ public enum ManageAccountRuleResult: XDRDiscriminatedUnion { return xdr } - public struct ManageAccountRuleResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountRuleResultCode.success.rawValue: + let data = try ManageAccountRuleResultSuccess(xdrData: &xdrData) + self = .success(data) + case ManageAccountRuleResultCode.ruleIsUsed.rawValue: + let lengthroleIDs = try Int32(xdrData: &xdrData) + var data = [Uint64]() + for _ in 1...lengthroleIDs { + data.append(try Uint64(xdrData: &xdrData)) + } + self = .ruleIsUsed(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageAccountRuleResultSuccess: XDRCodable { public var ruleID: Uint64 public var ext: ManageAccountRuleResultSuccessExt @@ -74,6 +93,11 @@ public enum ManageAccountRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try ManageAccountRuleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageAccountRuleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -95,6 +119,16 @@ public enum ManageAccountRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleOp.swift b/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleOp.swift index d385bc2..28c06dc 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAccountSpecificRuleOp: XDREncodable { +public struct ManageAccountSpecificRuleOp: XDRCodable { public var data: ManageAccountSpecificRuleOpData public var ext: ManageAccountSpecificRuleOpExt @@ -48,6 +48,11 @@ public struct ManageAccountSpecificRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageAccountSpecificRuleOpData(xdrData: &xdrData) + self.ext = try ManageAccountSpecificRuleOpExt(xdrData: &xdrData) + } + public enum ManageAccountSpecificRuleOpData: XDRDiscriminatedUnion { case create(CreateAccountSpecificRuleData) case remove(RemoveAccountSpecificRuleData) @@ -72,6 +77,21 @@ public struct ManageAccountSpecificRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountSpecificRuleAction.create.rawValue: + let data = try CreateAccountSpecificRuleData(xdrData: &xdrData) + self = .create(data) + case ManageAccountSpecificRuleAction.remove.rawValue: + let data = try RemoveAccountSpecificRuleData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageAccountSpecificRuleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,5 +114,15 @@ public struct ManageAccountSpecificRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleResult.swift b/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleResult.swift index 70e500e..6b283eb 100644 --- a/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageAccountSpecificRuleResult.swift @@ -47,7 +47,19 @@ public enum ManageAccountSpecificRuleResult: XDRDiscriminatedUnion { return xdr } - public struct ManageAccountSpecificRuleResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAccountSpecificRuleResultCode.success.rawValue: + let data = try ManageAccountSpecificRuleResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageAccountSpecificRuleResultSuccess: XDRCodable { public var ruleID: Uint64 public var ext: ManageAccountSpecificRuleResultSuccessExt @@ -68,6 +80,11 @@ public enum ManageAccountSpecificRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try ManageAccountSpecificRuleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageAccountSpecificRuleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -89,6 +106,16 @@ public enum ManageAccountSpecificRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetOp.swift b/Sources/TokenDWallet/Xdr/ManageAssetOp.swift index f3064e1..69f6f0e 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetOp.swift @@ -77,7 +77,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAssetOp: XDREncodable { +public struct ManageAssetOp: XDRCodable { public var requestID: Uint64 public var request: ManageAssetOpRequest public var ext: ManageAssetOpExt @@ -102,6 +102,12 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.request = try ManageAssetOpRequest(xdrData: &xdrData) + self.ext = try ManageAssetOpExt(xdrData: &xdrData) + } + public enum ManageAssetOpRequest: XDRDiscriminatedUnion { case createAssetCreationRequest(ManageAssetOpCreateAssetCreationRequest) case createAssetUpdateRequest(ManageAssetOpCreateAssetUpdateRequest) @@ -135,7 +141,31 @@ public struct ManageAssetOp: XDREncodable { return xdr } - public struct ManageAssetOpCreateAssetCreationRequest: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAssetAction.createAssetCreationRequest.rawValue: + let data = try ManageAssetOpCreateAssetCreationRequest(xdrData: &xdrData) + self = .createAssetCreationRequest(data) + case ManageAssetAction.createAssetUpdateRequest.rawValue: + let data = try ManageAssetOpCreateAssetUpdateRequest(xdrData: &xdrData) + self = .createAssetUpdateRequest(data) + case ManageAssetAction.cancelAssetRequest.rawValue: + let data = try CancelAssetRequest(xdrData: &xdrData) + self = .cancelAssetRequest(data) + case ManageAssetAction.changePreissuedAssetSigner.rawValue: + let data = try AssetChangePreissuedSigner(xdrData: &xdrData) + self = .changePreissuedAssetSigner(data) + case ManageAssetAction.updateMaxIssuance.rawValue: + let data = try UpdateMaxIssuance(xdrData: &xdrData) + self = .updateMaxIssuance(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct ManageAssetOpCreateAssetCreationRequest: XDRCodable { public var createAsset: AssetCreationRequest public var allTasks: Uint32? public var ext: ManageAssetOpCreateAssetCreationRequestExt @@ -160,6 +190,16 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.createAsset = try AssetCreationRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try ManageAssetOpCreateAssetCreationRequestExt(xdrData: &xdrData) + } + public enum ManageAssetOpCreateAssetCreationRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -181,9 +221,19 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct ManageAssetOpCreateAssetUpdateRequest: XDREncodable { + public struct ManageAssetOpCreateAssetUpdateRequest: XDRCodable { public var updateAsset: AssetUpdateRequest public var allTasks: Uint32? public var ext: ManageAssetOpCreateAssetUpdateRequestExt @@ -208,6 +258,16 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.updateAsset = try AssetUpdateRequest(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try ManageAssetOpCreateAssetUpdateRequestExt(xdrData: &xdrData) + } + public enum ManageAssetOpCreateAssetUpdateRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -229,6 +289,16 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } @@ -253,5 +323,15 @@ public struct ManageAssetOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetPairOp.swift b/Sources/TokenDWallet/Xdr/ManageAssetPairOp.swift index 8394df8..fc3d345 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetPairOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetPairOp.swift @@ -36,7 +36,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAssetPairOp: XDREncodable { +public struct ManageAssetPairOp: XDRCodable { public var action: ManageAssetPairAction public var base: AssetCode public var quote: AssetCode @@ -81,6 +81,17 @@ public struct ManageAssetPairOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.action = try ManageAssetPairAction(xdrData: &xdrData) + self.base = try AssetCode(xdrData: &xdrData) + self.quote = try AssetCode(xdrData: &xdrData) + self.physicalPrice = try Int64(xdrData: &xdrData) + self.physicalPriceCorrection = try Int64(xdrData: &xdrData) + self.maxPriceStep = try Int64(xdrData: &xdrData) + self.policies = try Int32(xdrData: &xdrData) + self.ext = try ManageAssetPairOpExt(xdrData: &xdrData) + } + public enum ManageAssetPairOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -102,5 +113,15 @@ public struct ManageAssetPairOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetPairResult.swift b/Sources/TokenDWallet/Xdr/ManageAssetPairResult.swift index adb7bc9..2e3169f 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetPairResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetPairResult.swift @@ -35,4 +35,16 @@ public enum ManageAssetPairResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAssetPairResultCode.success.rawValue: + let data = try ManageAssetPairSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetPairSuccess.swift b/Sources/TokenDWallet/Xdr/ManageAssetPairSuccess.swift index 9eb442c..98edd02 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetPairSuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetPairSuccess.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAssetPairSuccess: XDREncodable { +public struct ManageAssetPairSuccess: XDRCodable { public var currentPrice: Int64 public var ext: ManageAssetPairSuccessExt @@ -41,6 +41,11 @@ public struct ManageAssetPairSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.currentPrice = try Int64(xdrData: &xdrData) + self.ext = try ManageAssetPairSuccessExt(xdrData: &xdrData) + } + public enum ManageAssetPairSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct ManageAssetPairSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetResult.swift b/Sources/TokenDWallet/Xdr/ManageAssetResult.swift index 67ec4ae..33e65ed 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetResult.swift @@ -36,4 +36,16 @@ public enum ManageAssetResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageAssetResultCode.success.rawValue: + let data = try ManageAssetSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageAssetSuccess.swift b/Sources/TokenDWallet/Xdr/ManageAssetSuccess.swift index dfd3709..e24d0d6 100644 --- a/Sources/TokenDWallet/Xdr/ManageAssetSuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageAssetSuccess.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct ManageAssetSuccess: XDREncodable { +public struct ManageAssetSuccess: XDRCodable { public var requestID: Uint64 public var fulfilled: Bool public var ext: ManageAssetSuccessExt @@ -47,6 +47,12 @@ public struct ManageAssetSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.ext = try ManageAssetSuccessExt(xdrData: &xdrData) + } + public enum ManageAssetSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +74,15 @@ public struct ManageAssetSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageBalanceOp.swift b/Sources/TokenDWallet/Xdr/ManageBalanceOp.swift index 6c9dc19..b09d0ed 100644 --- a/Sources/TokenDWallet/Xdr/ManageBalanceOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageBalanceOp.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct ManageBalanceOp: XDREncodable { +public struct ManageBalanceOp: XDRCodable { public var action: ManageBalanceAction public var destination: AccountID public var asset: AssetCode @@ -53,6 +53,13 @@ public struct ManageBalanceOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.action = try ManageBalanceAction(xdrData: &xdrData) + self.destination = try AccountID(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.ext = try ManageBalanceOpExt(xdrData: &xdrData) + } + public enum ManageBalanceOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +81,15 @@ public struct ManageBalanceOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageBalanceResult.swift b/Sources/TokenDWallet/Xdr/ManageBalanceResult.swift index 1094d3b..64a85c2 100644 --- a/Sources/TokenDWallet/Xdr/ManageBalanceResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageBalanceResult.swift @@ -34,4 +34,16 @@ public enum ManageBalanceResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageBalanceResultCode.success.rawValue: + let data = try ManageBalanceSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageBalanceSuccess.swift b/Sources/TokenDWallet/Xdr/ManageBalanceSuccess.swift index 25f913f..92029e2 100644 --- a/Sources/TokenDWallet/Xdr/ManageBalanceSuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageBalanceSuccess.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct ManageBalanceSuccess: XDREncodable { +public struct ManageBalanceSuccess: XDRCodable { public var balanceID: BalanceID public var ext: ManageBalanceSuccessExt @@ -39,6 +39,11 @@ public struct ManageBalanceSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.balanceID = try BalanceID(xdrData: &xdrData) + self.ext = try ManageBalanceSuccessExt(xdrData: &xdrData) + } + public enum ManageBalanceSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -60,5 +65,15 @@ public struct ManageBalanceSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageContractOp.swift b/Sources/TokenDWallet/Xdr/ManageContractOp.swift index 98dc5d3..51ec874 100644 --- a/Sources/TokenDWallet/Xdr/ManageContractOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageContractOp.swift @@ -32,7 +32,7 @@ import Foundation // }; // =========================================================================== -public struct ManageContractOp: XDREncodable { +public struct ManageContractOp: XDRCodable { public var contractID: Uint64 public var data: ManageContractOpData public var ext: ManageContractOpExt @@ -57,6 +57,12 @@ public struct ManageContractOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.contractID = try Uint64(xdrData: &xdrData) + self.data = try ManageContractOpData(xdrData: &xdrData) + self.ext = try ManageContractOpExt(xdrData: &xdrData) + } + public enum ManageContractOpData: XDRDiscriminatedUnion { case addDetails(Longstring) case confirmCompleted() @@ -87,6 +93,25 @@ public struct ManageContractOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractAction.addDetails.rawValue: + let data = try Longstring(xdrData: &xdrData) + self = .addDetails(data) + case ManageContractAction.confirmCompleted.rawValue: self = .confirmCompleted() + case ManageContractAction.startDispute.rawValue: + let data = try Longstring(xdrData: &xdrData) + self = .startDispute(data) + case ManageContractAction.resolveDispute.rawValue: + let data = try Bool(xdrData: &xdrData) + self = .resolveDispute(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageContractOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -109,5 +134,15 @@ public struct ManageContractOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageContractRequestOp.swift b/Sources/TokenDWallet/Xdr/ManageContractRequestOp.swift index fce3ab7..35c3e05 100644 --- a/Sources/TokenDWallet/Xdr/ManageContractRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageContractRequestOp.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct ManageContractRequestOp: XDREncodable { +public struct ManageContractRequestOp: XDRCodable { public var details: ManageContractRequestOpDetails public var ext: ManageContractRequestOpExt @@ -45,6 +45,11 @@ public struct ManageContractRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageContractRequestOpDetails(xdrData: &xdrData) + self.ext = try ManageContractRequestOpExt(xdrData: &xdrData) + } + public enum ManageContractRequestOpDetails: XDRDiscriminatedUnion { case create(CreateContractRequest) case remove(Uint64) @@ -69,6 +74,21 @@ public struct ManageContractRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractRequestAction.create.rawValue: + let data = try CreateContractRequest(xdrData: &xdrData) + self = .create(data) + case ManageContractRequestAction.remove.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageContractRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -91,5 +111,15 @@ public struct ManageContractRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageContractRequestResult.swift b/Sources/TokenDWallet/Xdr/ManageContractRequestResult.swift index b4e1832..7a5bcdc 100644 --- a/Sources/TokenDWallet/Xdr/ManageContractRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageContractRequestResult.swift @@ -50,7 +50,19 @@ public enum ManageContractRequestResult: XDRDiscriminatedUnion { return xdr } - public struct ManageContractRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractRequestResultCode.success.rawValue: + let data = try ManageContractRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageContractRequestResultSuccess: XDRCodable { public var details: ManageContractRequestResultSuccessDetails public var ext: ManageContractRequestResultSuccessExt @@ -71,6 +83,11 @@ public enum ManageContractRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageContractRequestResultSuccessDetails(xdrData: &xdrData) + self.ext = try ManageContractRequestResultSuccessExt(xdrData: &xdrData) + } + public enum ManageContractRequestResultSuccessDetails: XDRDiscriminatedUnion { case create(CreateContractRequestResponse) case remove() @@ -95,6 +112,19 @@ public enum ManageContractRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractRequestAction.create.rawValue: + let data = try CreateContractRequestResponse(xdrData: &xdrData) + self = .create(data) + case ManageContractRequestAction.remove.rawValue: self = .remove() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageContractRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -117,6 +147,16 @@ public enum ManageContractRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageContractResponse.swift b/Sources/TokenDWallet/Xdr/ManageContractResponse.swift index 1059f8d..0673501 100644 --- a/Sources/TokenDWallet/Xdr/ManageContractResponse.swift +++ b/Sources/TokenDWallet/Xdr/ManageContractResponse.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct ManageContractResponse: XDREncodable { +public struct ManageContractResponse: XDRCodable { public var data: ManageContractResponseData public var ext: ManageContractResponseExt @@ -47,6 +47,11 @@ public struct ManageContractResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageContractResponseData(xdrData: &xdrData) + self.ext = try ManageContractResponseExt(xdrData: &xdrData) + } + public enum ManageContractResponseData: XDRDiscriminatedUnion { case confirmCompleted(Bool) @@ -68,6 +73,18 @@ public struct ManageContractResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractAction.confirmCompleted.rawValue: + let data = try Bool(xdrData: &xdrData) + self = .confirmCompleted(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageContractResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -90,5 +107,15 @@ public struct ManageContractResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageContractResult.swift b/Sources/TokenDWallet/Xdr/ManageContractResult.swift index 85c3f4e..9227d8c 100644 --- a/Sources/TokenDWallet/Xdr/ManageContractResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageContractResult.swift @@ -34,4 +34,16 @@ public enum ManageContractResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageContractResultCode.success.rawValue: + let data = try ManageContractResponse(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestOp.swift b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestOp.swift index 2a5983b..54d0e5c 100644 --- a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestOp.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct ManageCreatePollRequestOp: XDREncodable { +public struct ManageCreatePollRequestOp: XDRCodable { public var data: ManageCreatePollRequestOpData public var ext: ManageCreatePollRequestOpExt @@ -49,6 +49,11 @@ public struct ManageCreatePollRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageCreatePollRequestOpData(xdrData: &xdrData) + self.ext = try ManageCreatePollRequestOpExt(xdrData: &xdrData) + } + public enum ManageCreatePollRequestOpData: XDRDiscriminatedUnion { case create(CreatePollRequestData) case cancel(CancelPollRequestData) @@ -73,6 +78,21 @@ public struct ManageCreatePollRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageCreatePollRequestAction.create.rawValue: + let data = try CreatePollRequestData(xdrData: &xdrData) + self = .create(data) + case ManageCreatePollRequestAction.cancel.rawValue: + let data = try CancelPollRequestData(xdrData: &xdrData) + self = .cancel(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageCreatePollRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -95,5 +115,15 @@ public struct ManageCreatePollRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestResult.swift b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestResult.swift index 9b796fd..2b85abe 100644 --- a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestResult.swift @@ -35,4 +35,16 @@ public enum ManageCreatePollRequestResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageCreatePollRequestResultCode.success.rawValue: + let data = try ManageCreatePollRequestSuccessResult(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestSuccessResult.swift b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestSuccessResult.swift index 292e90b..4e2acc0 100644 --- a/Sources/TokenDWallet/Xdr/ManageCreatePollRequestSuccessResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageCreatePollRequestSuccessResult.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ManageCreatePollRequestSuccessResult: XDREncodable { +public struct ManageCreatePollRequestSuccessResult: XDRCodable { public var details: ManageCreatePollRequestSuccessResultDetails public var ext: ManageCreatePollRequestSuccessResultExt @@ -48,6 +48,11 @@ public struct ManageCreatePollRequestSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageCreatePollRequestSuccessResultDetails(xdrData: &xdrData) + self.ext = try ManageCreatePollRequestSuccessResultExt(xdrData: &xdrData) + } + public enum ManageCreatePollRequestSuccessResultDetails: XDRDiscriminatedUnion { case create(CreatePollRequestResponse) case cancel() @@ -72,6 +77,19 @@ public struct ManageCreatePollRequestSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageCreatePollRequestAction.create.rawValue: + let data = try CreatePollRequestResponse(xdrData: &xdrData) + self = .create(data) + case ManageCreatePollRequestAction.cancel.rawValue: self = .cancel() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageCreatePollRequestSuccessResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,5 +112,15 @@ public struct ManageCreatePollRequestSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryOp.swift b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryOp.swift index f51cbb6..f5d43c2 100644 --- a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageExternalSystemAccountIdPoolEntryOp: XDREncodable { +public struct ManageExternalSystemAccountIdPoolEntryOp: XDRCodable { public var actionInput: ManageExternalSystemAccountIdPoolEntryOpActionInput public var ext: ManageExternalSystemAccountIdPoolEntryOpExt @@ -50,6 +50,11 @@ public struct ManageExternalSystemAccountIdPoolEntryOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.actionInput = try ManageExternalSystemAccountIdPoolEntryOpActionInput(xdrData: &xdrData) + self.ext = try ManageExternalSystemAccountIdPoolEntryOpExt(xdrData: &xdrData) + } + public enum ManageExternalSystemAccountIdPoolEntryOpActionInput: XDRDiscriminatedUnion { case create(CreateExternalSystemAccountIdPoolEntryActionInput) case remove(DeleteExternalSystemAccountIdPoolEntryActionInput) @@ -74,6 +79,21 @@ public struct ManageExternalSystemAccountIdPoolEntryOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageExternalSystemAccountIdPoolEntryAction.create.rawValue: + let data = try CreateExternalSystemAccountIdPoolEntryActionInput(xdrData: &xdrData) + self = .create(data) + case ManageExternalSystemAccountIdPoolEntryAction.remove.rawValue: + let data = try DeleteExternalSystemAccountIdPoolEntryActionInput(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageExternalSystemAccountIdPoolEntryOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -96,5 +116,15 @@ public struct ManageExternalSystemAccountIdPoolEntryOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryResult.swift b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryResult.swift index 64b8bf5..e885cb2 100644 --- a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntryResult.swift @@ -35,4 +35,16 @@ public enum ManageExternalSystemAccountIdPoolEntryResult: XDRDiscriminatedUnion return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageExternalSystemAccountIdPoolEntryResultCode.success.rawValue: + let data = try ManageExternalSystemAccountIdPoolEntrySuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntrySuccess.swift b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntrySuccess.swift index b3343c0..bb372b9 100644 --- a/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntrySuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageExternalSystemAccountIdPoolEntrySuccess.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct ManageExternalSystemAccountIdPoolEntrySuccess: XDREncodable { +public struct ManageExternalSystemAccountIdPoolEntrySuccess: XDRCodable { public var poolEntryID: Uint64 public var ext: ManageExternalSystemAccountIdPoolEntrySuccessExt @@ -42,6 +42,11 @@ public struct ManageExternalSystemAccountIdPoolEntrySuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.poolEntryID = try Uint64(xdrData: &xdrData) + self.ext = try ManageExternalSystemAccountIdPoolEntrySuccessExt(xdrData: &xdrData) + } + public enum ManageExternalSystemAccountIdPoolEntrySuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -63,5 +68,15 @@ public struct ManageExternalSystemAccountIdPoolEntrySuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageInvoiceRequestOp.swift b/Sources/TokenDWallet/Xdr/ManageInvoiceRequestOp.swift index d45b279..d8e3c14 100644 --- a/Sources/TokenDWallet/Xdr/ManageInvoiceRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageInvoiceRequestOp.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct ManageInvoiceRequestOp: XDREncodable { +public struct ManageInvoiceRequestOp: XDRCodable { public var details: ManageInvoiceRequestOpDetails public var ext: ManageInvoiceRequestOpExt @@ -45,6 +45,11 @@ public struct ManageInvoiceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageInvoiceRequestOpDetails(xdrData: &xdrData) + self.ext = try ManageInvoiceRequestOpExt(xdrData: &xdrData) + } + public enum ManageInvoiceRequestOpDetails: XDRDiscriminatedUnion { case create(InvoiceCreationRequest) case remove(Uint64) @@ -69,6 +74,21 @@ public struct ManageInvoiceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageInvoiceRequestAction.create.rawValue: + let data = try InvoiceCreationRequest(xdrData: &xdrData) + self = .create(data) + case ManageInvoiceRequestAction.remove.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageInvoiceRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -91,5 +111,15 @@ public struct ManageInvoiceRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageInvoiceRequestResult.swift b/Sources/TokenDWallet/Xdr/ManageInvoiceRequestResult.swift index 2987ab3..ba9da58 100644 --- a/Sources/TokenDWallet/Xdr/ManageInvoiceRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageInvoiceRequestResult.swift @@ -51,7 +51,19 @@ public enum ManageInvoiceRequestResult: XDRDiscriminatedUnion { return xdr } - public struct ManageInvoiceRequestResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageInvoiceRequestResultCode.success.rawValue: + let data = try ManageInvoiceRequestResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageInvoiceRequestResultSuccess: XDRCodable { public var fulfilled: Bool public var details: ManageInvoiceRequestResultSuccessDetails public var ext: ManageInvoiceRequestResultSuccessExt @@ -76,6 +88,12 @@ public enum ManageInvoiceRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.fulfilled = try Bool(xdrData: &xdrData) + self.details = try ManageInvoiceRequestResultSuccessDetails(xdrData: &xdrData) + self.ext = try ManageInvoiceRequestResultSuccessExt(xdrData: &xdrData) + } + public enum ManageInvoiceRequestResultSuccessDetails: XDRDiscriminatedUnion { case create(CreateInvoiceRequestResponse) case remove() @@ -100,6 +118,19 @@ public enum ManageInvoiceRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageInvoiceRequestAction.create.rawValue: + let data = try CreateInvoiceRequestResponse(xdrData: &xdrData) + self = .create(data) + case ManageInvoiceRequestAction.remove.rawValue: self = .remove() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageInvoiceRequestResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -122,6 +153,16 @@ public enum ManageInvoiceRequestResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageKeyValueOp.swift b/Sources/TokenDWallet/Xdr/ManageKeyValueOp.swift index 1ad8792..09e4841 100644 --- a/Sources/TokenDWallet/Xdr/ManageKeyValueOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageKeyValueOp.swift @@ -32,7 +32,7 @@ import Foundation // }; // =========================================================================== -public struct ManageKeyValueOp: XDREncodable { +public struct ManageKeyValueOp: XDRCodable { public var key: Longstring public var action: ManageKeyValueOpAction public var ext: ManageKeyValueOpExt @@ -57,6 +57,12 @@ public struct ManageKeyValueOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.key = try Longstring(xdrData: &xdrData) + self.action = try ManageKeyValueOpAction(xdrData: &xdrData) + self.ext = try ManageKeyValueOpExt(xdrData: &xdrData) + } + public enum ManageKeyValueOpAction: XDRDiscriminatedUnion { case put(KeyValueEntryValue) case remove() @@ -81,6 +87,19 @@ public struct ManageKeyValueOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageKVAction.put.rawValue: + let data = try KeyValueEntryValue(xdrData: &xdrData) + self = .put(data) + case ManageKVAction.remove.rawValue: self = .remove() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageKeyValueOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -103,5 +122,15 @@ public struct ManageKeyValueOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageKeyValueResult.swift b/Sources/TokenDWallet/Xdr/ManageKeyValueResult.swift index 8976c51..0d17593 100644 --- a/Sources/TokenDWallet/Xdr/ManageKeyValueResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageKeyValueResult.swift @@ -35,4 +35,16 @@ public enum ManageKeyValueResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageKeyValueResultCode.success.rawValue: + let data = try ManageKeyValueSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageKeyValueSuccess.swift b/Sources/TokenDWallet/Xdr/ManageKeyValueSuccess.swift index bde2e75..ef69bed 100644 --- a/Sources/TokenDWallet/Xdr/ManageKeyValueSuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageKeyValueSuccess.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct ManageKeyValueSuccess: XDREncodable { +public struct ManageKeyValueSuccess: XDRCodable { public var ext: ManageKeyValueSuccessExt public init( @@ -35,6 +35,10 @@ public struct ManageKeyValueSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try ManageKeyValueSuccessExt(xdrData: &xdrData) + } + public enum ManageKeyValueSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct ManageKeyValueSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageLimitsOp.swift b/Sources/TokenDWallet/Xdr/ManageLimitsOp.swift index c403551..8eda8ac 100644 --- a/Sources/TokenDWallet/Xdr/ManageLimitsOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageLimitsOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ManageLimitsOp: XDREncodable { +public struct ManageLimitsOp: XDRCodable { public var details: ManageLimitsOpDetails public var ext: ManageLimitsOpExt @@ -48,6 +48,11 @@ public struct ManageLimitsOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageLimitsOpDetails(xdrData: &xdrData) + self.ext = try ManageLimitsOpExt(xdrData: &xdrData) + } + public enum ManageLimitsOpDetails: XDRDiscriminatedUnion { case create(LimitsCreateDetails) case remove(Uint64) @@ -72,6 +77,21 @@ public struct ManageLimitsOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageLimitsAction.create.rawValue: + let data = try LimitsCreateDetails(xdrData: &xdrData) + self = .create(data) + case ManageLimitsAction.remove.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageLimitsOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,5 +114,15 @@ public struct ManageLimitsOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageLimitsResult.swift b/Sources/TokenDWallet/Xdr/ManageLimitsResult.swift index 814972f..7dde3d6 100644 --- a/Sources/TokenDWallet/Xdr/ManageLimitsResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageLimitsResult.swift @@ -53,7 +53,19 @@ public enum ManageLimitsResult: XDRDiscriminatedUnion { return xdr } - public struct ManageLimitsResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageLimitsResultCode.success.rawValue: + let data = try ManageLimitsResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageLimitsResultSuccess: XDRCodable { public var details: ManageLimitsResultSuccessDetails public var ext: ManageLimitsResultSuccessExt @@ -74,6 +86,11 @@ public enum ManageLimitsResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ManageLimitsResultSuccessDetails(xdrData: &xdrData) + self.ext = try ManageLimitsResultSuccessExt(xdrData: &xdrData) + } + public enum ManageLimitsResultSuccessDetails: XDRDiscriminatedUnion { case create(Uint64) case remove() @@ -98,6 +115,19 @@ public enum ManageLimitsResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageLimitsAction.create.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .create(data) + case ManageLimitsAction.remove.rawValue: self = .remove() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageLimitsResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -120,6 +150,16 @@ public enum ManageLimitsResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageLimitsResultCode.swift b/Sources/TokenDWallet/Xdr/ManageLimitsResultCode.swift index 6108c08..00b2135 100644 --- a/Sources/TokenDWallet/Xdr/ManageLimitsResultCode.swift +++ b/Sources/TokenDWallet/Xdr/ManageLimitsResultCode.swift @@ -22,7 +22,9 @@ import Foundation // //: Limits cannot be created for account ID and account role simultaneously // CANNOT_CREATE_FOR_ACC_ID_AND_ACC_TYPE = -4, // FIXME ACC_ROLE ? // //: Limits entry is invalid (e.g. weeklyOut is less than dailyOut) -// INVALID_LIMITS = -5 +// INVALID_LIMITS = -5, +// //: Asset with provided asset code does not exist +// ASSET_NOT_FOUND = -6 // }; // =========================================================================== @@ -33,4 +35,5 @@ public enum ManageLimitsResultCode: Int32, XDREnum { case roleNotFound = -3 case cannotCreateForAccIdAndAccType = -4 case invalidLimits = -5 + case assetNotFound = -6 } diff --git a/Sources/TokenDWallet/Xdr/ManageOfferOp.swift b/Sources/TokenDWallet/Xdr/ManageOfferOp.swift index e81632a..d7b5f65 100644 --- a/Sources/TokenDWallet/Xdr/ManageOfferOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageOfferOp.swift @@ -42,7 +42,7 @@ import Foundation // }; // =========================================================================== -public struct ManageOfferOp: XDREncodable { +public struct ManageOfferOp: XDRCodable { public var baseBalance: BalanceID public var quoteBalance: BalanceID public var isBuy: Bool @@ -91,6 +91,18 @@ public struct ManageOfferOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.quoteBalance = try BalanceID(xdrData: &xdrData) + self.isBuy = try Bool(xdrData: &xdrData) + self.amount = try Int64(xdrData: &xdrData) + self.price = try Int64(xdrData: &xdrData) + self.fee = try Int64(xdrData: &xdrData) + self.offerID = try Uint64(xdrData: &xdrData) + self.orderBookID = try Uint64(xdrData: &xdrData) + self.ext = try ManageOfferOpExt(xdrData: &xdrData) + } + public enum ManageOfferOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -112,5 +124,15 @@ public struct ManageOfferOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageOfferRequest.swift b/Sources/TokenDWallet/Xdr/ManageOfferRequest.swift new file mode 100644 index 0000000..00bc951 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/ManageOfferRequest.swift @@ -0,0 +1,86 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct ManageOfferRequest +// { +// ManageOfferOp op; +// +// union switch (LedgerVersion v) +// { +// case EMPTY_VERSION: +// void; +// case MOVEMENT_REQUESTS_DETAILS: +// longstring creatorDetails; +// } ext; +// }; + +// =========================================================================== +public struct ManageOfferRequest: XDRCodable { + public var op: ManageOfferOp + public var ext: ManageOfferRequestExt + + public init( + op: ManageOfferOp, + ext: ManageOfferRequestExt) { + + self.op = op + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.op.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.op = try ManageOfferOp(xdrData: &xdrData) + self.ext = try ManageOfferRequestExt(xdrData: &xdrData) + } + + public enum ManageOfferRequestExt: XDRDiscriminatedUnion { + case emptyVersion() + case movementRequestsDetails(Longstring) + + public var discriminant: Int32 { + switch self { + case .emptyVersion: return LedgerVersion.emptyVersion.rawValue + case .movementRequestsDetails: return LedgerVersion.movementRequestsDetails.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .emptyVersion(): xdr.append(Data()) + case .movementRequestsDetails(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.movementRequestsDetails.rawValue: + let data = try Longstring(xdrData: &xdrData) + self = .movementRequestsDetails(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/ManageOfferResult.swift b/Sources/TokenDWallet/Xdr/ManageOfferResult.swift index f2854ed..f8fd9b4 100644 --- a/Sources/TokenDWallet/Xdr/ManageOfferResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageOfferResult.swift @@ -65,7 +65,25 @@ public enum ManageOfferResult: XDRDiscriminatedUnion { return xdr } - public struct ManageOfferResultPhysicalPriceRestriction: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageOfferResultCode.success.rawValue: + let data = try ManageOfferSuccessResult(xdrData: &xdrData) + self = .success(data) + case ManageOfferResultCode.physicalPriceRestriction.rawValue: + let data = try ManageOfferResultPhysicalPriceRestriction(xdrData: &xdrData) + self = .physicalPriceRestriction(data) + case ManageOfferResultCode.currentPriceRestriction.rawValue: + let data = try ManageOfferResultCurrentPriceRestriction(xdrData: &xdrData) + self = .currentPriceRestriction(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageOfferResultPhysicalPriceRestriction: XDRCodable { public var physicalPrice: Int64 public var ext: ManageOfferResultPhysicalPriceRestrictionExt @@ -86,6 +104,11 @@ public enum ManageOfferResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.physicalPrice = try Int64(xdrData: &xdrData) + self.ext = try ManageOfferResultPhysicalPriceRestrictionExt(xdrData: &xdrData) + } + public enum ManageOfferResultPhysicalPriceRestrictionExt: XDRDiscriminatedUnion { case emptyVersion() @@ -107,9 +130,19 @@ public enum ManageOfferResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } - public struct ManageOfferResultCurrentPriceRestriction: XDREncodable { + public struct ManageOfferResultCurrentPriceRestriction: XDRCodable { public var currentPrice: Int64 public var ext: ManageOfferResultCurrentPriceRestrictionExt @@ -130,6 +163,11 @@ public enum ManageOfferResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.currentPrice = try Int64(xdrData: &xdrData) + self.ext = try ManageOfferResultCurrentPriceRestrictionExt(xdrData: &xdrData) + } + public enum ManageOfferResultCurrentPriceRestrictionExt: XDRDiscriminatedUnion { case emptyVersion() @@ -151,6 +189,16 @@ public enum ManageOfferResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageOfferSuccessResult.swift b/Sources/TokenDWallet/Xdr/ManageOfferSuccessResult.swift index dadd63c..b840b1d 100644 --- a/Sources/TokenDWallet/Xdr/ManageOfferSuccessResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageOfferSuccessResult.swift @@ -37,7 +37,7 @@ import Foundation // }; // =========================================================================== -public struct ManageOfferSuccessResult: XDREncodable { +public struct ManageOfferSuccessResult: XDRCodable { public var offersClaimed: [ClaimOfferAtom] public var baseAsset: AssetCode public var quoteAsset: AssetCode @@ -70,6 +70,18 @@ public struct ManageOfferSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let lengthoffersClaimed = try Int32(xdrData: &xdrData) + self.offersClaimed = [ClaimOfferAtom]() + for _ in 1...lengthoffersClaimed { + self.offersClaimed.append(try ClaimOfferAtom(xdrData: &xdrData)) + } + self.baseAsset = try AssetCode(xdrData: &xdrData) + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.offer = try ManageOfferSuccessResultOffer(xdrData: &xdrData) + self.ext = try ManageOfferSuccessResultExt(xdrData: &xdrData) + } + public enum ManageOfferSuccessResultOffer: XDRDiscriminatedUnion { case created(OfferEntry) case updated(OfferEntry) @@ -94,6 +106,21 @@ public struct ManageOfferSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageOfferEffect.created.rawValue: + let data = try OfferEntry(xdrData: &xdrData) + self = .created(data) + case ManageOfferEffect.updated.rawValue: + let data = try OfferEntry(xdrData: &xdrData) + self = .updated(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageOfferSuccessResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -116,5 +143,15 @@ public struct ManageOfferSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManagePollOp.swift b/Sources/TokenDWallet/Xdr/ManagePollOp.swift index 56f11be..06e341f 100644 --- a/Sources/TokenDWallet/Xdr/ManagePollOp.swift +++ b/Sources/TokenDWallet/Xdr/ManagePollOp.swift @@ -33,7 +33,7 @@ import Foundation // }; // =========================================================================== -public struct ManagePollOp: XDREncodable { +public struct ManagePollOp: XDRCodable { public var pollID: Uint64 public var data: ManagePollOpData public var ext: ManagePollOpExt @@ -58,6 +58,12 @@ public struct ManagePollOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.data = try ManagePollOpData(xdrData: &xdrData) + self.ext = try ManagePollOpExt(xdrData: &xdrData) + } + public enum ManagePollOpData: XDRDiscriminatedUnion { case close(ClosePollData) case updateEndTime(UpdatePollEndTimeData) @@ -85,6 +91,24 @@ public struct ManagePollOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManagePollAction.close.rawValue: + let data = try ClosePollData(xdrData: &xdrData) + self = .close(data) + case ManagePollAction.updateEndTime.rawValue: + let data = try UpdatePollEndTimeData(xdrData: &xdrData) + self = .updateEndTime(data) + case ManagePollAction.cancel.rawValue: + let data = try EmptyExt(xdrData: &xdrData) + self = .cancel(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManagePollOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -107,5 +131,15 @@ public struct ManagePollOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManagePollResult.swift b/Sources/TokenDWallet/Xdr/ManagePollResult.swift index b5dbe6f..4c5b169 100644 --- a/Sources/TokenDWallet/Xdr/ManagePollResult.swift +++ b/Sources/TokenDWallet/Xdr/ManagePollResult.swift @@ -35,4 +35,16 @@ public enum ManagePollResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManagePollResultCode.success.rawValue: + let data = try EmptyExt(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSaleOp.swift b/Sources/TokenDWallet/Xdr/ManageSaleOp.swift index 4af8ed9..4b4be64 100644 --- a/Sources/TokenDWallet/Xdr/ManageSaleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageSaleOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ManageSaleOp: XDREncodable { +public struct ManageSaleOp: XDRCodable { public var saleID: Uint64 public var data: ManageSaleOpData public var ext: ManageSaleOpExt @@ -52,6 +52,12 @@ public struct ManageSaleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.data = try ManageSaleOpData(xdrData: &xdrData) + self.ext = try ManageSaleOpExt(xdrData: &xdrData) + } + public enum ManageSaleOpData: XDRDiscriminatedUnion { case createUpdateDetailsRequest(UpdateSaleDetailsData) case cancel() @@ -76,6 +82,19 @@ public struct ManageSaleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSaleAction.createUpdateDetailsRequest.rawValue: + let data = try UpdateSaleDetailsData(xdrData: &xdrData) + self = .createUpdateDetailsRequest(data) + case ManageSaleAction.cancel.rawValue: self = .cancel() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageSaleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -98,5 +117,15 @@ public struct ManageSaleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSaleResult.swift b/Sources/TokenDWallet/Xdr/ManageSaleResult.swift index 8b14e91..d5a90e6 100644 --- a/Sources/TokenDWallet/Xdr/ManageSaleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageSaleResult.swift @@ -35,4 +35,16 @@ public enum ManageSaleResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSaleResultCode.success.rawValue: + let data = try ManageSaleResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSaleResultSuccess.swift b/Sources/TokenDWallet/Xdr/ManageSaleResultSuccess.swift index 1896885..ef68e0e 100644 --- a/Sources/TokenDWallet/Xdr/ManageSaleResultSuccess.swift +++ b/Sources/TokenDWallet/Xdr/ManageSaleResultSuccess.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageSaleResultSuccess: XDREncodable { +public struct ManageSaleResultSuccess: XDRCodable { public var fulfilled: Bool public var response: ManageSaleResultSuccessResponse public var ext: ManageSaleResultSuccessExt @@ -54,6 +54,12 @@ public struct ManageSaleResultSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.fulfilled = try Bool(xdrData: &xdrData) + self.response = try ManageSaleResultSuccessResponse(xdrData: &xdrData) + self.ext = try ManageSaleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageSaleResultSuccessResponse: XDRDiscriminatedUnion { case createUpdateDetailsRequest(Uint64) case cancel() @@ -78,6 +84,19 @@ public struct ManageSaleResultSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSaleAction.createUpdateDetailsRequest.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .createUpdateDetailsRequest(data) + case ManageSaleAction.cancel.rawValue: self = .cancel() + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageSaleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -100,5 +119,15 @@ public struct ManageSaleResultSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerOp.swift b/Sources/TokenDWallet/Xdr/ManageSignerOp.swift index 4c7cf97..32e0c7c 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerOp.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct ManageSignerOp: XDREncodable { +public struct ManageSignerOp: XDRCodable { public var data: ManageSignerOpData public var ext: EmptyExt @@ -46,6 +46,11 @@ public struct ManageSignerOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageSignerOpData(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + public enum ManageSignerOpData: XDRDiscriminatedUnion { case create(UpdateSignerData) case update(UpdateSignerData) @@ -73,5 +78,23 @@ public struct ManageSignerOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerAction.create.rawValue: + let data = try UpdateSignerData(xdrData: &xdrData) + self = .create(data) + case ManageSignerAction.update.rawValue: + let data = try UpdateSignerData(xdrData: &xdrData) + self = .update(data) + case ManageSignerAction.remove.rawValue: + let data = try RemoveSignerData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerResult.swift b/Sources/TokenDWallet/Xdr/ManageSignerResult.swift index 8da54c2..c493344 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerResult.swift @@ -36,4 +36,16 @@ public enum ManageSignerResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerResultCode.success.rawValue: + let data = try EmptyExt(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerRoleOp.swift b/Sources/TokenDWallet/Xdr/ManageSignerRoleOp.swift index fabf474..cd4cdb4 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerRoleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerRoleOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageSignerRoleOp: XDREncodable { +public struct ManageSignerRoleOp: XDRCodable { public var data: ManageSignerRoleOpData public var ext: ManageSignerRoleOpExt @@ -50,6 +50,11 @@ public struct ManageSignerRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageSignerRoleOpData(xdrData: &xdrData) + self.ext = try ManageSignerRoleOpExt(xdrData: &xdrData) + } + public enum ManageSignerRoleOpData: XDRDiscriminatedUnion { case create(CreateSignerRoleData) case update(UpdateSignerRoleData) @@ -77,6 +82,24 @@ public struct ManageSignerRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerRoleAction.create.rawValue: + let data = try CreateSignerRoleData(xdrData: &xdrData) + self = .create(data) + case ManageSignerRoleAction.update.rawValue: + let data = try UpdateSignerRoleData(xdrData: &xdrData) + self = .update(data) + case ManageSignerRoleAction.remove.rawValue: + let data = try RemoveSignerRoleData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageSignerRoleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -99,5 +122,15 @@ public struct ManageSignerRoleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerRoleResult.swift b/Sources/TokenDWallet/Xdr/ManageSignerRoleResult.swift index f1c609c..2e91af5 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerRoleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerRoleResult.swift @@ -67,7 +67,31 @@ public enum ManageSignerRoleResult: XDRDiscriminatedUnion { return xdr } - public struct ManageSignerRoleResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerRoleResultCode.success.rawValue: + let data = try ManageSignerRoleResultSuccess(xdrData: &xdrData) + self = .success(data) + case ManageSignerRoleResultCode.ruleIdDuplication.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .ruleIdDuplication(data) + case ManageSignerRoleResultCode.defaultRuleIdDuplication.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .defaultRuleIdDuplication(data) + case ManageSignerRoleResultCode.noSuchRule.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .noSuchRule(data) + case ManageSignerRoleResultCode.tooManyRuleIds.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .tooManyRuleIds(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageSignerRoleResultSuccess: XDRCodable { public var roleID: Uint64 public var ext: ManageSignerRoleResultSuccessExt @@ -88,6 +112,11 @@ public enum ManageSignerRoleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try ManageSignerRoleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageSignerRoleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -109,6 +138,16 @@ public enum ManageSignerRoleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerRuleOp.swift b/Sources/TokenDWallet/Xdr/ManageSignerRuleOp.swift index c0fa47b..b3f5efb 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerRuleOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerRuleOp.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct ManageSignerRuleOp: XDREncodable { +public struct ManageSignerRuleOp: XDRCodable { public var data: ManageSignerRuleOpData public var ext: ManageSignerRuleOpExt @@ -50,6 +50,11 @@ public struct ManageSignerRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageSignerRuleOpData(xdrData: &xdrData) + self.ext = try ManageSignerRuleOpExt(xdrData: &xdrData) + } + public enum ManageSignerRuleOpData: XDRDiscriminatedUnion { case create(CreateSignerRuleData) case update(UpdateSignerRuleData) @@ -77,6 +82,24 @@ public struct ManageSignerRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerRuleAction.create.rawValue: + let data = try CreateSignerRuleData(xdrData: &xdrData) + self = .create(data) + case ManageSignerRuleAction.update.rawValue: + let data = try UpdateSignerRuleData(xdrData: &xdrData) + self = .update(data) + case ManageSignerRuleAction.remove.rawValue: + let data = try RemoveSignerRuleData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageSignerRuleOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -99,5 +122,15 @@ public struct ManageSignerRuleOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageSignerRuleResult.swift b/Sources/TokenDWallet/Xdr/ManageSignerRuleResult.swift index 41ce617..41692b1 100644 --- a/Sources/TokenDWallet/Xdr/ManageSignerRuleResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageSignerRuleResult.swift @@ -52,7 +52,26 @@ public enum ManageSignerRuleResult: XDRDiscriminatedUnion { return xdr } - public struct ManageSignerRuleResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageSignerRuleResultCode.success.rawValue: + let data = try ManageSignerRuleResultSuccess(xdrData: &xdrData) + self = .success(data) + case ManageSignerRuleResultCode.ruleIsUsed.rawValue: + let lengthroleIDs = try Int32(xdrData: &xdrData) + var data = [Uint64]() + for _ in 1...lengthroleIDs { + data.append(try Uint64(xdrData: &xdrData)) + } + self = .ruleIsUsed(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ManageSignerRuleResultSuccess: XDRCodable { public var ruleID: Uint64 public var ext: ManageSignerRuleResultSuccessExt @@ -73,6 +92,11 @@ public enum ManageSignerRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try ManageSignerRuleResultSuccessExt(xdrData: &xdrData) + } + public enum ManageSignerRuleResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,6 +118,16 @@ public enum ManageSignerRuleResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/ManageVoteOp.swift b/Sources/TokenDWallet/Xdr/ManageVoteOp.swift index 1e13c3e..b5ba350 100644 --- a/Sources/TokenDWallet/Xdr/ManageVoteOp.swift +++ b/Sources/TokenDWallet/Xdr/ManageVoteOp.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct ManageVoteOp: XDREncodable { +public struct ManageVoteOp: XDRCodable { public var data: ManageVoteOpData public var ext: ManageVoteOpExt @@ -48,6 +48,11 @@ public struct ManageVoteOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.data = try ManageVoteOpData(xdrData: &xdrData) + self.ext = try ManageVoteOpExt(xdrData: &xdrData) + } + public enum ManageVoteOpData: XDRDiscriminatedUnion { case create(CreateVoteData) case remove(RemoveVoteData) @@ -72,6 +77,21 @@ public struct ManageVoteOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageVoteAction.create.rawValue: + let data = try CreateVoteData(xdrData: &xdrData) + self = .create(data) + case ManageVoteAction.remove.rawValue: + let data = try RemoveVoteData(xdrData: &xdrData) + self = .remove(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ManageVoteOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,5 +114,15 @@ public struct ManageVoteOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ManageVoteResult.swift b/Sources/TokenDWallet/Xdr/ManageVoteResult.swift index 25d37f0..a6e34cd 100644 --- a/Sources/TokenDWallet/Xdr/ManageVoteResult.swift +++ b/Sources/TokenDWallet/Xdr/ManageVoteResult.swift @@ -35,4 +35,16 @@ public enum ManageVoteResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ManageVoteResultCode.success.rawValue: + let data = try EmptyExt(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/Memo.swift b/Sources/TokenDWallet/Xdr/Memo.swift index 81e9f0c..0b69831 100644 --- a/Sources/TokenDWallet/Xdr/Memo.swift +++ b/Sources/TokenDWallet/Xdr/Memo.swift @@ -52,4 +52,26 @@ public enum Memo: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case MemoType.memoNone.rawValue: self = .memoNone() + case MemoType.memoText.rawValue: + let data = try String(xdrData: &xdrData) + self = .memoText(data) + case MemoType.memoId.rawValue: + let data = try Uint64(xdrData: &xdrData) + self = .memoId(data) + case MemoType.memoHash.rawValue: + let data = try Hash(xdrData: &xdrData) + self = .memoHash(data) + case MemoType.memoReturn.rawValue: + let data = try Hash(xdrData: &xdrData) + self = .memoReturn(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/OfferEntry.swift b/Sources/TokenDWallet/Xdr/OfferEntry.swift index 32182f6..c37d866 100644 --- a/Sources/TokenDWallet/Xdr/OfferEntry.swift +++ b/Sources/TokenDWallet/Xdr/OfferEntry.swift @@ -35,7 +35,7 @@ import Foundation // }; // =========================================================================== -public struct OfferEntry: XDREncodable { +public struct OfferEntry: XDRCodable { public var offerID: Uint64 public var orderBookID: Uint64 public var ownerID: AccountID @@ -108,6 +108,24 @@ public struct OfferEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.offerID = try Uint64(xdrData: &xdrData) + self.orderBookID = try Uint64(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + self.isBuy = try Bool(xdrData: &xdrData) + self.base = try AssetCode(xdrData: &xdrData) + self.quote = try AssetCode(xdrData: &xdrData) + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.quoteBalance = try BalanceID(xdrData: &xdrData) + self.baseAmount = try Int64(xdrData: &xdrData) + self.quoteAmount = try Int64(xdrData: &xdrData) + self.createdAt = try Uint64(xdrData: &xdrData) + self.fee = try Int64(xdrData: &xdrData) + self.percentFee = try Int64(xdrData: &xdrData) + self.price = try Int64(xdrData: &xdrData) + self.ext = try OfferEntryExt(xdrData: &xdrData) + } + public enum OfferEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -129,5 +147,15 @@ public struct OfferEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/OpenSwapOp.swift b/Sources/TokenDWallet/Xdr/OpenSwapOp.swift new file mode 100644 index 0000000..525f93c --- /dev/null +++ b/Sources/TokenDWallet/Xdr/OpenSwapOp.swift @@ -0,0 +1,134 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct OpenSwapOp +// { +// //: Source balance of the swap +// BalanceID sourceBalance; +// //: Amount to send in swap +// uint64 amount; +// +// //: `destination` defines the type of instance that receives amount based on given PaymentDestinationType +// union switch (PaymentDestinationType type) { +// case ACCOUNT: +// AccountID accountID; +// case BALANCE: +// BalanceID balanceID; +// } destination; +// +// //: Fee data for the swap +// PaymentFeeData feeData; +// //: Arbitrary stringified json object provided by swap source +// longstring details; +// +// //: Hash of the secret +// Hash secretHash; +// //: Time till which swapped funds can be received by destination if valid secret is provided +// int64 lockTime; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct OpenSwapOp: XDRCodable { + public var sourceBalance: BalanceID + public var amount: Uint64 + public var destination: OpenSwapOpDestination + public var feeData: PaymentFeeData + public var details: Longstring + public var secretHash: Hash + public var lockTime: Int64 + public var ext: EmptyExt + + public init( + sourceBalance: BalanceID, + amount: Uint64, + destination: OpenSwapOpDestination, + feeData: PaymentFeeData, + details: Longstring, + secretHash: Hash, + lockTime: Int64, + ext: EmptyExt) { + + self.sourceBalance = sourceBalance + self.amount = amount + self.destination = destination + self.feeData = feeData + self.details = details + self.secretHash = secretHash + self.lockTime = lockTime + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.sourceBalance.toXDR()) + xdr.append(self.amount.toXDR()) + xdr.append(self.destination.toXDR()) + xdr.append(self.feeData.toXDR()) + xdr.append(self.details.toXDR()) + xdr.append(self.secretHash.toXDR()) + xdr.append(self.lockTime.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.sourceBalance = try BalanceID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.destination = try OpenSwapOpDestination(xdrData: &xdrData) + self.feeData = try PaymentFeeData(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.secretHash = try Hash(xdrData: &xdrData) + self.lockTime = try Int64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + public enum OpenSwapOpDestination: XDRDiscriminatedUnion { + case account(AccountID) + case balance(BalanceID) + + public var discriminant: Int32 { + switch self { + case .account: return PaymentDestinationType.account.rawValue + case .balance: return PaymentDestinationType.balance.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .account(let data): xdr.append(data.toXDR()) + case .balance(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PaymentDestinationType.account.rawValue: + let data = try AccountID(xdrData: &xdrData) + self = .account(data) + case PaymentDestinationType.balance.rawValue: + let data = try BalanceID(xdrData: &xdrData) + self = .balance(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/OpenSwapResult.swift b/Sources/TokenDWallet/Xdr/OpenSwapResult.swift new file mode 100644 index 0000000..e631076 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/OpenSwapResult.swift @@ -0,0 +1,50 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: OpenSwapResult is a result of OpenSwap operation application +// union OpenSwapResult switch (OpenSwapResultCode code) +// { +// case SUCCESS: +// OpenSwapSuccess success; +// default: +// void; +// }; + +// =========================================================================== +public enum OpenSwapResult: XDRDiscriminatedUnion { + case success(OpenSwapSuccess) + + public var discriminant: Int32 { + switch self { + case .success: return OpenSwapResultCode.success.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case OpenSwapResultCode.success.rawValue: + let data = try OpenSwapSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/OpenSwapResultCode.swift b/Sources/TokenDWallet/Xdr/OpenSwapResultCode.swift new file mode 100644 index 0000000..0abb447 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/OpenSwapResultCode.swift @@ -0,0 +1,57 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// enum OpenSwapResultCode +// { +// //: OpenSwap was successful +// SUCCESS = 0, +// +// //: Source and destination balances are the same +// MALFORMED = -1, +// //: Not enough funds in the source account +// UNDERFUNDED = -2, +// //: There is no balance found with an ID provided in `destinations.balanceID` +// //: Sender balance asset and receiver balance asset are not equal +// BALANCE_ASSETS_MISMATCHED = -3, +// //: There is no balance found with ID provided in `sourceBalanceID` +// SRC_BALANCE_NOT_FOUND = -4, +// //: Payment asset does not have a `SWAPPABLE` policy set +// NOT_ALLOWED_BY_ASSET_POLICY = -5, +// //: Overflow during total fee calculation +// INVALID_DESTINATION_FEE = -6, +// //: Payment fee amount is insufficient +// INSUFFICIENT_FEE_AMOUNT = -7, +// //: Fee charged from destination balance is greater than the amount +// AMOUNT_IS_LESS_THAN_DEST_FEE = -8, +// //: There is no account found with an ID provided in `destination.accountID` +// //: Amount precision and asset precision are mismatched +// INCORRECT_AMOUNT_PRECISION = -9, +// //: Not allowed to create swap with invalid json details +// INVALID_DETAILS = -10, +// //: Lock time is in the past +// INVALID_LOCK_TIME = -11, +// //: Zero amount is not allowed +// INVALID_AMOUNT = -12 +// +// }; + +// =========================================================================== +public enum OpenSwapResultCode: Int32, XDREnum { + case success = 0 + case malformed = -1 + case underfunded = -2 + case balanceAssetsMismatched = -3 + case srcBalanceNotFound = -4 + case notAllowedByAssetPolicy = -5 + case invalidDestinationFee = -6 + case insufficientFeeAmount = -7 + case amountIsLessThanDestFee = -8 + case incorrectAmountPrecision = -9 + case invalidDetails = -10 + case invalidLockTime = -11 + case invalidAmount = -12 +} diff --git a/Sources/TokenDWallet/Xdr/OpenSwapSuccess.swift b/Sources/TokenDWallet/Xdr/OpenSwapSuccess.swift new file mode 100644 index 0000000..08fb200 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/OpenSwapSuccess.swift @@ -0,0 +1,80 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: OpenSwapSuccess is used to pass saved ledger hash and license hash +// struct OpenSwapSuccess { +// uint64 swapID; +// +// //: ID of the destination account +// AccountID destination; +// //: ID of the destination balance +// BalanceID destinationBalance; +// +// //: Code of an asset used in swap +// AssetCode asset; +// +// //: Fee to be charged from the source balance +// Fee actualSourceFee; +// //: Fee to be charged from the destination balance +// Fee actualDestinationFee; +// +// //: reserved for future extension +// EmptyExt ext; +// }; + +// =========================================================================== +public struct OpenSwapSuccess: XDRCodable { + public var swapID: Uint64 + public var destination: AccountID + public var destinationBalance: BalanceID + public var asset: AssetCode + public var actualSourceFee: Fee + public var actualDestinationFee: Fee + public var ext: EmptyExt + + public init( + swapID: Uint64, + destination: AccountID, + destinationBalance: BalanceID, + asset: AssetCode, + actualSourceFee: Fee, + actualDestinationFee: Fee, + ext: EmptyExt) { + + self.swapID = swapID + self.destination = destination + self.destinationBalance = destinationBalance + self.asset = asset + self.actualSourceFee = actualSourceFee + self.actualDestinationFee = actualDestinationFee + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.swapID.toXDR()) + xdr.append(self.destination.toXDR()) + xdr.append(self.destinationBalance.toXDR()) + xdr.append(self.asset.toXDR()) + xdr.append(self.actualSourceFee.toXDR()) + xdr.append(self.actualDestinationFee.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.swapID = try Uint64(xdrData: &xdrData) + self.destination = try AccountID(xdrData: &xdrData) + self.destinationBalance = try BalanceID(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.actualSourceFee = try Fee(xdrData: &xdrData) + self.actualDestinationFee = try Fee(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/Operation.swift b/Sources/TokenDWallet/Xdr/Operation.swift index 34840e7..99ecb4e 100644 --- a/Sources/TokenDWallet/Xdr/Operation.swift +++ b/Sources/TokenDWallet/Xdr/Operation.swift @@ -103,12 +103,24 @@ import Foundation // InitiateKYCRecoveryOp initiateKYCRecoveryOp; // case CREATE_KYC_RECOVERY_REQUEST: // CreateKYCRecoveryRequestOp createKYCRecoveryRequestOp; +// case CREATE_MANAGE_OFFER_REQUEST: +// CreateManageOfferRequestOp createManageOfferRequestOp; +// case CREATE_PAYMENT_REQUEST: +// CreatePaymentRequestOp createPaymentRequestOp; +// case REMOVE_ASSET: +// RemoveAssetOp removeAssetOp; +// case OPEN_SWAP: +// OpenSwapOp openSwapOp; +// case CLOSE_SWAP: +// CloseSwapOp closeSwapOp; +// case CREATE_REDEMPTION_REQUEST: +// CreateRedemptionRequestOp createRedemptionRequestOp; // } // body; // }; // =========================================================================== -public struct Operation: XDREncodable { +public struct Operation: XDRCodable { public var sourceAccount: AccountID? public var body: OperationBody @@ -129,6 +141,15 @@ public struct Operation: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + if (try Bool(xdrData: &xdrData)) { + self.sourceAccount = try AccountID(xdrData: &xdrData) + } else { + self.sourceAccount = nil + } + self.body = try OperationBody(xdrData: &xdrData) + } + public enum OperationBody: XDRDiscriminatedUnion { case createAccount(CreateAccountOp) case createIssuanceRequest(CreateIssuanceRequestOp) @@ -174,6 +195,12 @@ public struct Operation: XDREncodable { case removeAssetPair(RemoveAssetPairOp) case initiateKycRecovery(InitiateKYCRecoveryOp) case createKycRecoveryRequest(CreateKYCRecoveryRequestOp) + case createManageOfferRequest(CreateManageOfferRequestOp) + case createPaymentRequest(CreatePaymentRequestOp) + case removeAsset(RemoveAssetOp) + case openSwap(OpenSwapOp) + case closeSwap(CloseSwapOp) + case createRedemptionRequest(CreateRedemptionRequestOp) public var discriminant: Int32 { switch self { @@ -221,6 +248,12 @@ public struct Operation: XDREncodable { case .removeAssetPair: return OperationType.removeAssetPair.rawValue case .initiateKycRecovery: return OperationType.initiateKycRecovery.rawValue case .createKycRecoveryRequest: return OperationType.createKycRecoveryRequest.rawValue + case .createManageOfferRequest: return OperationType.createManageOfferRequest.rawValue + case .createPaymentRequest: return OperationType.createPaymentRequest.rawValue + case .removeAsset: return OperationType.removeAsset.rawValue + case .openSwap: return OperationType.openSwap.rawValue + case .closeSwap: return OperationType.closeSwap.rawValue + case .createRedemptionRequest: return OperationType.createRedemptionRequest.rawValue } } @@ -274,10 +307,175 @@ public struct Operation: XDREncodable { case .removeAssetPair(let data): xdr.append(data.toXDR()) case .initiateKycRecovery(let data): xdr.append(data.toXDR()) case .createKycRecoveryRequest(let data): xdr.append(data.toXDR()) + case .createManageOfferRequest(let data): xdr.append(data.toXDR()) + case .createPaymentRequest(let data): xdr.append(data.toXDR()) + case .removeAsset(let data): xdr.append(data.toXDR()) + case .openSwap(let data): xdr.append(data.toXDR()) + case .closeSwap(let data): xdr.append(data.toXDR()) + case .createRedemptionRequest(let data): xdr.append(data.toXDR()) } return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case OperationType.createAccount.rawValue: + let data = try CreateAccountOp(xdrData: &xdrData) + self = .createAccount(data) + case OperationType.createIssuanceRequest.rawValue: + let data = try CreateIssuanceRequestOp(xdrData: &xdrData) + self = .createIssuanceRequest(data) + case OperationType.setFees.rawValue: + let data = try SetFeesOp(xdrData: &xdrData) + self = .setFees(data) + case OperationType.createWithdrawalRequest.rawValue: + let data = try CreateWithdrawalRequestOp(xdrData: &xdrData) + self = .createWithdrawalRequest(data) + case OperationType.manageBalance.rawValue: + let data = try ManageBalanceOp(xdrData: &xdrData) + self = .manageBalance(data) + case OperationType.manageAsset.rawValue: + let data = try ManageAssetOp(xdrData: &xdrData) + self = .manageAsset(data) + case OperationType.createPreissuanceRequest.rawValue: + let data = try CreatePreIssuanceRequestOp(xdrData: &xdrData) + self = .createPreissuanceRequest(data) + case OperationType.manageLimits.rawValue: + let data = try ManageLimitsOp(xdrData: &xdrData) + self = .manageLimits(data) + case OperationType.manageAssetPair.rawValue: + let data = try ManageAssetPairOp(xdrData: &xdrData) + self = .manageAssetPair(data) + case OperationType.manageOffer.rawValue: + let data = try ManageOfferOp(xdrData: &xdrData) + self = .manageOffer(data) + case OperationType.manageInvoiceRequest.rawValue: + let data = try ManageInvoiceRequestOp(xdrData: &xdrData) + self = .manageInvoiceRequest(data) + case OperationType.reviewRequest.rawValue: + let data = try ReviewRequestOp(xdrData: &xdrData) + self = .reviewRequest(data) + case OperationType.createSaleRequest.rawValue: + let data = try CreateSaleCreationRequestOp(xdrData: &xdrData) + self = .createSaleRequest(data) + case OperationType.checkSaleState.rawValue: + let data = try CheckSaleStateOp(xdrData: &xdrData) + self = .checkSaleState(data) + case OperationType.payout.rawValue: + let data = try PayoutOp(xdrData: &xdrData) + self = .payout(data) + case OperationType.createAmlAlert.rawValue: + let data = try CreateAMLAlertRequestOp(xdrData: &xdrData) + self = .createAmlAlert(data) + case OperationType.manageKeyValue.rawValue: + let data = try ManageKeyValueOp(xdrData: &xdrData) + self = .manageKeyValue(data) + case OperationType.createChangeRoleRequest.rawValue: + let data = try CreateChangeRoleRequestOp(xdrData: &xdrData) + self = .createChangeRoleRequest(data) + case OperationType.manageExternalSystemAccountIdPoolEntry.rawValue: + let data = try ManageExternalSystemAccountIdPoolEntryOp(xdrData: &xdrData) + self = .manageExternalSystemAccountIdPoolEntry(data) + case OperationType.bindExternalSystemAccountId.rawValue: + let data = try BindExternalSystemAccountIdOp(xdrData: &xdrData) + self = .bindExternalSystemAccountId(data) + case OperationType.payment.rawValue: + let data = try PaymentOp(xdrData: &xdrData) + self = .payment(data) + case OperationType.manageSale.rawValue: + let data = try ManageSaleOp(xdrData: &xdrData) + self = .manageSale(data) + case OperationType.createManageLimitsRequest.rawValue: + let data = try CreateManageLimitsRequestOp(xdrData: &xdrData) + self = .createManageLimitsRequest(data) + case OperationType.manageContractRequest.rawValue: + let data = try ManageContractRequestOp(xdrData: &xdrData) + self = .manageContractRequest(data) + case OperationType.manageContract.rawValue: + let data = try ManageContractOp(xdrData: &xdrData) + self = .manageContract(data) + case OperationType.cancelSaleRequest.rawValue: + let data = try CancelSaleCreationRequestOp(xdrData: &xdrData) + self = .cancelSaleRequest(data) + case OperationType.createAtomicSwapAskRequest.rawValue: + let data = try CreateAtomicSwapAskRequestOp(xdrData: &xdrData) + self = .createAtomicSwapAskRequest(data) + case OperationType.cancelAtomicSwapAsk.rawValue: + let data = try CancelAtomicSwapAskOp(xdrData: &xdrData) + self = .cancelAtomicSwapAsk(data) + case OperationType.createAtomicSwapBidRequest.rawValue: + let data = try CreateAtomicSwapBidRequestOp(xdrData: &xdrData) + self = .createAtomicSwapBidRequest(data) + case OperationType.manageAccountRole.rawValue: + let data = try ManageAccountRoleOp(xdrData: &xdrData) + self = .manageAccountRole(data) + case OperationType.manageAccountRule.rawValue: + let data = try ManageAccountRuleOp(xdrData: &xdrData) + self = .manageAccountRule(data) + case OperationType.manageSigner.rawValue: + let data = try ManageSignerOp(xdrData: &xdrData) + self = .manageSigner(data) + case OperationType.manageSignerRole.rawValue: + let data = try ManageSignerRoleOp(xdrData: &xdrData) + self = .manageSignerRole(data) + case OperationType.manageSignerRule.rawValue: + let data = try ManageSignerRuleOp(xdrData: &xdrData) + self = .manageSignerRule(data) + case OperationType.stamp.rawValue: + let data = try StampOp(xdrData: &xdrData) + self = .stamp(data) + case OperationType.license.rawValue: + let data = try LicenseOp(xdrData: &xdrData) + self = .license(data) + case OperationType.manageCreatePollRequest.rawValue: + let data = try ManageCreatePollRequestOp(xdrData: &xdrData) + self = .manageCreatePollRequest(data) + case OperationType.managePoll.rawValue: + let data = try ManagePollOp(xdrData: &xdrData) + self = .managePoll(data) + case OperationType.manageVote.rawValue: + let data = try ManageVoteOp(xdrData: &xdrData) + self = .manageVote(data) + case OperationType.manageAccountSpecificRule.rawValue: + let data = try ManageAccountSpecificRuleOp(xdrData: &xdrData) + self = .manageAccountSpecificRule(data) + case OperationType.cancelChangeRoleRequest.rawValue: + let data = try CancelChangeRoleRequestOp(xdrData: &xdrData) + self = .cancelChangeRoleRequest(data) + case OperationType.removeAssetPair.rawValue: + let data = try RemoveAssetPairOp(xdrData: &xdrData) + self = .removeAssetPair(data) + case OperationType.initiateKycRecovery.rawValue: + let data = try InitiateKYCRecoveryOp(xdrData: &xdrData) + self = .initiateKycRecovery(data) + case OperationType.createKycRecoveryRequest.rawValue: + let data = try CreateKYCRecoveryRequestOp(xdrData: &xdrData) + self = .createKycRecoveryRequest(data) + case OperationType.createManageOfferRequest.rawValue: + let data = try CreateManageOfferRequestOp(xdrData: &xdrData) + self = .createManageOfferRequest(data) + case OperationType.createPaymentRequest.rawValue: + let data = try CreatePaymentRequestOp(xdrData: &xdrData) + self = .createPaymentRequest(data) + case OperationType.removeAsset.rawValue: + let data = try RemoveAssetOp(xdrData: &xdrData) + self = .removeAsset(data) + case OperationType.openSwap.rawValue: + let data = try OpenSwapOp(xdrData: &xdrData) + self = .openSwap(data) + case OperationType.closeSwap.rawValue: + let data = try CloseSwapOp(xdrData: &xdrData) + self = .closeSwap(data) + case OperationType.createRedemptionRequest.rawValue: + let data = try CreateRedemptionRequestOp(xdrData: &xdrData) + self = .createRedemptionRequest(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/OperationFee.swift b/Sources/TokenDWallet/Xdr/OperationFee.swift index 1c48e0a..59fb492 100644 --- a/Sources/TokenDWallet/Xdr/OperationFee.swift +++ b/Sources/TokenDWallet/Xdr/OperationFee.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct OperationFee: XDREncodable { +public struct OperationFee: XDRCodable { public var operationType: OperationType public var amount: Uint64 public var ext: OperationFeeExt @@ -45,6 +45,12 @@ public struct OperationFee: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.operationType = try OperationType(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.ext = try OperationFeeExt(xdrData: &xdrData) + } + public enum OperationFeeExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct OperationFee: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/OperationMeta.swift b/Sources/TokenDWallet/Xdr/OperationMeta.swift index 2463da0..81e0cf9 100644 --- a/Sources/TokenDWallet/Xdr/OperationMeta.swift +++ b/Sources/TokenDWallet/Xdr/OperationMeta.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct OperationMeta: XDREncodable { +public struct OperationMeta: XDRCodable { public var changes: LedgerEntryChanges public init( @@ -27,4 +27,12 @@ public struct OperationMeta: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + let length = try Int32(xdrData: &xdrData) + self.changes = LedgerEntryChanges() + for _ in 1...length { + self.changes.append(try LedgerEntryChange(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/OperationResult.swift b/Sources/TokenDWallet/Xdr/OperationResult.swift index 45f9c63..0b6b44e 100644 --- a/Sources/TokenDWallet/Xdr/OperationResult.swift +++ b/Sources/TokenDWallet/Xdr/OperationResult.swift @@ -98,6 +98,18 @@ import Foundation // CreateKYCRecoveryRequestResult createKYCRecoveryRequestResult; // case INITIATE_KYC_RECOVERY: // InitiateKYCRecoveryResult initiateKYCRecoveryResult; +// case CREATE_MANAGE_OFFER_REQUEST: +// CreateManageOfferRequestResult createManageOfferRequestResult; +// case CREATE_PAYMENT_REQUEST: +// CreatePaymentRequestResult createPaymentRequestResult; +// case REMOVE_ASSET: +// RemoveAssetResult removeAssetResult; +// case OPEN_SWAP: +// OpenSwapResult openSwapResult; +// case CLOSE_SWAP: +// CloseSwapResult closeSwapResult; +// case CREATE_REDEMPTION_REQUEST: +// CreateRedemptionRequestResult createRedemptionRequestResult; // } // tr; // case opNO_ENTRY: @@ -135,6 +147,24 @@ public enum OperationResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case OperationResultCode.opinner.rawValue: + let data = try OperationResultTr(xdrData: &xdrData) + self = .opinner(data) + case OperationResultCode.opnoEntry.rawValue: + let data = try LedgerEntryType(xdrData: &xdrData) + self = .opnoEntry(data) + case OperationResultCode.opnoRolePermission.rawValue: + let data = try AccountRuleRequirement(xdrData: &xdrData) + self = .opnoRolePermission(data) + default: + throw XDRErrors.unknownEnumCase + } + } public enum OperationResultTr: XDRDiscriminatedUnion { case createAccount(CreateAccountResult) case createIssuanceRequest(CreateIssuanceRequestResult) @@ -180,6 +210,12 @@ public enum OperationResult: XDRDiscriminatedUnion { case removeAssetPair(RemoveAssetPairResult) case createKycRecoveryRequest(CreateKYCRecoveryRequestResult) case initiateKycRecovery(InitiateKYCRecoveryResult) + case createManageOfferRequest(CreateManageOfferRequestResult) + case createPaymentRequest(CreatePaymentRequestResult) + case removeAsset(RemoveAssetResult) + case openSwap(OpenSwapResult) + case closeSwap(CloseSwapResult) + case createRedemptionRequest(CreateRedemptionRequestResult) public var discriminant: Int32 { switch self { @@ -227,6 +263,12 @@ public enum OperationResult: XDRDiscriminatedUnion { case .removeAssetPair: return OperationType.removeAssetPair.rawValue case .createKycRecoveryRequest: return OperationType.createKycRecoveryRequest.rawValue case .initiateKycRecovery: return OperationType.initiateKycRecovery.rawValue + case .createManageOfferRequest: return OperationType.createManageOfferRequest.rawValue + case .createPaymentRequest: return OperationType.createPaymentRequest.rawValue + case .removeAsset: return OperationType.removeAsset.rawValue + case .openSwap: return OperationType.openSwap.rawValue + case .closeSwap: return OperationType.closeSwap.rawValue + case .createRedemptionRequest: return OperationType.createRedemptionRequest.rawValue } } @@ -280,10 +322,175 @@ public enum OperationResult: XDRDiscriminatedUnion { case .removeAssetPair(let data): xdr.append(data.toXDR()) case .createKycRecoveryRequest(let data): xdr.append(data.toXDR()) case .initiateKycRecovery(let data): xdr.append(data.toXDR()) + case .createManageOfferRequest(let data): xdr.append(data.toXDR()) + case .createPaymentRequest(let data): xdr.append(data.toXDR()) + case .removeAsset(let data): xdr.append(data.toXDR()) + case .openSwap(let data): xdr.append(data.toXDR()) + case .closeSwap(let data): xdr.append(data.toXDR()) + case .createRedemptionRequest(let data): xdr.append(data.toXDR()) } return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case OperationType.createAccount.rawValue: + let data = try CreateAccountResult(xdrData: &xdrData) + self = .createAccount(data) + case OperationType.createIssuanceRequest.rawValue: + let data = try CreateIssuanceRequestResult(xdrData: &xdrData) + self = .createIssuanceRequest(data) + case OperationType.setFees.rawValue: + let data = try SetFeesResult(xdrData: &xdrData) + self = .setFees(data) + case OperationType.createWithdrawalRequest.rawValue: + let data = try CreateWithdrawalRequestResult(xdrData: &xdrData) + self = .createWithdrawalRequest(data) + case OperationType.manageBalance.rawValue: + let data = try ManageBalanceResult(xdrData: &xdrData) + self = .manageBalance(data) + case OperationType.manageAsset.rawValue: + let data = try ManageAssetResult(xdrData: &xdrData) + self = .manageAsset(data) + case OperationType.createPreissuanceRequest.rawValue: + let data = try CreatePreIssuanceRequestResult(xdrData: &xdrData) + self = .createPreissuanceRequest(data) + case OperationType.manageLimits.rawValue: + let data = try ManageLimitsResult(xdrData: &xdrData) + self = .manageLimits(data) + case OperationType.manageAssetPair.rawValue: + let data = try ManageAssetPairResult(xdrData: &xdrData) + self = .manageAssetPair(data) + case OperationType.manageOffer.rawValue: + let data = try ManageOfferResult(xdrData: &xdrData) + self = .manageOffer(data) + case OperationType.manageInvoiceRequest.rawValue: + let data = try ManageInvoiceRequestResult(xdrData: &xdrData) + self = .manageInvoiceRequest(data) + case OperationType.reviewRequest.rawValue: + let data = try ReviewRequestResult(xdrData: &xdrData) + self = .reviewRequest(data) + case OperationType.createSaleRequest.rawValue: + let data = try CreateSaleCreationRequestResult(xdrData: &xdrData) + self = .createSaleRequest(data) + case OperationType.checkSaleState.rawValue: + let data = try CheckSaleStateResult(xdrData: &xdrData) + self = .checkSaleState(data) + case OperationType.payout.rawValue: + let data = try PayoutResult(xdrData: &xdrData) + self = .payout(data) + case OperationType.createAmlAlert.rawValue: + let data = try CreateAMLAlertRequestResult(xdrData: &xdrData) + self = .createAmlAlert(data) + case OperationType.manageKeyValue.rawValue: + let data = try ManageKeyValueResult(xdrData: &xdrData) + self = .manageKeyValue(data) + case OperationType.createChangeRoleRequest.rawValue: + let data = try CreateChangeRoleRequestResult(xdrData: &xdrData) + self = .createChangeRoleRequest(data) + case OperationType.manageExternalSystemAccountIdPoolEntry.rawValue: + let data = try ManageExternalSystemAccountIdPoolEntryResult(xdrData: &xdrData) + self = .manageExternalSystemAccountIdPoolEntry(data) + case OperationType.bindExternalSystemAccountId.rawValue: + let data = try BindExternalSystemAccountIdResult(xdrData: &xdrData) + self = .bindExternalSystemAccountId(data) + case OperationType.payment.rawValue: + let data = try PaymentResult(xdrData: &xdrData) + self = .payment(data) + case OperationType.manageSale.rawValue: + let data = try ManageSaleResult(xdrData: &xdrData) + self = .manageSale(data) + case OperationType.createManageLimitsRequest.rawValue: + let data = try CreateManageLimitsRequestResult(xdrData: &xdrData) + self = .createManageLimitsRequest(data) + case OperationType.manageContractRequest.rawValue: + let data = try ManageContractRequestResult(xdrData: &xdrData) + self = .manageContractRequest(data) + case OperationType.manageContract.rawValue: + let data = try ManageContractResult(xdrData: &xdrData) + self = .manageContract(data) + case OperationType.cancelSaleRequest.rawValue: + let data = try CancelSaleCreationRequestResult(xdrData: &xdrData) + self = .cancelSaleRequest(data) + case OperationType.createAtomicSwapAskRequest.rawValue: + let data = try CreateAtomicSwapAskRequestResult(xdrData: &xdrData) + self = .createAtomicSwapAskRequest(data) + case OperationType.cancelAtomicSwapAsk.rawValue: + let data = try CancelAtomicSwapAskResult(xdrData: &xdrData) + self = .cancelAtomicSwapAsk(data) + case OperationType.createAtomicSwapBidRequest.rawValue: + let data = try CreateAtomicSwapBidRequestResult(xdrData: &xdrData) + self = .createAtomicSwapBidRequest(data) + case OperationType.manageAccountRole.rawValue: + let data = try ManageAccountRoleResult(xdrData: &xdrData) + self = .manageAccountRole(data) + case OperationType.manageAccountRule.rawValue: + let data = try ManageAccountRuleResult(xdrData: &xdrData) + self = .manageAccountRule(data) + case OperationType.manageSigner.rawValue: + let data = try ManageSignerResult(xdrData: &xdrData) + self = .manageSigner(data) + case OperationType.manageSignerRole.rawValue: + let data = try ManageSignerRoleResult(xdrData: &xdrData) + self = .manageSignerRole(data) + case OperationType.manageSignerRule.rawValue: + let data = try ManageSignerRuleResult(xdrData: &xdrData) + self = .manageSignerRule(data) + case OperationType.stamp.rawValue: + let data = try StampResult(xdrData: &xdrData) + self = .stamp(data) + case OperationType.license.rawValue: + let data = try LicenseResult(xdrData: &xdrData) + self = .license(data) + case OperationType.managePoll.rawValue: + let data = try ManagePollResult(xdrData: &xdrData) + self = .managePoll(data) + case OperationType.manageCreatePollRequest.rawValue: + let data = try ManageCreatePollRequestResult(xdrData: &xdrData) + self = .manageCreatePollRequest(data) + case OperationType.manageVote.rawValue: + let data = try ManageVoteResult(xdrData: &xdrData) + self = .manageVote(data) + case OperationType.manageAccountSpecificRule.rawValue: + let data = try ManageAccountSpecificRuleResult(xdrData: &xdrData) + self = .manageAccountSpecificRule(data) + case OperationType.cancelChangeRoleRequest.rawValue: + let data = try CancelChangeRoleRequestResult(xdrData: &xdrData) + self = .cancelChangeRoleRequest(data) + case OperationType.removeAssetPair.rawValue: + let data = try RemoveAssetPairResult(xdrData: &xdrData) + self = .removeAssetPair(data) + case OperationType.createKycRecoveryRequest.rawValue: + let data = try CreateKYCRecoveryRequestResult(xdrData: &xdrData) + self = .createKycRecoveryRequest(data) + case OperationType.initiateKycRecovery.rawValue: + let data = try InitiateKYCRecoveryResult(xdrData: &xdrData) + self = .initiateKycRecovery(data) + case OperationType.createManageOfferRequest.rawValue: + let data = try CreateManageOfferRequestResult(xdrData: &xdrData) + self = .createManageOfferRequest(data) + case OperationType.createPaymentRequest.rawValue: + let data = try CreatePaymentRequestResult(xdrData: &xdrData) + self = .createPaymentRequest(data) + case OperationType.removeAsset.rawValue: + let data = try RemoveAssetResult(xdrData: &xdrData) + self = .removeAsset(data) + case OperationType.openSwap.rawValue: + let data = try OpenSwapResult(xdrData: &xdrData) + self = .openSwap(data) + case OperationType.closeSwap.rawValue: + let data = try CloseSwapResult(xdrData: &xdrData) + self = .closeSwap(data) + case OperationType.createRedemptionRequest.rawValue: + let data = try CreateRedemptionRequestResult(xdrData: &xdrData) + self = .createRedemptionRequest(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/OperationType.swift b/Sources/TokenDWallet/Xdr/OperationType.swift index 387c157..62710c0 100644 --- a/Sources/TokenDWallet/Xdr/OperationType.swift +++ b/Sources/TokenDWallet/Xdr/OperationType.swift @@ -50,7 +50,13 @@ import Foundation // CANCEL_CHANGE_ROLE_REQUEST = 47, // INITIATE_KYC_RECOVERY = 48, // CREATE_KYC_RECOVERY_REQUEST = 49, -// REMOVE_ASSET_PAIR = 50 +// REMOVE_ASSET_PAIR = 50, +// CREATE_MANAGE_OFFER_REQUEST = 51, +// CREATE_PAYMENT_REQUEST = 52, +// REMOVE_ASSET = 53, +// OPEN_SWAP = 54, +// CLOSE_SWAP = 55, +// CREATE_REDEMPTION_REQUEST = 56 // }; // =========================================================================== @@ -99,4 +105,10 @@ public enum OperationType: Int32, XDREnum { case initiateKycRecovery = 48 case createKycRecoveryRequest = 49 case removeAssetPair = 50 + case createManageOfferRequest = 51 + case createPaymentRequest = 52 + case removeAsset = 53 + case openSwap = 54 + case closeSwap = 55 + case createRedemptionRequest = 56 } diff --git a/Sources/TokenDWallet/Xdr/PaymentFeeData.swift b/Sources/TokenDWallet/Xdr/PaymentFeeData.swift index 5e0eb5d..0e425fe 100644 --- a/Sources/TokenDWallet/Xdr/PaymentFeeData.swift +++ b/Sources/TokenDWallet/Xdr/PaymentFeeData.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct PaymentFeeData: XDREncodable { +public struct PaymentFeeData: XDRCodable { public var sourceFee: Fee public var destinationFee: Fee public var sourcePaysForDest: Bool @@ -52,6 +52,13 @@ public struct PaymentFeeData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.sourceFee = try Fee(xdrData: &xdrData) + self.destinationFee = try Fee(xdrData: &xdrData) + self.sourcePaysForDest = try Bool(xdrData: &xdrData) + self.ext = try PaymentFeeDataExt(xdrData: &xdrData) + } + public enum PaymentFeeDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +80,15 @@ public struct PaymentFeeData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PaymentOp.swift b/Sources/TokenDWallet/Xdr/PaymentOp.swift index b7c4e07..a466d39 100644 --- a/Sources/TokenDWallet/Xdr/PaymentOp.swift +++ b/Sources/TokenDWallet/Xdr/PaymentOp.swift @@ -40,7 +40,7 @@ import Foundation // }; // =========================================================================== -public struct PaymentOp: XDREncodable { +public struct PaymentOp: XDRCodable { public var sourceBalanceID: BalanceID public var destination: PaymentOpDestination public var amount: Uint64 @@ -81,6 +81,16 @@ public struct PaymentOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.sourceBalanceID = try BalanceID(xdrData: &xdrData) + self.destination = try PaymentOpDestination(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.feeData = try PaymentFeeData(xdrData: &xdrData) + self.subject = try Longstring(xdrData: &xdrData) + self.reference = try Longstring(xdrData: &xdrData) + self.ext = try PaymentOpExt(xdrData: &xdrData) + } + public enum PaymentOpDestination: XDRDiscriminatedUnion { case account(AccountID) case balance(BalanceID) @@ -105,6 +115,21 @@ public struct PaymentOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PaymentDestinationType.account.rawValue: + let data = try AccountID(xdrData: &xdrData) + self = .account(data) + case PaymentDestinationType.balance.rawValue: + let data = try BalanceID(xdrData: &xdrData) + self = .balance(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum PaymentOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -127,5 +152,15 @@ public struct PaymentOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PaymentResponse.swift b/Sources/TokenDWallet/Xdr/PaymentResponse.swift index 02f1f79..08ab445 100644 --- a/Sources/TokenDWallet/Xdr/PaymentResponse.swift +++ b/Sources/TokenDWallet/Xdr/PaymentResponse.swift @@ -34,7 +34,7 @@ import Foundation // }; // =========================================================================== -public struct PaymentResponse: XDREncodable { +public struct PaymentResponse: XDRCodable { public var destination: AccountID public var destinationBalanceID: BalanceID public var asset: AssetCode @@ -79,6 +79,17 @@ public struct PaymentResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.destination = try AccountID(xdrData: &xdrData) + self.destinationBalanceID = try BalanceID(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.sourceSentUniversal = try Uint64(xdrData: &xdrData) + self.paymentID = try Uint64(xdrData: &xdrData) + self.actualSourcePaymentFee = try Fee(xdrData: &xdrData) + self.actualDestinationPaymentFee = try Fee(xdrData: &xdrData) + self.ext = try PaymentResponseExt(xdrData: &xdrData) + } + public enum PaymentResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -100,5 +111,15 @@ public struct PaymentResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PaymentResult.swift b/Sources/TokenDWallet/Xdr/PaymentResult.swift index 7e9236b..df1b308 100644 --- a/Sources/TokenDWallet/Xdr/PaymentResult.swift +++ b/Sources/TokenDWallet/Xdr/PaymentResult.swift @@ -34,4 +34,16 @@ public enum PaymentResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PaymentResultCode.success.rawValue: + let data = try PaymentResponse(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/PaymentResultCode.swift b/Sources/TokenDWallet/Xdr/PaymentResultCode.swift index 7259030..2a277be 100644 --- a/Sources/TokenDWallet/Xdr/PaymentResultCode.swift +++ b/Sources/TokenDWallet/Xdr/PaymentResultCode.swift @@ -41,7 +41,9 @@ import Foundation // //: There is no account found with an ID provided in `destination.accountID` // DESTINATION_ACCOUNT_NOT_FOUND = -14, // //: Amount precision and asset precision are mismatched -// INCORRECT_AMOUNT_PRECISION = -15 +// INCORRECT_AMOUNT_PRECISION = -15, +// //: Too much signs in subject +// INVALID_SUBJECT = -16 // }; // =========================================================================== @@ -62,4 +64,5 @@ public enum PaymentResultCode: Int32, XDREnum { case paymentAmountIsLessThanDestFee = -13 case destinationAccountNotFound = -14 case incorrectAmountPrecision = -15 + case invalidSubject = -16 } diff --git a/Sources/TokenDWallet/Xdr/PayoutOp.swift b/Sources/TokenDWallet/Xdr/PayoutOp.swift index 118b7b9..1e99752 100644 --- a/Sources/TokenDWallet/Xdr/PayoutOp.swift +++ b/Sources/TokenDWallet/Xdr/PayoutOp.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct PayoutOp: XDREncodable { +public struct PayoutOp: XDRCodable { public var asset: AssetCode public var sourceBalanceID: BalanceID public var maxPayoutAmount: Uint64 @@ -67,6 +67,16 @@ public struct PayoutOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.asset = try AssetCode(xdrData: &xdrData) + self.sourceBalanceID = try BalanceID(xdrData: &xdrData) + self.maxPayoutAmount = try Uint64(xdrData: &xdrData) + self.minPayoutAmount = try Uint64(xdrData: &xdrData) + self.minAssetHolderAmount = try Uint64(xdrData: &xdrData) + self.fee = try Fee(xdrData: &xdrData) + self.ext = try PayoutOpExt(xdrData: &xdrData) + } + public enum PayoutOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -88,5 +98,15 @@ public struct PayoutOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PayoutResponse.swift b/Sources/TokenDWallet/Xdr/PayoutResponse.swift index 99be598..c3b633c 100644 --- a/Sources/TokenDWallet/Xdr/PayoutResponse.swift +++ b/Sources/TokenDWallet/Xdr/PayoutResponse.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct PayoutResponse: XDREncodable { +public struct PayoutResponse: XDRCodable { public var receiverID: AccountID public var receiverBalanceID: BalanceID public var receivedAmount: Uint64 @@ -50,6 +50,13 @@ public struct PayoutResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.receiverID = try AccountID(xdrData: &xdrData) + self.receiverBalanceID = try BalanceID(xdrData: &xdrData) + self.receivedAmount = try Uint64(xdrData: &xdrData) + self.ext = try PayoutResponseExt(xdrData: &xdrData) + } + public enum PayoutResponseExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +78,15 @@ public struct PayoutResponse: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PayoutResult.swift b/Sources/TokenDWallet/Xdr/PayoutResult.swift index cb6860a..11e1c65 100644 --- a/Sources/TokenDWallet/Xdr/PayoutResult.swift +++ b/Sources/TokenDWallet/Xdr/PayoutResult.swift @@ -34,4 +34,16 @@ public enum PayoutResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PayoutResultCode.success.rawValue: + let data = try PayoutSuccessResult(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/PayoutSuccessResult.swift b/Sources/TokenDWallet/Xdr/PayoutSuccessResult.swift index d259909..956eeb1 100644 --- a/Sources/TokenDWallet/Xdr/PayoutSuccessResult.swift +++ b/Sources/TokenDWallet/Xdr/PayoutSuccessResult.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct PayoutSuccessResult: XDREncodable { +public struct PayoutSuccessResult: XDRCodable { public var payoutResponses: [PayoutResponse] public var actualPayoutAmount: Uint64 public var actualFee: Fee @@ -50,6 +50,17 @@ public struct PayoutSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let lengthpayoutResponses = try Int32(xdrData: &xdrData) + self.payoutResponses = [PayoutResponse]() + for _ in 1...lengthpayoutResponses { + self.payoutResponses.append(try PayoutResponse(xdrData: &xdrData)) + } + self.actualPayoutAmount = try Uint64(xdrData: &xdrData) + self.actualFee = try Fee(xdrData: &xdrData) + self.ext = try PayoutSuccessResultExt(xdrData: &xdrData) + } + public enum PayoutSuccessResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +82,15 @@ public struct PayoutSuccessResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PeerAddress.swift b/Sources/TokenDWallet/Xdr/PeerAddress.swift index a831e30..0d640fc 100644 --- a/Sources/TokenDWallet/Xdr/PeerAddress.swift +++ b/Sources/TokenDWallet/Xdr/PeerAddress.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct PeerAddress: XDREncodable { +public struct PeerAddress: XDRCodable { public var ip: PeerAddressIp public var port: Uint32 public var numFailures: Uint32 @@ -45,6 +45,12 @@ public struct PeerAddress: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ip = try PeerAddressIp(xdrData: &xdrData) + self.port = try Uint32(xdrData: &xdrData) + self.numFailures = try Uint32(xdrData: &xdrData) + } + public enum PeerAddressIp: XDRDiscriminatedUnion { case ipv4(XDRDataFixed4) case ipv6(XDRDataFixed16) @@ -69,5 +75,20 @@ public struct PeerAddress: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case IPAddrType.ipv4.rawValue: + let data = try XDRDataFixed4(xdrData: &xdrData) + self = .ipv4(data) + case IPAddrType.ipv6.rawValue: + let data = try XDRDataFixed16(xdrData: &xdrData) + self = .ipv6(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PendingStatisticsEntry.swift b/Sources/TokenDWallet/Xdr/PendingStatisticsEntry.swift index 3bc4a4f..7e0d72f 100644 --- a/Sources/TokenDWallet/Xdr/PendingStatisticsEntry.swift +++ b/Sources/TokenDWallet/Xdr/PendingStatisticsEntry.swift @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct PendingStatisticsEntry: XDREncodable { +public struct PendingStatisticsEntry: XDRCodable { public var statisticsID: Uint64 public var requestID: Uint64 public var amount: Uint64 @@ -50,6 +50,13 @@ public struct PendingStatisticsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.statisticsID = try Uint64(xdrData: &xdrData) + self.requestID = try Uint64(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.ext = try PendingStatisticsEntryExt(xdrData: &xdrData) + } + public enum PendingStatisticsEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -71,5 +78,15 @@ public struct PendingStatisticsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PollData.swift b/Sources/TokenDWallet/Xdr/PollData.swift index 3a20f30..2cf8de2 100644 --- a/Sources/TokenDWallet/Xdr/PollData.swift +++ b/Sources/TokenDWallet/Xdr/PollData.swift @@ -33,4 +33,16 @@ public enum PollData: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PollType.singleChoice.rawValue: + let data = try EmptyExt(xdrData: &xdrData) + self = .singleChoice(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/PollEntry.swift b/Sources/TokenDWallet/Xdr/PollEntry.swift index 5a93de2..0f19030 100644 --- a/Sources/TokenDWallet/Xdr/PollEntry.swift +++ b/Sources/TokenDWallet/Xdr/PollEntry.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct PollEntry: XDREncodable { +public struct PollEntry: XDRCodable { public var id: Uint64 public var permissionType: Uint32 public var numberOfChoices: Uint32 @@ -83,4 +83,18 @@ public struct PollEntry: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.permissionType = try Uint32(xdrData: &xdrData) + self.numberOfChoices = try Uint32(xdrData: &xdrData) + self.data = try PollData(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + self.resultProviderID = try AccountID(xdrData: &xdrData) + self.voteConfirmationRequired = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/PreIssuanceRequest.swift b/Sources/TokenDWallet/Xdr/PreIssuanceRequest.swift index e0d99b0..2e587fe 100644 --- a/Sources/TokenDWallet/Xdr/PreIssuanceRequest.swift +++ b/Sources/TokenDWallet/Xdr/PreIssuanceRequest.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct PreIssuanceRequest: XDREncodable { +public struct PreIssuanceRequest: XDRCodable { public var asset: AssetCode public var amount: Uint64 public var signature: DecoratedSignature @@ -66,6 +66,15 @@ public struct PreIssuanceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.asset = try AssetCode(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.signature = try DecoratedSignature(xdrData: &xdrData) + self.reference = try String64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try PreIssuanceRequestExt(xdrData: &xdrData) + } + public enum PreIssuanceRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -87,5 +96,15 @@ public struct PreIssuanceRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/PublicKey.swift b/Sources/TokenDWallet/Xdr/PublicKey.swift index 4f61115..6d17ac1 100644 --- a/Sources/TokenDWallet/Xdr/PublicKey.swift +++ b/Sources/TokenDWallet/Xdr/PublicKey.swift @@ -32,4 +32,16 @@ public enum PublicKey: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case CryptoKeyType.keyTypeEd25519.rawValue: + let data = try Uint256(xdrData: &xdrData) + self = .keyTypeEd25519(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/RedemptionRequest.swift b/Sources/TokenDWallet/Xdr/RedemptionRequest.swift new file mode 100644 index 0000000..85e1f50 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/RedemptionRequest.swift @@ -0,0 +1,104 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Body of a reviewable RedemptionRequest, contains parameters regarding AML alert +// struct RedemptionRequest { +// //: Balance to charge assets from. Balance must be in asset owned by requester. +// BalanceID sourceBalanceID; +// //: Account to transfer funds +// AccountID destination; +// +// //: Amount of redemption +// uint64 amount; +// +// //: Arbitrary stringified json object that can be used to attach data to be reviewed by an admin +// longstring creatorDetails; // details set by requester +// +// //: Reserved for future use +// union switch (LedgerVersion v) +// { +// case EMPTY_VERSION: +// void; +// } +// ext; +// }; + +// =========================================================================== +public struct RedemptionRequest: XDRCodable { + public var sourceBalanceID: BalanceID + public var destination: AccountID + public var amount: Uint64 + public var creatorDetails: Longstring + public var ext: RedemptionRequestExt + + public init( + sourceBalanceID: BalanceID, + destination: AccountID, + amount: Uint64, + creatorDetails: Longstring, + ext: RedemptionRequestExt) { + + self.sourceBalanceID = sourceBalanceID + self.destination = destination + self.amount = amount + self.creatorDetails = creatorDetails + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.sourceBalanceID.toXDR()) + xdr.append(self.destination.toXDR()) + xdr.append(self.amount.toXDR()) + xdr.append(self.creatorDetails.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.sourceBalanceID = try BalanceID(xdrData: &xdrData) + self.destination = try AccountID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try RedemptionRequestExt(xdrData: &xdrData) + } + + public enum RedemptionRequestExt: XDRDiscriminatedUnion { + case emptyVersion() + + public var discriminant: Int32 { + switch self { + case .emptyVersion: return LedgerVersion.emptyVersion.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .emptyVersion(): xdr.append(Data()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/RedemptionRequestResponse.swift b/Sources/TokenDWallet/Xdr/RedemptionRequestResponse.swift new file mode 100644 index 0000000..133f0c7 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/RedemptionRequestResponse.swift @@ -0,0 +1,109 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result of successful application of `CreateRedemptionRequest` operation +// struct RedemptionRequestResponse { +// //: ID of a newly created reviewable request +// uint64 requestID; +// //: Indicates whether or not the Redemption request was auto approved and fulfilled +// bool fulfilled; +// +// //: ID of destination balance (may be freshly created) +// BalanceID destinationBalanceID; +// //: Code of an asset used in payment +// AssetCode asset; +// //: Amount sent by the sender +// uint64 sourceSentUniversal; +// //: Reserved for future use +// union switch (LedgerVersion v) +// { +// case EMPTY_VERSION: +// void; +// } +// ext; +// }; + +// =========================================================================== +public struct RedemptionRequestResponse: XDRCodable { + public var requestID: Uint64 + public var fulfilled: Bool + public var destinationBalanceID: BalanceID + public var asset: AssetCode + public var sourceSentUniversal: Uint64 + public var ext: RedemptionRequestResponseExt + + public init( + requestID: Uint64, + fulfilled: Bool, + destinationBalanceID: BalanceID, + asset: AssetCode, + sourceSentUniversal: Uint64, + ext: RedemptionRequestResponseExt) { + + self.requestID = requestID + self.fulfilled = fulfilled + self.destinationBalanceID = destinationBalanceID + self.asset = asset + self.sourceSentUniversal = sourceSentUniversal + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.requestID.toXDR()) + xdr.append(self.fulfilled.toXDR()) + xdr.append(self.destinationBalanceID.toXDR()) + xdr.append(self.asset.toXDR()) + xdr.append(self.sourceSentUniversal.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.fulfilled = try Bool(xdrData: &xdrData) + self.destinationBalanceID = try BalanceID(xdrData: &xdrData) + self.asset = try AssetCode(xdrData: &xdrData) + self.sourceSentUniversal = try Uint64(xdrData: &xdrData) + self.ext = try RedemptionRequestResponseExt(xdrData: &xdrData) + } + + public enum RedemptionRequestResponseExt: XDRDiscriminatedUnion { + case emptyVersion() + + public var discriminant: Int32 { + switch self { + case .emptyVersion: return LedgerVersion.emptyVersion.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .emptyVersion(): xdr.append(Data()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + + } +} diff --git a/Sources/TokenDWallet/Xdr/ReferenceEntry.swift b/Sources/TokenDWallet/Xdr/ReferenceEntry.swift index cfa2d08..ea5c048 100644 --- a/Sources/TokenDWallet/Xdr/ReferenceEntry.swift +++ b/Sources/TokenDWallet/Xdr/ReferenceEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct ReferenceEntry: XDREncodable { +public struct ReferenceEntry: XDRCodable { public var sender: AccountID public var reference: String64 public var ext: ReferenceEntryExt @@ -45,6 +45,12 @@ public struct ReferenceEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.sender = try AccountID(xdrData: &xdrData) + self.reference = try String64(xdrData: &xdrData) + self.ext = try ReferenceEntryExt(xdrData: &xdrData) + } + public enum ReferenceEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct ReferenceEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAccountRoleData.swift b/Sources/TokenDWallet/Xdr/RemoveAccountRoleData.swift index c1d2061..5aedb22 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAccountRoleData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAccountRoleData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveAccountRoleData: XDREncodable { +public struct RemoveAccountRoleData: XDRCodable { public var roleID: Uint64 public var ext: RemoveAccountRoleDataExt @@ -41,6 +41,11 @@ public struct RemoveAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveAccountRoleDataExt(xdrData: &xdrData) + } + public enum RemoveAccountRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAccountRuleData.swift b/Sources/TokenDWallet/Xdr/RemoveAccountRuleData.swift index 01f3a30..5e0f354 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAccountRuleData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAccountRuleData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveAccountRuleData: XDREncodable { +public struct RemoveAccountRuleData: XDRCodable { public var ruleID: Uint64 public var ext: RemoveAccountRuleDataExt @@ -41,6 +41,11 @@ public struct RemoveAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveAccountRuleDataExt(xdrData: &xdrData) + } + public enum RemoveAccountRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAccountSpecificRuleData.swift b/Sources/TokenDWallet/Xdr/RemoveAccountSpecificRuleData.swift index 45a083a..8dd6fe3 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAccountSpecificRuleData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAccountSpecificRuleData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveAccountSpecificRuleData: XDREncodable { +public struct RemoveAccountSpecificRuleData: XDRCodable { public var ruleID: Uint64 public var ext: RemoveAccountSpecificRuleDataExt @@ -41,6 +41,11 @@ public struct RemoveAccountSpecificRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveAccountSpecificRuleDataExt(xdrData: &xdrData) + } + public enum RemoveAccountSpecificRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveAccountSpecificRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestOp.swift b/Sources/TokenDWallet/Xdr/RemoveAssetOp.swift similarity index 51% rename from Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestOp.swift rename to Sources/TokenDWallet/Xdr/RemoveAssetOp.swift index 9686013..1bda630 100644 --- a/Sources/TokenDWallet/Xdr/CreateASwapBidCreationRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAssetOp.swift @@ -5,10 +5,12 @@ import Foundation // === xdr source ============================================================ -// struct CreateASwapBidCreationRequestOp +// //: `RemoveAssetOp` changes the state of specified asset to removed +// struct RemoveAssetOp // { -// ASwapBidCreationRequest request; -// +// //: Defines an asset +// AssetCode code; +// //: reserved for future use // union switch (LedgerVersion v) // { // case EMPTY_VERSION: @@ -18,28 +20,33 @@ import Foundation // }; // =========================================================================== -public struct CreateASwapBidCreationRequestOp: XDREncodable { - public var request: ASwapBidCreationRequest - public var ext: CreateASwapBidCreationRequestOpExt +public struct RemoveAssetOp: XDRCodable { + public var code: AssetCode + public var ext: RemoveAssetOpExt public init( - request: ASwapBidCreationRequest, - ext: CreateASwapBidCreationRequestOpExt) { + code: AssetCode, + ext: RemoveAssetOpExt) { - self.request = request + self.code = code self.ext = ext } public func toXDR() -> Data { var xdr = Data() - xdr.append(self.request.toXDR()) + xdr.append(self.code.toXDR()) xdr.append(self.ext.toXDR()) return xdr } - public enum CreateASwapBidCreationRequestOpExt: XDRDiscriminatedUnion { + public init(xdrData: inout Data) throws { + self.code = try AssetCode(xdrData: &xdrData) + self.ext = try RemoveAssetOpExt(xdrData: &xdrData) + } + + public enum RemoveAssetOpExt: XDRDiscriminatedUnion { case emptyVersion() public var discriminant: Int32 { @@ -60,5 +67,15 @@ public struct CreateASwapBidCreationRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAssetPairOp.swift b/Sources/TokenDWallet/Xdr/RemoveAssetPairOp.swift index cfd87bb..6009cf5 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAssetPairOp.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAssetPairOp.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveAssetPairOp: XDREncodable { +public struct RemoveAssetPairOp: XDRCodable { public var base: AssetCode public var quote: AssetCode public var ext: RemoveAssetPairOpExt @@ -48,6 +48,12 @@ public struct RemoveAssetPairOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.base = try AssetCode(xdrData: &xdrData) + self.quote = try AssetCode(xdrData: &xdrData) + self.ext = try RemoveAssetPairOpExt(xdrData: &xdrData) + } + public enum RemoveAssetPairOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -69,5 +75,15 @@ public struct RemoveAssetPairOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAssetPairResult.swift b/Sources/TokenDWallet/Xdr/RemoveAssetPairResult.swift index 9af3b78..4ea6edb 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAssetPairResult.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAssetPairResult.swift @@ -34,4 +34,16 @@ public enum RemoveAssetPairResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case RemoveAssetPairResultCode.success.rawValue: + let data = try RemoveAssetPairSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAssetPairSuccess.swift b/Sources/TokenDWallet/Xdr/RemoveAssetPairSuccess.swift index f1b90f3..2cce785 100644 --- a/Sources/TokenDWallet/Xdr/RemoveAssetPairSuccess.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAssetPairSuccess.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveAssetPairSuccess: XDREncodable { +public struct RemoveAssetPairSuccess: XDRCodable { public var ext: RemoveAssetPairSuccessExt public init( @@ -35,6 +35,10 @@ public struct RemoveAssetPairSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try RemoveAssetPairSuccessExt(xdrData: &xdrData) + } + public enum RemoveAssetPairSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct RemoveAssetPairSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveAssetResult.swift b/Sources/TokenDWallet/Xdr/RemoveAssetResult.swift new file mode 100644 index 0000000..c1fc7b5 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/RemoveAssetResult.swift @@ -0,0 +1,49 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result of RemoveAsset operation application along with the result code +// union RemoveAssetResult switch (RemoveAssetResultCode code) { +// case SUCCESS: +// RemoveAssetSuccess success; +// default: +// void; +// }; + +// =========================================================================== +public enum RemoveAssetResult: XDRDiscriminatedUnion { + case success(RemoveAssetSuccess) + + public var discriminant: Int32 { + switch self { + case .success: return RemoveAssetResultCode.success.rawValue + } + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.discriminant.toXDR()) + + switch self { + case .success(let data): xdr.append(data.toXDR()) + } + + return xdr + } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case RemoveAssetResultCode.success.rawValue: + let data = try RemoveAssetSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } +} diff --git a/Sources/TokenDWallet/Xdr/RemoveAssetResultCode.swift b/Sources/TokenDWallet/Xdr/RemoveAssetResultCode.swift new file mode 100644 index 0000000..2309877 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/RemoveAssetResultCode.swift @@ -0,0 +1,42 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// //: Result codes for `RemoveAssetOp` +// enum RemoveAssetResultCode +// { +// //: Operation is successfully applied +// SUCCESS = 0, +// //: Asset code is invalid +// INVALID_ASSET_CODE = -1, +// //: Asset can't be deleted as there exist asset pairs with it +// HAS_PAIR = -2, +// //: Asset can't be deleted as it has active offers +// HAS_ACTIVE_OFFERS = -3, +// //: Asset can't be deleted as it has active sales +// HAS_ACTIVE_SALES = -4, +// //: Asset can't be deleted as it has active atomic swaps +// HAS_ACTIVE_ATOMIC_SWAPS = -5, +// //: Asset can't be deleted as it has active swaps +// HAS_ACTIVE_SWAPS = -6, +// //: Asset can't be deleted as it is stats quote asset +// CANNOT_REMOVE_STATS_QUOTE_ASSET = -7, +// //: Cannot delete asset, as some balances in target asset have non-empty locked amount +// HAS_PENDING_MOVEMENTS = -8 +// }; + +// =========================================================================== +public enum RemoveAssetResultCode: Int32, XDREnum { + case success = 0 + case invalidAssetCode = -1 + case hasPair = -2 + case hasActiveOffers = -3 + case hasActiveSales = -4 + case hasActiveAtomicSwaps = -5 + case hasActiveSwaps = -6 + case cannotRemoveStatsQuoteAsset = -7 + case hasPendingMovements = -8 +} diff --git a/Sources/TokenDWallet/Xdr/ASwapBidExtended.swift b/Sources/TokenDWallet/Xdr/RemoveAssetSuccess.swift similarity index 59% rename from Sources/TokenDWallet/Xdr/ASwapBidExtended.swift rename to Sources/TokenDWallet/Xdr/RemoveAssetSuccess.swift index b3c06c0..74968d4 100644 --- a/Sources/TokenDWallet/Xdr/ASwapBidExtended.swift +++ b/Sources/TokenDWallet/Xdr/RemoveAssetSuccess.swift @@ -5,11 +5,9 @@ import Foundation // === xdr source ============================================================ -// struct ASwapBidExtended +// //: Result of successful `RemoveAssetOp` application +// struct RemoveAssetSuccess // { -// //: ID of the newly created bid as a result of successful review of Create Atomic Swap Bid Request -// uint64 bidID; -// // //: Reserved for future use // union switch (LedgerVersion v) // { @@ -20,28 +18,28 @@ import Foundation // }; // =========================================================================== -public struct ASwapBidExtended: XDREncodable { - public var bidID: Uint64 - public var ext: ASwapBidExtendedExt +public struct RemoveAssetSuccess: XDRCodable { + public var ext: RemoveAssetSuccessExt public init( - bidID: Uint64, - ext: ASwapBidExtendedExt) { + ext: RemoveAssetSuccessExt) { - self.bidID = bidID self.ext = ext } public func toXDR() -> Data { var xdr = Data() - xdr.append(self.bidID.toXDR()) xdr.append(self.ext.toXDR()) return xdr } - public enum ASwapBidExtendedExt: XDRDiscriminatedUnion { + public init(xdrData: inout Data) throws { + self.ext = try RemoveAssetSuccessExt(xdrData: &xdrData) + } + + public enum RemoveAssetSuccessExt: XDRDiscriminatedUnion { case emptyVersion() public var discriminant: Int32 { @@ -62,5 +60,15 @@ public struct ASwapBidExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveSignerData.swift b/Sources/TokenDWallet/Xdr/RemoveSignerData.swift index 53c28f7..aab46fa 100644 --- a/Sources/TokenDWallet/Xdr/RemoveSignerData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveSignerData.swift @@ -16,7 +16,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveSignerData: XDREncodable { +public struct RemoveSignerData: XDRCodable { public var publicKey: PublicKey public var ext: EmptyExt @@ -36,4 +36,9 @@ public struct RemoveSignerData: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.publicKey = try PublicKey(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveSignerRoleData.swift b/Sources/TokenDWallet/Xdr/RemoveSignerRoleData.swift index dce9a83..87c055d 100644 --- a/Sources/TokenDWallet/Xdr/RemoveSignerRoleData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveSignerRoleData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveSignerRoleData: XDREncodable { +public struct RemoveSignerRoleData: XDRCodable { public var roleID: Uint64 public var ext: RemoveSignerRoleDataExt @@ -41,6 +41,11 @@ public struct RemoveSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveSignerRoleDataExt(xdrData: &xdrData) + } + public enum RemoveSignerRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveSignerRuleData.swift b/Sources/TokenDWallet/Xdr/RemoveSignerRuleData.swift index cb4ba1e..706ea62 100644 --- a/Sources/TokenDWallet/Xdr/RemoveSignerRuleData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveSignerRuleData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveSignerRuleData: XDREncodable { +public struct RemoveSignerRuleData: XDRCodable { public var ruleID: Uint64 public var ext: RemoveSignerRuleDataExt @@ -41,6 +41,11 @@ public struct RemoveSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveSignerRuleDataExt(xdrData: &xdrData) + } + public enum RemoveSignerRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RemoveVoteData.swift b/Sources/TokenDWallet/Xdr/RemoveVoteData.swift index af3ac52..c1f2fd5 100644 --- a/Sources/TokenDWallet/Xdr/RemoveVoteData.swift +++ b/Sources/TokenDWallet/Xdr/RemoveVoteData.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct RemoveVoteData: XDREncodable { +public struct RemoveVoteData: XDRCodable { public var pollID: Uint64 public var ext: RemoveVoteDataExt @@ -41,6 +41,11 @@ public struct RemoveVoteData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.ext = try RemoveVoteDataExt(xdrData: &xdrData) + } + public enum RemoveVoteDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct RemoveVoteData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/RequestTypedResource.swift b/Sources/TokenDWallet/Xdr/RequestTypedResource.swift deleted file mode 100644 index 3989ea8..0000000 --- a/Sources/TokenDWallet/Xdr/RequestTypedResource.swift +++ /dev/null @@ -1,138 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -import Foundation - -// === xdr source ============================================================ - -// union RequestTypedResource switch (ReviewableRequestType requestType) -// { -// case CREATE_SALE: -// struct -// { -// uint64 type; -// -// EmptyExt ext; -// } sale; -// case CREATE_ISSUANCE: -// struct -// { -// AssetCode assetCode; -// uint64 assetType; -// -// EmptyExt ext; -// } issuance; -// case CREATE_WITHDRAW: -// struct -// { -// AssetCode assetCode; -// uint64 assetType; -// -// EmptyExt ext; -// } withdraw; -// default: -// EmptyExt ext; -// }; - -// =========================================================================== -public enum RequestTypedResource: XDRDiscriminatedUnion { - case createSale(RequestTypedResourceSale) - case createIssuance(RequestTypedResourceIssuance) - case createWithdraw(RequestTypedResourceWithdraw) - - public var discriminant: Int32 { - switch self { - case .createSale: return ReviewableRequestType.createSale.rawValue - case .createIssuance: return ReviewableRequestType.createIssuance.rawValue - case .createWithdraw: return ReviewableRequestType.createWithdraw.rawValue - } - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.discriminant.toXDR()) - - switch self { - case .createSale(let data): xdr.append(data.toXDR()) - case .createIssuance(let data): xdr.append(data.toXDR()) - case .createWithdraw(let data): xdr.append(data.toXDR()) - } - - return xdr - } - public struct RequestTypedResourceSale: XDREncodable { - public var type: Uint64 - public var ext: EmptyExt - - public init( - type: Uint64, - ext: EmptyExt) { - - self.type = type - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.type.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - } - public struct RequestTypedResourceIssuance: XDREncodable { - public var assetCode: AssetCode - public var assetType: Uint64 - public var ext: EmptyExt - - public init( - assetCode: AssetCode, - assetType: Uint64, - ext: EmptyExt) { - - self.assetCode = assetCode - self.assetType = assetType - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.assetCode.toXDR()) - xdr.append(self.assetType.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - } - public struct RequestTypedResourceWithdraw: XDREncodable { - public var assetCode: AssetCode - public var assetType: Uint64 - public var ext: EmptyExt - - public init( - assetCode: AssetCode, - assetType: Uint64, - ext: EmptyExt) { - - self.assetCode = assetCode - self.assetType = assetType - self.ext = ext - } - - public func toXDR() -> Data { - var xdr = Data() - - xdr.append(self.assetCode.toXDR()) - xdr.append(self.assetType.toXDR()) - xdr.append(self.ext.toXDR()) - - return xdr - } - - } -} diff --git a/Sources/TokenDWallet/Xdr/ReviewDetails.swift b/Sources/TokenDWallet/Xdr/ReviewDetails.swift index 3c07701..035e252 100644 --- a/Sources/TokenDWallet/Xdr/ReviewDetails.swift +++ b/Sources/TokenDWallet/Xdr/ReviewDetails.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct ReviewDetails: XDREncodable { +public struct ReviewDetails: XDRCodable { public var tasksToAdd: Uint32 public var tasksToRemove: Uint32 public var externalDetails: String @@ -52,6 +52,13 @@ public struct ReviewDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.tasksToAdd = try Uint32(xdrData: &xdrData) + self.tasksToRemove = try Uint32(xdrData: &xdrData) + self.externalDetails = try String(xdrData: &xdrData) + self.ext = try ReviewDetailsExt(xdrData: &xdrData) + } + public enum ReviewDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +80,15 @@ public struct ReviewDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ReviewRequestOp.swift b/Sources/TokenDWallet/Xdr/ReviewRequestOp.swift index fdaf911..6964358 100644 --- a/Sources/TokenDWallet/Xdr/ReviewRequestOp.swift +++ b/Sources/TokenDWallet/Xdr/ReviewRequestOp.swift @@ -44,7 +44,7 @@ import Foundation // }; // =========================================================================== -public struct ReviewRequestOp: XDREncodable { +public struct ReviewRequestOp: XDRCodable { public var requestID: Uint64 public var requestHash: Hash public var requestDetails: ReviewRequestOpRequestDetails @@ -85,6 +85,16 @@ public struct ReviewRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.requestHash = try Hash(xdrData: &xdrData) + self.requestDetails = try ReviewRequestOpRequestDetails(xdrData: &xdrData) + self.action = try ReviewRequestOpAction(xdrData: &xdrData) + self.reason = try Longstring(xdrData: &xdrData) + self.reviewDetails = try ReviewDetails(xdrData: &xdrData) + self.ext = try ReviewRequestOpExt(xdrData: &xdrData) + } + public enum ReviewRequestOpRequestDetails: XDRDiscriminatedUnion { case createWithdraw(WithdrawalDetails) case updateLimits(LimitsUpdateDetails) @@ -118,6 +128,30 @@ public struct ReviewRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ReviewableRequestType.createWithdraw.rawValue: + let data = try WithdrawalDetails(xdrData: &xdrData) + self = .createWithdraw(data) + case ReviewableRequestType.updateLimits.rawValue: + let data = try LimitsUpdateDetails(xdrData: &xdrData) + self = .updateLimits(data) + case ReviewableRequestType.createAmlAlert.rawValue: + let data = try AMLAlertDetails(xdrData: &xdrData) + self = .createAmlAlert(data) + case ReviewableRequestType.createInvoice.rawValue: + let data = try BillPayDetails(xdrData: &xdrData) + self = .createInvoice(data) + case ReviewableRequestType.manageContract.rawValue: + let data = try ContractDetails(xdrData: &xdrData) + self = .manageContract(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ReviewRequestOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -140,5 +174,15 @@ public struct ReviewRequestOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ReviewRequestResult.swift b/Sources/TokenDWallet/Xdr/ReviewRequestResult.swift index 2a08d8d..afe6ed3 100644 --- a/Sources/TokenDWallet/Xdr/ReviewRequestResult.swift +++ b/Sources/TokenDWallet/Xdr/ReviewRequestResult.swift @@ -10,6 +10,10 @@ import Foundation // { // case SUCCESS: // ExtendedResult success; +// case MANAGE_OFFER_FAILED: +// ManageOfferResultCode manageOfferCode; +// case PAYMENT_FAILED: +// PaymentResultCode paymentCode; // default: // void; // }; @@ -17,10 +21,14 @@ import Foundation // =========================================================================== public enum ReviewRequestResult: XDRDiscriminatedUnion { case success(ExtendedResult) + case manageOfferFailed(ManageOfferResultCode) + case paymentFailed(PaymentResultCode) public var discriminant: Int32 { switch self { case .success: return ReviewRequestResultCode.success.rawValue + case .manageOfferFailed: return ReviewRequestResultCode.manageOfferFailed.rawValue + case .paymentFailed: return ReviewRequestResultCode.paymentFailed.rawValue } } @@ -31,8 +39,28 @@ public enum ReviewRequestResult: XDRDiscriminatedUnion { switch self { case .success(let data): xdr.append(data.toXDR()) + case .manageOfferFailed(let data): xdr.append(data.toXDR()) + case .paymentFailed(let data): xdr.append(data.toXDR()) } return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ReviewRequestResultCode.success.rawValue: + let data = try ExtendedResult(xdrData: &xdrData) + self = .success(data) + case ReviewRequestResultCode.manageOfferFailed.rawValue: + let data = try ManageOfferResultCode(xdrData: &xdrData) + self = .manageOfferFailed(data) + case ReviewRequestResultCode.paymentFailed.rawValue: + let data = try PaymentResultCode(xdrData: &xdrData) + self = .paymentFailed(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/ReviewRequestResultCode.swift b/Sources/TokenDWallet/Xdr/ReviewRequestResultCode.swift index f1701ac..a33801c 100644 --- a/Sources/TokenDWallet/Xdr/ReviewRequestResultCode.swift +++ b/Sources/TokenDWallet/Xdr/ReviewRequestResultCode.swift @@ -9,7 +9,7 @@ import Foundation // enum ReviewRequestResultCode // { // //: Codes considered as "success" for an operation -// //: Operation is applied successfuly +// //: Operation is applied successfully // SUCCESS = 0, // // //: Codes considered as "failure" for an operation @@ -127,8 +127,13 @@ import Foundation // // //KYC // //:Signer data is invalid - either weight is wrong or details are invalid -// INVALID_SIGNER_DATA = -1600 +// INVALID_SIGNER_DATA = -1600, // +// // offer +// MANAGE_OFFER_FAILED = -1700, +// +// // payment +// PAYMENT_FAILED = -1800 // }; // =========================================================================== @@ -194,4 +199,6 @@ public enum ReviewRequestResultCode: Int32, XDREnum { case quoteAssetCannotBeSwapped = -1501 case atomicSwapBidOwnerFullLine = -1504 case invalidSignerData = -1600 + case manageOfferFailed = -1700 + case paymentFailed = -1800 } diff --git a/Sources/TokenDWallet/Xdr/ReviewableRequestEntry.swift b/Sources/TokenDWallet/Xdr/ReviewableRequestEntry.swift index 05816e9..a5fa335 100644 --- a/Sources/TokenDWallet/Xdr/ReviewableRequestEntry.swift +++ b/Sources/TokenDWallet/Xdr/ReviewableRequestEntry.swift @@ -47,6 +47,12 @@ import Foundation // CreatePollRequest createPollRequest; // case KYC_RECOVERY: // KYCRecoveryRequest kycRecoveryRequest; +// case MANAGE_OFFER: +// ManageOfferRequest manageOfferRequest; +// case CREATE_PAYMENT: +// CreatePaymentRequest createPaymentRequest; +// case PERFORM_REDEMPTION: +// RedemptionRequest redemptionRequest; // } body; // // TasksExt tasks; @@ -61,7 +67,7 @@ import Foundation // }; // =========================================================================== -public struct ReviewableRequestEntry: XDREncodable { +public struct ReviewableRequestEntry: XDRCodable { public var requestID: Uint64 public var hash: Hash public var requestor: AccountID @@ -114,6 +120,23 @@ public struct ReviewableRequestEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.hash = try Hash(xdrData: &xdrData) + self.requestor = try AccountID(xdrData: &xdrData) + self.rejectReason = try Longstring(xdrData: &xdrData) + self.reviewer = try AccountID(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.reference = try String64(xdrData: &xdrData) + } else { + self.reference = nil + } + self.createdAt = try Int64(xdrData: &xdrData) + self.body = try ReviewableRequestEntryBody(xdrData: &xdrData) + self.tasks = try TasksExt(xdrData: &xdrData) + self.ext = try ReviewableRequestEntryExt(xdrData: &xdrData) + } + public enum ReviewableRequestEntryBody: XDRDiscriminatedUnion { case createAsset(AssetCreationRequest) case updateAsset(AssetUpdateRequest) @@ -131,6 +154,9 @@ public struct ReviewableRequestEntry: XDREncodable { case createAtomicSwapBid(CreateAtomicSwapBidRequest) case createPoll(CreatePollRequest) case kycRecovery(KYCRecoveryRequest) + case manageOffer(ManageOfferRequest) + case createPayment(CreatePaymentRequest) + case performRedemption(RedemptionRequest) public var discriminant: Int32 { switch self { @@ -150,6 +176,9 @@ public struct ReviewableRequestEntry: XDREncodable { case .createAtomicSwapBid: return ReviewableRequestType.createAtomicSwapBid.rawValue case .createPoll: return ReviewableRequestType.createPoll.rawValue case .kycRecovery: return ReviewableRequestType.kycRecovery.rawValue + case .manageOffer: return ReviewableRequestType.manageOffer.rawValue + case .createPayment: return ReviewableRequestType.createPayment.rawValue + case .performRedemption: return ReviewableRequestType.performRedemption.rawValue } } @@ -175,11 +204,80 @@ public struct ReviewableRequestEntry: XDREncodable { case .createAtomicSwapBid(let data): xdr.append(data.toXDR()) case .createPoll(let data): xdr.append(data.toXDR()) case .kycRecovery(let data): xdr.append(data.toXDR()) + case .manageOffer(let data): xdr.append(data.toXDR()) + case .createPayment(let data): xdr.append(data.toXDR()) + case .performRedemption(let data): xdr.append(data.toXDR()) } return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ReviewableRequestType.createAsset.rawValue: + let data = try AssetCreationRequest(xdrData: &xdrData) + self = .createAsset(data) + case ReviewableRequestType.updateAsset.rawValue: + let data = try AssetUpdateRequest(xdrData: &xdrData) + self = .updateAsset(data) + case ReviewableRequestType.createPreIssuance.rawValue: + let data = try PreIssuanceRequest(xdrData: &xdrData) + self = .createPreIssuance(data) + case ReviewableRequestType.createIssuance.rawValue: + let data = try IssuanceRequest(xdrData: &xdrData) + self = .createIssuance(data) + case ReviewableRequestType.createWithdraw.rawValue: + let data = try WithdrawalRequest(xdrData: &xdrData) + self = .createWithdraw(data) + case ReviewableRequestType.createSale.rawValue: + let data = try SaleCreationRequest(xdrData: &xdrData) + self = .createSale(data) + case ReviewableRequestType.updateLimits.rawValue: + let data = try LimitsUpdateRequest(xdrData: &xdrData) + self = .updateLimits(data) + case ReviewableRequestType.createAmlAlert.rawValue: + let data = try AMLAlertRequest(xdrData: &xdrData) + self = .createAmlAlert(data) + case ReviewableRequestType.changeRole.rawValue: + let data = try ChangeRoleRequest(xdrData: &xdrData) + self = .changeRole(data) + case ReviewableRequestType.updateSaleDetails.rawValue: + let data = try UpdateSaleDetailsRequest(xdrData: &xdrData) + self = .updateSaleDetails(data) + case ReviewableRequestType.createInvoice.rawValue: + let data = try InvoiceRequest(xdrData: &xdrData) + self = .createInvoice(data) + case ReviewableRequestType.manageContract.rawValue: + let data = try ContractRequest(xdrData: &xdrData) + self = .manageContract(data) + case ReviewableRequestType.createAtomicSwapAsk.rawValue: + let data = try CreateAtomicSwapAskRequest(xdrData: &xdrData) + self = .createAtomicSwapAsk(data) + case ReviewableRequestType.createAtomicSwapBid.rawValue: + let data = try CreateAtomicSwapBidRequest(xdrData: &xdrData) + self = .createAtomicSwapBid(data) + case ReviewableRequestType.createPoll.rawValue: + let data = try CreatePollRequest(xdrData: &xdrData) + self = .createPoll(data) + case ReviewableRequestType.kycRecovery.rawValue: + let data = try KYCRecoveryRequest(xdrData: &xdrData) + self = .kycRecovery(data) + case ReviewableRequestType.manageOffer.rawValue: + let data = try ManageOfferRequest(xdrData: &xdrData) + self = .manageOffer(data) + case ReviewableRequestType.createPayment.rawValue: + let data = try CreatePaymentRequest(xdrData: &xdrData) + self = .createPayment(data) + case ReviewableRequestType.performRedemption.rawValue: + let data = try RedemptionRequest(xdrData: &xdrData) + self = .performRedemption(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum ReviewableRequestEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -202,5 +300,15 @@ public struct ReviewableRequestEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/ReviewableRequestResource.swift b/Sources/TokenDWallet/Xdr/ReviewableRequestResource.swift index fa13e13..374e535 100644 --- a/Sources/TokenDWallet/Xdr/ReviewableRequestResource.swift +++ b/Sources/TokenDWallet/Xdr/ReviewableRequestResource.swift @@ -89,6 +89,55 @@ import Foundation // //: reserved for future extension // EmptyExt ext; // } createPoll; +// case MANAGE_OFFER: +// struct +// { +// //: type of base asset +// uint64 baseAssetType; +// //: type of quote asset +// uint64 quoteAssetType; +// +// //: code of base asset +// AssetCode baseAssetCode; +// //: code of quote asset +// AssetCode quoteAssetCode; +// +// bool isBuy; +// //: 0 means creation, +// //: 1 means removing, +// //: 2 means participate in sale, +// //: 3 means remove participation in sale, +// //: UINT32_MAX means any action. +// uint32 manageAction; +// +// //: ID of the order book. +// uint64 orderBookID; +// +// //: reserved for future extension +// EmptyExt ext; +// } manageOffer; +// case CREATE_PAYMENT: +// struct +// { +// //: Code of asset in which payment is being made +// AssetCode assetCode; +// //: Type of asset in which payment is being made +// uint64 assetType; +// +// //: reserved for future extension +// EmptyExt ext; +// } createPayment; +// case PERFORM_REDEMPTION: +// struct +// { +// //: Code of asset in which redemption is being made +// AssetCode assetCode; +// //: Type of asset in which redemption is being made +// uint64 assetType; +// +// //: reserved for future extension +// EmptyExt ext; +// } performRedemption; // default: // //: reserved for future extension // EmptyExt ext; @@ -102,6 +151,9 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { case createAtomicSwapAsk(ReviewableRequestResourceCreateAtomicSwapAskExt) case createAtomicSwapBid(ReviewableRequestResourceCreateAtomicSwapBidExt) case createPoll(ReviewableRequestResourceCreatePoll) + case manageOffer(ReviewableRequestResourceManageOffer) + case createPayment(ReviewableRequestResourceCreatePayment) + case performRedemption(ReviewableRequestResourcePerformRedemption) public var discriminant: Int32 { switch self { @@ -111,6 +163,9 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { case .createAtomicSwapAsk: return ReviewableRequestType.createAtomicSwapAsk.rawValue case .createAtomicSwapBid: return ReviewableRequestType.createAtomicSwapBid.rawValue case .createPoll: return ReviewableRequestType.createPoll.rawValue + case .manageOffer: return ReviewableRequestType.manageOffer.rawValue + case .createPayment: return ReviewableRequestType.createPayment.rawValue + case .performRedemption: return ReviewableRequestType.performRedemption.rawValue } } @@ -126,11 +181,50 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { case .createAtomicSwapAsk(let data): xdr.append(data.toXDR()) case .createAtomicSwapBid(let data): xdr.append(data.toXDR()) case .createPoll(let data): xdr.append(data.toXDR()) + case .manageOffer(let data): xdr.append(data.toXDR()) + case .createPayment(let data): xdr.append(data.toXDR()) + case .performRedemption(let data): xdr.append(data.toXDR()) } return xdr } - public struct ReviewableRequestResourceCreateSale: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case ReviewableRequestType.createSale.rawValue: + let data = try ReviewableRequestResourceCreateSale(xdrData: &xdrData) + self = .createSale(data) + case ReviewableRequestType.createIssuance.rawValue: + let data = try ReviewableRequestResourceCreateIssuance(xdrData: &xdrData) + self = .createIssuance(data) + case ReviewableRequestType.createWithdraw.rawValue: + let data = try ReviewableRequestResourceCreateWithdraw(xdrData: &xdrData) + self = .createWithdraw(data) + case ReviewableRequestType.createAtomicSwapAsk.rawValue: + let data = try ReviewableRequestResourceCreateAtomicSwapAskExt(xdrData: &xdrData) + self = .createAtomicSwapAsk(data) + case ReviewableRequestType.createAtomicSwapBid.rawValue: + let data = try ReviewableRequestResourceCreateAtomicSwapBidExt(xdrData: &xdrData) + self = .createAtomicSwapBid(data) + case ReviewableRequestType.createPoll.rawValue: + let data = try ReviewableRequestResourceCreatePoll(xdrData: &xdrData) + self = .createPoll(data) + case ReviewableRequestType.manageOffer.rawValue: + let data = try ReviewableRequestResourceManageOffer(xdrData: &xdrData) + self = .manageOffer(data) + case ReviewableRequestType.createPayment.rawValue: + let data = try ReviewableRequestResourceCreatePayment(xdrData: &xdrData) + self = .createPayment(data) + case ReviewableRequestType.performRedemption.rawValue: + let data = try ReviewableRequestResourcePerformRedemption(xdrData: &xdrData) + self = .performRedemption(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct ReviewableRequestResourceCreateSale: XDRCodable { public var type: Uint64 public var ext: EmptyExt @@ -151,8 +245,13 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.type = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct ReviewableRequestResourceCreateIssuance: XDREncodable { + public struct ReviewableRequestResourceCreateIssuance: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -177,8 +276,14 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct ReviewableRequestResourceCreateWithdraw: XDREncodable { + public struct ReviewableRequestResourceCreateWithdraw: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -203,6 +308,12 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } public enum ReviewableRequestResourceCreateAtomicSwapAskExt: XDRDiscriminatedUnion { case emptyVersion() @@ -228,7 +339,20 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } - public struct ReviewableRequestResourceCreateAtomicSwapAskExtCreateAtomicSwapAsk: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.atomicSwapReturning.rawValue: + let data = try ReviewableRequestResourceCreateAtomicSwapAskExtCreateAtomicSwapAsk(xdrData: &xdrData) + self = .atomicSwapReturning(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct ReviewableRequestResourceCreateAtomicSwapAskExtCreateAtomicSwapAsk: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -253,6 +377,12 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } public enum ReviewableRequestResourceCreateAtomicSwapBidExt: XDRDiscriminatedUnion { @@ -279,7 +409,20 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } - public struct ReviewableRequestResourceCreateAtomicSwapBidExtCreateAtomicSwapBid: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.atomicSwapReturning.rawValue: + let data = try ReviewableRequestResourceCreateAtomicSwapBidExtCreateAtomicSwapBid(xdrData: &xdrData) + self = .atomicSwapReturning(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct ReviewableRequestResourceCreateAtomicSwapBidExtCreateAtomicSwapBid: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -304,9 +447,15 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } - public struct ReviewableRequestResourceCreatePoll: XDREncodable { + public struct ReviewableRequestResourceCreatePoll: XDRCodable { public var permissionType: Uint32 public var ext: EmptyExt @@ -327,5 +476,131 @@ public enum ReviewableRequestResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.permissionType = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } + public struct ReviewableRequestResourceManageOffer: XDRCodable { + public var baseAssetType: Uint64 + public var quoteAssetType: Uint64 + public var baseAssetCode: AssetCode + public var quoteAssetCode: AssetCode + public var isBuy: Bool + public var manageAction: Uint32 + public var orderBookID: Uint64 + public var ext: EmptyExt + + public init( + baseAssetType: Uint64, + quoteAssetType: Uint64, + baseAssetCode: AssetCode, + quoteAssetCode: AssetCode, + isBuy: Bool, + manageAction: Uint32, + orderBookID: Uint64, + ext: EmptyExt) { + + self.baseAssetType = baseAssetType + self.quoteAssetType = quoteAssetType + self.baseAssetCode = baseAssetCode + self.quoteAssetCode = quoteAssetCode + self.isBuy = isBuy + self.manageAction = manageAction + self.orderBookID = orderBookID + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.baseAssetType.toXDR()) + xdr.append(self.quoteAssetType.toXDR()) + xdr.append(self.baseAssetCode.toXDR()) + xdr.append(self.quoteAssetCode.toXDR()) + xdr.append(self.isBuy.toXDR()) + xdr.append(self.manageAction.toXDR()) + xdr.append(self.orderBookID.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.baseAssetType = try Uint64(xdrData: &xdrData) + self.quoteAssetType = try Uint64(xdrData: &xdrData) + self.baseAssetCode = try AssetCode(xdrData: &xdrData) + self.quoteAssetCode = try AssetCode(xdrData: &xdrData) + self.isBuy = try Bool(xdrData: &xdrData) + self.manageAction = try Uint32(xdrData: &xdrData) + self.orderBookID = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } + public struct ReviewableRequestResourceCreatePayment: XDRCodable { + public var assetCode: AssetCode + public var assetType: Uint64 + public var ext: EmptyExt + + public init( + assetCode: AssetCode, + assetType: Uint64, + ext: EmptyExt) { + + self.assetCode = assetCode + self.assetType = assetType + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.assetCode.toXDR()) + xdr.append(self.assetType.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } + public struct ReviewableRequestResourcePerformRedemption: XDRCodable { + public var assetCode: AssetCode + public var assetType: Uint64 + public var ext: EmptyExt + + public init( + assetCode: AssetCode, + assetType: Uint64, + ext: EmptyExt) { + + self.assetCode = assetCode + self.assetType = assetType + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.assetCode.toXDR()) + xdr.append(self.assetType.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } diff --git a/Sources/TokenDWallet/Xdr/ReviewableRequestType.swift b/Sources/TokenDWallet/Xdr/ReviewableRequestType.swift index 53e9bbb..839e818 100644 --- a/Sources/TokenDWallet/Xdr/ReviewableRequestType.swift +++ b/Sources/TokenDWallet/Xdr/ReviewableRequestType.swift @@ -24,7 +24,10 @@ import Foundation // CREATE_POLL = 14, // CREATE_ATOMIC_SWAP_ASK = 16, // CREATE_ATOMIC_SWAP_BID = 17, -// KYC_RECOVERY = 18 +// KYC_RECOVERY = 18, +// MANAGE_OFFER = 19, +// CREATE_PAYMENT = 20, +// PERFORM_REDEMPTION = 21 // }; // =========================================================================== @@ -47,4 +50,7 @@ public enum ReviewableRequestType: Int32, XDREnum { case createAtomicSwapAsk = 16 case createAtomicSwapBid = 17 case kycRecovery = 18 + case manageOffer = 19 + case createPayment = 20 + case performRedemption = 21 } diff --git a/Sources/TokenDWallet/Xdr/SCPBallot.swift b/Sources/TokenDWallet/Xdr/SCPBallot.swift index 6faf75b..ac43b8c 100644 --- a/Sources/TokenDWallet/Xdr/SCPBallot.swift +++ b/Sources/TokenDWallet/Xdr/SCPBallot.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct SCPBallot: XDREncodable { +public struct SCPBallot: XDRCodable { public var counter: Uint32 public var value: Value @@ -32,4 +32,9 @@ public struct SCPBallot: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.counter = try Uint32(xdrData: &xdrData) + self.value = try Value(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/SCPEnvelope.swift b/Sources/TokenDWallet/Xdr/SCPEnvelope.swift index 100db37..c9799f3 100644 --- a/Sources/TokenDWallet/Xdr/SCPEnvelope.swift +++ b/Sources/TokenDWallet/Xdr/SCPEnvelope.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct SCPEnvelope: XDREncodable { +public struct SCPEnvelope: XDRCodable { public var statement: SCPStatement public var signature: Signature @@ -32,4 +32,9 @@ public struct SCPEnvelope: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.statement = try SCPStatement(xdrData: &xdrData) + self.signature = try Signature(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/SCPHistoryEntry.swift b/Sources/TokenDWallet/Xdr/SCPHistoryEntry.swift index 36a3100..280d385 100644 --- a/Sources/TokenDWallet/Xdr/SCPHistoryEntry.swift +++ b/Sources/TokenDWallet/Xdr/SCPHistoryEntry.swift @@ -32,4 +32,16 @@ public enum SCPHistoryEntry: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: + let data = try SCPHistoryEntryV0(xdrData: &xdrData) + self = .emptyVersion(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/SCPHistoryEntryV0.swift b/Sources/TokenDWallet/Xdr/SCPHistoryEntryV0.swift index 379f989..99f49a3 100644 --- a/Sources/TokenDWallet/Xdr/SCPHistoryEntryV0.swift +++ b/Sources/TokenDWallet/Xdr/SCPHistoryEntryV0.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct SCPHistoryEntryV0: XDREncodable { +public struct SCPHistoryEntryV0: XDRCodable { public var quorumSets: [SCPQuorumSet] public var ledgerMessages: LedgerSCPMessages @@ -32,4 +32,13 @@ public struct SCPHistoryEntryV0: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + let lengthquorumSets = try Int32(xdrData: &xdrData) + self.quorumSets = [SCPQuorumSet]() + for _ in 1...lengthquorumSets { + self.quorumSets.append(try SCPQuorumSet(xdrData: &xdrData)) + } + self.ledgerMessages = try LedgerSCPMessages(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/SCPNomination.swift b/Sources/TokenDWallet/Xdr/SCPNomination.swift index d75c66b..e662e46 100644 --- a/Sources/TokenDWallet/Xdr/SCPNomination.swift +++ b/Sources/TokenDWallet/Xdr/SCPNomination.swift @@ -13,7 +13,7 @@ import Foundation // }; // =========================================================================== -public struct SCPNomination: XDREncodable { +public struct SCPNomination: XDRCodable { public var quorumSetHash: Hash public var votes: [Value] public var accepted: [Value] @@ -37,4 +37,18 @@ public struct SCPNomination: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.quorumSetHash = try Hash(xdrData: &xdrData) + let lengthvotes = try Int32(xdrData: &xdrData) + self.votes = [Value]() + for _ in 1...lengthvotes { + self.votes.append(try Value(xdrData: &xdrData)) + } + let lengthaccepted = try Int32(xdrData: &xdrData) + self.accepted = [Value]() + for _ in 1...lengthaccepted { + self.accepted.append(try Value(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/SCPQuorumSet.swift b/Sources/TokenDWallet/Xdr/SCPQuorumSet.swift index 7d6204d..961d746 100644 --- a/Sources/TokenDWallet/Xdr/SCPQuorumSet.swift +++ b/Sources/TokenDWallet/Xdr/SCPQuorumSet.swift @@ -13,7 +13,7 @@ import Foundation // }; // =========================================================================== -public struct SCPQuorumSet: XDREncodable { +public struct SCPQuorumSet: XDRCodable { public var threshold: Uint32 public var validators: [PublicKey] public var innerSets: [SCPQuorumSet] @@ -37,4 +37,18 @@ public struct SCPQuorumSet: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.threshold = try Uint32(xdrData: &xdrData) + let lengthvalidators = try Int32(xdrData: &xdrData) + self.validators = [PublicKey]() + for _ in 1...lengthvalidators { + self.validators.append(try PublicKey(xdrData: &xdrData)) + } + let lengthinnerSets = try Int32(xdrData: &xdrData) + self.innerSets = [SCPQuorumSet]() + for _ in 1...lengthinnerSets { + self.innerSets.append(try SCPQuorumSet(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/SCPStatement.swift b/Sources/TokenDWallet/Xdr/SCPStatement.swift index d5a2fb8..0bdcc0c 100644 --- a/Sources/TokenDWallet/Xdr/SCPStatement.swift +++ b/Sources/TokenDWallet/Xdr/SCPStatement.swift @@ -45,7 +45,7 @@ import Foundation // }; // =========================================================================== -public struct SCPStatement: XDREncodable { +public struct SCPStatement: XDRCodable { public var nodeID: NodeID public var slotIndex: Uint64 public var pledges: SCPStatementPledges @@ -70,6 +70,12 @@ public struct SCPStatement: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.nodeID = try NodeID(xdrData: &xdrData) + self.slotIndex = try Uint64(xdrData: &xdrData) + self.pledges = try SCPStatementPledges(xdrData: &xdrData) + } + public enum SCPStatementPledges: XDRDiscriminatedUnion { case prepare(SCPStatementPrepare) case confirm(SCPStatementConfirm) @@ -100,7 +106,28 @@ public struct SCPStatement: XDREncodable { return xdr } - public struct SCPStatementPrepare: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case SCPStatementType.prepare.rawValue: + let data = try SCPStatementPrepare(xdrData: &xdrData) + self = .prepare(data) + case SCPStatementType.confirm.rawValue: + let data = try SCPStatementConfirm(xdrData: &xdrData) + self = .confirm(data) + case SCPStatementType.externalize.rawValue: + let data = try SCPStatementExternalize(xdrData: &xdrData) + self = .externalize(data) + case SCPStatementType.nominate.rawValue: + let data = try SCPNomination(xdrData: &xdrData) + self = .nominate(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct SCPStatementPrepare: XDRCodable { public var quorumSetHash: Hash public var ballot: SCPBallot public var prepared: SCPBallot? @@ -137,8 +164,25 @@ public struct SCPStatement: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.quorumSetHash = try Hash(xdrData: &xdrData) + self.ballot = try SCPBallot(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.prepared = try SCPBallot(xdrData: &xdrData) + } else { + self.prepared = nil + } + if (try Bool(xdrData: &xdrData)) { + self.preparedPrime = try SCPBallot(xdrData: &xdrData) + } else { + self.preparedPrime = nil + } + self.nC = try Uint32(xdrData: &xdrData) + self.nH = try Uint32(xdrData: &xdrData) + } + } - public struct SCPStatementConfirm: XDREncodable { + public struct SCPStatementConfirm: XDRCodable { public var ballot: SCPBallot public var nPrepared: Uint32 public var nCommit: Uint32 @@ -171,8 +215,16 @@ public struct SCPStatement: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ballot = try SCPBallot(xdrData: &xdrData) + self.nPrepared = try Uint32(xdrData: &xdrData) + self.nCommit = try Uint32(xdrData: &xdrData) + self.nH = try Uint32(xdrData: &xdrData) + self.quorumSetHash = try Hash(xdrData: &xdrData) + } + } - public struct SCPStatementExternalize: XDREncodable { + public struct SCPStatementExternalize: XDRCodable { public var commit: SCPBallot public var nH: Uint32 public var commitQuorumSetHash: Hash @@ -197,6 +249,12 @@ public struct SCPStatement: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.commit = try SCPBallot(xdrData: &xdrData) + self.nH = try Uint32(xdrData: &xdrData) + self.commitQuorumSetHash = try Hash(xdrData: &xdrData) + } + } } } diff --git a/Sources/TokenDWallet/Xdr/SaleCanceled.swift b/Sources/TokenDWallet/Xdr/SaleCanceled.swift index 262caac..568dddf 100644 --- a/Sources/TokenDWallet/Xdr/SaleCanceled.swift +++ b/Sources/TokenDWallet/Xdr/SaleCanceled.swift @@ -17,7 +17,7 @@ import Foundation // }; // =========================================================================== -public struct SaleCanceled: XDREncodable { +public struct SaleCanceled: XDRCodable { public var ext: SaleCanceledExt public init( @@ -34,6 +34,10 @@ public struct SaleCanceled: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try SaleCanceledExt(xdrData: &xdrData) + } + public enum SaleCanceledExt: XDRDiscriminatedUnion { case emptyVersion() @@ -55,5 +59,15 @@ public struct SaleCanceled: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleCreationRequest.swift b/Sources/TokenDWallet/Xdr/SaleCreationRequest.swift index a4fea01..0f9fe3b 100644 --- a/Sources/TokenDWallet/Xdr/SaleCreationRequest.swift +++ b/Sources/TokenDWallet/Xdr/SaleCreationRequest.swift @@ -7,11 +7,8 @@ import Foundation // //: SaleCreationRequest is used to create a sale with provided parameters // struct SaleCreationRequest -// { -// //: Type of sale -// //: 1: basic sale -// //: 2: crowdfunding sale -// //: 3: fixed price sale +// { +// //: Some custom sale type that can be used while setting account rules // uint64 saleType; // //: Asset code of an asset to sell on sale // AssetCode baseAsset; // asset for which sale will be performed @@ -29,7 +26,7 @@ import Foundation // longstring creatorDetails; // details set by requester // //: Parameters specific to a particular sale type // SaleTypeExt saleTypeExt; -// //: +// //: // uint64 requiredBaseAssetForHardCap; // //: Used to keep track of rejected requests updates. `SequenceNumber` increases after each rejected SaleCreationRequest update. // uint32 sequenceNumber; @@ -42,14 +39,14 @@ import Foundation // case EMPTY_VERSION: // void; // case ADD_SALE_WHITELISTS: -// //: array of rules that define participation rules. One global rule must be specified. +// //: array of rules that define participation rules. One global rule must be specified. // CreateAccountSaleRuleData saleRules<>; // } // ext; // }; // =========================================================================== -public struct SaleCreationRequest: XDREncodable { +public struct SaleCreationRequest: XDRCodable { public var saleType: Uint64 public var baseAsset: AssetCode public var defaultQuoteAsset: AssetCode @@ -114,6 +111,26 @@ public struct SaleCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleType = try Uint64(xdrData: &xdrData) + self.baseAsset = try AssetCode(xdrData: &xdrData) + self.defaultQuoteAsset = try AssetCode(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + self.softCap = try Uint64(xdrData: &xdrData) + self.hardCap = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.saleTypeExt = try SaleTypeExt(xdrData: &xdrData) + self.requiredBaseAssetForHardCap = try Uint64(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + let lengthquoteAssets = try Int32(xdrData: &xdrData) + self.quoteAssets = [SaleCreationRequestQuoteAsset]() + for _ in 1...lengthquoteAssets { + self.quoteAssets.append(try SaleCreationRequestQuoteAsset(xdrData: &xdrData)) + } + self.ext = try SaleCreationRequestExt(xdrData: &xdrData) + } + public enum SaleCreationRequestExt: XDRDiscriminatedUnion { case emptyVersion() case addSaleWhitelists([CreateAccountSaleRuleData]) @@ -138,5 +155,22 @@ public struct SaleCreationRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.addSaleWhitelists.rawValue: + let lengthsaleRules = try Int32(xdrData: &xdrData) + var data = [CreateAccountSaleRuleData]() + for _ in 1...lengthsaleRules { + data.append(try CreateAccountSaleRuleData(xdrData: &xdrData)) + } + self = .addSaleWhitelists(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleCreationRequestQuoteAsset.swift b/Sources/TokenDWallet/Xdr/SaleCreationRequestQuoteAsset.swift index 767f8e1..6fbebf3 100644 --- a/Sources/TokenDWallet/Xdr/SaleCreationRequestQuoteAsset.swift +++ b/Sources/TokenDWallet/Xdr/SaleCreationRequestQuoteAsset.swift @@ -7,7 +7,7 @@ import Foundation // //: SaleCreationRequestQuoteAsset is a structure that contains an asset code with price // struct SaleCreationRequestQuoteAsset { -// //: AssetCode of quote asset +// //: AssetCode of quote asset // AssetCode quoteAsset; // asset in which participation will be accepted // //: Price of sale base asset in relation to a quote asset // uint64 price; // price for 1 baseAsset in relation to a quote asset @@ -21,7 +21,7 @@ import Foundation // }; // =========================================================================== -public struct SaleCreationRequestQuoteAsset: XDREncodable { +public struct SaleCreationRequestQuoteAsset: XDRCodable { public var quoteAsset: AssetCode public var price: Uint64 public var ext: SaleCreationRequestQuoteAssetExt @@ -46,6 +46,12 @@ public struct SaleCreationRequestQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.price = try Uint64(xdrData: &xdrData) + self.ext = try SaleCreationRequestQuoteAssetExt(xdrData: &xdrData) + } + public enum SaleCreationRequestQuoteAssetExt: XDRDiscriminatedUnion { case emptyVersion() @@ -67,5 +73,15 @@ public struct SaleCreationRequestQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleEntry.swift b/Sources/TokenDWallet/Xdr/SaleEntry.swift index 21ab502..92e9deb 100644 --- a/Sources/TokenDWallet/Xdr/SaleEntry.swift +++ b/Sources/TokenDWallet/Xdr/SaleEntry.swift @@ -35,7 +35,7 @@ import Foundation // }; // =========================================================================== -public struct SaleEntry: XDREncodable { +public struct SaleEntry: XDRCodable { public var saleID: Uint64 public var saleType: Uint64 public var ownerID: AccountID @@ -112,6 +112,29 @@ public struct SaleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.saleType = try Uint64(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + self.baseAsset = try AssetCode(xdrData: &xdrData) + self.startTime = try Uint64(xdrData: &xdrData) + self.endTime = try Uint64(xdrData: &xdrData) + self.defaultQuoteAsset = try AssetCode(xdrData: &xdrData) + self.softCap = try Uint64(xdrData: &xdrData) + self.hardCap = try Uint64(xdrData: &xdrData) + self.currentCapInBase = try Uint64(xdrData: &xdrData) + self.maxAmountToBeSold = try Uint64(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + let lengthquoteAssets = try Int32(xdrData: &xdrData) + self.quoteAssets = [SaleQuoteAsset]() + for _ in 1...lengthquoteAssets { + self.quoteAssets.append(try SaleQuoteAsset(xdrData: &xdrData)) + } + self.baseBalance = try BalanceID(xdrData: &xdrData) + self.saleTypeExt = try SaleTypeExt(xdrData: &xdrData) + self.ext = try SaleEntryExt(xdrData: &xdrData) + } + public enum SaleEntryExt: XDRDiscriminatedUnion { case emptyVersion() case addSaleWhitelists() @@ -136,5 +159,16 @@ public struct SaleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.addSaleWhitelists.rawValue: self = .addSaleWhitelists() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleExtended.swift b/Sources/TokenDWallet/Xdr/SaleExtended.swift index eeffc5f..ebfd3cd 100644 --- a/Sources/TokenDWallet/Xdr/SaleExtended.swift +++ b/Sources/TokenDWallet/Xdr/SaleExtended.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct SaleExtended: XDREncodable { +public struct SaleExtended: XDRCodable { public var saleID: Uint64 public var ext: SaleExtendedExt @@ -41,6 +41,11 @@ public struct SaleExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.ext = try SaleExtendedExt(xdrData: &xdrData) + } + public enum SaleExtendedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -62,5 +67,15 @@ public struct SaleExtended: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleQuoteAsset.swift b/Sources/TokenDWallet/Xdr/SaleQuoteAsset.swift index e4bd7c0..ef2ca33 100644 --- a/Sources/TokenDWallet/Xdr/SaleQuoteAsset.swift +++ b/Sources/TokenDWallet/Xdr/SaleQuoteAsset.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct SaleQuoteAsset: XDREncodable { +public struct SaleQuoteAsset: XDRCodable { public var quoteAsset: AssetCode public var price: Uint64 public var quoteBalance: BalanceID @@ -52,6 +52,14 @@ public struct SaleQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.quoteAsset = try AssetCode(xdrData: &xdrData) + self.price = try Uint64(xdrData: &xdrData) + self.quoteBalance = try BalanceID(xdrData: &xdrData) + self.currentCap = try Uint64(xdrData: &xdrData) + self.ext = try SaleQuoteAssetExt(xdrData: &xdrData) + } + public enum SaleQuoteAssetExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +81,15 @@ public struct SaleQuoteAsset: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleType.swift b/Sources/TokenDWallet/Xdr/SaleType.swift index cec7f40..e1d3e0c 100644 --- a/Sources/TokenDWallet/Xdr/SaleType.swift +++ b/Sources/TokenDWallet/Xdr/SaleType.swift @@ -9,7 +9,9 @@ import Foundation // BASIC_SALE = 1, // sale creator specifies price for each quote asset // CROWD_FUNDING = 2, // sale creator does not specify price, // // price is defined on sale close based on amount of base asset to be sold and amount of quote assets collected -// FIXED_PRICE=3 +// FIXED_PRICE=3, +// +// IMMEDIATE=4 // }; // =========================================================================== @@ -17,4 +19,5 @@ public enum SaleType: Int32, XDREnum { case basicSale = 1 case crowdFunding = 2 case fixedPrice = 3 + case immediate = 4 } diff --git a/Sources/TokenDWallet/Xdr/SaleTypeExt.swift b/Sources/TokenDWallet/Xdr/SaleTypeExt.swift index 4efa5d8..38d868f 100644 --- a/Sources/TokenDWallet/Xdr/SaleTypeExt.swift +++ b/Sources/TokenDWallet/Xdr/SaleTypeExt.swift @@ -13,6 +13,8 @@ import Foundation // CrowdFundingSale crowdFundingSale; // case FIXED_PRICE: // FixedPriceSale fixedPriceSale; +// case IMMEDIATE: +// ImmediateSale immediateSale; // }; // =========================================================================== @@ -20,12 +22,14 @@ public enum SaleTypeExt: XDRDiscriminatedUnion { case basicSale(BasicSale) case crowdFunding(CrowdFundingSale) case fixedPrice(FixedPriceSale) + case immediate(ImmediateSale) public var discriminant: Int32 { switch self { case .basicSale: return SaleType.basicSale.rawValue case .crowdFunding: return SaleType.crowdFunding.rawValue case .fixedPrice: return SaleType.fixedPrice.rawValue + case .immediate: return SaleType.immediate.rawValue } } @@ -38,8 +42,30 @@ public enum SaleTypeExt: XDRDiscriminatedUnion { case .basicSale(let data): xdr.append(data.toXDR()) case .crowdFunding(let data): xdr.append(data.toXDR()) case .fixedPrice(let data): xdr.append(data.toXDR()) + case .immediate(let data): xdr.append(data.toXDR()) } return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case SaleType.basicSale.rawValue: + let data = try BasicSale(xdrData: &xdrData) + self = .basicSale(data) + case SaleType.crowdFunding.rawValue: + let data = try CrowdFundingSale(xdrData: &xdrData) + self = .crowdFunding(data) + case SaleType.fixedPrice.rawValue: + let data = try FixedPriceSale(xdrData: &xdrData) + self = .fixedPrice(data) + case SaleType.immediate.rawValue: + let data = try ImmediateSale(xdrData: &xdrData) + self = .immediate(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/SaleUpdated.swift b/Sources/TokenDWallet/Xdr/SaleUpdated.swift index 05dc233..cabe6df 100644 --- a/Sources/TokenDWallet/Xdr/SaleUpdated.swift +++ b/Sources/TokenDWallet/Xdr/SaleUpdated.swift @@ -17,7 +17,7 @@ import Foundation // }; // =========================================================================== -public struct SaleUpdated: XDREncodable { +public struct SaleUpdated: XDRCodable { public var ext: SaleUpdatedExt public init( @@ -34,6 +34,10 @@ public struct SaleUpdated: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try SaleUpdatedExt(xdrData: &xdrData) + } + public enum SaleUpdatedExt: XDRDiscriminatedUnion { case emptyVersion() @@ -55,5 +59,15 @@ public struct SaleUpdated: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SetFeesOp.swift b/Sources/TokenDWallet/Xdr/SetFeesOp.swift index b79832f..2a44bda 100644 --- a/Sources/TokenDWallet/Xdr/SetFeesOp.swift +++ b/Sources/TokenDWallet/Xdr/SetFeesOp.swift @@ -22,7 +22,7 @@ import Foundation // }; // =========================================================================== -public struct SetFeesOp: XDREncodable { +public struct SetFeesOp: XDRCodable { public var fee: FeeEntry? public var isDelete: Bool public var ext: SetFeesOpExt @@ -47,6 +47,16 @@ public struct SetFeesOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + if (try Bool(xdrData: &xdrData)) { + self.fee = try FeeEntry(xdrData: &xdrData) + } else { + self.fee = nil + } + self.isDelete = try Bool(xdrData: &xdrData) + self.ext = try SetFeesOpExt(xdrData: &xdrData) + } + public enum SetFeesOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -68,5 +78,15 @@ public struct SetFeesOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SetFeesResult.swift b/Sources/TokenDWallet/Xdr/SetFeesResult.swift index baef001..56a91d7 100644 --- a/Sources/TokenDWallet/Xdr/SetFeesResult.swift +++ b/Sources/TokenDWallet/Xdr/SetFeesResult.swift @@ -43,7 +43,19 @@ public enum SetFeesResult: XDRDiscriminatedUnion { return xdr } - public struct SetFeesResultSuccess: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case SetFeesResultCode.success.rawValue: + let data = try SetFeesResultSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct SetFeesResultSuccess: XDRCodable { public var ext: SetFeesResultSuccessExt public init( @@ -60,6 +72,10 @@ public enum SetFeesResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try SetFeesResultSuccessExt(xdrData: &xdrData) + } + public enum SetFeesResultSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -81,6 +97,16 @@ public enum SetFeesResult: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } } diff --git a/Sources/TokenDWallet/Xdr/SignerEntry.swift b/Sources/TokenDWallet/Xdr/SignerEntry.swift index 6bd79df..dee0854 100644 --- a/Sources/TokenDWallet/Xdr/SignerEntry.swift +++ b/Sources/TokenDWallet/Xdr/SignerEntry.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct SignerEntry: XDREncodable { +public struct SignerEntry: XDRCodable { public var pubKey: PublicKey public var accountID: AccountID public var weight: Uint32 @@ -68,6 +68,16 @@ public struct SignerEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.pubKey = try PublicKey(xdrData: &xdrData) + self.accountID = try AccountID(xdrData: &xdrData) + self.weight = try Uint32(xdrData: &xdrData) + self.identity = try Uint32(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try SignerEntryExt(xdrData: &xdrData) + } + public enum SignerEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -89,5 +99,15 @@ public struct SignerEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SignerRoleEntry.swift b/Sources/TokenDWallet/Xdr/SignerRoleEntry.swift index 3bfd57b..712ff74 100644 --- a/Sources/TokenDWallet/Xdr/SignerRoleEntry.swift +++ b/Sources/TokenDWallet/Xdr/SignerRoleEntry.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct SignerRoleEntry: XDREncodable { +public struct SignerRoleEntry: XDRCodable { public var id: Uint64 public var ruleIDs: [Uint64] public var ownerID: AccountID @@ -57,6 +57,18 @@ public struct SignerRoleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.ownerID = try AccountID(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try SignerRoleEntryExt(xdrData: &xdrData) + } + public enum SignerRoleEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -78,5 +90,15 @@ public struct SignerRoleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SignerRuleAction.swift b/Sources/TokenDWallet/Xdr/SignerRuleAction.swift index f62df72..01fedf7 100644 --- a/Sources/TokenDWallet/Xdr/SignerRuleAction.swift +++ b/Sources/TokenDWallet/Xdr/SignerRuleAction.swift @@ -25,7 +25,9 @@ import Foundation // CLOSE = 15, // UPDATE_END_TIME = 16, // CREATE_WITH_TASKS = 17, -// CREATE_FOR_OTHER_WITH_TASKS = 18 +// CREATE_FOR_OTHER_WITH_TASKS = 18, +// REMOVE_FOR_OTHER = 19, +// EXCHANGE = 20 // }; // =========================================================================== @@ -48,4 +50,6 @@ public enum SignerRuleAction: Int32, XDREnum { case updateEndTime = 16 case createWithTasks = 17 case createForOtherWithTasks = 18 + case removeForOther = 19 + case exchange = 20 } diff --git a/Sources/TokenDWallet/Xdr/SignerRuleEntry.swift b/Sources/TokenDWallet/Xdr/SignerRuleEntry.swift index fb265bf..5f01201 100644 --- a/Sources/TokenDWallet/Xdr/SignerRuleEntry.swift +++ b/Sources/TokenDWallet/Xdr/SignerRuleEntry.swift @@ -29,7 +29,7 @@ import Foundation // }; // =========================================================================== -public struct SignerRuleEntry: XDREncodable { +public struct SignerRuleEntry: XDRCodable { public var id: Uint64 public var resource: SignerRuleResource public var action: SignerRuleAction @@ -74,6 +74,17 @@ public struct SignerRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.resource = try SignerRuleResource(xdrData: &xdrData) + self.action = try SignerRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.isDefault = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ownerID = try AccountID(xdrData: &xdrData) + self.ext = try SignerRuleEntryExt(xdrData: &xdrData) + } + public enum SignerRuleEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -95,5 +106,15 @@ public struct SignerRuleEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SignerRuleResource.swift b/Sources/TokenDWallet/Xdr/SignerRuleResource.swift index 6adeb9b..f856dfa 100644 --- a/Sources/TokenDWallet/Xdr/SignerRuleResource.swift +++ b/Sources/TokenDWallet/Xdr/SignerRuleResource.swift @@ -156,6 +156,17 @@ import Foundation // EmptyExt ext; // } accountSpecificRule; // } accountSpecificRuleExt; +// case SWAP: +// struct +// { +// //: code of the asset +// AssetCode assetCode; +// //: type of the asset +// uint64 assetType; +// +// //: reserved for future extension +// EmptyExt ext; +// } swap; // default: // //: reserved for future extension // EmptyExt ext; @@ -177,6 +188,7 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { case vote(SignerRuleResourceVote) case initiateKycRecovery(SignerRuleResourceInitiateKYCRecovery) case accountSpecificRule(SignerRuleResourceAccountSpecificRuleExt) + case swap(SignerRuleResourceSwap) public var discriminant: Int32 { switch self { @@ -194,6 +206,7 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { case .vote: return LedgerEntryType.vote.rawValue case .initiateKycRecovery: return LedgerEntryType.initiateKycRecovery.rawValue case .accountSpecificRule: return LedgerEntryType.accountSpecificRule.rawValue + case .swap: return LedgerEntryType.swap.rawValue } } @@ -217,11 +230,64 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { case .vote(let data): xdr.append(data.toXDR()) case .initiateKycRecovery(let data): xdr.append(data.toXDR()) case .accountSpecificRule(let data): xdr.append(data.toXDR()) + case .swap(let data): xdr.append(data.toXDR()) } return xdr } - public struct SignerRuleResourceReviewableRequest: XDREncodable { + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerEntryType.reviewableRequest.rawValue: + let data = try SignerRuleResourceReviewableRequest(xdrData: &xdrData) + self = .reviewableRequest(data) + case LedgerEntryType.asset.rawValue: + let data = try SignerRuleResourceAsset(xdrData: &xdrData) + self = .asset(data) + case LedgerEntryType.any.rawValue: self = .any() + case LedgerEntryType.offerEntry.rawValue: + let data = try SignerRuleResourceOffer(xdrData: &xdrData) + self = .offerEntry(data) + case LedgerEntryType.sale.rawValue: + let data = try SignerRuleResourceSale(xdrData: &xdrData) + self = .sale(data) + case LedgerEntryType.atomicSwapAsk.rawValue: + let data = try SignerRuleResourceAtomicSwapAsk(xdrData: &xdrData) + self = .atomicSwapAsk(data) + case LedgerEntryType.signerRule.rawValue: + let data = try SignerRuleResourceSignerRule(xdrData: &xdrData) + self = .signerRule(data) + case LedgerEntryType.signerRole.rawValue: + let data = try SignerRuleResourceSignerRole(xdrData: &xdrData) + self = .signerRole(data) + case LedgerEntryType.signer.rawValue: + let data = try SignerRuleResourceSigner(xdrData: &xdrData) + self = .signer(data) + case LedgerEntryType.keyValue.rawValue: + let data = try SignerRuleResourceKeyValue(xdrData: &xdrData) + self = .keyValue(data) + case LedgerEntryType.poll.rawValue: + let data = try SignerRuleResourcePoll(xdrData: &xdrData) + self = .poll(data) + case LedgerEntryType.vote.rawValue: + let data = try SignerRuleResourceVote(xdrData: &xdrData) + self = .vote(data) + case LedgerEntryType.initiateKycRecovery.rawValue: + let data = try SignerRuleResourceInitiateKYCRecovery(xdrData: &xdrData) + self = .initiateKycRecovery(data) + case LedgerEntryType.accountSpecificRule.rawValue: + let data = try SignerRuleResourceAccountSpecificRuleExt(xdrData: &xdrData) + self = .accountSpecificRule(data) + case LedgerEntryType.swap.rawValue: + let data = try SignerRuleResourceSwap(xdrData: &xdrData) + self = .swap(data) + default: + throw XDRErrors.unknownEnumCase + } + } + public struct SignerRuleResourceReviewableRequest: XDRCodable { public var details: ReviewableRequestResource public var tasksToAdd: Uint64 public var tasksToRemove: Uint64 @@ -254,8 +320,16 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.details = try ReviewableRequestResource(xdrData: &xdrData) + self.tasksToAdd = try Uint64(xdrData: &xdrData) + self.tasksToRemove = try Uint64(xdrData: &xdrData) + self.allTasks = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceAsset: XDREncodable { + public struct SignerRuleResourceAsset: XDRCodable { public var assetCode: AssetCode public var assetType: Uint64 public var ext: EmptyExt @@ -280,8 +354,14 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceOffer: XDREncodable { + public struct SignerRuleResourceOffer: XDRCodable { public var baseAssetType: Uint64 public var quoteAssetType: Uint64 public var baseAssetCode: AssetCode @@ -318,8 +398,17 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.baseAssetType = try Uint64(xdrData: &xdrData) + self.quoteAssetType = try Uint64(xdrData: &xdrData) + self.baseAssetCode = try AssetCode(xdrData: &xdrData) + self.quoteAssetCode = try AssetCode(xdrData: &xdrData) + self.isBuy = try Bool(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceSale: XDREncodable { + public struct SignerRuleResourceSale: XDRCodable { public var saleID: Uint64 public var saleType: Uint64 public var ext: EmptyExt @@ -344,8 +433,14 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.saleType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceAtomicSwapAsk: XDREncodable { + public struct SignerRuleResourceAtomicSwapAsk: XDRCodable { public var assetType: Uint64 public var assetCode: AssetCode public var ext: EmptyExt @@ -370,8 +465,14 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.assetType = try Uint64(xdrData: &xdrData) + self.assetCode = try AssetCode(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceSignerRule: XDREncodable { + public struct SignerRuleResourceSignerRule: XDRCodable { public var isDefault: Bool public var ext: EmptyExt @@ -392,8 +493,13 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.isDefault = try Bool(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceSignerRole: XDREncodable { + public struct SignerRuleResourceSignerRole: XDRCodable { public var roleID: Uint64 public var ext: EmptyExt @@ -414,8 +520,13 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceSigner: XDREncodable { + public struct SignerRuleResourceSigner: XDRCodable { public var roleID: Uint64 public var ext: EmptyExt @@ -436,8 +547,13 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceKeyValue: XDREncodable { + public struct SignerRuleResourceKeyValue: XDRCodable { public var keyPrefix: Longstring public var ext: EmptyExt @@ -458,8 +574,13 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.keyPrefix = try Longstring(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourcePoll: XDREncodable { + public struct SignerRuleResourcePoll: XDRCodable { public var pollID: Uint64 public var permissionType: Uint32 public var ext: EmptyExt @@ -484,8 +605,14 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.permissionType = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceVote: XDREncodable { + public struct SignerRuleResourceVote: XDRCodable { public var pollID: Uint64 public var permissionType: Uint32 public var ext: EmptyExt @@ -510,8 +637,14 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.permissionType = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } - public struct SignerRuleResourceInitiateKYCRecovery: XDREncodable { + public struct SignerRuleResourceInitiateKYCRecovery: XDRCodable { public var roleID: Uint64 public var ext: EmptyExt @@ -532,6 +665,11 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } public enum SignerRuleResourceAccountSpecificRuleExt: XDRDiscriminatedUnion { case emptyVersion() @@ -557,7 +695,20 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } - public struct SignerRuleResourceAccountSpecificRuleExtAccountSpecificRule: XDREncodable { + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + case LedgerVersion.addAccSpecificRuleResource.rawValue: + let data = try SignerRuleResourceAccountSpecificRuleExtAccountSpecificRule(xdrData: &xdrData) + self = .addAccSpecificRuleResource(data) + default: + throw XDRErrors.unknownEnumCase + } + } + + public struct SignerRuleResourceAccountSpecificRuleExtAccountSpecificRule: XDRCodable { public var ledgerKey: LedgerKey public var ext: EmptyExt @@ -578,6 +729,43 @@ public enum SignerRuleResource: XDRDiscriminatedUnion { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerKey = try LedgerKey(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + } } + public struct SignerRuleResourceSwap: XDRCodable { + public var assetCode: AssetCode + public var assetType: Uint64 + public var ext: EmptyExt + + public init( + assetCode: AssetCode, + assetType: Uint64, + ext: EmptyExt) { + + self.assetCode = assetCode + self.assetType = assetType + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.assetCode.toXDR()) + xdr.append(self.assetType.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.assetType = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } + + } } diff --git a/Sources/TokenDWallet/Xdr/SingleChoiceVote.swift b/Sources/TokenDWallet/Xdr/SingleChoiceVote.swift index 3412bec..ef58b08 100644 --- a/Sources/TokenDWallet/Xdr/SingleChoiceVote.swift +++ b/Sources/TokenDWallet/Xdr/SingleChoiceVote.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct SingleChoiceVote: XDREncodable { +public struct SingleChoiceVote: XDRCodable { public var choice: Uint32 public var ext: EmptyExt @@ -32,4 +32,9 @@ public struct SingleChoiceVote: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.choice = try Uint32(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/StampEntry.swift b/Sources/TokenDWallet/Xdr/StampEntry.swift index ead4f93..9a2921a 100644 --- a/Sources/TokenDWallet/Xdr/StampEntry.swift +++ b/Sources/TokenDWallet/Xdr/StampEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct StampEntry: XDREncodable { +public struct StampEntry: XDRCodable { public var ledgerHash: Hash public var licenseHash: Hash public var ext: StampEntryExt @@ -45,6 +45,12 @@ public struct StampEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerHash = try Hash(xdrData: &xdrData) + self.licenseHash = try Hash(xdrData: &xdrData) + self.ext = try StampEntryExt(xdrData: &xdrData) + } + public enum StampEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct StampEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/StampOp.swift b/Sources/TokenDWallet/Xdr/StampOp.swift index c3d7af2..d272a9e 100644 --- a/Sources/TokenDWallet/Xdr/StampOp.swift +++ b/Sources/TokenDWallet/Xdr/StampOp.swift @@ -18,7 +18,7 @@ import Foundation // }; // =========================================================================== -public struct StampOp: XDREncodable { +public struct StampOp: XDRCodable { public var ext: StampOpExt public init( @@ -35,6 +35,10 @@ public struct StampOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ext = try StampOpExt(xdrData: &xdrData) + } + public enum StampOpExt: XDRDiscriminatedUnion { case emptyVersion() @@ -56,5 +60,15 @@ public struct StampOp: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/StampResult.swift b/Sources/TokenDWallet/Xdr/StampResult.swift index d12d84f..f9a7427 100644 --- a/Sources/TokenDWallet/Xdr/StampResult.swift +++ b/Sources/TokenDWallet/Xdr/StampResult.swift @@ -35,4 +35,16 @@ public enum StampResult: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case StampResultCode.success.rawValue: + let data = try StampSuccess(xdrData: &xdrData) + self = .success(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/StampSuccess.swift b/Sources/TokenDWallet/Xdr/StampSuccess.swift index 53d29d5..fa27a19 100644 --- a/Sources/TokenDWallet/Xdr/StampSuccess.swift +++ b/Sources/TokenDWallet/Xdr/StampSuccess.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct StampSuccess: XDREncodable { +public struct StampSuccess: XDRCodable { public var ledgerHash: Hash public var licenseHash: Hash public var ext: StampSuccessExt @@ -48,6 +48,12 @@ public struct StampSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerHash = try Hash(xdrData: &xdrData) + self.licenseHash = try Hash(xdrData: &xdrData) + self.ext = try StampSuccessExt(xdrData: &xdrData) + } + public enum StampSuccessExt: XDRDiscriminatedUnion { case emptyVersion() @@ -69,5 +75,15 @@ public struct StampSuccess: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/StatisticsEntry.swift b/Sources/TokenDWallet/Xdr/StatisticsEntry.swift index 2db98bf..aa70671 100644 --- a/Sources/TokenDWallet/Xdr/StatisticsEntry.swift +++ b/Sources/TokenDWallet/Xdr/StatisticsEntry.swift @@ -26,7 +26,7 @@ import Foundation // }; // =========================================================================== -public struct StatisticsEntry: XDREncodable { +public struct StatisticsEntry: XDRCodable { public var accountID: AccountID public var dailyOutcome: Uint64 public var weeklyOutcome: Uint64 @@ -67,6 +67,16 @@ public struct StatisticsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.accountID = try AccountID(xdrData: &xdrData) + self.dailyOutcome = try Uint64(xdrData: &xdrData) + self.weeklyOutcome = try Uint64(xdrData: &xdrData) + self.monthlyOutcome = try Uint64(xdrData: &xdrData) + self.annualOutcome = try Uint64(xdrData: &xdrData) + self.updatedAt = try Int64(xdrData: &xdrData) + self.ext = try StatisticsEntryExt(xdrData: &xdrData) + } + public enum StatisticsEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -88,5 +98,15 @@ public struct StatisticsEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/StatisticsV2Entry.swift b/Sources/TokenDWallet/Xdr/StatisticsV2Entry.swift index c1eec5a..0537f2a 100644 --- a/Sources/TokenDWallet/Xdr/StatisticsV2Entry.swift +++ b/Sources/TokenDWallet/Xdr/StatisticsV2Entry.swift @@ -30,7 +30,7 @@ import Foundation // }; // =========================================================================== -public struct StatisticsV2Entry: XDREncodable { +public struct StatisticsV2Entry: XDRCodable { public var id: Uint64 public var accountID: AccountID public var statsOpType: StatsOpType @@ -87,6 +87,20 @@ public struct StatisticsV2Entry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.accountID = try AccountID(xdrData: &xdrData) + self.statsOpType = try StatsOpType(xdrData: &xdrData) + self.assetCode = try AssetCode(xdrData: &xdrData) + self.isConvertNeeded = try Bool(xdrData: &xdrData) + self.dailyOutcome = try Uint64(xdrData: &xdrData) + self.weeklyOutcome = try Uint64(xdrData: &xdrData) + self.monthlyOutcome = try Uint64(xdrData: &xdrData) + self.annualOutcome = try Uint64(xdrData: &xdrData) + self.updatedAt = try Int64(xdrData: &xdrData) + self.ext = try StatisticsV2EntryExt(xdrData: &xdrData) + } + public enum StatisticsV2EntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -108,5 +122,15 @@ public struct StatisticsV2Entry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/StellarMessage.swift b/Sources/TokenDWallet/Xdr/StellarMessage.swift index fb3e2c0..e39fe9a 100644 --- a/Sources/TokenDWallet/Xdr/StellarMessage.swift +++ b/Sources/TokenDWallet/Xdr/StellarMessage.swift @@ -96,4 +96,54 @@ public enum StellarMessage: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case MessageType.errorMsg.rawValue: + let data = try Error(xdrData: &xdrData) + self = .errorMsg(data) + case MessageType.hello.rawValue: + let data = try Hello(xdrData: &xdrData) + self = .hello(data) + case MessageType.auth.rawValue: + let data = try Auth(xdrData: &xdrData) + self = .auth(data) + case MessageType.dontHave.rawValue: + let data = try DontHave(xdrData: &xdrData) + self = .dontHave(data) + case MessageType.getPeers.rawValue: self = .getPeers() + case MessageType.peers.rawValue: + let lengthpeers = try Int32(xdrData: &xdrData) + var data = [PeerAddress]() + for _ in 1...lengthpeers { + data.append(try PeerAddress(xdrData: &xdrData)) + } + self = .peers(data) + case MessageType.getTxSet.rawValue: + let data = try Uint256(xdrData: &xdrData) + self = .getTxSet(data) + case MessageType.txSet.rawValue: + let data = try TransactionSet(xdrData: &xdrData) + self = .txSet(data) + case MessageType.transaction.rawValue: + let data = try TransactionEnvelope(xdrData: &xdrData) + self = .transaction(data) + case MessageType.getScpQuorumset.rawValue: + let data = try Uint256(xdrData: &xdrData) + self = .getScpQuorumset(data) + case MessageType.scpQuorumset.rawValue: + let data = try SCPQuorumSet(xdrData: &xdrData) + self = .scpQuorumset(data) + case MessageType.scpMessage.rawValue: + let data = try SCPEnvelope(xdrData: &xdrData) + self = .scpMessage(data) + case MessageType.getScpState.rawValue: + let data = try Uint32(xdrData: &xdrData) + self = .getScpState(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/StellarValue.swift b/Sources/TokenDWallet/Xdr/StellarValue.swift index 98a46c5..bc303a7 100644 --- a/Sources/TokenDWallet/Xdr/StellarValue.swift +++ b/Sources/TokenDWallet/Xdr/StellarValue.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct StellarValue: XDREncodable { +public struct StellarValue: XDRCodable { public var txSetHash: Hash public var closeTime: Uint64 public var upgrades: [UpgradeType] @@ -56,6 +56,17 @@ public struct StellarValue: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.txSetHash = try Hash(xdrData: &xdrData) + self.closeTime = try Uint64(xdrData: &xdrData) + let lengthupgrades = try Int32(xdrData: &xdrData) + self.upgrades = [UpgradeType]() + for _ in 1...lengthupgrades { + self.upgrades.append(try UpgradeType(xdrData: &xdrData)) + } + self.ext = try StellarValueExt(xdrData: &xdrData) + } + public enum StellarValueExt: XDRDiscriminatedUnion { case emptyVersion() @@ -77,5 +88,15 @@ public struct StellarValue: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/SwapEntry.swift b/Sources/TokenDWallet/Xdr/SwapEntry.swift new file mode 100644 index 0000000..0accb8f --- /dev/null +++ b/Sources/TokenDWallet/Xdr/SwapEntry.swift @@ -0,0 +1,102 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +// === xdr source ============================================================ + +// struct SwapEntry +// { +// uint64 id; +// +// Hash secretHash; +// +// AccountID source; +// BalanceID sourceBalance; +// +// BalanceID destinationBalance; +// +// longstring details; +// +// uint64 amount; +// +// int64 createdAt; +// int64 lockTime; +// +// uint64 fee; +// +// EmptyExt ext; +// }; + +// =========================================================================== +public struct SwapEntry: XDRCodable { + public var id: Uint64 + public var secretHash: Hash + public var source: AccountID + public var sourceBalance: BalanceID + public var destinationBalance: BalanceID + public var details: Longstring + public var amount: Uint64 + public var createdAt: Int64 + public var lockTime: Int64 + public var fee: Uint64 + public var ext: EmptyExt + + public init( + id: Uint64, + secretHash: Hash, + source: AccountID, + sourceBalance: BalanceID, + destinationBalance: BalanceID, + details: Longstring, + amount: Uint64, + createdAt: Int64, + lockTime: Int64, + fee: Uint64, + ext: EmptyExt) { + + self.id = id + self.secretHash = secretHash + self.source = source + self.sourceBalance = sourceBalance + self.destinationBalance = destinationBalance + self.details = details + self.amount = amount + self.createdAt = createdAt + self.lockTime = lockTime + self.fee = fee + self.ext = ext + } + + public func toXDR() -> Data { + var xdr = Data() + + xdr.append(self.id.toXDR()) + xdr.append(self.secretHash.toXDR()) + xdr.append(self.source.toXDR()) + xdr.append(self.sourceBalance.toXDR()) + xdr.append(self.destinationBalance.toXDR()) + xdr.append(self.details.toXDR()) + xdr.append(self.amount.toXDR()) + xdr.append(self.createdAt.toXDR()) + xdr.append(self.lockTime.toXDR()) + xdr.append(self.fee.toXDR()) + xdr.append(self.ext.toXDR()) + + return xdr + } + + public init(xdrData: inout Data) throws { + self.id = try Uint64(xdrData: &xdrData) + self.secretHash = try Hash(xdrData: &xdrData) + self.source = try AccountID(xdrData: &xdrData) + self.sourceBalance = try BalanceID(xdrData: &xdrData) + self.destinationBalance = try BalanceID(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.createdAt = try Int64(xdrData: &xdrData) + self.lockTime = try Int64(xdrData: &xdrData) + self.fee = try Uint64(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } +} diff --git a/Sources/TokenDWallet/Xdr/TasksExt.swift b/Sources/TokenDWallet/Xdr/TasksExt.swift index fe868a2..20cf485 100644 --- a/Sources/TokenDWallet/Xdr/TasksExt.swift +++ b/Sources/TokenDWallet/Xdr/TasksExt.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct TasksExt: XDREncodable { +public struct TasksExt: XDRCodable { public var allTasks: Uint32 public var pendingTasks: Uint32 public var externalDetails: [Longstring] @@ -52,6 +52,17 @@ public struct TasksExt: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.allTasks = try Uint32(xdrData: &xdrData) + self.pendingTasks = try Uint32(xdrData: &xdrData) + let lengthexternalDetails = try Int32(xdrData: &xdrData) + self.externalDetails = [Longstring]() + for _ in 1...lengthexternalDetails { + self.externalDetails.append(try Longstring(xdrData: &xdrData)) + } + self.ext = try TasksExtExt(xdrData: &xdrData) + } + public enum TasksExtExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +84,15 @@ public struct TasksExt: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/TimeBounds.swift b/Sources/TokenDWallet/Xdr/TimeBounds.swift index 88bbbb8..ef8bad2 100644 --- a/Sources/TokenDWallet/Xdr/TimeBounds.swift +++ b/Sources/TokenDWallet/Xdr/TimeBounds.swift @@ -15,7 +15,7 @@ import Foundation // }; // =========================================================================== -public struct TimeBounds: XDREncodable { +public struct TimeBounds: XDRCodable { public var minTime: Uint64 public var maxTime: Uint64 @@ -35,4 +35,9 @@ public struct TimeBounds: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.minTime = try Uint64(xdrData: &xdrData) + self.maxTime = try Uint64(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/Transaction.swift b/Sources/TokenDWallet/Xdr/Transaction.swift index 5d9b0e6..1a4d479 100644 --- a/Sources/TokenDWallet/Xdr/Transaction.swift +++ b/Sources/TokenDWallet/Xdr/Transaction.swift @@ -36,7 +36,7 @@ import Foundation // }; // =========================================================================== -public struct Transaction: XDREncodable { +public struct Transaction: XDRCodable { public var sourceAccount: AccountID public var salt: Salt public var timeBounds: TimeBounds @@ -73,6 +73,19 @@ public struct Transaction: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.sourceAccount = try AccountID(xdrData: &xdrData) + self.salt = try Salt(xdrData: &xdrData) + self.timeBounds = try TimeBounds(xdrData: &xdrData) + self.memo = try Memo(xdrData: &xdrData) + let lengthoperations = try Int32(xdrData: &xdrData) + self.operations = [Operation]() + for _ in 1...lengthoperations { + self.operations.append(try Operation(xdrData: &xdrData)) + } + self.ext = try TransactionExt(xdrData: &xdrData) + } + public enum TransactionExt: XDRDiscriminatedUnion { case emptyVersion() @@ -94,5 +107,15 @@ public struct Transaction: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionEnvelope.swift b/Sources/TokenDWallet/Xdr/TransactionEnvelope.swift index 44cdc9b..8726ec2 100644 --- a/Sources/TokenDWallet/Xdr/TransactionEnvelope.swift +++ b/Sources/TokenDWallet/Xdr/TransactionEnvelope.swift @@ -13,7 +13,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionEnvelope: XDREncodable { +public struct TransactionEnvelope: XDRCodable { public var tx: Transaction public var signatures: [DecoratedSignature] @@ -33,4 +33,13 @@ public struct TransactionEnvelope: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.tx = try Transaction(xdrData: &xdrData) + let lengthsignatures = try Int32(xdrData: &xdrData) + self.signatures = [DecoratedSignature]() + for _ in 1...lengthsignatures { + self.signatures.append(try DecoratedSignature(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionHistoryEntry.swift b/Sources/TokenDWallet/Xdr/TransactionHistoryEntry.swift index b332410..d5e5071 100644 --- a/Sources/TokenDWallet/Xdr/TransactionHistoryEntry.swift +++ b/Sources/TokenDWallet/Xdr/TransactionHistoryEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionHistoryEntry: XDREncodable { +public struct TransactionHistoryEntry: XDRCodable { public var ledgerSeq: Uint32 public var txSet: TransactionSet public var ext: TransactionHistoryEntryExt @@ -45,6 +45,12 @@ public struct TransactionHistoryEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerSeq = try Uint32(xdrData: &xdrData) + self.txSet = try TransactionSet(xdrData: &xdrData) + self.ext = try TransactionHistoryEntryExt(xdrData: &xdrData) + } + public enum TransactionHistoryEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct TransactionHistoryEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionHistoryResultEntry.swift b/Sources/TokenDWallet/Xdr/TransactionHistoryResultEntry.swift index 4c75d9c..ad2297c 100644 --- a/Sources/TokenDWallet/Xdr/TransactionHistoryResultEntry.swift +++ b/Sources/TokenDWallet/Xdr/TransactionHistoryResultEntry.swift @@ -20,7 +20,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionHistoryResultEntry: XDREncodable { +public struct TransactionHistoryResultEntry: XDRCodable { public var ledgerSeq: Uint32 public var txResultSet: TransactionResultSet public var ext: TransactionHistoryResultEntryExt @@ -45,6 +45,12 @@ public struct TransactionHistoryResultEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ledgerSeq = try Uint32(xdrData: &xdrData) + self.txResultSet = try TransactionResultSet(xdrData: &xdrData) + self.ext = try TransactionHistoryResultEntryExt(xdrData: &xdrData) + } + public enum TransactionHistoryResultEntryExt: XDRDiscriminatedUnion { case emptyVersion() @@ -66,5 +72,15 @@ public struct TransactionHistoryResultEntry: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionMeta.swift b/Sources/TokenDWallet/Xdr/TransactionMeta.swift index 7c0973d..80964a1 100644 --- a/Sources/TokenDWallet/Xdr/TransactionMeta.swift +++ b/Sources/TokenDWallet/Xdr/TransactionMeta.swift @@ -32,4 +32,20 @@ public enum TransactionMeta: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: + let lengthoperations = try Int32(xdrData: &xdrData) + var data = [OperationMeta]() + for _ in 1...lengthoperations { + data.append(try OperationMeta(xdrData: &xdrData)) + } + self = .emptyVersion(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionResult.swift b/Sources/TokenDWallet/Xdr/TransactionResult.swift index 8674cfb..3c677b1 100644 --- a/Sources/TokenDWallet/Xdr/TransactionResult.swift +++ b/Sources/TokenDWallet/Xdr/TransactionResult.swift @@ -31,7 +31,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionResult: XDREncodable { +public struct TransactionResult: XDRCodable { public var feeCharged: Int64 public var result: TransactionResultResult public var ext: TransactionResultExt @@ -56,6 +56,12 @@ public struct TransactionResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.feeCharged = try Int64(xdrData: &xdrData) + self.result = try TransactionResultResult(xdrData: &xdrData) + self.ext = try TransactionResultExt(xdrData: &xdrData) + } + public enum TransactionResultResult: XDRDiscriminatedUnion { case txsuccess([OperationResult]) case txfailed([OperationResult]) @@ -83,6 +89,32 @@ public struct TransactionResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case TransactionResultCode.txsuccess.rawValue: + let lengthresults = try Int32(xdrData: &xdrData) + var data = [OperationResult]() + for _ in 1...lengthresults { + data.append(try OperationResult(xdrData: &xdrData)) + } + self = .txsuccess(data) + case TransactionResultCode.txfailed.rawValue: + let lengthresults = try Int32(xdrData: &xdrData) + var data = [OperationResult]() + for _ in 1...lengthresults { + data.append(try OperationResult(xdrData: &xdrData)) + } + self = .txfailed(data) + case TransactionResultCode.txnoRolePermission.rawValue: + let data = try AccountRuleRequirement(xdrData: &xdrData) + self = .txnoRolePermission(data) + default: + throw XDRErrors.unknownEnumCase + } + } + } public enum TransactionResultExt: XDRDiscriminatedUnion { case emptyVersion() @@ -105,5 +137,15 @@ public struct TransactionResult: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionResultPair.swift b/Sources/TokenDWallet/Xdr/TransactionResultPair.swift index 0d1bac8..1aba120 100644 --- a/Sources/TokenDWallet/Xdr/TransactionResultPair.swift +++ b/Sources/TokenDWallet/Xdr/TransactionResultPair.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionResultPair: XDREncodable { +public struct TransactionResultPair: XDRCodable { public var transactionHash: Hash public var result: TransactionResult @@ -32,4 +32,9 @@ public struct TransactionResultPair: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.transactionHash = try Hash(xdrData: &xdrData) + self.result = try TransactionResult(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionResultSet.swift b/Sources/TokenDWallet/Xdr/TransactionResultSet.swift index c8d81a0..5c8d984 100644 --- a/Sources/TokenDWallet/Xdr/TransactionResultSet.swift +++ b/Sources/TokenDWallet/Xdr/TransactionResultSet.swift @@ -11,7 +11,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionResultSet: XDREncodable { +public struct TransactionResultSet: XDRCodable { public var results: [TransactionResultPair] public init( @@ -27,4 +27,12 @@ public struct TransactionResultSet: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + let lengthresults = try Int32(xdrData: &xdrData) + self.results = [TransactionResultPair]() + for _ in 1...lengthresults { + self.results.append(try TransactionResultPair(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/TransactionSet.swift b/Sources/TokenDWallet/Xdr/TransactionSet.swift index 4e0cf6f..f3b2403 100644 --- a/Sources/TokenDWallet/Xdr/TransactionSet.swift +++ b/Sources/TokenDWallet/Xdr/TransactionSet.swift @@ -12,7 +12,7 @@ import Foundation // }; // =========================================================================== -public struct TransactionSet: XDREncodable { +public struct TransactionSet: XDRCodable { public var previousLedgerHash: Hash public var txs: [TransactionEnvelope] @@ -32,4 +32,13 @@ public struct TransactionSet: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.previousLedgerHash = try Hash(xdrData: &xdrData) + let lengthtxs = try Int32(xdrData: &xdrData) + self.txs = [TransactionEnvelope]() + for _ in 1...lengthtxs { + self.txs.append(try TransactionEnvelope(xdrData: &xdrData)) + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateAccountRoleData.swift b/Sources/TokenDWallet/Xdr/UpdateAccountRoleData.swift index 8ea749d..fe1bae9 100644 --- a/Sources/TokenDWallet/Xdr/UpdateAccountRoleData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateAccountRoleData.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateAccountRoleData: XDREncodable { +public struct UpdateAccountRoleData: XDRCodable { public var roleID: Uint64 public var details: Longstring public var ruleIDs: [Uint64] @@ -53,6 +53,17 @@ public struct UpdateAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.ext = try UpdateAccountRoleDataExt(xdrData: &xdrData) + } + public enum UpdateAccountRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +85,15 @@ public struct UpdateAccountRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateAccountRuleData.swift b/Sources/TokenDWallet/Xdr/UpdateAccountRuleData.swift index ae89f2c..58dfafd 100644 --- a/Sources/TokenDWallet/Xdr/UpdateAccountRuleData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateAccountRuleData.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateAccountRuleData: XDREncodable { +public struct UpdateAccountRuleData: XDRCodable { public var ruleID: Uint64 public var resource: AccountRuleResource public var action: AccountRuleAction @@ -65,6 +65,15 @@ public struct UpdateAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.resource = try AccountRuleResource(xdrData: &xdrData) + self.action = try AccountRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try UpdateAccountRuleDataExt(xdrData: &xdrData) + } + public enum UpdateAccountRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -86,5 +95,15 @@ public struct UpdateAccountRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateMaxIssuance.swift b/Sources/TokenDWallet/Xdr/UpdateMaxIssuance.swift index 71e1483..b7cf679 100644 --- a/Sources/TokenDWallet/Xdr/UpdateMaxIssuance.swift +++ b/Sources/TokenDWallet/Xdr/UpdateMaxIssuance.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateMaxIssuance: XDREncodable { +public struct UpdateMaxIssuance: XDRCodable { public var assetCode: AssetCode public var maxIssuanceAmount: Uint64 public var ext: UpdateMaxIssuanceExt @@ -48,6 +48,12 @@ public struct UpdateMaxIssuance: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.assetCode = try AssetCode(xdrData: &xdrData) + self.maxIssuanceAmount = try Uint64(xdrData: &xdrData) + self.ext = try UpdateMaxIssuanceExt(xdrData: &xdrData) + } + public enum UpdateMaxIssuanceExt: XDRDiscriminatedUnion { case emptyVersion() @@ -69,5 +75,15 @@ public struct UpdateMaxIssuance: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdatePollEndTimeData.swift b/Sources/TokenDWallet/Xdr/UpdatePollEndTimeData.swift index 8a17931..9bf1865 100644 --- a/Sources/TokenDWallet/Xdr/UpdatePollEndTimeData.swift +++ b/Sources/TokenDWallet/Xdr/UpdatePollEndTimeData.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct UpdatePollEndTimeData: XDREncodable { +public struct UpdatePollEndTimeData: XDRCodable { public var newEndTime: Uint64 public var ext: UpdatePollEndTimeDataExt @@ -40,6 +40,11 @@ public struct UpdatePollEndTimeData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.newEndTime = try Uint64(xdrData: &xdrData) + self.ext = try UpdatePollEndTimeDataExt(xdrData: &xdrData) + } + public enum UpdatePollEndTimeDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -61,5 +66,15 @@ public struct UpdatePollEndTimeData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateSaleDetailsData.swift b/Sources/TokenDWallet/Xdr/UpdateSaleDetailsData.swift index 4533c75..0be0942 100644 --- a/Sources/TokenDWallet/Xdr/UpdateSaleDetailsData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateSaleDetailsData.swift @@ -24,7 +24,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateSaleDetailsData: XDREncodable { +public struct UpdateSaleDetailsData: XDRCodable { public var requestID: Uint64 public var creatorDetails: Longstring public var allTasks: Uint32? @@ -53,6 +53,17 @@ public struct UpdateSaleDetailsData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.requestID = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + if (try Bool(xdrData: &xdrData)) { + self.allTasks = try Uint32(xdrData: &xdrData) + } else { + self.allTasks = nil + } + self.ext = try UpdateSaleDetailsDataExt(xdrData: &xdrData) + } + public enum UpdateSaleDetailsDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -74,5 +85,15 @@ public struct UpdateSaleDetailsData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateSaleDetailsRequest.swift b/Sources/TokenDWallet/Xdr/UpdateSaleDetailsRequest.swift index b748f4b..3a1190a 100644 --- a/Sources/TokenDWallet/Xdr/UpdateSaleDetailsRequest.swift +++ b/Sources/TokenDWallet/Xdr/UpdateSaleDetailsRequest.swift @@ -23,7 +23,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateSaleDetailsRequest: XDREncodable { +public struct UpdateSaleDetailsRequest: XDRCodable { public var saleID: Uint64 public var creatorDetails: Longstring public var sequenceNumber: Uint32 @@ -52,6 +52,13 @@ public struct UpdateSaleDetailsRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.saleID = try Uint64(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.sequenceNumber = try Uint32(xdrData: &xdrData) + self.ext = try UpdateSaleDetailsRequestExt(xdrData: &xdrData) + } + public enum UpdateSaleDetailsRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -73,5 +80,15 @@ public struct UpdateSaleDetailsRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateSignerData.swift b/Sources/TokenDWallet/Xdr/UpdateSignerData.swift index 2a1a1e8..0ba31ec 100644 --- a/Sources/TokenDWallet/Xdr/UpdateSignerData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateSignerData.swift @@ -27,7 +27,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateSignerData: XDREncodable { +public struct UpdateSignerData: XDRCodable { public var publicKey: PublicKey public var roleID: Uint64 public var weight: Uint32 @@ -63,4 +63,13 @@ public struct UpdateSignerData: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.publicKey = try PublicKey(xdrData: &xdrData) + self.roleID = try Uint64(xdrData: &xdrData) + self.weight = try Uint32(xdrData: &xdrData) + self.identity = try Uint32(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateSignerRoleData.swift b/Sources/TokenDWallet/Xdr/UpdateSignerRoleData.swift index 4c118de..d14117e 100644 --- a/Sources/TokenDWallet/Xdr/UpdateSignerRoleData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateSignerRoleData.swift @@ -25,7 +25,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateSignerRoleData: XDREncodable { +public struct UpdateSignerRoleData: XDRCodable { public var roleID: Uint64 public var ruleIDs: [Uint64] public var details: Longstring @@ -54,6 +54,17 @@ public struct UpdateSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.roleID = try Uint64(xdrData: &xdrData) + let lengthruleIDs = try Int32(xdrData: &xdrData) + self.ruleIDs = [Uint64]() + for _ in 1...lengthruleIDs { + self.ruleIDs.append(try Uint64(xdrData: &xdrData)) + } + self.details = try Longstring(xdrData: &xdrData) + self.ext = try UpdateSignerRoleDataExt(xdrData: &xdrData) + } + public enum UpdateSignerRoleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -75,5 +86,15 @@ public struct UpdateSignerRoleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/UpdateSignerRuleData.swift b/Sources/TokenDWallet/Xdr/UpdateSignerRuleData.swift index 3b215d1..d4c7587 100644 --- a/Sources/TokenDWallet/Xdr/UpdateSignerRuleData.swift +++ b/Sources/TokenDWallet/Xdr/UpdateSignerRuleData.swift @@ -30,7 +30,7 @@ import Foundation // }; // =========================================================================== -public struct UpdateSignerRuleData: XDREncodable { +public struct UpdateSignerRuleData: XDRCodable { public var ruleID: Uint64 public var resource: SignerRuleResource public var action: SignerRuleAction @@ -71,6 +71,16 @@ public struct UpdateSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.ruleID = try Uint64(xdrData: &xdrData) + self.resource = try SignerRuleResource(xdrData: &xdrData) + self.action = try SignerRuleAction(xdrData: &xdrData) + self.forbids = try Bool(xdrData: &xdrData) + self.isDefault = try Bool(xdrData: &xdrData) + self.details = try Longstring(xdrData: &xdrData) + self.ext = try UpdateSignerRuleDataExt(xdrData: &xdrData) + } + public enum UpdateSignerRuleDataExt: XDRDiscriminatedUnion { case emptyVersion() @@ -92,5 +102,15 @@ public struct UpdateSignerRuleData: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/VoteData.swift b/Sources/TokenDWallet/Xdr/VoteData.swift index e62366e..d777c83 100644 --- a/Sources/TokenDWallet/Xdr/VoteData.swift +++ b/Sources/TokenDWallet/Xdr/VoteData.swift @@ -34,4 +34,16 @@ public enum VoteData: XDRDiscriminatedUnion { return xdr } + + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case PollType.singleChoice.rawValue: + let data = try SingleChoiceVote(xdrData: &xdrData) + self = .singleChoice(data) + default: + throw XDRErrors.unknownEnumCase + } + } } diff --git a/Sources/TokenDWallet/Xdr/VoteEntry.swift b/Sources/TokenDWallet/Xdr/VoteEntry.swift index 8937f03..dad3268 100644 --- a/Sources/TokenDWallet/Xdr/VoteEntry.swift +++ b/Sources/TokenDWallet/Xdr/VoteEntry.swift @@ -17,7 +17,7 @@ import Foundation // }; // =========================================================================== -public struct VoteEntry: XDREncodable { +public struct VoteEntry: XDRCodable { public var pollID: Uint64 public var voterID: AccountID public var data: VoteData @@ -45,4 +45,11 @@ public struct VoteEntry: XDREncodable { return xdr } + + public init(xdrData: inout Data) throws { + self.pollID = try Uint64(xdrData: &xdrData) + self.voterID = try AccountID(xdrData: &xdrData) + self.data = try VoteData(xdrData: &xdrData) + self.ext = try EmptyExt(xdrData: &xdrData) + } } diff --git a/Sources/TokenDWallet/Xdr/WithdrawalDetails.swift b/Sources/TokenDWallet/Xdr/WithdrawalDetails.swift index b4009cb..d413302 100644 --- a/Sources/TokenDWallet/Xdr/WithdrawalDetails.swift +++ b/Sources/TokenDWallet/Xdr/WithdrawalDetails.swift @@ -19,7 +19,7 @@ import Foundation // }; // =========================================================================== -public struct WithdrawalDetails: XDREncodable { +public struct WithdrawalDetails: XDRCodable { public var externalDetails: String public var ext: WithdrawalDetailsExt @@ -40,6 +40,11 @@ public struct WithdrawalDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.externalDetails = try String(xdrData: &xdrData) + self.ext = try WithdrawalDetailsExt(xdrData: &xdrData) + } + public enum WithdrawalDetailsExt: XDRDiscriminatedUnion { case emptyVersion() @@ -61,5 +66,15 @@ public struct WithdrawalDetails: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/WithdrawalRequest.swift b/Sources/TokenDWallet/Xdr/WithdrawalRequest.swift index 0bd7a46..83fc6c6 100644 --- a/Sources/TokenDWallet/Xdr/WithdrawalRequest.swift +++ b/Sources/TokenDWallet/Xdr/WithdrawalRequest.swift @@ -28,7 +28,7 @@ import Foundation // }; // =========================================================================== -public struct WithdrawalRequest: XDREncodable { +public struct WithdrawalRequest: XDRCodable { public var balance: BalanceID public var amount: Uint64 public var universalAmount: Uint64 @@ -65,6 +65,15 @@ public struct WithdrawalRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + self.balance = try BalanceID(xdrData: &xdrData) + self.amount = try Uint64(xdrData: &xdrData) + self.universalAmount = try Uint64(xdrData: &xdrData) + self.fee = try Fee(xdrData: &xdrData) + self.creatorDetails = try Longstring(xdrData: &xdrData) + self.ext = try WithdrawalRequestExt(xdrData: &xdrData) + } + public enum WithdrawalRequestExt: XDRDiscriminatedUnion { case emptyVersion() @@ -86,5 +95,15 @@ public struct WithdrawalRequest: XDREncodable { return xdr } + public init(xdrData: inout Data) throws { + let discriminant = try Int32(xdrData: &xdrData) + + switch discriminant { + case LedgerVersion.emptyVersion.rawValue: self = .emptyVersion() + default: + throw XDRErrors.unknownEnumCase + } + } + } } diff --git a/Sources/TokenDWallet/Xdr/XDRArrayFixed4.swift b/Sources/TokenDWallet/Xdr/XDRArrayFixed4.swift new file mode 100644 index 0000000..a79bf84 --- /dev/null +++ b/Sources/TokenDWallet/Xdr/XDRArrayFixed4.swift @@ -0,0 +1,17 @@ +// Automatically generated by xdrgen +// DO NOT EDIT or your changes may be overwritten + +import Foundation + +/// Fixed length byte array +public struct XDRArrayFixed4: XDRArrayFixed { + public typealias Element = WrappedElement + + public static var length: Int { return 4 } + + public var wrapped: [WrappedElement] + + public init() { + self.wrapped = [WrappedElement]() + } +}