Skip to content

Commit f8b8b2c

Browse files
Merge pull request #403 from Adamant-im/dev/trello.com/c/XEj672SB
[trello.com/c/XEj672SB] feat: support v4 lisk node
2 parents 7c35535 + 1dbdfe2 commit f8b8b2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4910
-369
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 52;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -3695,7 +3695,7 @@
36953695
"$(inherited)",
36963696
"@executable_path/Frameworks",
36973697
);
3698-
MARKETING_VERSION = 3.3.0;
3698+
MARKETING_VERSION = 3.3.1;
36993699
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev";
37003700
PRODUCT_NAME = "$(TARGET_NAME)";
37013701
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -3726,7 +3726,7 @@
37263726
"$(inherited)",
37273727
"@executable_path/Frameworks",
37283728
);
3729-
MARKETING_VERSION = 3.3.0;
3729+
MARKETING_VERSION = 3.3.1;
37303730
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger";
37313731
PRODUCT_NAME = "$(TARGET_NAME)";
37323732
PROVISIONING_PROFILE_SPECIFIER = "";

Adamant/Modules/Wallets/Adamant/AdmWalletService+DynamicConstants.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension AdmWalletService {
4646
}
4747

4848
var minNodeVersion: String? {
49-
"0.7.0"
49+
"0.8.0"
5050
}
5151

5252
static let explorerAddress = "https://explorer.adamant.im/tx/"
@@ -62,8 +62,9 @@ Node(url: URL(string: "https://debate.adamant.im")!, altUrl: URL(string: "http:/
6262
Node(url: URL(string: "http://78.47.205.206:36666")!),
6363
Node(url: URL(string: "http://5.161.53.74:36666")!),
6464
Node(url: URL(string: "http://184.94.215.92:45555")!),
65-
Node(url: URL(string: "https://node1.adamant.business")!),
65+
Node(url: URL(string: "https://node1.adamant.business")!, altUrl: URL(string: "http://194.233.75.29:45555")),
6666
Node(url: URL(string: "https://node2.blockchain2fa.io")!),
67+
Node(url: URL(string: "https://sunshine.adamant.im")!),
6768
]
6869
}
6970

