Skip to content

Commit

Permalink
add protocol 21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed May 13, 2024
1 parent 0c2e9b9 commit 514dc92
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 39 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To integrate stellar SDK into your Xcode project using CocoaPods, specify it in
use_frameworks!

target '<Your Target Name>' do
pod 'stellar-ios-mac-sdk', '~> 2.6.0'
pod 'stellar-ios-mac-sdk', '~> 2.6.1'
end
```

Expand All @@ -44,15 +44,15 @@ $ brew install carthage
To integrate stellar-ios-mac-sdk into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "soneso/stellar-ios-mac-sdk" ~> 2.6.0
github "soneso/stellar-ios-mac-sdk" ~> 2.6.1
```

Run `carthage update` to build the framework and drag the build `stellar-ios-mac-sdk.framework` into your Xcode project.

### Swift Package Manager

```swift
.package(name: "stellarsdk", url: "[email protected]:Soneso/stellar-ios-mac-sdk.git", from: "2.6.0"),
.package(name: "stellarsdk", url: "[email protected]:Soneso/stellar-ios-mac-sdk.git", from: "2.6.1"),
```

### Manual
Expand Down
2 changes: 1 addition & 1 deletion stellar-ios-mac-sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "stellar-ios-mac-sdk"
s.version = "2.6.0"
s.version = "2.6.1"
s.summary = "Fully featured iOS and macOS SDK that provides APIs to build transactions and connect to Horizon server for the Stellar ecosystem."
s.module_name = 'stellarsdk'
s.swift_version = '5.0'
Expand Down
2 changes: 1 addition & 1 deletion stellarsdk/stellarsdk/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.6.0</string>
<string>2.6.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
54 changes: 51 additions & 3 deletions stellarsdk/stellarsdk/responses/xdr/ContractXDR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,58 @@ public enum ContractCostType: Int32 {
case vmCachedInstantiation = 12
case invokeVmFunction = 13
case computeKeccak256Hash = 14
case computeEcdsaSecp256k1Sig = 15
case decodeEcdsaCurve256Sig = 15
case recoverEcdsaSecp256k1Key = 16
case int256AddSub = 17
case int256Mul = 18
case int256Div = 19
case int256Pow = 20
case int256Shift = 21
case ChaCha20DrawBytes = 22
case chaCha20DrawBytes = 22
case parseWasmInstructions = 23
// Cost of parsing a known number of wasm functions.
case parseWasmFunctions = 24
// Cost of parsing a known number of wasm globals.
case parseWasmGlobals = 25
// Cost of parsing a known number of wasm table entries.
case parseWasmTableEntries = 26
// Cost of parsing a known number of wasm types.
case parseWasmTypes = 27
// Cost of parsing a known number of wasm data segments.
case parseWasmDataSegments = 28
// Cost of parsing a known number of wasm element segments.
case parseWasmElemSegments = 29
// Cost of parsing a known number of wasm imports.
case parseWasmImports = 30
// Cost of parsing a known number of wasm exports.
case parseWasmExports = 31
// Cost of parsing a known number of data segment bytes.
case parseWasmDataSegmentBytes = 32
// Cost of instantiating wasm bytes that only encode instructions.
case instantiateWasmInstructions = 33
// Cost of instantiating a known number of wasm functions.
case instantiateWasmFunctions = 34
// Cost of instantiating a known number of wasm globals.
case instantiateWasmGlobals = 35
// Cost of instantiating a known number of wasm table entries.
case instantiateWasmTableEntries = 36
// Cost of instantiating a known number of wasm types.
case instantiateWasmTypes = 37
// Cost of instantiating a known number of wasm data segments.
case instantiateWasmDataSegments = 38
// Cost of instantiating a known number of wasm element segments.
case instantiateWasmElemSegments = 39
// Cost of instantiating a known number of wasm imports.
case instantiateWasmImports = 40
// Cost of instantiating a known number of wasm exports.
case instantiateWasmExports = 41
// Cost of instantiating a known number of data segment bytes.
case instantiateWasmDataSegmentBytes = 42
// Cost of decoding a bytes array representing an uncompressed SEC-1 encoded
// point on a 256-bit elliptic curve
case sec1DecodePointUncompressed = 43
// Cost of verifying an ECDSA Secp256r1 signature
case verifyEcdsaSecp256r1Sig = 44
}

