Skip to content

Commit

Permalink
Merge pull request #60 from unstoppabledomains/layer-two
Browse files Browse the repository at this point in the history
Layer two
  • Loading branch information
DeRain authored Nov 9, 2021
2 parents e6a7332 + 61a939b commit 8627f99
Show file tree
Hide file tree
Showing 33 changed files with 2,078 additions and 1,021 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

.idea/
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Resolution-swift CHANGELOG

## 3.0.0

### Breaking changes
- Library initialization has been changed.
- Uns configurations now require setup for ETH network for L1 and poligon network for L2
- `Resolution#getNetwork` has been removed. It is redundant since anyone who is using the library will have the configurations built-in
- `Resolution#batchOwners` has changed signature. It now returns a map [String: String?] of domain to owner addresses.
- `Resolution#tokensOwnedBy` has been removed
- ENS considered deprecated and will be removed in the future

### New methods and features
- 🎉 🎉 🎉 Add Polygon Layer 2 support!
- Introducing `Resolution#allRecords` method. It resolves a domain and returns all records the domain has been configured on the chain as a map [String: String] record to value
- Introducing `Resolution#locations` method which will help to determine domains location (blockhain, networkId) and useful metadata like owner, resolver, registry addresses, provider url if possible.
`public struct Location: Equatable {
var registryAddress: String?
var resolverAddress: String?
var networkId: String?
var blockchain: String?
var owner: String?
var providerURL: String?
}`


## 2.0.1
- Fix `Resolution#tokensOwnedBy` issue with lowercased addresses.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Unstoppable Domains
Copyright (c) 2021 Unstoppable Domains

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ Resoultion supports decentralized domains across three main zones:
## Cocoa Pods

```ruby
pod 'UnstoppableDomainsResolution', '~> 2.0.1'
pod 'UnstoppableDomainsResolution', '~> 3.0.0'
```

## Swift Package Manager

```swift
package.dependencies.append(
.package(url: "https://github.com/unstoppabledomains/resolution-swift", from: "2.0.1")
.package(url: "https://github.com/unstoppabledomains/resolution-swift", from: "3.0.0")
)
```

Expand All @@ -63,7 +63,21 @@ guard let resolution = try? Resolution() else {
}