Adamant/Modules/Wallets/Bitcoin/BtcTransferViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ final class BtcTransferViewController: TransferViewControllerBase {
4747

4848
Task {
4949
do {
50-
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
50+
let transaction = try await service.createTransaction(
51+
recipient: recipient,
52+
amount: amount,
53+
fee: transactionFee
54+
)
5155

5256
// Send adm report
5357
if let reportRecipient = admReportRecipient,

Adamant/Modules/Wallets/Bitcoin/BtcWalletService+Send.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension BtcWalletService: WalletServiceTwoStepSend {
1414
typealias T = BitcoinKit.Transaction
1515

1616
// MARK: Create & Send
17-
func createTransaction(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
17+
func createTransaction(recipient: String, amount: Decimal, fee: Decimal) async throws -> BitcoinKit.Transaction {
1818
// MARK: 1. Prepare
1919
guard let wallet = self.btcWallet else {
2020
throw WalletServiceError.notLogged
@@ -27,7 +27,7 @@ extension BtcWalletService: WalletServiceTwoStepSend {
2727
}
2828

2929
let rawAmount = NSDecimalNumber(decimal: amount * BtcWalletService.multiplier).uint64Value
30-
let fee = NSDecimalNumber(decimal: self.transactionFee * BtcWalletService.multiplier).uint64Value
30+
let fee = NSDecimalNumber(decimal: fee * BtcWalletService.multiplier).uint64Value
3131

3232
// MARK: 2. Search for unspent transactions
3333

Adamant/Modules/Wallets/Dash/DashTransferViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ final class DashTransferViewController: TransferViewControllerBase {
4949
Task {
5050
do {
5151
// Create transaction
52-
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
52+
let transaction = try await service.createTransaction(
53+
recipient: recipient,
54+
amount: amount,
55+
fee: transactionFee
56+
)
5357

5458
// Send adm report
5559
if let reportRecipient = admReportRecipient,

Adamant/Modules/Wallets/Dash/DashWalletService+DynamicConstants.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ extension DashWalletService {
6161

6262
static var nodes: [Node] {
6363
[
64-
Node(url: URL(string: "https://dashnode1.adamant.im")!),
64+
Node(url: URL(string: "https://dashnode1.adamant.im")!, altUrl: URL(string: "http://45.85.147.224:44099")),
65+
Node(url: URL(string: "https://dashnode2.adamant.im")!, altUrl: URL(string: "http://207.180.210.95:44099")),
6566
]
6667
}
6768

Adamant/Modules/Wallets/Dash/DashWalletService+Send.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ extension DashWalletService: WalletServiceTwoStepSend {
1616
// MARK: Create & Send
1717
func create(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
1818
guard let lastTransaction = self.lastTransactionId else {
19-
return try await createTransaction(recipient: recipient, amount: amount)
19+
return try await createTransaction(
20+
recipient: recipient,
21+
amount: amount,
22+
fee: transactionFee
23+
)
2024
}
2125

2226
let transaction = try await getTransaction(by: lastTransaction)
@@ -27,10 +31,18 @@ extension DashWalletService: WalletServiceTwoStepSend {
2731
throw WalletServiceError.remoteServiceError(message: "WAIT_FOR_COMPLETION", error: nil)
2832
}
2933

30-
return try await createTransaction(recipient: recipient, amount: amount)
34+
return try await createTransaction(
35+
recipient: recipient,
36+
amount: amount,
37+
fee: transactionFee
38+
)
3139
}
3240

33-
func createTransaction(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
41+
func createTransaction(
42+
recipient: String,
43+
amount: Decimal,
44+
fee: Decimal
45+
) async throws -> BitcoinKit.Transaction {
3446
// MARK: 1. Prepare
3547
guard let wallet = self.dashWallet else {
3648
throw WalletServiceError.notLogged
@@ -43,7 +55,7 @@ extension DashWalletService: WalletServiceTwoStepSend {
4355
}
4456

4557
let rawAmount = NSDecimalNumber(decimal: amount * DashWalletService.multiplier).uint64Value
46-
let fee = NSDecimalNumber(decimal: self.transactionFee * DashWalletService.multiplier).uint64Value
58+
let fee = NSDecimalNumber(decimal: fee * DashWalletService.multiplier).uint64Value
4759

4860
// MARK: 2. Search for unspent transactions
4961

Adamant/Modules/Wallets/Doge/DogeTransferViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ final class DogeTransferViewController: TransferViewControllerBase {
4040
Task {
4141
do {
4242
// Create transaction
43-
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
43+
let transaction = try await service.createTransaction(
44+
recipient: recipient,
45+
amount: amount,
46+
fee: transactionFee
47+
)
4448

4549
// Send adm report
4650
if let reportRecipient = admReportRecipient,

Adamant/Modules/Wallets/Doge/DogeWalletService+DynamicConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension DogeWalletService {
6161

6262
static var nodes: [Node] {
6363
[
64-
Node(url: URL(string: "https://dogenode1.adamant.im")!),
64+
Node(url: URL(string: "https://dogenode1.adamant.im")!, altUrl: URL(string: "http://5.9.99.62:44099")),
6565
Node(url: URL(string: "https://dogenode2.adamant.im")!, altUrl: URL(string: "http://176.9.32.126:44098")),
6666
]
6767
}

Adamant/Modules/Wallets/Doge/DogeWalletService+Send.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ extension DogeWalletService: WalletServiceTwoStepSend {
2121
typealias T = BitcoinKit.Transaction
2222

2323
// MARK: Create & Send
24-
func createTransaction(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
24+
func createTransaction(
25+
recipient: String,
26+
amount: Decimal,
27+
fee: Decimal
28+
) async throws -> BitcoinKit.Transaction {
2529
// Prepare
2630
guard let wallet = self.dogeWallet else {
2731
throw WalletServiceError.notLogged
@@ -34,7 +38,7 @@ extension DogeWalletService: WalletServiceTwoStepSend {
3438
}
3539

3640
let rawAmount = NSDecimalNumber(decimal: amount * DogeWalletService.multiplier).uint64Value
37-
let fee = NSDecimalNumber(decimal: self.transactionFee * DogeWalletService.multiplier).uint64Value
41+
let fee = NSDecimalNumber(decimal: fee * DogeWalletService.multiplier).uint64Value
3842

3943
// Search for unspent transactions
4044
do {

Adamant/Modules/Wallets/ERC20/ERC20TransferViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ final class ERC20TransferViewController: TransferViewControllerBase {
4444
Task {
4545
do {
4646
// Create transaction
47-
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
47+
let transaction = try await service.createTransaction(
48+
recipient: recipient,
49+
amount: amount,
50+
fee: transactionFee
51+
)
4852

4953
guard let txHash = transaction.txHash else {
5054
throw WalletServiceError.internalError(

Adamant/Modules/Wallets/ERC20/ERC20WalletService+Send.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ extension ERC20WalletService: WalletServiceTwoStepSend {
1616
typealias T = CodableTransaction
1717

1818
// MARK: Create & Send
19-
func createTransaction(recipient: String, amount: Decimal) async throws -> CodableTransaction {
19+
func createTransaction(
20+
recipient: String,
21+
amount: Decimal,
22+
fee: Decimal
23+
) async throws -> CodableTransaction {
2024
guard let ethWallet = ethWallet else {
2125
throw WalletServiceError.notLogged
2226
}

Adamant/Modules/Wallets/Ethereum/EthTransferViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ final class EthTransferViewController: TransferViewControllerBase {
3838
Task {
3939
do {
4040
// Create transaction
41-
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
41+
let transaction = try await service.createTransaction(
42+
recipient: recipient,
43+
amount: amount,
44+
fee: transactionFee
45+
)
4246

4347
guard let txHash = transaction.txHash else {
4448
throw WalletServiceError.internalError(

Adamant/Modules/Wallets/Ethereum/EthWalletService+Send.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ extension CodableTransaction: RawTransaction {
2222
extension EthWalletService: WalletServiceTwoStepSend {
2323
typealias T = CodableTransaction
2424

25-
func createTransaction(recipient: String, amount: Decimal) async throws -> CodableTransaction {
25+
func createTransaction(
26+
recipient: String,
27+
amount: Decimal,
28+
fee: Decimal
29+
) async throws -> CodableTransaction {
2630
try await ethApiService.requestWeb3 { [weak self] web3 in
2731
guard let self = self else { throw WalletServiceError.internalError(.unknownError) }
2832
return try await createTransaction(recipient: recipient, amount: amount, web3: web3)

Adamant/Modules/Wallets/Lisk/LskApiCore.swift

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,32 @@ class LskApiCore: BlockchainHealthCheckableService {
3333
}
3434
}
3535

36+
func request<Output>(
37+
node: CommonKit.Node,
38+
_ body: @Sendable @escaping (APIClient) async throws -> Output
39+
) async -> WalletServiceResult<Output> {
40+
let client = makeClient(node: node)
41+
42+
do {
43+
return .success(try await body(client))
44+
} catch {
45+
return .failure(mapError(error))
46+
}
47+
}
48+
3649
func getStatusInfo(node: CommonKit.Node) async -> WalletServiceResult<NodeStatusInfo> {
3750
let startTimestamp = Date.now.timeIntervalSince1970
3851

39-
return await request(node: node) { client, completion in
40-
LiskKit.Node(client: client).info { completion($0) }
52+
return await request(node: node) { client in
53+
try await LiskKit.Node(client: client).info()
4154
}.map { model in
42-
.init(
43-
ping: Date.now.timeIntervalSince1970 - startTimestamp,
44-
height: model.data.height ?? .zero,
45-
wsEnabled: false,
46-
wsPort: nil,
47-
version: nil
48-
)
55+
.init(
56+
ping: Date.now.timeIntervalSince1970 - startTimestamp,
57+
height: model.height ?? .zero,
58+
wsEnabled: false,
59+
wsPort: nil,
60+
version: nil
61+
)
4962
}
5063
}
5164
}
@@ -69,3 +82,11 @@ private func mapError(_ error: APIError) -> WalletServiceError {
6982
return .remoteServiceError(message: error.message, error: error)
7083
}
7184
}
85+
86+
private func mapError(_ error: Error) -> WalletServiceError {
87+
if let error = error as? APIError {
88+
return mapError(error)
89+
}
90+
91+
return .remoteServiceError(message: error.localizedDescription, error: error)
92+
}

Adamant/Modules/Wallets/Lisk/LskNodeApiService.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,18 @@ final class LskNodeApiService: WalletApiService {
3636
}
3737

3838
func requestTransactionsApi<Output>(
39-
body: @escaping @Sendable (
40-
_ api: Transactions,
41-
_ completion: @escaping @Sendable (LiskKit.Result<Output>) -> Void
42-
) -> Void
39+
_ request: @Sendable @escaping (Transactions) async throws -> Output
4340
) async -> WalletServiceResult<Output> {
44-
await requestClient { client, completion in
45-
body(.init(client: client), completion)
41+
await requestClient { client in
42+
try await request(Transactions(client: client))
4643
}
4744
}
4845

4946
func requestAccountsApi<Output>(
50-
body: @escaping @Sendable (
51-
_ api: Accounts,
52-
_ completion: @escaping @Sendable (LiskKit.Result<Output>) -> Void
53-
) -> Void
47+
_ request: @Sendable @escaping (Accounts) async throws -> Output
5448
) async -> WalletServiceResult<Output> {
55-
await requestClient { client, completion in
56-
body(.init(client: client), completion)
49+
await requestClient { client in
50+
try await request(Accounts(client: client))
5751
}
5852
}
5953

@@ -75,4 +69,12 @@ private extension LskNodeApiService {
7569
await core.request(node: node, body: body)
7670
}
7771
}
72+
73+
func requestClient<Output>(
74+
_ body: @Sendable @escaping (APIClient) async throws -> Output
75+
) async -> WalletServiceResult<Output> {
76+
await api.request { core, node in
77+
await core.request(node: node, body)
78+
}
79+
}
7880
}

Adamant/Modules/Wallets/Lisk/LskServiceApiService.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ final class LskServiceApiService: WalletApiService {
5252
) -> Void
5353
) async -> WalletServiceResult<Output> {
5454
await requestClient { client, completion in
55-
body(.init(client: client, version: .v2), completion)
55+
body(.init(client: client, version: .v3), completion)
56+
}
57+
}
58+
59+
func requestServiceApi<Output>(
60+
_ request: @Sendable @escaping (LiskKit.Service) async throws -> Output
61+
) async -> WalletServiceResult<Output> {
62+
await requestClient { client in
63+
try await request(LiskKit.Service(client: client, version: .v3))
5664
}
5765
}
5866
}
@@ -68,4 +76,12 @@ private extension LskServiceApiService {
6876
await core.request(node: node, body: body)
6977
}
7078
}
79+
80+
func requestClient<Output>(
81+
_ body: @Sendable @escaping (APIClient) async throws -> Output
82+
) async -> WalletServiceResult<Output> {
83+
await api.request { core, node in
84+
await core.request(node: node, body)
85+
}
86+
}
7187
}

Adamant/Modules/Wallets/Lisk/LskTransactionsViewController.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,16 @@ extension TransactionEntity: TransactionDetails {
179179
return id
180180
}
181181

182-
var senderAddress: String {
183-
return LiskKit.Crypto.getBase32Address(from: senderPublicKey)
184-
}
185-
186182
var recipientAddress: String {
187-
return self.asset.recipientAddressBase32
183+
recipientAddressBase32
188184
}
189185

190186
var dateValue: Date? {
191187
return nil
192188
}
193189

194190
var amountValue: Decimal? {
195-
let value = BigUInt(self.asset.amount)
191+
let value = BigUInt(self.params.amount)
196192

197193
return value.asDecimal(exponent: LskWalletService.currencyExponent)
198194
}

0 commit comments

Comments
 (0)