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

Remove StarknetChainId #142

Merged
merged 14 commits into from
Feb 6, 2024
Merged
20 changes: 0 additions & 20 deletions Sources/Starknet/Data/StarknetChainId.swift
Original file line number Diff line number Diff line change
@@ -1,20 +0,0 @@
import BigInt
import Foundation

public enum StarknetChainId: String, Codable, Equatable {
case mainnet = "0x534e5f4d41494e"
case goerli = "0x534e5f474f45524c49"
case sepolia = "0x534e5f5345504f4c4941"
case integration_sepolia = "0x534e5f494e544547524154494f4e5f5345504f4c4941"

public var feltValue: Felt {
Felt(fromHex: self.rawValue)!
}

enum CodingKeys: String, CodingKey {
case mainnet = "0x534e5f4d41494e"
case goerli = "0x534e5f474f45524c49"
case sepolia = "0x534e5f5345504f4c4941"
case integration_sepolia = "0x534e5f494e544547524154494f4e5f5345504f4c4941"
}
}
16 changes: 8 additions & 8 deletions Sources/Starknet/Data/Transaction/TransactionHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class StarknetTransactionHashCalculator {
entryPointSelector: Felt,
calldata: StarknetCalldata,
maxFee: Felt,
chainId: StarknetChainId,
chainId: Felt,
nonce: Felt
) -> Felt {
StarknetCurve.pedersenOn(
Expand All @@ -21,12 +21,12 @@ public class StarknetTransactionHashCalculator {
entryPointSelector,
StarknetCurve.pedersenOn(calldata),
maxFee,
chainId.feltValue,
chainId,
nonce
)
}

private class func prepareCommonTransactionV3Fields(of transaction: any StarknetTransactionV3, address: Felt, chainId: StarknetChainId) -> [Felt] {
private class func prepareCommonTransactionV3Fields(of transaction: any StarknetTransactionV3, address: Felt, chainId: Felt) -> [Felt] {
let transactionType = transaction.type
let version = transaction.version
let tip = transaction.tip
Expand All @@ -45,7 +45,7 @@ public class StarknetTransactionHashCalculator {
+ StarknetTransactionHashCalculator.resourceBoundsForFee(resourceBounds)
),
StarknetPoseidon.poseidonHash(paymasterData),
chainId.feltValue,
chainId,
nonce,
StarknetTransactionHashCalculator.dataAvailabilityModes(
feeDataAvailabilityMode: feeDataAvailabilityMode,
Expand All @@ -54,7 +54,7 @@ public class StarknetTransactionHashCalculator {
]
}

public class func computeHash(of transaction: StarknetInvokeTransactionV1, chainId: StarknetChainId) -> Felt {
public class func computeHash(of transaction: StarknetInvokeTransactionV1, chainId: Felt) -> Felt {
computeCommonDeprecatedTransactionHash(
transactionType: transaction.type,
version: transaction.version,
Expand All @@ -67,7 +67,7 @@ public class StarknetTransactionHashCalculator {
)
}

public class func computeHash(of transaction: StarknetInvokeTransactionV3, chainId: StarknetChainId) -> Felt {
public class func computeHash(of transaction: StarknetInvokeTransactionV3, chainId: Felt) -> Felt {
let commonFields = StarknetTransactionHashCalculator.prepareCommonTransactionV3Fields(
of: transaction,
address: transaction.senderAddress,
Expand All @@ -81,7 +81,7 @@ public class StarknetTransactionHashCalculator {
)
}

public class func computeHash(of transaction: StarknetDeployAccountTransactionV1, chainId: StarknetChainId) -> Felt {
public class func computeHash(of transaction: StarknetDeployAccountTransactionV1, chainId: Felt) -> Felt {
let contractAddress = StarknetContractAddressCalculator.calculateFrom(
classHash: transaction.classHash,
calldata: transaction.constructorCalldata,
Expand All @@ -102,7 +102,7 @@ public class StarknetTransactionHashCalculator {
)
}

public class func computeHash(of transaction: StarknetDeployAccountTransactionV3, chainId: StarknetChainId) -> Felt {
public class func computeHash(of transaction: StarknetDeployAccountTransactionV3, chainId: Felt) -> Felt {
let contractAddress = StarknetContractAddressCalculator.calculateFrom(
classHash: transaction.classHash,
calldata: transaction.constructorCalldata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public class StarknetProvider: StarknetProviderProtocol {
return result
}

public func getChainId() async throws -> StarknetChainId {
public func getChainId() async throws -> Felt {
let params = EmptySequence()

let result = try await makeRequest(method: .getChainId, params: params, receive: StarknetChainId.self)
let result = try await makeRequest(method: .getChainId, params: params, receive: Felt.self)

return result
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Starknet/Providers/StarknetProviderProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public protocol StarknetProviderProtocol {
/// Get the currently configured Starknet chain id
///
/// - Returns: The Starknet chain id
func getChainId() async throws -> StarknetChainId
func getChainId() async throws -> Felt

/// Simulate running a given list of transactions, and generate the execution trace
///
Expand Down
2 changes: 1 addition & 1 deletion Tests/StarknetTests/Providers/ProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class ProviderTests: XCTestCase {
func testGetChainId() async throws {
let chainId = try await provider.getChainId()

XCTAssertEqual(chainId, .goerli)
XCTAssertEqual(chainId.toShortString(), "SN_GOERLI")
}

func testSpecVersion() async throws {
Expand Down
Loading