public enum SCErrorXDR: XDRCodable {
Expand Down Expand Up @@ -188,7 +232,11 @@ public enum SCAddressXDR: XDRCodable {
}

public init(contractId: String) throws {
if let contractIdData = contractId.data(using: .hexadecimal) {
var contractIdHex = contractId
if contractId.hasPrefix("C") {
contractIdHex = try contractId.decodeContractIdHex()
}
if let contractIdData = contractIdHex.data(using: .hexadecimal) {
self = .contract(WrappedData32(contractIdData))
} else {
throw StellarSDKError.encodingError(message: "error xdr encoding invoke host function operation, invalid contract id")
Expand Down
5 changes: 5 additions & 0 deletions stellarsdk/stellarsdk/responses/xdr/LedgerEntryXDR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public struct LedgerEntryXDR: XDRCodable {
reserved = try container.decode(LedgerEntryExtXDR.self)
}

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

public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(lastModifiedLedgerSeq)
Expand Down
136 changes: 130 additions & 6 deletions stellarsdk/stellarsdk/responses/xdr/LedgerExtryDataXDR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,19 @@ public struct ContractDataEntryXDR: XDRCodable {
}

public struct ContractCodeEntryXDR: XDRCodable {
public var ext: ExtensionPoint
public var ext: ContractCodeEntryExt
public var hash: WrappedData32
public var code: Data

public init(ext: ExtensionPoint, hash: WrappedData32, code:Data) {
public init(ext: ContractCodeEntryExt, hash: WrappedData32, code:Data) {
self.ext = ext
self.hash = hash
self.code = code
}

public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
ext = try container.decode(ExtensionPoint.self)
ext = try container.decode(ContractCodeEntryExt.self)
hash = try container.decode(WrappedData32.self)
code = try container.decode(Data.self)
}
Expand All @@ -264,6 +264,126 @@ public struct ContractCodeEntryXDR: XDRCodable {
}
}

public struct ContractCodeCostInputsXDR: XDRCodable {
public var ext:ExtensionPoint
public var nInstructions: UInt32
public var nFunctions: UInt32
public var nGlobals: UInt32
public var nTableEntries: UInt32
public var nTypes: UInt32
public var nDataSegments: UInt32
public var nElemSegments: UInt32
public var nImports: UInt32
public var nExports: UInt32
public var nDataSegmentBytes: UInt32

public init(ext: ExtensionPoint, nInstructions: UInt32, nFunctions: UInt32, nGlobals: UInt32, nTableEntries: UInt32, nTypes: UInt32, nDataSegments: UInt32, nElemSegments: UInt32, nImports: UInt32, nExports: UInt32, nDataSegmentBytes: UInt32) {
self.ext = ext
self.nInstructions = nInstructions
self.nFunctions = nFunctions
self.nGlobals = nGlobals
self.nTableEntries = nTableEntries
self.nTypes = nTypes
self.nDataSegments = nDataSegments
self.nElemSegments = nElemSegments
self.nImports = nImports
self.nExports = nExports
self.nDataSegmentBytes = nDataSegmentBytes
}

public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
ext = try container.decode(ExtensionPoint.self)
nInstructions = try container.decode(UInt32.self)
nFunctions = try container.decode(UInt32.self)
nGlobals = try container.decode(UInt32.self)
nTableEntries = try container.decode(UInt32.self)
nTypes = try container.decode(UInt32.self)
nDataSegments = try container.decode(UInt32.self)
nElemSegments = try container.decode(UInt32.self)
nImports = try container.decode(UInt32.self)
nExports = try container.decode(UInt32.self)
nDataSegmentBytes = try container.decode(UInt32.self)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(ext)
try container.encode(nInstructions)
try container.encode(nFunctions)
try container.encode(nGlobals)
try container.encode(nTypes)
try container.encode(nDataSegments)
try container.encode(nElemSegments)
try container.encode(nImports)
try container.encode(nExports)
try container.encode(nInstructions)
try container.encode(nDataSegmentBytes)

}
}

public struct ContractCodeEntryExtV1: XDRCodable {
public var ext:ExtensionPoint
public var costInputs: ContractCodeCostInputsXDR

public init(ext: ExtensionPoint, costInputs: ContractCodeCostInputsXDR) {
self.ext = ext
self.costInputs = costInputs
}

public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
ext = try container.decode(ExtensionPoint.self)
costInputs = try container.decode(ContractCodeCostInputsXDR.self)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(ext)
try container.encode(costInputs)
}
}

public enum ContractCodeEntryExt: XDRCodable {
case void
case v1 (ContractCodeEntryExtV1)

public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
let code = try container.decode(Int32.self)

switch code {
case 0:
self = .void
case 1:
self = .v1(try ContractCodeEntryExtV1(from: decoder))
default:
self = .void
}
}

private func type() -> Int32 {
switch self {
case .void: return 0
case .v1: return 1
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()

try container.encode(type())

switch self {
case .void:
return
case .v1(let extV1):
try container.encode(extV1)
}
}
}

public struct ConfigSettingContractBandwidthV0XDR: XDRCodable {

public var ledgerMaxTxsSizeBytes: UInt32
Expand Down Expand Up @@ -630,17 +750,19 @@ public struct StateArchivalSettingsXDR: XDRCodable {
public var tempRentRateDenominator: Int64
public var maxEntriesToArchive: UInt32
public var bucketListSizeWindowSampleSize: UInt32
public var evictionScanSize: UInt64
public var bucketListWindowSamplePeriod: UInt32
public var evictionScanSize: UInt32
public var startingEvictionScanLevel: UInt32

public init(maxEntryTTL: UInt32, minTemporaryTTL: UInt32, minPersistentTTL: UInt32, persistentRentRateDenominator: Int64, tempRentRateDenominator: Int64, maxEntriesToArchive: UInt32, bucketListSizeWindowSampleSize: UInt32, evictionScanSize: UInt64, startingEvictionScanLevel: UInt32) {
public init(maxEntryTTL: UInt32, minTemporaryTTL: UInt32, minPersistentTTL: UInt32, persistentRentRateDenominator: Int64, tempRentRateDenominator: Int64, maxEntriesToArchive: UInt32, bucketListSizeWindowSampleSize: UInt32, bucketListWindowSamplePeriod: UInt32, evictionScanSize: UInt32, startingEvictionScanLevel: UInt32) {
self.maxEntryTTL = maxEntryTTL
self.minTemporaryTTL = minTemporaryTTL
self.minPersistentTTL = minPersistentTTL
self.persistentRentRateDenominator = persistentRentRateDenominator
self.tempRentRateDenominator = tempRentRateDenominator
self.maxEntriesToArchive = maxEntriesToArchive
self.bucketListSizeWindowSampleSize = bucketListSizeWindowSampleSize
self.bucketListWindowSamplePeriod = bucketListWindowSamplePeriod
self.evictionScanSize = evictionScanSize
self.startingEvictionScanLevel = startingEvictionScanLevel
}
Expand All @@ -654,7 +776,8 @@ public struct StateArchivalSettingsXDR: XDRCodable {
tempRentRateDenominator = try container.decode(Int64.self)
maxEntriesToArchive = try container.decode(UInt32.self)
bucketListSizeWindowSampleSize = try container.decode(UInt32.self)
evictionScanSize = try container.decode(UInt64.self)
bucketListWindowSamplePeriod = try container.decode(UInt32.self)
evictionScanSize = try container.decode(UInt32.self)
startingEvictionScanLevel = try container.decode(UInt32.self)
}

Expand All @@ -667,6 +790,7 @@ public struct StateArchivalSettingsXDR: XDRCodable {
try container.encode(tempRentRateDenominator)
try container.encode(maxEntriesToArchive)
try container.encode(bucketListSizeWindowSampleSize)
try container.encode(bucketListWindowSamplePeriod)
try container.encode(evictionScanSize)
try container.encode(startingEvictionScanLevel)
}
Expand Down
5 changes: 5 additions & 0 deletions stellarsdk/stellarsdk/responses/xdr/LedgerKeyXDR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public enum LedgerKeyXDR: XDRCodable {
self = .account(acc)
}
}

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

public func type() -> Int32 {
switch self {
Expand Down
Loading

0 comments on commit 514dc92

Please sign in to comment.