From d731c41e3c6597091b118cccbeed8365128c3d55 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 5 Nov 2021 15:30:06 +0300 Subject: [PATCH] add wx balance --- .../Sources/Services/Node/Models/AddressData.swift | 12 ++++++++++++ .../Node/Services/AddressesNodeService.swift | 13 +++++++++++++ .../Protocols/AddressesNodeServiceProtocol.swift | 3 +++ .../Services/Node/Targets/AddressesNodeTarget.swift | 9 ++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/WavesSDK/Sources/Services/Node/Models/AddressData.swift b/WavesSDK/Sources/Services/Node/Models/AddressData.swift index 7b78785..c6861a8 100644 --- a/WavesSDK/Sources/Services/Node/Models/AddressData.swift +++ b/WavesSDK/Sources/Services/Node/Models/AddressData.swift @@ -20,4 +20,16 @@ extension NodeService.DTO { self.key = key } } + + public struct AddressesWXData: Decodable { + public let type: String + public let value: String + public let key: String + + public init(type: String, value: String, key: String) { + self.type = type + self.value = value + self.key = key + } + } } diff --git a/WavesSDK/Sources/Services/Node/Services/AddressesNodeService.swift b/WavesSDK/Sources/Services/Node/Services/AddressesNodeService.swift index 548d750..ca64187 100644 --- a/WavesSDK/Sources/Services/Node/Services/AddressesNodeService.swift +++ b/WavesSDK/Sources/Services/Node/Services/AddressesNodeService.swift @@ -52,6 +52,19 @@ final class AddressesNodeService: InternalWavesService, AddressesNodeServiceProt .map(NodeService.DTO.AddressesData.self) .asObservable() } + + func getWXAddressData(address: String, key: String) -> Observable { + let target: NodeService.Target.Addresses = .init(kind: .getWXData(address: address, key: key), + nodeUrl: enviroment.nodeUrl) + + return addressesProvider + .rx + .request(target) + .filterSuccessfulStatusAndRedirectCodes() + .catchError { error -> Single in Single.error(error) } + .map(NodeService.DTO.AddressesWXData.self) + .asObservable() + } func addressesBalance(addresses: [String]) -> Observable<[NodeService.DTO.WavesBalance]> { let target: NodeService.Target.Addresses = .init( diff --git a/WavesSDK/Sources/Services/Node/Services/Protocols/AddressesNodeServiceProtocol.swift b/WavesSDK/Sources/Services/Node/Services/Protocols/AddressesNodeServiceProtocol.swift index 1c6d583..c38e348 100644 --- a/WavesSDK/Sources/Services/Node/Services/Protocols/AddressesNodeServiceProtocol.swift +++ b/WavesSDK/Sources/Services/Node/Services/Protocols/AddressesNodeServiceProtocol.swift @@ -21,6 +21,7 @@ public extension NodeService.DTO { } public protocol AddressesNodeServiceProtocol { + /** Account's Waves balance - Parameter: address Address @@ -35,6 +36,8 @@ public protocol AddressesNodeServiceProtocol { func scriptInfo(address: String) -> Observable func getAddressData(address: String, key: String) -> Observable + + func getWXAddressData(address: String, key: String) -> Observable func addressesBalance(addresses: [String]) -> Observable<[NodeService.DTO.WavesBalance]> } diff --git a/WavesSDK/Sources/Services/Node/Targets/AddressesNodeTarget.swift b/WavesSDK/Sources/Services/Node/Targets/AddressesNodeTarget.swift index a736d60..6c97125 100644 --- a/WavesSDK/Sources/Services/Node/Targets/AddressesNodeTarget.swift +++ b/WavesSDK/Sources/Services/Node/Targets/AddressesNodeTarget.swift @@ -26,6 +26,8 @@ extension NodeService.Target { case scriptInfo(id: String) case getData(address: String, key: String) + + case getWXData(address: String, key: String) case getAddressesBalance(addresses: [String]) } @@ -52,6 +54,9 @@ extension NodeService.Target.Addresses: NodeTargetType { case let .getData(address, key): return Constants.addresses + "/" + "data" + "/" + address.urlEscaped + "/" + "\(key)".urlEscaped + + case let .getWXData(address, key): + return Constants.addresses + "/" + "data" + "/" + address.urlEscaped + "/" + "\(key)" case .getAddressesBalance: return Constants.addresses + "/" + Constants.balance @@ -60,7 +65,7 @@ extension NodeService.Target.Addresses: NodeTargetType { var method: Moya.Method { switch kind { - case .getAddressBalance, .scriptInfo, .getData: + case .getAddressBalance, .scriptInfo, .getData, .getWXData: return .get case .getAddressesBalance: return .post @@ -69,6 +74,8 @@ extension NodeService.Target.Addresses: NodeTargetType { var task: Task { switch kind { + case .getWXData: + return .requestPlain case .getAddressBalance, .scriptInfo, .getData: return .requestParameters(parameters: ["r": "\(Date().timeIntervalSince1970)"], encoding: URLEncoding.default)