Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wx balance #85

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions WavesSDK/Sources/Services/Node/Models/AddressData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
13 changes: 13 additions & 0 deletions WavesSDK/Sources/Services/Node/Services/AddressesNodeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ final class AddressesNodeService: InternalWavesService, AddressesNodeServiceProt
.map(NodeService.DTO.AddressesData.self)
.asObservable()
}

func getWXAddressData(address: String, key: String) -> Observable<NodeService.DTO.AddressesWXData> {
let target: NodeService.Target.Addresses = .init(kind: .getWXData(address: address, key: key),
nodeUrl: enviroment.nodeUrl)

return addressesProvider
.rx
.request(target)
.filterSuccessfulStatusAndRedirectCodes()
.catchError { error -> Single<Response> in Single.error(error) }
.map(NodeService.DTO.AddressesWXData.self)
.asObservable()
}

func addressesBalance(addresses: [String]) -> Observable<[NodeService.DTO.WavesBalance]> {
let target: NodeService.Target.Addresses = .init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public extension NodeService.DTO {
}

public protocol AddressesNodeServiceProtocol {

/**
Account's Waves balance
- Parameter: address Address
Expand All @@ -35,6 +36,8 @@ public protocol AddressesNodeServiceProtocol {
func scriptInfo(address: String) -> Observable<NodeService.DTO.AddressScriptInfo>

func getAddressData(address: String, key: String) -> Observable<NodeService.DTO.AddressesData>

func getWXAddressData(address: String, key: String) -> Observable<NodeService.DTO.AddressesWXData>

func addressesBalance(addresses: [String]) -> Observable<[NodeService.DTO.WavesBalance]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down