@@ -17,7 +17,15 @@ public extension SolanaAPIClient {
1717 observeSignatureStatus ( signature: signature, timeout: 60 , delay: 2 )
1818 }
1919
20- // MARK: - Additional methods
20+ /// Get fee per signature
21+ func getLamportsPerSignature( ) async throws -> UInt64 ? {
22+ try await getFees ( commitment: nil ) . feeCalculator? . lamportsPerSignature
23+ }
24+
25+ /// Convenience method for request(method:params:) with no params
26+ func request< Entity> ( method: String ) async throws -> Entity where Entity: Decodable {
27+ try await request ( method: method, params: [ ] )
28+ }
2129
2230 func getMultipleMintDatas(
2331 mintAddresses: [ String ] ,
@@ -37,6 +45,32 @@ public extension SolanaAPIClient {
3745 return mintDict
3846 }
3947
48+ /// Wait until transaction is confirmed, return even when there is one or more confirmations and request timed out
49+ /// - Parameters:
50+ /// - signature: signature of the transaction
51+ /// - ignoreStatus: ignore status and return true even when observation is timed out
52+ func waitForConfirmation( signature: String , ignoreStatus: Bool , timeout: Int = 60 , delay: Int = 2 ) async throws {
53+ var statuses = [ PendingTransactionStatus] ( )
54+ for try await status in observeSignatureStatus ( signature: signature, timeout: timeout, delay: delay) {
55+ statuses. append ( status)
56+ }
57+
58+ // if the status is important
59+ if !ignoreStatus {
60+ guard let lastStatus = statuses. last else {
61+ throw TransactionConfirmationError . unconfirmed
62+ }
63+ switch lastStatus {
64+ case . confirmed, . finalized:
65+ return
66+ default :
67+ throw TransactionConfirmationError . unconfirmed
68+ }
69+ }
70+ }
71+
72+ // MARK: - Additional methods
73+
4074 func checkIfAssociatedTokenAccountExists(
4175 owner: PublicKey ,
4276 mint: String
@@ -121,30 +155,6 @@ public extension SolanaAPIClient {
121155 return ( destination: toPublicKey, isUnregisteredAsocciatedToken: isUnregisteredAsocciatedToken)
122156 }
123157
124- /// Wait until transaction is confirmed, return even when there is one or more confirmations and request timed out
125- /// - Parameters:
126- /// - signature: signature of the transaction
127- /// - ignoreStatus: ignore status and return true even when observation is timed out
128- func waitForConfirmation( signature: String , ignoreStatus: Bool , timeout: Int = 60 , delay: Int = 2 ) async throws {
129- var statuses = [ PendingTransactionStatus] ( )
130- for try await status in observeSignatureStatus ( signature: signature, timeout: timeout, delay: delay) {
131- statuses. append ( status)
132- }
133-
134- // if the status is important
135- if !ignoreStatus {
136- guard let lastStatus = statuses. last else {
137- throw TransactionConfirmationError . unconfirmed
138- }
139- switch lastStatus {
140- case . confirmed, . finalized:
141- return
142- default :
143- throw TransactionConfirmationError . unconfirmed
144- }
145- }
146- }
147-
148158 /// Returns all information associated with the account of provided Pubkey
149159 /// - Parameters:
150160 /// - account: Pubkey of account to query, as base-58 encoded string
@@ -158,14 +168,4 @@ public extension SolanaAPIClient {
158168 }
159169 return info
160170 }
161-
162- /// Get fee per signature
163- func getLamportsPerSignature( ) async throws -> UInt64 ? {
164- try await getFees ( commitment: nil ) . feeCalculator? . lamportsPerSignature
165- }
166-
167- /// Convenience method for request(method:params:) with no params
168- func request< Entity> ( method: String ) async throws -> Entity where Entity: Decodable {
169- try await request ( method: method, params: [ ] )
170- }
171171}
0 commit comments