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

Feature/3913 add chia transaction builder #381

Merged
merged 62 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2bec06b
IOS-3913 add init commit for chia transaction builder
skibinalexander Jul 14, 2023
3aab5be
Merge branch 'feature/IOS-3987-add-chia-address-service' into feature…
skibinalexander Jul 15, 2023
ca00620
IOS-3913 Add chia network provider implementation
skibinalexander Jul 15, 2023
4b0ab1b
IOS-3913 Revert wrong changes
skibinalexander Jul 16, 2023
e1666d1
IOS-3913 Add implementation network service
skibinalexander Jul 17, 2023
bd2987d
IOS-3913 Add implementation chia transaction sign builder
skibinalexander Jul 18, 2023
80a7b69
IOS-3913 Add implementation condition
skibinalexander Jul 18, 2023
af57eb8
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Jul 24, 2023
4fc583a
IOS-3913 Add implementation transaction builder
skibinalexander Jul 24, 2023
7126f92
IOS-3913 Add acc value for reduce
skibinalexander Jul 24, 2023
27b43c5
IOS-3913 Add chia condition transaction builder
skibinalexander Jul 24, 2023
dc2f880
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Jul 24, 2023
f84a218
IOS-3913 Add implementation befor aug scheme
skibinalexander Jul 25, 2023
a87aff7
IOS-3913 Add aug scheme for aggregate g2map point
skibinalexander Jul 25, 2023
1e1c999
IOS-3913 Add encode value chia transaction
skibinalexander Jul 25, 2023
e937981
IOS-3913 Add chia transaction completed building
skibinalexander Jul 25, 2023
81ae6cf
Merge branch 'feature/IOS-3987-add-chia-address-service' into feature…
skibinalexander Jul 26, 2023
57fef32
IOS-3913 Make chia transaction uint64 amount
skibinalexander Jul 26, 2023
5fe78ef
IOS-3913 Add send transaction model
skibinalexander Jul 27, 2023
e85c2f2
IOS-3913 Fix review constants
skibinalexander Jul 27, 2023
8ecf943
IOS-3913 Add send transaction logic
skibinalexander Jul 31, 2023
e11764f
Merge branch 'feature/IOS-3987-add-chia-address-service' into feature…
skibinalexander Jul 31, 2023
d4ddc56
IOS-3913 Success sending transaction for chia
skibinalexander Jul 31, 2023
7033e4a
Merge branch 'feature/IOS-3987-add-chia-address-service' into feature…
skibinalexander Aug 2, 2023
e07b703
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 2, 2023
4370624
IOS-3913 Fee fee calculation
skibinalexander Aug 2, 2023
88db54a
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 2, 2023
99cd1b2
IOS-3913 Fix calculate fee for transactions
skibinalexander Aug 2, 2023
585d43f
IOS-3913 Remove inout Bls_Signature fraemwork
skibinalexander Aug 3, 2023
4f3561d
IOS-3913 Remove keys from visible
skibinalexander Aug 3, 2023
1ca6040
IOS-3913 Remove unsue library
skibinalexander Aug 6, 2023
1d8d873
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 6, 2023
eb41d89
IOS-3913 Revert podfile.lock
skibinalexander Aug 6, 2023
74a95ae
IOS-3913 Ready for review
skibinalexander Aug 7, 2023
b91c11e
IOS-3913 remove force uwrap
skibinalexander Aug 7, 2023
0e39bc4
IOS-3913 Fix review comments
skibinalexander Aug 10, 2023
76ac7d7
IOS-3914 Fix error app
skibinalexander Aug 10, 2023
caf34f8
IOS-3913 Fix review comments
skibinalexander Aug 10, 2023
80b34df
IOS-3913 Fix review comment for ,
skibinalexander Aug 10, 2023
91d2404
IOS-3913 Fix review comment for chiaEncode
skibinalexander Aug 10, 2023
e6dd013
IOS-3913 Fix review comments
skibinalexander Aug 11, 2023
e9db06c
IOS-3913 Fix self no need implement
skibinalexander Aug 11, 2023
1f91f1d
IOS-3913 Fix review comments
skibinalexander Aug 11, 2023
6adc7a4
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 11, 2023
dbfb1ea
IOS-3913 Fix review comments
skibinalexander Aug 11, 2023
c81910f
IOS-3913 Fix test vectors and update tangemSdk tag
skibinalexander Aug 11, 2023
c871dcc
IOS-3913 Update test vector
skibinalexander Aug 11, 2023
2bc9ee6
IOS-3913 Add skip for tezos
skibinalexander Aug 11, 2023
a290f43
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 11, 2023
045f4b3
IOS-3913 Update allow fragments
skibinalexander Aug 11, 2023
56a4e15
IOS-3913 Move uint64 to int64 for chia
skibinalexander Aug 13, 2023
c7c5b51
IOS-3913 Fix review comments
skibinalexander Aug 14, 2023
606e9f9
IOS-3913 Add allow fee selection
skibinalexander Aug 14, 2023
339214d
IOS-3913 remove spaces
skibinalexander Aug 14, 2023
b8dcda4
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 14, 2023
f8ea5ac
IOS-3913 Fix resolve merge conflicts
skibinalexander Aug 14, 2023
1af1125
IOS-3913 Add new tangemSdk tag
skibinalexander Aug 15, 2023
8891fed
IOS-3913 Fix comment space
skibinalexander Aug 15, 2023
7b13438
IOS-3913 Update podfile.lock
skibinalexander Aug 15, 2023
68907dc
IOS-3913 Make private lib BLS-Signature
skibinalexander Aug 15, 2023
88496e9
Merge branch 'develop' into feature/3913-add-chia-transaction-builder
skibinalexander Aug 15, 2023
9b77858
IOS-3913 Update tangemSdk tag
skibinalexander Aug 15, 2023
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
56 changes: 56 additions & 0 deletions BlockchainSdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
2D9A91A429BB8C1700476EA6 /* TONProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A919D29BB8C1700476EA6 /* TONProvider.swift */; };
2D9A91A529BB8C1700476EA6 /* TONProviderRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A919E29BB8C1700476EA6 /* TONProviderRequest.swift */; };
2D9A91A729BB8C2E00476EA6 /* WalletCoreAddressService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A91A629BB8C2E00476EA6 /* WalletCoreAddressService.swift */; };
2DA139F72A8AD82E00E3C374 /* ChiaModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139F42A8AD82E00E3C374 /* ChiaModels.swift */; };
2DA139F82A8AD82E00E3C374 /* Chia+Int64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139F52A8AD82E00E3C374 /* Chia+Int64.swift */; };
2DA139F92A8AD82E00E3C374 /* ChiaCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139F62A8AD82E00E3C374 /* ChiaCondition.swift */; };
2DA13A022A8AD83B00E3C374 /* ChiaNetworkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139FC2A8AD83B00E3C374 /* ChiaNetworkProvider.swift */; };
2DA13A032A8AD83B00E3C374 /* ChiaProviderTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139FD2A8AD83B00E3C374 /* ChiaProviderTarget.swift */; };
2DA13A042A8AD83B00E3C374 /* ChiaProviderRequests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139FE2A8AD83B00E3C374 /* ChiaProviderRequests.swift */; };
2DA13A052A8AD83B00E3C374 /* ChiaProviderResponses.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA139FF2A8AD83B00E3C374 /* ChiaProviderResponses.swift */; };
2DA13A062A8AD83B00E3C374 /* ChiaNetworkUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA13A002A8AD83B00E3C374 /* ChiaNetworkUrl.swift */; };
2DA13A072A8AD83B00E3C374 /* ChiaNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA13A012A8AD83B00E3C374 /* ChiaNetworkService.swift */; };
2DA13A092A8AD84F00E3C374 /* ChiaTransactionBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA13A082A8AD84F00E3C374 /* ChiaTransactionBuilder.swift */; };
2DA8AB0D2A433A1000C75D85 /* ExceptionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA8AB0C2A433A1000C75D85 /* ExceptionHandler.swift */; };
2DBBE94D29C8686000971539 /* OptimismWalletAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DBBE94C29C8686000971539 /* OptimismWalletAssembly.swift */; };
2DBBE95029C8DBEA00971539 /* TONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DBBE94F29C8DBEA00971539 /* TONTests.swift */; };
Expand Down Expand Up @@ -426,6 +436,16 @@
2D9A919D29BB8C1700476EA6 /* TONProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TONProvider.swift; sourceTree = "<group>"; };
2D9A919E29BB8C1700476EA6 /* TONProviderRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TONProviderRequest.swift; sourceTree = "<group>"; };
2D9A91A629BB8C2E00476EA6 /* WalletCoreAddressService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletCoreAddressService.swift; sourceTree = "<group>"; };
2DA139F42A8AD82E00E3C374 /* ChiaModels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaModels.swift; sourceTree = "<group>"; };
2DA139F52A8AD82E00E3C374 /* Chia+Int64.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Chia+Int64.swift"; sourceTree = "<group>"; };
2DA139F62A8AD82E00E3C374 /* ChiaCondition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaCondition.swift; sourceTree = "<group>"; };
2DA139FC2A8AD83B00E3C374 /* ChiaNetworkProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaNetworkProvider.swift; sourceTree = "<group>"; };
2DA139FD2A8AD83B00E3C374 /* ChiaProviderTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaProviderTarget.swift; sourceTree = "<group>"; };
2DA139FE2A8AD83B00E3C374 /* ChiaProviderRequests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaProviderRequests.swift; sourceTree = "<group>"; };
2DA139FF2A8AD83B00E3C374 /* ChiaProviderResponses.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaProviderResponses.swift; sourceTree = "<group>"; };
2DA13A002A8AD83B00E3C374 /* ChiaNetworkUrl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaNetworkUrl.swift; sourceTree = "<group>"; };
2DA13A012A8AD83B00E3C374 /* ChiaNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaNetworkService.swift; sourceTree = "<group>"; };
2DA13A082A8AD84F00E3C374 /* ChiaTransactionBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChiaTransactionBuilder.swift; sourceTree = "<group>"; };
2DA8AB0C2A433A1000C75D85 /* ExceptionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExceptionHandler.swift; sourceTree = "<group>"; };
2DBBE94C29C8686000971539 /* OptimismWalletAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptimismWalletAssembly.swift; sourceTree = "<group>"; };
2DBBE94F29C8DBEA00971539 /* TONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TONTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -802,6 +822,9 @@
2D19767B2A613F27006C4D3E /* Common */ = {
isa = PBXGroup;
children = (
2DA139F52A8AD82E00E3C374 /* Chia+Int64.swift */,
2DA139F62A8AD82E00E3C374 /* ChiaCondition.swift */,
2DA139F42A8AD82E00E3C374 /* ChiaModels.swift */,
2D78F4132A5D955700962CCA /* ClvmProgram.swift */,
2D3328C22A779ACC00C4A84C /* ChiaPuzzleUtils.swift */,
);
Expand Down Expand Up @@ -834,6 +857,7 @@
2D19767B2A613F27006C4D3E /* Common */,
2D78F4092A5C3CBE00962CCA /* ChiaAddressService.swift */,
2D78F40B2A5C3CCF00962CCA /* ChiaWalletManager.swift */,
2DA13A082A8AD84F00E3C374 /* ChiaTransactionBuilder.swift */,
);
path = Chia;
sourceTree = "<group>";
Expand Down Expand Up @@ -888,6 +912,27 @@
path = TONProviderProvider;
sourceTree = "<group>";
};
2DA139FA2A8AD83B00E3C374 /* Chia */ = {
isa = PBXGroup;
children = (
2DA139FB2A8AD83B00E3C374 /* Provider */,
2DA13A002A8AD83B00E3C374 /* ChiaNetworkUrl.swift */,
2DA13A012A8AD83B00E3C374 /* ChiaNetworkService.swift */,
);
path = Chia;
sourceTree = "<group>";
};
2DA139FB2A8AD83B00E3C374 /* Provider */ = {
isa = PBXGroup;
children = (
2DA139FC2A8AD83B00E3C374 /* ChiaNetworkProvider.swift */,
2DA139FD2A8AD83B00E3C374 /* ChiaProviderTarget.swift */,
2DA139FE2A8AD83B00E3C374 /* ChiaProviderRequests.swift */,
2DA139FF2A8AD83B00E3C374 /* ChiaProviderResponses.swift */,
);
path = Provider;
sourceTree = "<group>";
};
2DBBE94E29C8DBD900971539 /* TON */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1152,6 +1197,7 @@
5D01BCE0243F7F6F0048D1BA /* XRP */,
2D9A919629BB8C1700476EA6 /* TON */,
EF2BC61C29DAC62C003D3F18 /* Ravencoin */,
2DA139FA2A8AD83B00E3C374 /* Chia */,
);
path = BlockchainService;
sourceTree = "<group>";
Expand Down Expand Up @@ -2241,6 +2287,7 @@
5D7D242925136254001B9A4F /* XRPLedger.swift in Sources */,
5DF9151D253DB85500B927DD /* TezosNetworkService.swift in Sources */,
5DEAFA9224447D350032E316 /* ThenProcessable.swift in Sources */,
2DA13A022A8AD83B00E3C374 /* ChiaNetworkProvider.swift in Sources */,
5DCC817623FAE6D500DFC460 /* AnyPublisher+Response.swift in Sources */,
EF666C302A2F3F200044986F /* BitcoinBech32AddressService.swift in Sources */,
2DDE5BA329C4F8D200A5B708 /* TezosWalletAssembly.swift in Sources */,
Expand Down Expand Up @@ -2270,6 +2317,7 @@
2D9A919329BB8BFF00476EA6 /* TONTransactionBuilder.swift in Sources */,
B0F9DCA125FB4C9B00C0AF18 /* MultiNetworkProvider.swift in Sources */,
5D7D243B25136254001B9A4F /* URandom.swift in Sources */,
2DA139F92A8AD82E00E3C374 /* ChiaCondition.swift in Sources */,
2DDE5BAE29C4F8D200A5B708 /* TronWalletAssembly.swift in Sources */,
EF609FC72A20D4E9004E6D4E /* OptimismWalletManager.swift in Sources */,
DA63B09B29CB3FC700AC6E49 /* KaspaNetworkProvider.swift in Sources */,
Expand All @@ -2278,12 +2326,14 @@
2DDE5BAC29C4F8D200A5B708 /* SubstrateWalletAssembly.swift in Sources */,
5D88C809256BCD6C00020028 /* XRPTransactionParams.swift in Sources */,
5DED72C623A13377006D79AE /* StellarAddressService.swift in Sources */,
2DA13A052A8AD83B00E3C374 /* ChiaProviderResponses.swift in Sources */,
EF31EA1829DC6B4700A59FBE /* RavencoinFee.swift in Sources */,
2D9A91A529BB8C1700476EA6 /* TONProviderRequest.swift in Sources */,
5D7D242C25136254001B9A4F /* WebSocket.swift in Sources */,
E9941AC92927846B00399DE3 /* BlockBookTarget.swift in Sources */,
2DC5DAB429B9E6A10039154A /* WalletCoreSigner.swift in Sources */,
5D7D243325136254001B9A4F /* XRPAddress.swift in Sources */,
2DA13A062A8AD83B00E3C374 /* ChiaNetworkUrl.swift in Sources */,
B0C34958267B83580027CC9D /* BitcoinModels.swift in Sources */,
DA63B0A029CB3FC700AC6E49 /* KaspaAddressComponents.swift in Sources */,
DA30812B2817BF3C00DE41F1 /* Tron.pb.swift in Sources */,
Expand Down Expand Up @@ -2340,10 +2390,12 @@
5D0EEE69253EF75200758FDC /* TezosFee.swift in Sources */,
5D4B33C223F72C0400C93A84 /* BitcoinCashNetworkService.swift in Sources */,
EFD717CA2A25EA8500E5430D /* WalletCoreABIEncoder.swift in Sources */,
2DA13A042A8AD83B00E3C374 /* ChiaProviderRequests.swift in Sources */,
5D4B33BE23F6EA3700C93A84 /* BlockchairResponses.swift in Sources */,
5D88C80B256BCDBB00020028 /* StellarTransactionParams.swift in Sources */,
5D88838927D3BB8B008744E1 /* WalletError.swift in Sources */,
5DE3BF9E239FA2F400E8815D /* SegWitBech32.swift in Sources */,
2DA13A092A8AD84F00E3C374 /* ChiaTransactionBuilder.swift in Sources */,
EFBE768E2A79435200CD918B /* UTXOTransactionHistoryProvider.swift in Sources */,
5D6DEAB6243CC09A00510EC8 /* EthereumTransactionBuilder.swift in Sources */,
DA9F76F527EC9CB400F0665C /* TronTarget.swift in Sources */,
Expand Down Expand Up @@ -2466,6 +2518,7 @@
5DFF005F2521F772005203FB /* DucatusWalletManager.swift in Sources */,
DA63B09C29CB3FC700AC6E49 /* KaspaTarget.swift in Sources */,
5D7D243C25136254001B9A4F /* SerializerDefinitions.swift in Sources */,
2DA13A072A8AD83B00E3C374 /* ChiaNetworkService.swift in Sources */,
5DEAFA8E244472CD0032E316 /* Amount.swift in Sources */,
2D9A91A729BB8C2E00476EA6 /* WalletCoreAddressService.swift in Sources */,
2D9A91A729BB8C2E00476EA6 /* WalletCoreAddressService.swift in Sources */,
Expand All @@ -2479,6 +2532,7 @@
B04E8D5025F8F67F00821CBE /* RosettaNetworkProvider.swift in Sources */,
5D845516243DEAC80072155E /* AdaliteTarget.swift in Sources */,
EFD39C9F2A6E6C700055D215 /* AddressTypesConfig.swift in Sources */,
2DA139F82A8AD82E00E3C374 /* Chia+Int64.swift in Sources */,
5DCC817823FAE6F700DFC460 /* MoyaPublisher.swift in Sources */,
5D7D242B25136254001B9A4F /* HTTP.swift in Sources */,
5D7D242E25136254001B9A4F /* XrpData.swift in Sources */,
Expand All @@ -2501,6 +2555,7 @@
B07EE8B225AC1504009DB163 /* DateFormatter+.swift in Sources */,
5D557CB523ACCAD2009B32AF /* BlockcypherNetworkProvider.swift in Sources */,
5D7D243725136254001B9A4F /* XRPCurrentLedgerInfo.swift in Sources */,
2DA13A032A8AD83B00E3C374 /* ChiaProviderTarget.swift in Sources */,
EF666C2A2A2DFB120044986F /* WalletManagerFactory.swift in Sources */,
DA63B09F29CB3FC700AC6E49 /* KaspaAddressService.swift in Sources */,
DA656FCA295454C10092CC61 /* Constants.swift in Sources */,
Expand Down Expand Up @@ -2534,6 +2589,7 @@
DA9F76EF27EC9BCD00F0665C /* TronNetworkService.swift in Sources */,
DA19F5E129DFE32600FD57A3 /* StellarNetworkProvider.swift in Sources */,
5D0EEE6B253EFBF600758FDC /* TezosWalletManager.swift in Sources */,
2DA139F72A8AD82E00E3C374 /* ChiaModels.swift in Sources */,
5DED72B8239FE2E3006D79AE /* Decimal+.swift in Sources */,
DAE30DFB279164500056C5A3 /* SolanaDummyAccountStorage.swift in Sources */,
5D389ECC23ACFDCF00740FE9 /* MoyaProvider+Combine.swift in Sources */,
Expand Down
66 changes: 66 additions & 0 deletions BlockchainSdk/BlockchainService/Chia/ChiaNetworkService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ChiaNetworkService.swift
// BlockchainSdk
//
// Created by skibinalexander on 14.07.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import Foundation
import Combine

