Skip to content

Commit

Permalink
Merge pull request #410 from Adamant-im/master
Browse files Browse the repository at this point in the history
Lisk Mainnet v4 support & new Dash and Lisk nodes
  • Loading branch information
StanislavDevIOS authored Dec 27, 2023
2 parents 6c78795 + ff2cc61 commit 07d3b2e
Show file tree
Hide file tree
Showing 47 changed files with 4,917 additions and 370 deletions.
6 changes: 3 additions & 3 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -3695,7 +3695,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.3.0;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -3726,7 +3726,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.3.0;
MARKETING_VERSION = 3.3.1;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension AdmWalletService {
}

var minNodeVersion: String? {
"0.7.0"
"0.8.0"
}

static let explorerAddress = "https://explorer.adamant.im/tx/"
Expand All @@ -62,8 +62,9 @@ Node(url: URL(string: "https://debate.adamant.im")!, altUrl: URL(string: "http:/
Node(url: URL(string: "http://78.47.205.206:36666")!),
Node(url: URL(string: "http://5.161.53.74:36666")!),
Node(url: URL(string: "http://184.94.215.92:45555")!),
Node(url: URL(string: "https://node1.adamant.business")!),
Node(url: URL(string: "https://node1.adamant.business")!, altUrl: URL(string: "http://194.233.75.29:45555")),
Node(url: URL(string: "https://node2.blockchain2fa.io")!),
Node(url: URL(string: "https://sunshine.adamant.im")!),
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ final class BtcTransferViewController: TransferViewControllerBase {

Task {
do {
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
let transaction = try await service.createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)

// Send adm report
if let reportRecipient = admReportRecipient,
Expand Down
4 changes: 2 additions & 2 deletions Adamant/Modules/Wallets/Bitcoin/BtcWalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension BtcWalletService: WalletServiceTwoStepSend {
typealias T = BitcoinKit.Transaction

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

let rawAmount = NSDecimalNumber(decimal: amount * BtcWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: self.transactionFee * BtcWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: fee * BtcWalletService.multiplier).uint64Value

// MARK: 2. Search for unspent transactions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ final class DashTransferViewController: TransferViewControllerBase {
Task {
do {
// Create transaction
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
let transaction = try await service.createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)

// Send adm report
if let reportRecipient = admReportRecipient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ extension DashWalletService {

static var nodes: [Node] {
[
Node(url: URL(string: "https://dashnode1.adamant.im")!),
Node(url: URL(string: "https://dashnode1.adamant.im")!, altUrl: URL(string: "http://45.85.147.224:44099")),
Node(url: URL(string: "https://dashnode2.adamant.im")!, altUrl: URL(string: "http://207.180.210.95:44099")),
]
}

Expand Down
20 changes: 16 additions & 4 deletions Adamant/Modules/Wallets/Dash/DashWalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ extension DashWalletService: WalletServiceTwoStepSend {
// MARK: Create & Send
func create(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
guard let lastTransaction = self.lastTransactionId else {
return try await createTransaction(recipient: recipient, amount: amount)
return try await createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)
}

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

return try await createTransaction(recipient: recipient, amount: amount)
return try await createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)
}

func createTransaction(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
func createTransaction(
recipient: String,
amount: Decimal,
fee: Decimal
) async throws -> BitcoinKit.Transaction {
// MARK: 1. Prepare
guard let wallet = self.dashWallet else {
throw WalletServiceError.notLogged
Expand All @@ -43,7 +55,7 @@ extension DashWalletService: WalletServiceTwoStepSend {
}

let rawAmount = NSDecimalNumber(decimal: amount * DashWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: self.transactionFee * DashWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: fee * DashWalletService.multiplier).uint64Value

// MARK: 2. Search for unspent transactions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ final class DogeTransferViewController: TransferViewControllerBase {
Task {
do {
// Create transaction
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
let transaction = try await service.createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)

// Send adm report
if let reportRecipient = admReportRecipient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension DogeWalletService {

static var nodes: [Node] {
[
Node(url: URL(string: "https://dogenode1.adamant.im")!),
Node(url: URL(string: "https://dogenode1.adamant.im")!, altUrl: URL(string: "http://5.9.99.62:44099")),
Node(url: URL(string: "https://dogenode2.adamant.im")!, altUrl: URL(string: "http://176.9.32.126:44098")),
]
}
Expand Down
8 changes: 6 additions & 2 deletions Adamant/Modules/Wallets/Doge/DogeWalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ extension DogeWalletService: WalletServiceTwoStepSend {
typealias T = BitcoinKit.Transaction

// MARK: Create & Send
func createTransaction(recipient: String, amount: Decimal) async throws -> BitcoinKit.Transaction {
func createTransaction(
recipient: String,
amount: Decimal,
fee: Decimal
) async throws -> BitcoinKit.Transaction {
// Prepare
guard let wallet = self.dogeWallet else {
throw WalletServiceError.notLogged
Expand All @@ -34,7 +38,7 @@ extension DogeWalletService: WalletServiceTwoStepSend {
}

let rawAmount = NSDecimalNumber(decimal: amount * DogeWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: self.transactionFee * DogeWalletService.multiplier).uint64Value
let fee = NSDecimalNumber(decimal: fee * DogeWalletService.multiplier).uint64Value

// Search for unspent transactions
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ final class ERC20TransferViewController: TransferViewControllerBase {
Task {
do {
// Create transaction
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
let transaction = try await service.createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)

guard let txHash = transaction.txHash else {
throw WalletServiceError.internalError(
Expand Down
6 changes: 5 additions & 1 deletion Adamant/Modules/Wallets/ERC20/ERC20WalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ extension ERC20WalletService: WalletServiceTwoStepSend {
typealias T = CodableTransaction

// MARK: Create & Send
func createTransaction(recipient: String, amount: Decimal) async throws -> CodableTransaction {
func createTransaction(
recipient: String,
amount: Decimal,
fee: Decimal
) async throws -> CodableTransaction {
guard let ethWallet = ethWallet else {
throw WalletServiceError.notLogged
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ final class EthTransferViewController: TransferViewControllerBase {
Task {
do {
// Create transaction
let transaction = try await service.createTransaction(recipient: recipient, amount: amount)
let transaction = try await service.createTransaction(
recipient: recipient,
amount: amount,
fee: transactionFee
)

guard let txHash = transaction.txHash else {
throw WalletServiceError.internalError(
Expand Down
6 changes: 5 additions & 1 deletion Adamant/Modules/Wallets/Ethereum/EthWalletService+Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ extension CodableTransaction: RawTransaction {
extension EthWalletService: WalletServiceTwoStepSend {
typealias T = CodableTransaction

func createTransaction(recipient: String, amount: Decimal) async throws -> CodableTransaction {
func createTransaction(
recipient: String,
amount: Decimal,
fee: Decimal
) async throws -> CodableTransaction {
try await ethApiService.requestWeb3 { [weak self] web3 in
guard let self = self else { throw WalletServiceError.internalError(.unknownError) }
return try await createTransaction(recipient: recipient, amount: amount, web3: web3)
Expand Down
39 changes: 30 additions & 9 deletions Adamant/Modules/Wallets/Lisk/LskApiCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,32 @@ class LskApiCore: BlockchainHealthCheckableService {
}
}

func request<Output>(
node: CommonKit.Node,
_ body: @Sendable @escaping (APIClient) async throws -> Output
) async -> WalletServiceResult<Output> {
let client = makeClient(node: node)

do {
return .success(try await body(client))
} catch {
return .failure(mapError(error))
}
}

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

return await request(node: node) { client, completion in
LiskKit.Node(client: client).info { completion($0) }
return await request(node: node) { client in
try await LiskKit.Node(client: client).info()
}.map { model in
.init(
ping: Date.now.timeIntervalSince1970 - startTimestamp,
height: model.data.height ?? .zero,
wsEnabled: false,
wsPort: nil,
version: nil
)
.init(
ping: Date.now.timeIntervalSince1970 - startTimestamp,
height: model.height ?? .zero,
wsEnabled: false,
wsPort: nil,
version: nil
)
}
}
}
Expand All @@ -69,3 +82,11 @@ private func mapError(_ error: APIError) -> WalletServiceError {
return .remoteServiceError(message: error.message, error: error)
}
}

private func mapError(_ error: Error) -> WalletServiceError {
if let error = error as? APIError {
return mapError(error)
}

return .remoteServiceError(message: error.localizedDescription, error: error)
}
26 changes: 14 additions & 12 deletions Adamant/Modules/Wallets/Lisk/LskNodeApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,18 @@ final class LskNodeApiService: WalletApiService {
}

func requestTransactionsApi<Output>(
body: @escaping @Sendable (
_ api: Transactions,
_ completion: @escaping @Sendable (LiskKit.Result<Output>) -> Void
) -> Void
_ request: @Sendable @escaping (Transactions) async throws -> Output
) async -> WalletServiceResult<Output> {
await requestClient { client, completion in
body(.init(client: client), completion)
await requestClient { client in
try await request(Transactions(client: client))
}
}

func requestAccountsApi<Output>(
body: @escaping @Sendable (
_ api: Accounts,
_ completion: @escaping @Sendable (LiskKit.Result<Output>) -> Void
) -> Void
_ request: @Sendable @escaping (Accounts) async throws -> Output
) async -> WalletServiceResult<Output> {
await requestClient { client, completion in
body(.init(client: client), completion)
await requestClient { client in
try await request(Accounts(client: client))
}
}

Expand All @@ -75,4 +69,12 @@ private extension LskNodeApiService {
await core.request(node: node, body: body)
}
}

func requestClient<Output>(
_ body: @Sendable @escaping (APIClient) async throws -> Output
) async -> WalletServiceResult<Output> {
await api.request { core, node in
await core.request(node: node, body)
}
}
}
18 changes: 17 additions & 1 deletion Adamant/Modules/Wallets/Lisk/LskServiceApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ final class LskServiceApiService: WalletApiService {
) -> Void
) async -> WalletServiceResult<Output> {
await requestClient { client, completion in
body(.init(client: client, version: .v2), completion)
body(.init(client: client, version: .v3), completion)
}
}

func requestServiceApi<Output>(
_ request: @Sendable @escaping (LiskKit.Service) async throws -> Output
) async -> WalletServiceResult<Output> {
await requestClient { client in
try await request(LiskKit.Service(client: client, version: .v3))
}
}
}
Expand All @@ -68,4 +76,12 @@ private extension LskServiceApiService {
await core.request(node: node, body: body)
}
}

func requestClient<Output>(
_ body: @Sendable @escaping (APIClient) async throws -> Output
) async -> WalletServiceResult<Output> {
await api.request { core, node in
await core.request(node: node, body)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,16 @@ extension TransactionEntity: TransactionDetails {
return id
}

var senderAddress: String {
return LiskKit.Crypto.getBase32Address(from: senderPublicKey)
}

var recipientAddress: String {
return self.asset.recipientAddressBase32
recipientAddressBase32
}

var dateValue: Date? {
return nil
}

var amountValue: Decimal? {
let value = BigUInt(self.asset.amount)
let value = BigUInt(self.params.amount)

return value.asDecimal(exponent: LskWalletService.currencyExponent)
}
Expand Down
Loading

0 comments on commit 07d3b2e

Please sign in to comment.