Skip to content

Commit

Permalink
Merge pull request #6 from blocto/fix/udpate-reference-type
Browse files Browse the repository at this point in the history
Fix - update auth property of reference type
  • Loading branch information
yuhsuan19 authored Sep 16, 2024
2 parents f6402b1 + 2f09442 commit 811894b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cadence.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Cadence'
s.version = '0.6.0'
s.version = '0.7.0'
s.summary = 'JSON-Cadence Data Interchange Format Wrapper'

s.homepage = 'https://github.com/portto/flow-swift-sdk'
Expand Down
4 changes: 2 additions & 2 deletions FlowSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FlowSDK'
s.version = '0.6.0'
s.version = '0.7.0'
s.summary = 'Flow blockchain swift SDK'

s.homepage = 'https://github.com/portto/flow-swift-sdk'
Expand All @@ -21,7 +21,7 @@ Pod::Spec.new do |s|
ss.source_files = "Sources/FlowSDK/**/*"
ss.dependency "BigInt", "~> 5.2.0"
ss.dependency "CryptoSwift", "~> 1.5.1"
ss.dependency "Cadence", "~> 0.6.0"
ss.dependency "Cadence", "~> 0.7.0"
ss.dependency "gRPC-Swiftp", "~> 1.8.2"
ss.dependency "secp256k1Swift", "~> 0.7.4"
end
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ platform :ios, '13.0'
use_frameworks!

target 'ExampleApp' do
pod 'FlowSDK', '~> 0.6.0'
pod 'FlowSDK', '~> 0.7.0'
end
```

### Swift Package Manager

- File > Swift Packages > Add Package Dependency
- Add `https://github.com/portto/flow-swift-sdk.git`
- Select "Up to Next Major" with "0.6.0"
- Select "Up to Next Major" with "0.7.0"

# Usage

Expand Down
23 changes: 20 additions & 3 deletions Sources/Cadence/CType/ReferenceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,28 @@
import Foundation

public struct ReferenceType: Equatable, Codable {
public let authorized: Bool
public let authorization: Authorization
public let type: FType

public init(authorized: Bool, type: FType) {
self.authorized = authorized
public init(authorization: Authorization, type: FType) {
self.authorization = authorization
self.type = type
}
}

public extension ReferenceType {
struct Authorization: Codable, Equatable {
public let kind: AuthorizationKind

public init(kind: AuthorizationKind) {
self.kind = kind
}
}

enum AuthorizationKind: String, Codable {
case unauthorized = "Unauthorized"
case entitlementMapAuthorization = "EntitlementMapAuthorization"
case entitlementConjunctionSet = "EntitlementConjunctionSet"
case entitlementDisjunctionSet = "EntitlementDisjunctionSet"
}
}
6 changes: 1 addition & 5 deletions Sources/Cadence/FType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ public enum FType: Equatable {
case let .function(functionType):
return functionType.typeId
case let .reference(referenceType):
var id = "&\(referenceType.type.id)"
if referenceType.authorized {
id = "auth" + id
}
return id
return referenceType.authorization.kind.rawValue + "&\(referenceType.type.id)"
case let .restriction(restrictionType):
return restrictionType.typeId
case let .capability(borrowType):
Expand Down
14 changes: 10 additions & 4 deletions Tests/CadenceTests/StaticTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,10 @@ final class StaticTypeTests: XCTestCase {
let jsonData = """
{
"kind": "Reference",
"authorized": true,
"authorization": {
"kind": "Unauthorized",
"entitlements": null
},
"type": {
"kind": "String"
}
Expand All @@ -1387,7 +1390,7 @@ final class StaticTypeTests: XCTestCase {
let value = try decoder.decode(FType.self, from: jsonData)

// Then
XCTAssertEqual(value, .reference(.init(authorized: true, type: .string)))
XCTAssertEqual(value, .reference(.init(authorization: .init(kind: .unauthorized), type: .string)))
XCTAssertEqual(value.kind, .reference)
}

Expand Down Expand Up @@ -1450,7 +1453,10 @@ final class StaticTypeTests: XCTestCase {
"kind": "Capability",
"type": {
"kind": "Reference",
"authorized": true,
"authorization": {
"kind": "EntitlementMapAuthorization",
"entitlements": null
},
"type": {
"kind": "String"
}
Expand All @@ -1463,7 +1469,7 @@ final class StaticTypeTests: XCTestCase {

// Then
XCTAssertEqual(value, .capability(
borrowType: .reference(.init(authorized: true, type: .string))
borrowType: .reference(.init(authorization: .init(kind: .entitlementMapAuthorization), type: .string))
))
XCTAssertEqual(value.kind, .capability)
}
Expand Down
14 changes: 7 additions & 7 deletions examples/cocoapods/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- _NIODataStructures (2.40.0)
- BigInt (5.2.0)
- Cadence (0.6.0):
- Cadence (0.7.0):
- BigInt (~> 5.2.0)
- CryptoSwift (~> 1.5.1)
- CGRPCZlibp (1.8.2)
Expand All @@ -14,11 +14,11 @@ PODS:
- CNIOLinux (2.40.0)
- CNIOWindows (2.40.0)
- CryptoSwift (1.5.1)
- FlowSDK (0.6.0):
- FlowSDK/FlowSDK (= 0.6.0)
- FlowSDK/FlowSDK (0.6.0):
- FlowSDK (0.7.0):
- FlowSDK/FlowSDK (= 0.7.0)
- FlowSDK/FlowSDK (0.7.0):
- BigInt (~> 5.2.0)
- Cadence (~> 0.6.0)
- Cadence (~> 0.7.0)
- CryptoSwift (~> 1.5.1)
- gRPC-Swiftp (~> 1.8.2)
- secp256k1Swift (~> 0.7.4)
Expand Down Expand Up @@ -212,7 +212,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
_NIODataStructures: 3d45d8e70a1d17a15b1dc59d102c63dbc0525ffd
BigInt: f668a80089607f521586bbe29513d708491ef2f7
Cadence: 6fdb8bf299e512132d7e87d3cb0f569b92471eaf
Cadence: 9da7b2a3a168464a2781cff4cee55622e61c19fc
CGRPCZlibp: 2f3e1e7a6d6cb481d4d1a26d3ec09aefacf09cbb
CNIOAtomics: 8edf08644e5e6fa0f021c239be9e8beb1cd9ef18
CNIOBoringSSL: 2c9c96c2e95f15e83fb8d26b9738d939cc39ae33
Expand All @@ -222,7 +222,7 @@ SPEC CHECKSUMS:
CNIOLinux: 62e3505f50de558c393dc2f273dde71dcce518da
CNIOWindows: 3047f2d8165848a3936a0a755fee27c6b5ee479b
CryptoSwift: c4f2debceb38bf44c80659afe009f71e23e4a082
FlowSDK: 5710e38a29fbf5a1948020a41fa3ed174cf58a2c
FlowSDK: cb955510a2c9ab1fff56ae5595181b28e26b7970
gRPC-Swiftp: 1f5a05ce5b544bff3dce93223e72829daac26113
Logging: beeb016c9c80cf77042d62e83495816847ef108b
secp256k1Swift: ea49d2b06724444a03cf7938a2d3fc7acc4c0f08
Expand Down

0 comments on commit 811894b

Please sign in to comment.