class ChiaNetworkService: MultiNetworkProvider {
// MARK: - Protperties

let providers: [ChiaNetworkProvider]
var currentProviderIndex: Int = 0

private var blockchain: Blockchain

// MARK: - Init

init(providers: [ChiaNetworkProvider], blockchain: Blockchain) {
self.providers = providers
self.blockchain = blockchain
}

// MARK: - Implementation

func getUnspents(puzzleHash: String) -> AnyPublisher<[ChiaCoin], Error> {
providerPublisher { provider in
provider
.getUnspents(puzzleHash: puzzleHash)
.map { response in
return response.coinRecords.map { $0.coin }
}
.eraseToAnyPublisher()
}
}

func send(spendBundle: ChiaSpendBundle) -> AnyPublisher<String, Error> {
providerPublisher { provider in
provider
.sendTransaction(body: ChiaTransactionBody(spendBundle: spendBundle))
.map { response in
return ""
}
.eraseToAnyPublisher()
}
}

func getFee(with cost: Int64) -> AnyPublisher<[Fee], Error> {
providerPublisher { [unowned self] provider in
provider
.getFeeEstimate(body: .init(cost: cost, targetTimes: [60, 300]))
.map { response in
let fees = response.estimates.map { estimate in
let value = estimate / self.blockchain.decimalValue.uint64Value
let amount = Amount(with: self.blockchain, value: Decimal(value))
return Fee(amount)
}
return fees
}
.eraseToAnyPublisher()
}
}
}
43 changes: 43 additions & 0 deletions BlockchainSdk/BlockchainService/Chia/ChiaNetworkUrl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ChiaNetworkUrl.swift
// BlockchainSdk
//
// Created by skibinalexander on 14.07.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import Foundation

