-
Notifications
You must be signed in to change notification settings - Fork 9
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
7 changed files
with
161 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// FeesResponse.swift | ||
// BDKSwiftExampleWallet | ||
// | ||
// Created by Matthew Ramsden on 8/23/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecommendedFees: Codable, Equatable { | ||
let fastestFee: Int | ||
let halfHourFee: Int | ||
let hourFee: Int | ||
let economyFee: Int | ||
let minimumFee: Int | ||
} |
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,27 @@ | ||
// | ||
// FeeService.swift | ||
// BDKSwiftExampleWallet | ||
// | ||
// Created by Matthew Ramsden on 8/23/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct FeeService { | ||
func fees() async throws -> RecommendedFees { | ||
guard let url = URL(string: "https://mempool.space/api/v1/fees/recommended") else { throw FeeServiceError.invalidURL } | ||
let (data, response) = try await URLSession.shared.data(from: url) | ||
guard let httpResponse = response as? HTTPURLResponse, | ||
200...299 ~= httpResponse.statusCode | ||
else { throw FeeServiceError.invalidServerResponse } | ||
let jsonDecoder = JSONDecoder() | ||
let jsonObject = try jsonDecoder.decode(RecommendedFees.self, from: data) | ||
return jsonObject | ||
} | ||
} | ||
|
||
enum FeeServiceError: Error { | ||
case invalidURL | ||
case invalidServerResponse | ||
case serialization | ||
} |
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