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

Support RPC 0.8.0 #530

Draft
wants to merge 77 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
6ff3a2f
Adapt execution resources in data classes and methods
franciszekjob Oct 20, 2024
4c2014d
Update tests
franciszekjob Oct 20, 2024
625aa24
Add failure reason to transaction receipt
franciszekjob Oct 20, 2024
b0005b6
Add JSON RPC error data classes
franciszekjob Oct 21, 2024
4587b9d
Add contract execution error
franciszekjob Oct 21, 2024
5a96c51
Add `failureReason` to `GetTransactionStatusResponse`
franciszekjob Oct 21, 2024
3c95565
Merge branch 'feat/519-2-transaction-status-error' into feat/519-3-st…
franciszekjob Oct 21, 2024
d547cb7
Fix linting
franciszekjob Oct 21, 2024
25fdf9b
Add `getMessagesStatus` in providers
franciszekjob Oct 21, 2024
74658de
Add todos for `getMessagesStatus` tests
franciszekjob Oct 22, 2024
84f7dc5
Add `getStorageProof` in `Provider`
franciszekjob Oct 22, 2024
5b81467
Add `GetStorageProofPayload`
franciszekjob Oct 22, 2024
07a1f6f
Add `StorageProof`, `MerkleNode`, `ChildrenHashes`, `NodeHashToNodeMa…
franciszekjob Oct 22, 2024
12138c6
Add `ContractStorageKey`
franciszekjob Oct 22, 2024
06a8fd9
Refactor `getStorageProof`
franciszekjob Oct 22, 2024
31f798c
Add `getStorageProof` test with todo
franciszekjob Oct 22, 2024
0842ce5
Fix linting
franciszekjob Oct 22, 2024
c77b48b
Remove error-related changes
franciszekjob Oct 22, 2024
6683874
Add missing params in KDoc
franciszekjob Oct 22, 2024
ddea038
Update tests
franciszekjob Oct 22, 2024
a1358d9
Rename todo; Fix `getMessagesStatus` name
franciszekjob Oct 23, 2024
74f35a2
Rename todos
franciszekjob Oct 23, 2024
ff8e36a
Merge branch 'main' into feat/519-rpc-0.8.0
franciszekjob Oct 23, 2024
13d81ad
Fix `NodeHashToNodeMapping`
franciszekjob Oct 23, 2024
9097231
Fix linting
franciszekjob Oct 23, 2024
1384afd
Merge branch 'feat/519-rpc-0.8.0' of https://github.com/software-mans…
franciszekjob Oct 23, 2024
54d16f6
Update `getStorageProof`
franciszekjob Oct 23, 2024
bbd417c
Fix linting
franciszekjob Oct 23, 2024
b34bb52
Fix typo in `GetMessagesStatusResponse`
franciszekjob Oct 23, 2024
4bf6139
Refactor `getMessagesStatus`
franciszekjob Oct 23, 2024
97796fa
Update todo text
franciszekjob Oct 23, 2024
475a7f7
Fix transaction hash calculator tests
franciszekjob Oct 23, 2024
9a55b18
Update lib/src/main/kotlin/com/swmansion/starknet/data/types/Response…
franciszekjob Oct 24, 2024
836a456
Update lib/src/main/kotlin/com/swmansion/starknet/data/types/Payloads.kt
franciszekjob Oct 24, 2024
b734973
Fix `GetMessagesStatusResponse`
franciszekjob Oct 24, 2024
c6b4806
Merge branch 'feat/519-rpc-0.8.0' of https://github.com/software-mans…
franciszekjob Oct 24, 2024
2725046
Add `MessageStatusList` data class and serializer
franciszekjob Oct 24, 2024
18ad358
Fix linting
franciszekjob Oct 24, 2024
54d4402
Change return type of `getStorageProof` to `HttpRequest<StorageProof>`
franciszekjob Oct 24, 2024
8688732
Refactor `NodeHashToNodeMappingItem`; Add `BinaryNode` and `EdgeNode`
franciszekjob Oct 24, 2024
797911f
Fix linting
franciszekjob Oct 24, 2024
11d2eaa
Remove unnecessarily added failure reason from tx receipt
franciszekjob Oct 24, 2024
6614380
Refactor passing resource bounds
franciszekjob Oct 24, 2024
303317f
Fix linting
franciszekjob Oct 24, 2024
a183504
Update `DeclareParamsV3` and `InvokeParamsV3` constructor params
franciszekjob Oct 24, 2024
635c6a6
Fix resource bounds params in `StandardAccount`
franciszekjob Oct 24, 2024
a380e39
Fix linting
franciszekjob Oct 24, 2024
3af0e5c
Add fixes for resource bounds
franciszekjob Oct 24, 2024
63b8bd8
Fix linting
franciszekjob Oct 24, 2024
1e6190b
Rename `computationResources` to executionResources`
franciszekjob Oct 25, 2024
a8722bb
Update mock jsons in tests
franciszekjob Oct 25, 2024
5688593
Add `InnerCallExecutionResources`
franciszekjob Oct 25, 2024
8f3061f
Add `DataResources` sealed class
franciszekjob Oct 25, 2024
96dbac3
Fix linting
franciszekjob Oct 25, 2024
25fe29c
Rename `DataResources` to `Resources`
franciszekjob Oct 25, 2024
2b1c478
Restore `JvmName` annotation in `Resources.kt`
franciszekjob Oct 25, 2024
8215452
Remove unnecessary formatting changes
franciszekjob Oct 25, 2024
4ae1582
Add `ResourceBoundsMapping.ZERO`
franciszekjob Oct 27, 2024
f5c88a8
Add `MerkleNodeSerializer`
franciszekjob Oct 28, 2024
edc9f9f
Fix linting
franciszekjob Oct 28, 2024
e675851
Refactor `MerkleNodeSerializer.deserialize`
franciszekjob Oct 28, 2024
e3a29c4
Fix linting
franciszekjob Oct 28, 2024
202dc74
Add tests for `getMessageStatus` and `getStorageProof`
franciszekjob Oct 28, 2024
35c7ca8
Fix linting
franciszekjob Oct 28, 2024
b297869
Change merkle node serializer to polymorphic
franciszekjob Oct 28, 2024
b584d1e
Add `MerkleNodeTest`
franciszekjob Oct 28, 2024
475a068
Fix linting
franciszekjob Oct 28, 2024
1719520
Remove test for `getStorageProof` with invalid merkle nodes
franciszekjob Oct 28, 2024
d7ee2ec
Update values in `MerkleNodeTest`
franciszekjob Oct 28, 2024
d56d2ae
Fix typo in `contracts_storage_keys`
franciszekjob Oct 28, 2024
20a7ab4
Rename `ContractStorageKey` to `ContractStorageKeys`
franciszekjob Oct 28, 2024
f541cf0
Rename file `ContractStorageKey` to `ContractStorageKeys`
franciszekjob Oct 28, 2024
7853259
Rename `key` to `storageKeys`
franciszekjob Oct 28, 2024
0c3a2c1
Make `blockId` optional in `getStorageProof`
franciszekjob Oct 28, 2024
0a36ee7
Make `blockId` optional in `JsonRpcProvider.getStorageProof`
franciszekjob Oct 28, 2024
7518f18
Change `path` type to `NumAsHex`
franciszekjob Oct 28, 2024
1c8a7e0
Revert optional block id changes
franciszekjob Oct 28, 2024
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
18 changes: 10 additions & 8 deletions lib/src/main/kotlin/com/swmansion/starknet/account/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,19 @@ interface Account {
* @param calldata constructor calldata for the contract deployment
* @param salt salt used to calculate address of the new contract
* @param forFeeEstimate when set to `true`, it changes the version to `2^128+version` so the signed transaction can only be used for fee estimation
* @param resourceBounds L1 and L2 resource bounds for the transaction
* @return signed deploy account payload
*/
fun signDeployAccountV3(
classHash: Felt,
calldata: Calldata,
salt: Felt,
l1ResourceBounds: ResourceBounds,
resourceBounds: ResourceBoundsMapping,
forFeeEstimate: Boolean,
): DeployAccountTransactionV3 {
val params = DeployAccountParamsV3(
nonce = Felt.ZERO,
l1ResourceBounds = l1ResourceBounds,
resourceBounds = resourceBounds,
)
return signDeployAccountV3(classHash, calldata, salt, params, forFeeEstimate)
}
Expand All @@ -212,17 +213,18 @@ interface Account {
* @param classHash hash of the contract that will be deployed. Has to be declared first!
* @param calldata constructor calldata for the contract deployment
* @param salt salt used to calculate address of the new contract
* @param resourceBounds L1 and L2 resource bounds for the transaction
* @return signed deploy account payload
*/
fun signDeployAccountV3(
classHash: Felt,
calldata: Calldata,
salt: Felt,
l1ResourceBounds: ResourceBounds,
resourceBounds: ResourceBoundsMapping,
): DeployAccountTransactionV3 {
val params = DeployAccountParamsV3(
nonce = Felt.ZERO,
l1ResourceBounds = l1ResourceBounds,
resourceBounds = resourceBounds,
)
return signDeployAccountV3(classHash, calldata, salt, params, false)
}
Expand Down Expand Up @@ -333,10 +335,10 @@ interface Account {
* Execute list of calls on Starknet.
*
* @param calls a list of calls to be executed.
* @param l1ResourceBounds L1 resource bounds for the transaction.
* @param resourceBounds L1 and L2 resource bounds for the transaction
* @return Invoke function response, containing transaction hash.
*/
fun executeV3(calls: List<Call>, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse>
fun executeV3(calls: List<Call>, resourceBounds: ResourceBoundsMapping): Request<InvokeFunctionResponse>

/**
* Execute single call using version 1 invoke transaction.
Expand All @@ -355,10 +357,10 @@ interface Account {
* Execute single call on Starknet.
*
* @param call a call to be executed.
* @param l1ResourceBounds L1 resource bounds for the transaction.
* @param resourceBounds L1 and L2 resource bounds for the transaction
* @return Invoke function response, containing transaction hash.
*/
fun executeV3(call: Call, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse>
fun executeV3(call: Call, resourceBounds: ResourceBoundsMapping): Request<InvokeFunctionResponse>

/**
* Execute a list of calls using version 1 invoke transaction with automatically estimated fee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ class StandardAccount @JvmOverloads constructor(
}
}

override fun executeV3(calls: List<Call>, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse> {
override fun executeV3(calls: List<Call>, resourceBounds: ResourceBoundsMapping): Request<InvokeFunctionResponse> {
return getNonce().compose { nonce ->
val signParams = InvokeParamsV3(
nonce = nonce,
l1ResourceBounds = l1ResourceBounds,
resourceBounds = resourceBounds,
)
val payload = signV3(calls, signParams, false)

Expand All @@ -343,7 +343,7 @@ class StandardAccount @JvmOverloads constructor(
amountMultiplier = estimateAmountMultiplier,
unitPriceMultiplier = estimateUnitPriceMultiplier,
)
executeV3(calls, resourceBounds.l1Gas)
executeV3(calls, resourceBounds)
}
}

Expand All @@ -363,16 +363,16 @@ class StandardAccount @JvmOverloads constructor(
override fun executeV3(calls: List<Call>): Request<InvokeFunctionResponse> {
return estimateFeeV3(calls).compose { estimateFee ->
val resourceBounds = estimateFee.values.first().toResourceBounds()
executeV3(calls, resourceBounds.l1Gas)
executeV3(calls, resourceBounds)
}
}

override fun executeV1(call: Call, maxFee: Felt): Request<InvokeFunctionResponse> {
return executeV1(listOf(call), maxFee)
}

override fun executeV3(call: Call, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse> {
return executeV3(listOf(call), l1ResourceBounds)
override fun executeV3(call: Call, resourceBounds: ResourceBoundsMapping): Request<InvokeFunctionResponse> {
return executeV3(listOf(call), resourceBounds)
}

override fun executeV1(call: Call, estimateFeeMultiplier: Double): Request<InvokeFunctionResponse> {
Expand Down Expand Up @@ -541,7 +541,10 @@ class StandardAccount @JvmOverloads constructor(
private fun buildEstimateFeeV3Payload(calls: List<Call>, nonce: Felt): List<ExecutableTransaction> {
val executionParams = InvokeParamsV3(
nonce = nonce,
l1ResourceBounds = ResourceBounds.ZERO,
resourceBounds = ResourceBoundsMapping(
ResourceBounds.ZERO,
ResourceBounds.ZERO,
),
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
)
val payload = signV3(calls, executionParams, true)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.swmansion.starknet.data.serializers

import com.swmansion.starknet.data.types.MessageStatus
import com.swmansion.starknet.data.types.MessageStatusList
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.listSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

internal object MessageStatusListSerializer : KSerializer<MessageStatusList> {
private val listSerializer = ListSerializer(MessageStatus.serializer())

@OptIn(ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = listSerialDescriptor<MessageStatus>()

override fun serialize(encoder: Encoder, value: MessageStatusList) {
encoder.encodeSerializableValue(listSerializer, value.values)
}

override fun deserialize(decoder: Decoder): MessageStatusList {
val list = decoder.decodeSerializableValue(listSerializer)
return MessageStatusList(list)
}
}
19 changes: 19 additions & 0 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sealed interface Block : StarknetResponse {
val sequencerAddress: Felt
val parentHash: Felt
val l1GasPrice: ResourcePrice
val l2GasPrice: ResourcePrice
val l1DataGasPrice: ResourcePrice
val l1DataAvailabilityMode: L1DAMode
val starknetVersion: String
Expand Down Expand Up @@ -107,6 +108,9 @@ data class ProcessedBlockWithTransactions(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down Expand Up @@ -137,6 +141,9 @@ data class PendingBlockWithTransactions(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down Expand Up @@ -192,6 +199,9 @@ data class ProcessedBlockWithReceipts(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down Expand Up @@ -219,6 +229,9 @@ data class PendingBlockWithReceipts(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down Expand Up @@ -263,6 +276,9 @@ data class ProcessedBlockWithTransactionHashes(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down Expand Up @@ -290,6 +306,9 @@ data class PendingBlockWithTransactionHashes(
@SerialName("l1_gas_price")
override val l1GasPrice: ResourcePrice,

@SerialName("l2_gas_price")
override val l2GasPrice: ResourcePrice,

@SerialName("l1_data_gas_price")
override val l1DataGasPrice: ResourcePrice,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.swmansion.starknet.data.types

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ContractStorageKey(
@SerialName("contract_address")
val contractAddress: Felt,

@SerialName("storage_keys")
val key: List<Felt>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swmansion.starknet.data.types

import com.swmansion.starknet.data.serializers.MessageStatusListSerializer
import kotlinx.serialization.Serializable

@Serializable(with = MessageStatusListSerializer::class)
data class MessageStatusList(val values: List<MessageStatus>) : StarknetResponse
18 changes: 6 additions & 12 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Params.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ data class InvokeParamsV3 private constructor(
override val nonceDataAvailabilityMode: DAMode,
override val feeDataAvailabilityMode: DAMode,
) : ParamsV3() {
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds) : this(
constructor(nonce: Felt, resourceBounds: ResourceBoundsMapping) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
),
resourceBounds = resourceBounds,
tip = Uint64.ZERO,
paymasterData = emptyList(),
accountDeploymentData = emptyList(),
Expand All @@ -66,11 +64,9 @@ data class DeclareParamsV3 private constructor(
override val nonceDataAvailabilityMode: DAMode,
override val feeDataAvailabilityMode: DAMode,
) : ParamsV3() {
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds) : this(
constructor(nonce: Felt, resourceBounds: ResourceBoundsMapping) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
),
resourceBounds = resourceBounds,
tip = Uint64.ZERO,
paymasterData = emptyList(),
accountDeploymentData = emptyList(),
Expand All @@ -95,12 +91,10 @@ data class DeployAccountParamsV3 private constructor(
@JvmOverloads
constructor(
nonce: Felt = Felt.ZERO,
l1ResourceBounds: ResourceBounds,
resourceBounds: ResourceBoundsMapping,
) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
),
resourceBounds = resourceBounds,
tip = Uint64.ZERO,
paymasterData = emptyList(),
nonceDataAvailabilityMode = DAMode.L1,
Expand Down
21 changes: 21 additions & 0 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Payloads.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ internal data class GetTransactionStatusPayload(
val transactionHash: Felt,
)

@Serializable
internal data class GetMessagesStatusPayload(
@SerialName("transaction_hash")
val transactionHash: NumAsHex,
)

@Serializable
internal data class EstimateTransactionFeePayload(
@SerialName("request")
Expand Down Expand Up @@ -83,6 +89,21 @@ internal data class GetNoncePayload(
override val blockId: BlockId,
) : PayloadWithBlockId()

@Serializable
internal data class GetStorageProofPayload constructor(
@SerialName("block_id")
val blockId: BlockId,
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved

@SerialName("class_hashes")
val classHashes: List<Felt>? = null,

@SerialName("contract_addresses")
val contractAddresses: List<Felt>? = null,

@SerialName("contract_storage_keys")
val contractStorageKeys: List<ContractStorageKey>? = null,
)

@Serializable
internal data class GetBlockWithTransactionsPayload(
@SerialName("block_id")
Expand Down
Loading
Loading