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

[trello.com/c/qDelB45V] Add the height and the version to IPFS #657

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions Adamant/Helpers/NodeGroup+Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,10 @@ extension NodeGroup {

var heightType: Node.HeightType? {
switch self {
case .btc, .eth, .klyNode, .klyService, .doge, .dash, .adm:
case .btc, .eth, .klyNode, .klyService, .doge, .dash, .adm, .ipfs:
.blocks
case .infoService:
.date
case .ipfs:
.none
}
}

Expand Down
35 changes: 33 additions & 2 deletions Adamant/Models/IPFSNodeStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,40 @@
//

import Foundation
import CommonKit
VeretennikovSV marked this conversation as resolved.
Show resolved Hide resolved

struct IPFSNodeStatus: Codable {
let version: String
struct IPFSNodeStatus: Decodable {
private enum CodingKeys: String, CodingKey {
case version
case timestamp
}

let height: Int
let version: Version?

init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let versionStringValue = try container.decodeIfPresent(String.self, forKey: .version)
if let versions = versionStringValue?.components(separatedBy: ".").compactMap({ Int($0) }) {
version = .init(versions)
} else {
version = nil
}
let timestamp = try container.decode(UInt64.self, forKey: .timestamp)
let timeStampInSeconds = String(timestamp / 1000)

/// Chicking the len of string representation of a timestamp in seconds
/// to cut first two symbols from it and convert it to height
if timeStampInSeconds.count >= 2 {
let subString = timeStampInSeconds[
timeStampInSeconds.index(timeStampInSeconds.startIndex, offsetBy: 2)..<timeStampInSeconds.endIndex
]
let string = String(subString)
height = Int(string) ?? .zero
} else {
height = .zero
}
just-software-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}

/* JSON
Expand Down
8 changes: 4 additions & 4 deletions Adamant/Services/FilesNetworkManager/IPFSApiCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ extension IPFSApiCore: BlockchainHealthCheckableService {
let statusResponse = await getNodeStatus(origin: origin)
let ping = Date.now.timeIntervalSince1970 - startTimestamp

return statusResponse.map { _ in
.init(
return statusResponse.map { data in
return .init(
ping: ping,
height: .zero,
height: data.height,
wsEnabled: false,
wsPort: nil,
version: nil
version: data.version
)
}
}
Expand Down