enum ChiaEndpointType {
Balashov152 marked this conversation as resolved.
Show resolved Hide resolved
case fireAcademy(isTestnet: Bool)
}

struct ChiaNetworkEndpoint {
public let url: URL
public let apiKeyValue: String?

init(url: URL, apiKeyValue: String?) {
self.url = url
self.apiKeyValue = apiKeyValue
}
}

struct ChiaNetworkNode {
let apiKeyValue: String
let endpointType: ChiaEndpointType

var endpoint: ChiaNetworkEndpoint {
switch endpointType {
case .fireAcademy(let testnet):
let url = testnet ?
URL(string: "https://kraken.fireacademy.io/leaflet-testnet10/")! :
URL(string: "https://kraken.fireacademy.io/leaflet/")!
return ChiaNetworkEndpoint(url: url, apiKeyValue: apiKeyValue)
}
}

init(apiKeyValue: String, endpointType: ChiaEndpointType) {
self.apiKeyValue = apiKeyValue
self.endpointType = endpointType
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// ChiaNetworkProvider.swift
// BlockchainSdk
//
// Created by skibinalexander on 14.07.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import Foundation
import Combine
import Moya

struct ChiaNetworkProvider: HostProvider {
// MARK: - HostProvider
Balashov152 marked this conversation as resolved.
Show resolved Hide resolved

/// Blockchain API host
var host: String {
node.endpoint.url.hostOrUnknown
}

/// Configuration connection node for provider
private let node: ChiaNetworkNode

// MARK: - Properties

/// Network provider of blockchain
private let network: NetworkProvider<ChiaProviderTarget>

// MARK: - Init

init(
node: ChiaNetworkNode,
networkConfig: NetworkProviderConfiguration
) {
self.node = node
self.network = .init(configuration: networkConfig)
}

// MARK: - Implementation

func getUnspents(puzzleHash: String) -> AnyPublisher<ChiaCoinRecordsResponse, Error> {
let target = ChiaProviderTarget(
node: node,
targetType: .getCoinRecordsBy(puzzleHashBody: .init(puzzleHash: puzzleHash))
)

return requestPublisher(for: target)
}

func sendTransaction(body: ChiaTransactionBody) -> AnyPublisher<ChiaSendTransactionResponse, Error> {
let target = ChiaProviderTarget(
node: node,
targetType: .sendTransaction(body: body)
)

return requestPublisher(for: target)
}

func getFeeEstimate(body: ChiaFeeEstimateBody) -> AnyPublisher<ChiaEstimateFeeResponse, Error> {
let target = ChiaProviderTarget(
node: node,
targetType: .getFeeEstimate(body: body)
)

return requestPublisher(for: target)
}

// MARK: - Private Implementation

private func requestPublisher<T: ChiaStatusResponse>(for target: ChiaProviderTarget) -> AnyPublisher<T, Error> {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase

return network.requestPublisher(target)
.filterSuccessfulStatusAndRedirectCodes()
.map(T.self, using: decoder)
.tryMap{ response in
guard response.success else {
throw WalletError.empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта кинутая ошибка не будет далее безусловно замаплена в WalletError.failedToParseNetworkResponse? Если да - то это ожидаемое поведение?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта кинутая ошибка не будет далее безусловно замаплена в WalletError.failedToParseNetworkResponse? Если да - то это ожидаемое поведение?

Не суверен, что эта ошибка предназначена для таких целей, @tureck1y подскажи пожалуйста?

}

return response
}
.mapError { error in
return WalletError.failedToParseNetworkResponse
}
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ChiaProviderRequests.swift
// BlockchainSdk
//
// Created by skibinalexander on 18.07.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import Foundation

struct ChiaPuzzleHashBody: Encodable {
let puzzleHash: String
}

struct ChiaTransactionBody: Encodable {
let spendBundle: ChiaSpendBundle
}

struct ChiaFeeEstimateBody: Encodable {
let cost: Int64
let targetTimes: [Int]
}
Loading
Loading