Skip to content

Commit

Permalink
Add monthly income service.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Jun 24, 2024
1 parent 344bd7d commit ad65694
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/SubVTData/Model/Report/MonthlyIncomeReport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation

public struct MonthlyIncome: Hashable {
public let year: UInt32
public let month: UInt32
public let income: Decimal
}

extension MonthlyIncome: Codable {}

public struct MonthlyIncomeReport {
public let rewardee: AccountId
public let tokenSymbol: String
public let monthlyIncome: [MonthlyIncome]
}

extension MonthlyIncomeReport: Codable {}
9 changes: 9 additions & 0 deletions Sources/SubVTData/Service/REST/ReportService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@ public final class ReportService: BaseRESTService {
method: .get
)
}

public func getMonthlyIncomeReport(
rewardeeAccountId: AccountId
) -> ServiceResponsePublisher<MonthlyIncomeReport> {
return perform(
path: "/validator/\(rewardeeAccountId.toHex())/income/monthly",
method: .get
)
}
}
14 changes: 14 additions & 0 deletions Tests/SubVTDataTests/ReportServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ final class ReportServiceTests: BaseTest {
}
}

func test19GetMonthlyIncome() {
testServiceCall(
publisher: service.getMonthlyIncomeReport(
rewardeeAccountId: validatorAccountId
)
) {
(report, error) in
print("\(report!.monthlyIncome[0].income)")
XCTAssertNil(error)
}
}

static var allTests = [
("test01GetSingleEraReport", test01GetSingleEraReport),
("test02GetMultipleEraReport", test02GetMultipleEraReport),
Expand All @@ -262,5 +274,7 @@ final class ReportServiceTests: BaseTest {
("test15GetSingleSessionValidatorReport", test15GetSingleSessionValidatorReport),
("test16GetMultipleSessionValidatorReport", test16GetMultipleSessionValidatorReport),
("test17GetCurrentSession", test17GetCurrentSession),
("test18GetNetworkStatus", test18GetNetworkStatus),
("test19GetMonthlyIncome", test19GetMonthlyIncome),
]
}

0 comments on commit ad65694

Please sign in to comment.