-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// SubstrateService.swift | ||
// | ||
// | ||
// Created by Yehor Popovych on 07/11/2023. | ||
// | ||
|
||
import Foundation | ||
import CTesseractBin | ||
#if !COCOAPODS | ||
import TesseractTransportsShared | ||
#endif | ||
|
||
public enum SubstrateAccountType { | ||
case sr25519 | ||
case ed25519 | ||
case ecdsa | ||
} | ||
|
||
public struct SubstrateGetAccountResponse { | ||
public let pubKey: Data | ||
public let path: String | ||
|
||
public init(pubKey: Data, path: String) { | ||
self.pubKey = pubKey | ||
self.path = path | ||
} | ||
} | ||
|
||
public protocol SubstrateService { | ||
func getAccount( | ||
type: SubstrateAccountType | ||
) async -> Result<SubstrateGetAccountResponse, TesseractError> | ||
|
||
func signTransation( | ||
type: SubstrateAccountType, path: String, | ||
extrinsic: Data, metadata: Data, types: Data | ||
) async -> Result<Data, TesseractError> | ||
} | ||
|
||
extension CTesseract.SubstrateAccountType: CType { | ||
public init() { self.init(0) } | ||
} | ||
|
||
extension CTesseract.SubstrateGetAccountResponse: CType, CPtr { | ||
public typealias Val = SubstrateGetAccountResponse | ||
|
||
public func copied() -> SubstrateGetAccountResponse { | ||
SubstrateGetAccountResponse(pubKey: public_key.copied(), | ||
path: path.copied()) | ||
} | ||
|
||
public mutating func owned() -> SubstrateGetAccountResponse { | ||
defer { self.free() } | ||
return self.copied() | ||
} | ||
|
||
public mutating func free() { | ||
tesseract_substrate_get_account_response_free(&self) | ||
} | ||
} | ||
|
||
extension SubstrateGetAccountResponse: AsCPtrCopy { | ||
public typealias CopyPtr = CTesseract.SubstrateGetAccountResponse | ||
|
||
public func copiedPtr() -> CTesseract.SubstrateGetAccountResponse { | ||
CTesseract.SubstrateGetAccountResponse(public_key: pubKey.copiedPtr(), | ||
path: path.copiedPtr()) | ||
} | ||
} | ||
|
||
extension SubstrateAccountType: CValue { | ||
public typealias CVal = CTesseract.SubstrateAccountType | ||
|
||
public init(cvalue val: CTesseract.SubstrateAccountType) { | ||
switch val { | ||
case SubstrateAccountType_Ed25519: self = .ed25519 | ||
case SubstrateAccountType_Sr25519: self = .sr25519 | ||
case SubstrateAccountType_Ecdsa: self = .ecdsa | ||
default: fatalError("Unsupported account type: \(val)") | ||
} | ||
} | ||
|
||
public var asCValue: CTesseract.SubstrateAccountType { | ||
switch self { | ||
case .sr25519: return SubstrateAccountType_Sr25519 | ||
case .ed25519: return SubstrateAccountType_Ed25519 | ||
case .ecdsa: return SubstrateAccountType_Ecdsa | ||
} | ||
} | ||
} | ||
|
||
extension CFuture_SubstrateGetAccountResponse: CFuturePtr { | ||
public typealias CVal = CTesseract.SubstrateGetAccountResponse | ||
public typealias Val = SubstrateGetAccountResponse | ||
|
||
public mutating func _onComplete(cb: @escaping (CResult<CVal>) -> Void) -> CResult<CVal>? { | ||
_withOnCompleteContext(cb) { ctx, value, error in | ||
self.set_on_complete(&self, ctx, value, error) { ctx, val, err in | ||
Self._onCompleteCallback(ctx, val, err) | ||
} | ||
} | ||
} | ||
|
||
public mutating func _setupSetOnCompleteFunc() { | ||
self.set_on_complete = { this, ctx, value, error, cb in | ||
Self._setOnCompleteFunc(this, ctx, value, error) { this, val, err in | ||
cb?(this, val, err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// TestService.swift | ||
// | ||
// | ||
// Created by Yehor Popovych on 07/11/2023. | ||
// | ||
|
||
import Foundation | ||
#if !COCOAPODS | ||
import TesseractTransportsShared | ||
#endif | ||
|
||
public protocol TestService { | ||
func signTransation(req: String) async -> Result<String, TesseractError> | ||
} |