// Or, if you want to use a specific providerUrl and network:
guard let resolution = try? Resolution(providerUrl: "https://mainnet.infura.io/v3/<YOUR_PROJECT_ID_HERE>", network: "mainnet") else {
guard let resolution = try? Resolution(
configs: Configurations(
uns: UnsLocations(
layer1: NamingServiceConfig(
providerUrl: "https://rinkeby.infura.io/v3/3c25f57353234b1b853e9861050f4817",
network: "rinkeby"),
layer2: NamingServiceConfig(
providerUrl: "https://polygon-mumbai.infura.io/v3/3c25f57353234b1b853e9861050f4817",
network: "polygon-mumbai")
),
zns: NamingServiceConfig(
providerUrl: "https://dev-api.zilliqa.com",
network: "testnet")
)
) else {
print ("Init of Resolution instance with custom parameters failed...")
return
}
Expand Down Expand Up @@ -146,10 +160,20 @@ You can update each naming service separately

```swift
let resolution = try Resolution(configs: Configurations(
uns: NamingServiceConfig(
providerUrl: "https://rinkeby.infura.io/v3/3c25f57353234b1b853e9861050f4817",
network: "rinkeby"
)
uns: UnsLocations = UnsLocations(
layer1: NamingServiceConfig(
providerUrl: "https://mainnet.infura.io/v3/3c25f57353234b1b853e9861050f4817",
network: "mainnet"),
layer2: NamingServiceConfig(
providerUrl: "https://polygon-mainnet.infura.io/v3/3c25f57353234b1b853e9861050f4817",
network: "polygon-mainnet")
),
ens: NamingServiceConfig = NamingServiceConfig(
providerUrl: "https://mainnet.infura.io/v3/d423cf2499584d7fbe171e33b42cfbee",
network: "mainnet"),
zns: NamingServiceConfig = NamingServiceConfig(
providerUrl: "https://api.zilliqa.com",
network: "mainnet")
)
);

Expand Down Expand Up @@ -191,7 +215,7 @@ As opposed to the single `owner(domain: _, completion: _)` method, this batch re
resolution.batchOwners(domains: ["brad.crypto", "otherbrad.crypto"]) { result in
switch result {
case .success(let returnValue):
// returnValue: [String?] = <array of owners's addresses>
// returnValue: [String: String?] = <map of domains to owner address>
let domainOwner = returnValue
case .failure(let error):
XCTFail("Expected owner, but got \(error)")
Expand Down
22 changes: 21 additions & 1 deletion Resolution.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
30A69245251385A70079EC69 /* unsProxyReader.json in Resources */ = {isa = PBXBuildFile; fileRef = 30A69244251385A70079EC69 /* unsProxyReader.json */; };
3E08BE762727EB2F009BAD0B /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE8A93B26FAC81A005FD616 /* TestHelpers.swift */; };
3E105520258C95D300652FC7 /* DnsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E10551F258C95D300652FC7 /* DnsType.swift */; };
3E105524258CB73400652FC7 /* DnsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E105523258CB73400652FC7 /* DnsUtils.swift */; };
3E10552E258CBD0900652FC7 /* DnsRecordsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E10552D258CBD0900652FC7 /* DnsRecordsError.swift */; };
Expand All @@ -27,12 +28,17 @@
3EAFA40224EE312A008791E9 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EAFA40124EE312A008791E9 /* Utilities.swift */; };
3EAFA40424EE32B2008791E9 /* CommonNamingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EAFA40324EE32B2008791E9 /* CommonNamingService.swift */; };
3EB45BCC26E9684B00D25F10 /* resolver-keys.json in Resources */ = {isa = PBXBuildFile; fileRef = 3EB45BCB26E9684B00D25F10 /* resolver-keys.json */; };
3EB45BD726E96FC500D25F10 /* UNSLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EB45BD626E96FC500D25F10 /* UNSLayer.swift */; };
3EB45BDD26EAB26100D25F10 /* AsyncResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EB45BDC26EAB26100D25F10 /* AsyncResolver.swift */; };
3EC9E0482697F2E0001521B4 /* ensResolver.json in Resources */ = {isa = PBXBuildFile; fileRef = 8449EDFB2513BA3D00DABB57 /* ensResolver.json */; };
3ECD84AE25A6AEE1001772DD /* UsdtVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ECD84AD25A6AEE1001772DD /* UsdtVersion.swift */; };
3EE4DA0D24E367720097540B /* Resolution.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EE4DA0324E367720097540B /* Resolution.framework */; };
3EE4DA1224E367720097540B /* ResolutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE4DA1124E367720097540B /* ResolutionTests.swift */; };
3EE4DA1424E367720097540B /* resolution.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EE4DA0624E367720097540B /* resolution.h */; settings = {ATTRIBUTES = (Public, ); }; };
3EE4DA1E24E367D40097540B /* Resolution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE4DA1D24E367D40097540B /* Resolution.swift */; };
3EE8A94226FD44C3005FD616 /* UnsLayerL2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE8A94126FD44C3005FD616 /* UnsLayerL2Tests.swift */; };
3EE8A94526FD46A7005FD616 /* unsRegistry.json in Resources */ = {isa = PBXBuildFile; fileRef = 3E2AC93D24E4FC9F008EBC39 /* unsRegistry.json */; };
3EE8A95C26FD47A8005FD616 /* unsProxyReader.json in Resources */ = {isa = PBXBuildFile; fileRef = 30A69244251385A70079EC69 /* unsProxyReader.json */; };
8402F708250935FE0007F01D /* ContractZNS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8402F707250935FD0007F01D /* ContractZNS.swift */; };
8449EDFA25139F2500DABB57 /* ensRegistry.json in Resources */ = {isa = PBXBuildFile; fileRef = 8449EDF925139F2500DABB57 /* ensRegistry.json */; };
845B401D251389A4006AB08E /* ENS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845B401C251389A4006AB08E /* ENS.swift */; };
Expand Down Expand Up @@ -87,6 +93,8 @@
3EAFA40124EE312A008791E9 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
3EAFA40324EE32B2008791E9 /* CommonNamingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonNamingService.swift; sourceTree = "<group>"; };
3EB45BCB26E9684B00D25F10 /* resolver-keys.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "resolver-keys.json"; sourceTree = "<group>"; };
3EB45BD626E96FC500D25F10 /* UNSLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNSLayer.swift; sourceTree = "<group>"; };
3EB45BDC26EAB26100D25F10 /* AsyncResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncResolver.swift; sourceTree = "<group>"; };
3EC9E04B2697FF84001521B4 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
3EC9E04E2698002F001521B4 /* UnstoppableDomainsResolution.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnstoppableDomainsResolution.podspec; sourceTree = "<group>"; };
3ECD84AD25A6AEE1001772DD /* UsdtVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UsdtVersion.swift; sourceTree = "<group>"; };
Expand All @@ -97,6 +105,8 @@
3EE4DA1124E367720097540B /* ResolutionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResolutionTests.swift; sourceTree = "<group>"; };
3EE4DA1324E367720097540B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3EE4DA1D24E367D40097540B /* Resolution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resolution.swift; sourceTree = "<group>"; };
3EE8A93B26FAC81A005FD616 /* TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = "<group>"; };
3EE8A94126FD44C3005FD616 /* UnsLayerL2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsLayerL2Tests.swift; sourceTree = "<group>"; };
8402F707250935FD0007F01D /* ContractZNS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContractZNS.swift; sourceTree = "<group>"; };
8425AED824FFBADF00BBCBBA /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
8449EDF925139F2500DABB57 /* ensRegistry.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ensRegistry.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -165,8 +175,9 @@
isa = PBXGroup;
children = (
3EAFA40324EE32B2008791E9 /* CommonNamingService.swift */,
3E2AC91B24E4FA28008EBC39 /* UNS.swift */,
845B401C251389A4006AB08E /* ENS.swift */,
3E2AC91B24E4FA28008EBC39 /* UNS.swift */,
3EB45BD626E96FC500D25F10 /* UNSLayer.swift */,
848E21082507890A008707D2 /* ZNS.swift */,
);
path = NamingServices;
Expand Down Expand Up @@ -250,9 +261,11 @@
3EE4DA1024E367720097540B /* ResolutionTests */ = {
isa = PBXGroup;
children = (
3EE8A93B26FAC81A005FD616 /* TestHelpers.swift */,
3EE4DA1124E367720097540B /* ResolutionTests.swift */,
3EE4DA1324E367720097540B /* Info.plist */,
849E07D124F9499900A793D3 /* XCTestManifests.swift */,
3EE8A94126FD44C3005FD616 /* UnsLayerL2Tests.swift */,
);
path = ResolutionTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -283,6 +296,7 @@
3EAFA40124EE312A008791E9 /* Utilities.swift */,
848E210B25079D61008707D2 /* Types.swift */,
3ECD84AD25A6AEE1001772DD /* UsdtVersion.swift */,
3EB45BDC26EAB26100D25F10 /* AsyncResolver.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -474,6 +488,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3EE8A95C26FD47A8005FD616 /* unsProxyReader.json in Resources */,
3EE8A94526FD46A7005FD616 /* unsRegistry.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -527,12 +543,14 @@
3ECD84AE25A6AEE1001772DD /* UsdtVersion.swift in Sources */,
3E2AC91C24E4FA28008EBC39 /* UNS.swift in Sources */,
845B401D251389A4006AB08E /* ENS.swift in Sources */,
3EB45BD726E96FC500D25F10 /* UNSLayer.swift in Sources */,
3E33F99925DCFAB400627C71 /* Configurations.swift in Sources */,
B6F2075825DBD89800140CE3 /* ABIParameterTypes.swift in Sources */,
B6F2075A25DBD89800140CE3 /* ABIExtensions.swift in Sources */,
B6F2075625DBD89800140CE3 /* ABIElements.swift in Sources */,
3EAFA40424EE32B2008791E9 /* CommonNamingService.swift in Sources */,
3E2AC91F24E4FA35008EBC39 /* NamingService.swift in Sources */,
3EB45BDD26EAB26100D25F10 /* AsyncResolver.swift in Sources */,
B6F2075525DBD89800140CE3 /* ABIDecoder.swift in Sources */,
848E21092507890A008707D2 /* ZNS.swift in Sources */,
B6E79938260223CE00F65894 /* Base58.swift in Sources */,
Expand Down Expand Up @@ -563,6 +581,8 @@
files = (
3EE4DA1224E367720097540B /* ResolutionTests.swift in Sources */,
B6F2076125DBD8C800140CE3 /* EthereumABITests.swift in Sources */,
3EE8A94226FD44C3005FD616 /* UnsLayerL2Tests.swift in Sources */,
3E08BE762727EB2F009BAD0B /* TestHelpers.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BlueprintIdentifier = "3EE4DA0224E367720097540B"
BuildableName = "Resolution.framework"
BlueprintName = "UnstoppableDomainsResolution"
ReferencedContainer = "container:Resolution.xcodeproj">
ReferencedContainer = "container:resolution.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -35,7 +35,7 @@
BlueprintIdentifier = "3EE4DA0B24E367720097540B"
BuildableName = "ResolutionTests.xctest"
BlueprintName = "ResolutionTests"
ReferencedContainer = "container:Resolution.xcodeproj">
ReferencedContainer = "container:resolution.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
Expand Down Expand Up @@ -63,7 +63,7 @@
BlueprintIdentifier = "3EE4DA0224E367720097540B"
BuildableName = "Resolution.framework"
BlueprintName = "UnstoppableDomainsResolution"
ReferencedContainer = "container:Resolution.xcodeproj">
ReferencedContainer = "container:resolution.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,66 +204,4 @@ extension ABIDecoder {
return (Data(elementItself), nextElement)
}
}

public static func decodeLog(event: ABI.Element.Event, eventLogTopics: [Data], eventLogData: Data) -> [String: Any]? {
if event.topic != eventLogTopics[0] && !event.anonymous {
return nil
}
var eventContent = [String: Any]()
eventContent["name"]=event.name
let logs = eventLogTopics
let dataForProcessing = eventLogData
let indexedInputs = event.inputs.filter { (inp) -> Bool in
return inp.indexed
}
if logs.count == 1 && indexedInputs.count > 0 {
return nil
}
let nonIndexedInputs = event.inputs.filter { (inp) -> Bool in
return !inp.indexed
}
let nonIndexedTypes = nonIndexedInputs.compactMap { (inp) -> ABI.Element.ParameterType in
return inp.type
}
guard logs.count == indexedInputs.count + 1 else {return nil}
var indexedValues = [AnyObject]()
for i in 0 ..< indexedInputs.count {
let data = logs[i+1]
let input = indexedInputs[i]
if !input.type.isStatic || input.type.isArray || input.type.memoryUsage != 32 {
let (v, _) = ABIDecoder.decodeSingleType(type: .bytes(length: 32), data: data)
guard let valueUnwrapped = v else {return nil}
indexedValues.append(valueUnwrapped)
} else {
let (v, _) = ABIDecoder.decodeSingleType(type: input.type, data: data)
guard let valueUnwrapped = v else {return nil}
indexedValues.append(valueUnwrapped)
}
}
let v = ABIDecoder.decode(types: nonIndexedTypes, data: dataForProcessing)
guard let nonIndexedValues = v else {return nil}
var indexedInputCounter = 0
var nonIndexedInputCounter = 0
for i in 0 ..< event.inputs.count {
let el = event.inputs[i]
if el.indexed {
let name = "\(i)"
let value = indexedValues[indexedInputCounter]
eventContent[name] = value
if el.name != "" {
eventContent[el.name] = value
}
indexedInputCounter += 1
} else {
let name = "\(i)"
let value = nonIndexedValues[nonIndexedInputCounter]
eventContent[name] = value
if el.name != "" {
eventContent[el.name] = value
}
nonIndexedInputCounter += 1
}
}
return eventContent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,3 @@ extension ABI.Element {
}
}
}

extension ABI.Element.Event {
public func decodeReturnedLogs(eventLogTopics: [Data], eventLogData: Data) -> [String: Any]? {
guard
let eventContent = ABIDecoder.decodeLog(event: self, eventLogTopics: eventLogTopics, eventLogData: eventLogData)
else {
return nil
}
return eventContent
}
}
Loading

0 comments on commit 8627f99

Please sign in to comment.