From 5f9c166c3561999ad8c155c4b22635986704c82d Mon Sep 17 00:00:00 2001 From: "Konstantin Yurchenko, Jr." Date: Wed, 4 Sep 2024 22:36:47 -0700 Subject: [PATCH 1/3] Fixes cross-module dependecy issues. --- Package.resolved | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Package.resolved b/Package.resolved index b492a9817..675e9716f 100644 --- a/Package.resolved +++ b/Package.resolved @@ -2,12 +2,12 @@ "object": { "pins": [ { - "package": "secp256k1", - "repositoryURL": "https://github.com/Boilertalk/secp256k1.swift.git", - "state": { - "branch": null, - "revision": "cd187c632fb812fd93711a9f7e644adb7e5f97f0", - "version": "0.1.7" + "identity" : "secp256k1.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/GigaBitcoin/secp256k1.swift", + "state" : { + "revision" : "9683e8e311c76d8114cd308b697dad2f9fc58fed", + "version" : "0.17.0" } }, { From 7dccf6e0c23b41220a0c0855c11f32c8deaa4123 Mon Sep 17 00:00:00 2001 From: "Konstantin Yurchenko, Jr." Date: Wed, 4 Sep 2024 23:22:23 -0700 Subject: [PATCH 2/3] Fixes cross-module dependecy issues. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index ce1a6c617..21fd423e5 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( ], dependencies: [ // Main depedencies - .package(url: "https://github.com/Boilertalk/secp256k1.swift.git", from: "0.1.0"), + .package(url: "https://github.com/GigaBitcoin/secp256k1.swift", from: "0.1.0"), .package(url: "https://github.com/bitmark-inc/tweetnacl-swiftwrap.git", from: "1.0.2"), .package(url: "https://github.com/bigearsenal/task-retrying-swift.git", from: "2.0.0"), From fe74c67dd909ff639c0d28839931c54980a179e7 Mon Sep 17 00:00:00 2001 From: "Konstantin Yurchenko, Jr." Date: Sun, 8 Sep 2024 13:27:40 -0700 Subject: [PATCH 3/3] Implements getLatestBlockhash and deprecats getRecentBlockhash. --- .../SolanaSwift/APIClient/APIClient+Extension.swift | 4 ++-- .../APIClient/Networking/JSONRPCAPIClient.swift | 4 ++-- Sources/SolanaSwift/APIClient/SolanaAPIClient.swift | 9 ++++----- .../BlockchainClient/BlockchainClient.swift | 2 +- .../BlockchainClient/SolanaBlockchainClient.swift | 8 ++++---- .../APIClient/APIClientTests.swift | 8 ++++---- .../BlockchainClientWithNativeSOLTests.swift | 10 +++++----- .../BlockchainClientWithTokenProgramTests.swift | 6 +++--- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Sources/SolanaSwift/APIClient/APIClient+Extension.swift b/Sources/SolanaSwift/APIClient/APIClient+Extension.swift index 27fec1fd3..c8bad58c2 100644 --- a/Sources/SolanaSwift/APIClient/APIClient+Extension.swift +++ b/Sources/SolanaSwift/APIClient/APIClient+Extension.swift @@ -22,8 +22,8 @@ public extension SolanaAPIClient { try await getMinimumBalanceForRentExemption(dataLength: span, commitment: "recent") } - func getRecentBlockhash() async throws -> String { - try await getRecentBlockhash(commitment: nil) + func getLatestBlockhash() async throws -> String { + try await getLatestBlockhash(commitment: nil) } func observeSignatureStatus(signature: String) -> AsyncStream { diff --git a/Sources/SolanaSwift/APIClient/Networking/JSONRPCAPIClient.swift b/Sources/SolanaSwift/APIClient/Networking/JSONRPCAPIClient.swift index c1cb2841e..023180f65 100644 --- a/Sources/SolanaSwift/APIClient/Networking/JSONRPCAPIClient.swift +++ b/Sources/SolanaSwift/APIClient/Networking/JSONRPCAPIClient.swift @@ -104,8 +104,8 @@ public class JSONRPCAPIClient: SolanaAPIClient { ) } - public func getRecentBlockhash(commitment: Commitment? = nil) async throws -> String { - let result: Rpc = try await get(method: "getRecentBlockhash", + public func getLatestBlockhash(commitment: Commitment? = nil) async throws -> String { + let result: Rpc = try await get(method: "getLatestBlockhash", params: [RequestConfiguration(commitment: commitment)]) guard let blockhash = result.value.blockhash else { throw APIClientError.blockhashNotFound diff --git a/Sources/SolanaSwift/APIClient/SolanaAPIClient.swift b/Sources/SolanaSwift/APIClient/SolanaAPIClient.swift index d8faa89b2..674d7bdc7 100644 --- a/Sources/SolanaSwift/APIClient/SolanaAPIClient.swift +++ b/Sources/SolanaSwift/APIClient/SolanaAPIClient.swift @@ -279,14 +279,13 @@ public protocol SolanaAPIClient { /// func observeSignatureStatus(signature: String, timeout: Int, delay: Int) -> AsyncStream - /// Returns a recent block hash from the ledger, and a fee schedule that can be used to compute the cost of - /// submitting a transaction using it. + /// Returns the latest block hash from the ledger /// - Parameters: /// - commitment: (optional) Commitment /// - Throws: APIClientError - /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash + /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getlatestblockhash /// - func getRecentBlockhash(commitment: Commitment?) async throws -> String + func getLatestBlockhash(commitment: Commitment?) async throws -> String /// Returns signatures for confirmed transactions that include the given address in their accountKeys list. /// Returns signatures backwards in time from the provided signature or most recent confirmed block @@ -294,7 +293,7 @@ public protocol SolanaAPIClient { /// - address: account address as base-58 encoded string /// - configs: (optional) Configuration object /// - Throws: APIClientError - /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash + /// - SeeAlso https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturesforaddress /// func getSignaturesForAddress(address: String, configs: RequestConfiguration?) async throws -> [SignatureInfo] diff --git a/Sources/SolanaSwift/BlockchainClient/BlockchainClient.swift b/Sources/SolanaSwift/BlockchainClient/BlockchainClient.swift index 8e9c007e6..61861093f 100644 --- a/Sources/SolanaSwift/BlockchainClient/BlockchainClient.swift +++ b/Sources/SolanaSwift/BlockchainClient/BlockchainClient.swift @@ -46,7 +46,7 @@ public class BlockchainClient: SolanaBlockchainClient { } let expectedFee = try feeCalculator.calculateNetworkFee(transaction: transaction) - let blockhash = try await apiClient.getRecentBlockhash() + let blockhash = try await apiClient.getLatestBlockhash() transaction.recentBlockhash = blockhash // if any signers, sign diff --git a/Sources/SolanaSwift/BlockchainClient/SolanaBlockchainClient.swift b/Sources/SolanaSwift/BlockchainClient/SolanaBlockchainClient.swift index 02acb60d7..01b02dd6a 100644 --- a/Sources/SolanaSwift/BlockchainClient/SolanaBlockchainClient.swift +++ b/Sources/SolanaSwift/BlockchainClient/SolanaBlockchainClient.swift @@ -48,10 +48,10 @@ public extension SolanaBlockchainClient { retryDelay: 1, timeoutInSeconds: 60 ) { - let recentBlockhash = try await self.apiClient.getRecentBlockhash() + let latestBlockhash = try await self.apiClient.getLatestBlockhash() let serializedTransaction = try self.signAndSerialize( preparedTransaction: preparedTransaction, - recentBlockhash: recentBlockhash + recentBlockhash: latestBlockhash ) return try await self.apiClient.sendTransaction( transaction: serializedTransaction, @@ -67,10 +67,10 @@ public extension SolanaBlockchainClient { func simulateTransaction( preparedTransaction: PreparedTransaction ) async throws -> SimulationResult { - let recentBlockhash = try await apiClient.getRecentBlockhash() + let latestBlockhash = try await apiClient.getLatestBlockhash() let serializedTransaction = try signAndSerialize( preparedTransaction: preparedTransaction, - recentBlockhash: recentBlockhash + recentBlockhash: latestBlockhash ) return try await apiClient.simulateTransaction( transaction: serializedTransaction, configs: RequestConfiguration( diff --git a/Tests/SolanaSwiftUnitTests/APIClient/APIClientTests.swift b/Tests/SolanaSwiftUnitTests/APIClient/APIClientTests.swift index 6c8a7b4c3..3b84b0378 100644 --- a/Tests/SolanaSwiftUnitTests/APIClient/APIClientTests.swift +++ b/Tests/SolanaSwiftUnitTests/APIClient/APIClientTests.swift @@ -200,10 +200,10 @@ class APIClientTests: XCTestCase { XCTAssertEqual(result, 890_880) } - func testGetRecentBlockhash() async throws { - let mock = NetworkManagerMock(NetworkManagerMockJSON["getRecentBlockhash"]!) + func testGetLatestBlockhash() async throws { + let mock = NetworkManagerMock(NetworkManagerMockJSON["getLatestBlockhash"]!) let apiClient = JSONRPCAPIClient(endpoint: endpoint, networkManager: mock) - let result = try! await apiClient.getRecentBlockhash(commitment: nil) + let result = try! await apiClient.getLatestBlockhash(commitment: nil) XCTAssertNotNil(result) XCTAssertEqual(result, "63ionHTAM94KaSujUCg23hfg7TLharchq5BYXdLGqia1") } @@ -375,7 +375,7 @@ private var NetworkManagerMockJSON = [ "getEpochInfo": "{\"jsonrpc\":\"2.0\",\"result\":{\"absoluteSlot\":131686768,\"blockHeight\":119443373,\"epoch\":304,\"slotIndex\":358768,\"slotsInEpoch\":432000,\"transactionCount\":71271072342},\"id\":\"AE699DFA-84E8-495C-8B06-F30DDFA6C56D\"}\n", "getFees": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":131770081},\"value\":{\"blockhash\":\"7jvToPQ4ASj3xohjM117tMqmtppQDaWVADZyaLFnytFr\",\"feeCalculator\":{\"lamportsPerSignature\":5000},\"lastValidBlockHeight\":119512694,\"lastValidSlot\":131770381}},\"id\":\"3FF1AACE-812A-4106-8C34-6EF66237673C\"}\n", "getMinimumBalanceForRentExemption": "{\"jsonrpc\":\"2.0\",\"result\":890880,\"id\":\"25423C5F-2FF3-4134-8CB3-9090BFCB2CE3\"}\n", - "getRecentBlockhash": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":131780453},\"value\":{\"blockhash\":\"63ionHTAM94KaSujUCg23hfg7TLharchq5BYXdLGqia1\",\"feeCalculator\":{\"lamportsPerSignature\":5000}}},\"id\":\"21D61199-F235-4CC9-9BE6-06745D3AC69E\"}\n", + "getLatestBlockhash": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":131780453},\"value\":{\"blockhash\":\"63ionHTAM94KaSujUCg23hfg7TLharchq5BYXdLGqia1\"}},\"id\":\"21D61199-F235-4CC9-9BE6-06745D3AC69E\"}\n", "getMultipleAccounts": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":132420615},\"value\":[{\"data\":[\"APoAh5MDAAAAAAKLjuya35R64GfrOPbupmMcxJ1pmaH2fciYq9DxSQ88FioLlNul6FnDNF06/RKhMFBVI8fFQKRYcqukjYZitosKxZBjjg9hLR2AsDm2e/itloPtlrPeVDPIVdnO4+dmM2JiSZHdhsj7+Fn94OTNte9elt1ek0p487C2fLrFA9CvUPerjZvfP97EqlF9OXbPSzaGJzdmfWhk4jRnThsg5scAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAObFpMVhxY3CRrzEcywhYTa4a4SsovPp4wKPRTbTJVtzAfQBZAAAAABDU47UFrGnHMTsb0EaE1TBoVQGvCIHKJ4/EvpK3zvIfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACsWQY44PYS0dgLA5tnv4rZaD7Zaz3lQzyFXZzuPnZjMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\",\"base64\"],\"executable\":false,\"lamports\":1345194,\"owner\":\"617jbWo616ggkDxvW1Le8pV38XLbVSyWY8ae6QUmGBAU\",\"rentEpoch\":306}]},\"id\":\"D5BCACBB-3CE7-44D6-8F66-C57470A90440\"}\n", "getMultipleMintDatas": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":132426903},\"value\":[{\"data\":[\"AQAAABzjWe1aAS4E+hQrnHUaHF6Hz9CgFhuchf/TG3jN/Nj2dbn7oe7/EAAGAQEAAAAqnl7btTwEZ5CY/3sSZRcUQ0/AjFYqmjuGEQXmctQicw==\",\"base64\"],\"executable\":false,\"lamports\":122356825965,\"owner\":\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\"rentEpoch\":306},{\"data\":[\"AQAAAAXqnPFs5BGY8aSZN8iMNwqU1K//ibW6y470XmMku3j3J0UE6/G2BgAGAQEAAAAF6pzxbOQRmPGkmTfIjDcKlNSv/4m1usuO9F5jJLt49w==\",\"base64\"],\"executable\":false,\"lamports\":23879870146,\"owner\":\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\",\"rentEpoch\":306}]},\"id\":\"65766E4D-F678-489A-943B-8D70B5C6F1ED\"}\n", "simulateTransaction": "{\"jsonrpc\":\"2.0\",\"result\":{\"context\":{\"slot\":132581497},\"value\":{\"accounts\":null,\"err\":\"AccountNotFound\",\"logs\":[],\"unitsConsumed\":0}},\"id\":\"3916EC69-2924-40E7-8843-8CBA8C6DB14C\"}\n", diff --git a/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithNativeSOLTests.swift b/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithNativeSOLTests.swift index acea5e369..ca3c4d86e 100644 --- a/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithNativeSOLTests.swift +++ b/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithNativeSOLTests.swift @@ -32,10 +32,10 @@ class BlockchainClientWithNativeSOLTests: XCTestCase { feePayer: account.publicKey ) - let recentBlockhash = try await apiClient.getRecentBlockhash() + let latestBlockhash = try await apiClient.getLatestBlockhash() let serializedTransaction = try blockchain.signAndSerialize( preparedTransaction: tx, - recentBlockhash: recentBlockhash + recentBlockhash: latestBlockhash ) XCTAssertEqual(tx.expectedFee, .init(transaction: 5000, accountBalances: 0)) @@ -57,10 +57,10 @@ class BlockchainClientWithNativeSOLTests: XCTestCase { feePayer: account.publicKey ) - let recentBlockhash = try await apiClient.getRecentBlockhash() + let latestBlockhash = try await apiClient.getLatestBlockhash() let serializedTransaction = try blockchain.signAndSerialize( preparedTransaction: tx, - recentBlockhash: recentBlockhash + recentBlockhash: latestBlockhash ) XCTAssertEqual(tx.expectedFee, .init(transaction: 5000, accountBalances: 0)) @@ -184,7 +184,7 @@ private class MockAPIClient: SolanaAPIClient { ) } - func getRecentBlockhash(commitment _: Commitment?) async throws -> String { + func getLatestBlockhash(commitment _: Commitment?) async throws -> String { switch testCase { case "testPrepareSendingNativeSOL()": return "DSfeYUm7WDw1YnKodR361rg8sUzUCGdat9V7fSKPFgzq" diff --git a/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithTokenProgramTests.swift b/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithTokenProgramTests.swift index f9952b914..8c51e97a5 100644 --- a/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithTokenProgramTests.swift +++ b/Tests/SolanaSwiftUnitTests/BlockchainClient/BlockchainClientWithTokenProgramTests.swift @@ -99,10 +99,10 @@ final class BlockchainClientWithTokenProgramTests: XCTestCase { XCTAssertEqual(tx.expectedFee, expectedFee) - let recentBlockhash = try await apiClient.getRecentBlockhash() + let latestBlockhash = try await apiClient.getLatestBlockhash() let serializedTransaction = try blockchainClient.signAndSerialize( preparedTransaction: tx, - recentBlockhash: recentBlockhash + recentBlockhash: latestBlockhash ) XCTAssertEqual(serializedTransaction, expectedSerializedTransaction) } @@ -221,7 +221,7 @@ private class MockAPIClient: SolanaAPIClient { ) } - func getRecentBlockhash(commitment _: Commitment?) async throws -> String { + func getLatestBlockhash(commitment _: Commitment?) async throws -> String { switch testCase { case "testPrepareSendingNativeSOL()": return "DSfeYUm7WDw1YnKodR361rg8sUzUCGdat9V7fSKPFgzq"