Skip to content

Commit

Permalink
[trello.com/c/PdYjG3m2] Added alt_ip processing
Browse files Browse the repository at this point in the history
  • Loading branch information
“just-software-dev” committed Jul 30, 2024
1 parent 3bfaa58 commit 4677722
Show file tree
Hide file tree
Showing 51 changed files with 739 additions and 405 deletions.
20 changes: 20 additions & 0 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
93294B9A2AAD624100911109 /* WalletFactoryCompose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93294B992AAD624100911109 /* WalletFactoryCompose.swift */; };
932B34E92974AA4A002A75BA /* ChatPreservationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932B34E82974AA4A002A75BA /* ChatPreservationProtocol.swift */; };
932F77592989F999006D8801 /* ChatCellManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932F77582989F999006D8801 /* ChatCellManager.swift */; };
9332DBCD2C58C398000EC872 /* OldNodeWithGroupDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9332DBCC2C58C398000EC872 /* OldNodeWithGroupDTO.swift */; };
9338AE7F2AEF43DA001D32DF /* NodesStorageProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9338AE7E2AEF43DA001D32DF /* NodesStorageProtocol.swift */; };
9338AE812AEF4B8E001D32DF /* NodesStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9338AE802AEF4B8E001D32DF /* NodesStorage.swift */; };
9338AE842AEF5EFA001D32DF /* APICoreProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9338AE832AEF5EFA001D32DF /* APICoreProtocol.swift */; };
Expand Down Expand Up @@ -322,6 +323,8 @@
93CCAE7B2B06D9B500EA5B94 /* DogeBlocksDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93CCAE7A2B06D9B500EA5B94 /* DogeBlocksDTO.swift */; };
93CCAE7E2B06DA6C00EA5B94 /* DogeBlockDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93CCAE7D2B06DA6C00EA5B94 /* DogeBlockDTO.swift */; };
93CCAE802B06E2D100EA5B94 /* ApiServiceError+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93CCAE7F2B06E2D100EA5B94 /* ApiServiceError+Extension.swift */; };
93D02C802C564EF90011D819 /* NodeWithGroupDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93D02C7F2C564EF90011D819 /* NodeWithGroupDTO.swift */; };
93D02C822C564F710011D819 /* NodeWithGroup+NodeWithGroupDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93D02C812C564F710011D819 /* NodeWithGroup+NodeWithGroupDTO.swift */; };
93E1232F2A6DF8EF004DF33B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 93E123312A6DF8EF004DF33B /* InfoPlist.strings */; };
93E123382A6DFD15004DF33B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 93E1233A2A6DFD15004DF33B /* Localizable.strings */; };
93E1233F2A6DFE24004DF33B /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 93E123412A6DFE24004DF33B /* Localizable.stringsdict */; };
Expand Down Expand Up @@ -873,6 +876,7 @@
93294B992AAD624100911109 /* WalletFactoryCompose.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletFactoryCompose.swift; sourceTree = "<group>"; };
932B34E82974AA4A002A75BA /* ChatPreservationProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatPreservationProtocol.swift; sourceTree = "<group>"; };
932F77582989F999006D8801 /* ChatCellManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCellManager.swift; sourceTree = "<group>"; };
9332DBCC2C58C398000EC872 /* OldNodeWithGroupDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OldNodeWithGroupDTO.swift; sourceTree = "<group>"; };
9338AE7E2AEF43DA001D32DF /* NodesStorageProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodesStorageProtocol.swift; sourceTree = "<group>"; };
9338AE802AEF4B8E001D32DF /* NodesStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodesStorage.swift; sourceTree = "<group>"; };
9338AE832AEF5EFA001D32DF /* APICoreProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICoreProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -964,6 +968,8 @@
93CCAE7A2B06D9B500EA5B94 /* DogeBlocksDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DogeBlocksDTO.swift; sourceTree = "<group>"; };
93CCAE7D2B06DA6C00EA5B94 /* DogeBlockDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DogeBlockDTO.swift; sourceTree = "<group>"; };
93CCAE7F2B06E2D100EA5B94 /* ApiServiceError+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ApiServiceError+Extension.swift"; sourceTree = "<group>"; };
93D02C7F2C564EF90011D819 /* NodeWithGroupDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeWithGroupDTO.swift; sourceTree = "<group>"; };
93D02C812C564F710011D819 /* NodeWithGroup+NodeWithGroupDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NodeWithGroup+NodeWithGroupDTO.swift"; sourceTree = "<group>"; };
93E123302A6DF8EF004DF33B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
93E123322A6DF8F1004DF33B /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/InfoPlist.strings; sourceTree = "<group>"; };
93E123332A6DF8F2004DF33B /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1835,6 +1841,15 @@
path = DTO;
sourceTree = "<group>";
};
93D02C7E2C564DEE0011D819 /* Keychain */ = {
isa = PBXGroup;
children = (
93D02C7F2C564EF90011D819 /* NodeWithGroupDTO.swift */,
9332DBCC2C58C398000EC872 /* OldNodeWithGroupDTO.swift */,
);
path = Keychain;
sourceTree = "<group>";
};
93E123342A6DFCA6004DF33B /* NotificationsShared */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2045,6 +2060,7 @@
E913C9091FFFA95A001A83F7 /* Models */ = {
isa = PBXGroup;
children = (
93D02C7E2C564DEE0011D819 /* Keychain */,
E91947B72000326B001362F8 /* ServerResponses */,
E95F859220094B8E0070534A /* CoreData */,
E91947B320002809001362F8 /* AdamantAccount.swift */,
Expand Down Expand Up @@ -2117,6 +2133,7 @@
936658942B0AC15300BDB2D3 /* Node+UI.swift */,
3AF53F8C2B3DCFA300B30312 /* NodeGroup+Constants.swift */,
3AA3880B2B69201B00125684 /* ADM+JsonDecode.swift */,
93D02C812C564F710011D819 /* NodeWithGroup+NodeWithGroupDTO.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -3059,6 +3076,7 @@
E9E7CD8D20026B6600DFC4DB /* DialogService.swift in Sources */,
E9E7CDB72003994E00DFC4DB /* AdamantUtilities+extended.swift in Sources */,
E9147B6320505C7500145913 /* QRCodeReader+adamant.swift in Sources */,
9332DBCD2C58C398000EC872 /* OldNodeWithGroupDTO.swift in Sources */,
E90055F720EC200900D0CB2D /* SecurityViewController.swift in Sources */,
939FA3422B0D6F0000710EC6 /* SelfRemovableHostingController.swift in Sources */,
644EC35E20F34F1E00F40C73 /* DelegateDetailsViewController.swift in Sources */,
Expand Down Expand Up @@ -3132,6 +3150,7 @@
E9E7CD932002740500DFC4DB /* AdamantAccountService.swift in Sources */,
41330F7629F1509400CB587C /* AdamantCellAnimation.swift in Sources */,
64FA53CD20E1300B006783C9 /* EthTransactionsViewController.swift in Sources */,
93D02C822C564F710011D819 /* NodeWithGroup+NodeWithGroupDTO.swift in Sources */,
6449BA6A235CA0930033B936 /* ERC20Wallet.swift in Sources */,
E9147B612050599000145913 /* LoginViewController+QR.swift in Sources */,
9399F5ED29A85A48006C3E30 /* ChatCacheService.swift in Sources */,
Expand Down Expand Up @@ -3190,6 +3209,7 @@
648BCA6D213D384F00875EB5 /* AvatarService.swift in Sources */,
E95F856F2007B61D0070534A /* GetPublicKeyResponse.swift in Sources */,
3A26D94B2C3D3838003AD832 /* KlyTransactionsViewController.swift in Sources */,
93D02C802C564EF90011D819 /* NodeWithGroupDTO.swift in Sources */,
936658992B0AD32600BDB2D3 /* CoinsNodesListViewModel+ApiServices.swift in Sources */,
644EC34D20EFA60900F40C73 /* AdamantApi+Delegates.swift in Sources */,
E940088F2119A9E800CD2D67 /* BigInt+Decimal.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Adamant/Helpers/Node+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension Node {

func indicatorString(isRest: Bool, isWs: Bool) -> String {
let connections = [
isRest ? scheme.rawValue : nil,
isRest ? preferredOrigin.scheme.rawValue : nil,
isWs ? "ws" : nil
].compactMap { $0 }

Expand Down
19 changes: 19 additions & 0 deletions Adamant/Helpers/NodeWithGroup+NodeWithGroupDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NodeWithGroup+NodeWithGroupDTO.swift
// Adamant
//
// Created by Andrew G on 28.07.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

extension NodeWithGroup {
func mapToDto() -> NodeWithGroupDTO {
.init(group: group, node: node.mapToDto())
}
}

extension NodeWithGroupDTO {
func mapToModel() -> NodeWithGroup {
.init(group: group, node: node.mapToModel())
}
}
14 changes: 14 additions & 0 deletions Adamant/Models/Keychain/NodeWithGroupDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NodeWithGroupDTO.swift
// Adamant
//
// Created by Andrew G on 28.07.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import CommonKit

struct NodeWithGroupDTO: Codable {
let group: NodeGroup
let node: NodeDTO
}
20 changes: 20 additions & 0 deletions Adamant/Models/Keychain/OldNodeWithGroupDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// OldNodeWithGroupDTO.swift
// Adamant
//
// Created by Andrew G on 30.07.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import CommonKit

struct OldNodeWithGroupDTO: Codable {
let group: NodeGroup
let node: OldNodeDTO
}

extension OldNodeWithGroupDTO {
func mapToModernDto() -> NodeWithGroupDTO {
.init(group: group, node: node.mapToModernDto())
}
}
2 changes: 1 addition & 1 deletion Adamant/Models/NodeWithGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CommonKit

struct NodeWithGroup: Codable, Equatable {
struct NodeWithGroup: Equatable {
let group: NodeGroup
var node: Node
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class CoinsNodesListViewModel: ObservableObject {
}

func setIsEnabled(id: UUID, value: Bool) {
nodesStorage.updateNodeParams(id: id, isEnabled: value)
nodesStorage.updateNode(id: id) { $0.isEnabled = value }
}

func reset() {
Expand Down
48 changes: 28 additions & 20 deletions Adamant/Modules/NodesEditor/NodeEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class NodeEditorViewController: FormViewController {
super.viewDidLoad()

if let node = node {
self.navigationItem.title = node.host
self.navigationItem.title = node.mainOrigin.host
} else {
self.navigationItem.title = String.adamant.nodesEditor.newNodeTitle
}
Expand All @@ -131,7 +131,7 @@ final class NodeEditorViewController: FormViewController {
$0.tag = Rows.host.tag
$0.placeholder = Rows.host.placeholder

$0.value = node?.host
$0.value = node?.mainOrigin.host
}

// Port
Expand All @@ -140,18 +140,18 @@ final class NodeEditorViewController: FormViewController {
$0.tag = Rows.port.tag

if let node = node {
$0.value = node.port
$0.placeholder = String(node.scheme.defaultPort)
$0.value = node.mainOrigin.port
$0.placeholder = String(node.mainOrigin.scheme.defaultPort)
} else {
$0.placeholder = String(Node.URLScheme.default.defaultPort)
$0.placeholder = String(NodeOrigin.URLScheme.default.defaultPort)
}
}

// Scheme
<<< PickerInlineRow<Node.URLScheme> {
<<< PickerInlineRow<NodeOrigin.URLScheme> {
$0.title = Rows.scheme.localized
$0.tag = Rows.scheme.tag
$0.value = node?.scheme ?? Node.URLScheme.default
$0.value = node?.mainOrigin.scheme ?? NodeOrigin.URLScheme.default
$0.options = [.https, .http]
$0.baseCell.detailTextLabel?.textColor = .adamant.textColor
}.onExpandInlineRow { (cell, _, inlineRow) in
Expand All @@ -161,7 +161,7 @@ final class NodeEditorViewController: FormViewController {
if let scheme = row.value {
portRow.placeholder = String(scheme.defaultPort)
} else {
portRow.placeholder = String(Node.URLScheme.default.defaultPort)
portRow.placeholder = String(NodeOrigin.URLScheme.default.defaultPort)
}

portRow.updateCell()
Expand Down Expand Up @@ -223,11 +223,11 @@ extension NodeEditorViewController {
}

let host = rawUrl.trimmingCharacters(in: .whitespaces)
let scheme: Node.URLScheme
let scheme: NodeOrigin.URLScheme

if
let row = form.rowBy(tag: Rows.scheme.tag),
let value = row.baseValue as? Node.URLScheme
let value = row.baseValue as? NodeOrigin.URLScheme
{
scheme = value
} else {
Expand All @@ -243,21 +243,29 @@ extension NodeEditorViewController {

let result: NodeEditorResult
if let node = node {
nodesStorage.updateNodeParams(
id: node.id,
scheme: scheme,
host: host,
port: port
)
nodesStorage.updateNode(id: node.id) { node in
node.mainOrigin.scheme = scheme
node.mainOrigin.host = host
node.mainOrigin.port = port
}

result = .nodeUpdated
} else {
result = .new(node: Node(
scheme: scheme,
host: host,
result = .new(node: .init(
id: .init(),
isEnabled: true,
wsEnabled: false,
port: port
mainOrigin: .init(
scheme: scheme,
host: host,
port: port
),
altOrigin: nil,
version: nil,
height: nil,
ping: nil,
connectionStatus: nil,
preferMainOrigin: nil
))
}

Expand Down
2 changes: 1 addition & 1 deletion Adamant/Modules/NodesEditor/NodesListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ extension NodesListViewController {
statusString: node.statusString(showVersion: true) ?? .empty,
isEnabled: node.isEnabled,
nodeUpdateAction: .init(id: node.id.uuidString) { [nodesStorage] isEnabled in
nodesStorage.updateNodeParams(id: node.id, isEnabled: isEnabled)
nodesStorage.updateNode(id: node.id) { $0.isEnabled = isEnabled }
}
)
}
Expand Down
20 changes: 10 additions & 10 deletions Adamant/Modules/Wallets/Bitcoin/BtcApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ final class BtcApiCore: BlockchainHealthCheckableService {
}

func request<Output>(
node: Node,
_ request: @Sendable @escaping (APICoreProtocol, Node) async -> ApiServiceResult<Output>
origin: NodeOrigin,
_ request: @Sendable @escaping (APICoreProtocol, NodeOrigin) async -> ApiServiceResult<Output>
) async -> WalletServiceResult<Output> {
await request(apiCore, node).mapError { $0.asWalletServiceError() }
await request(apiCore, origin).mapError { $0.asWalletServiceError() }
}

func getStatusInfo(node: Node) async -> WalletServiceResult<NodeStatusInfo> {
func getStatusInfo(origin: NodeOrigin) async -> WalletServiceResult<NodeStatusInfo> {
let startTimestamp = Date.now.timeIntervalSince1970

let response = await apiCore.sendRequestRPC(
node: node,
origin: origin,
path: BtcApiCommands.getRPC(),
requests: [
.init(method: BtcApiCommands.blockchainInfoMethod),
Expand Down Expand Up @@ -80,16 +80,16 @@ final class BtcApiService: WalletApiService {
}

func request<Output>(
_ request: @Sendable @escaping (APICoreProtocol, Node) async -> ApiServiceResult<Output>
_ request: @Sendable @escaping (APICoreProtocol, NodeOrigin) async -> ApiServiceResult<Output>
) async -> WalletServiceResult<Output> {
await api.request { core, node in
await core.request(node: node, request)
await api.request { core, origin in
await core.request(origin: origin, request)
}
}

func getStatusInfo() async -> WalletServiceResult<NodeStatusInfo> {
await api.request { core, node in
await core.getStatusInfo(node: node)
await api.request { core, origin in
await core.getStatusInfo(origin: origin)
}
}
}
9 changes: 4 additions & 5 deletions Adamant/Modules/Wallets/Bitcoin/BtcWalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ extension BtcWalletService: WalletServiceTwoStepSend {
let txHex = transaction.serialized().hex

// MARK: Sending request
let responseData = try await btcApiService.request { core, node in
let responseData = try await btcApiService.request { core, origin in
await core.sendRequest(
node: node,
origin: origin,
path: BtcApiCommands.sendTransaction(),
method: .post,
parameters: [String.empty: txHex],
Expand All @@ -88,9 +88,9 @@ extension BtcWalletService: WalletServiceTwoStepSend {
let address = wallet.address
let parameters = ["noCache": "1"]

let responseData = try await btcApiService.request { core, node in
let responseData = try await btcApiService.request { core, origin in
await core.sendRequest(
node: node,
origin: origin,
path: BtcApiCommands.getUnspentTransactions(for: address),
method: .get,
parameters: parameters,
Expand Down Expand Up @@ -128,5 +128,4 @@ extension BtcWalletService: WalletServiceTwoStepSend {

return utxos
}

}
Loading

0 comments on commit 4677722

Please sign in to comment.