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 57 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
57 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
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
14 changes: 12 additions & 2 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,22 @@ 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 l1ResourceBounds L1 resource bounds for the transaction
* @param l2ResourceBounds L2 resource bounds for the transaction
* @return signed deploy account payload
*/
fun signDeployAccountV3(
classHash: Felt,
calldata: Calldata,
salt: Felt,
l1ResourceBounds: ResourceBounds,
l2ResourceBounds: ResourceBounds,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should just go ahead and accept ResourceBoundsMapping in all of these methods?

Previously, there was no reason to do so. Now, my rationale is:

  1. It would simplify the signature
  2. These methods will probably be often used with the same values, so might as well reduce boilerplate
  3. When estimating fee prior to executing transactions, we can right away run EstimateFeeResponse.toResourceBounds and pass the result, transforming this:
            val resourceBounds = estimateFee.values.first().toResourceBounds()
            executeV3(calls, resourceBounds.l1Gas, resourceBounds.l2Gas)

to more intuitive:

            val resourceBounds = estimateFee.values.first().toResourceBounds()
            executeV3(calls, resourceBounds)

that doesn't require any knowledge of l1 or l2 gas to execute txs with auto estimated fees

Copy link
Collaborator Author

@franciszekjob franciszekjob Oct 24, 2024

Choose a reason for hiding this comment

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

Definitely, makes sense. Refactored.

I just don't fully like the fact that now the param of type ResourceBoundsMapping is named resourceBounds 😆 , but looks like it's because of this, so we can leave it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just don't fully like the fact that now the param of type ResourceBoundsMapping is named resourceBounds 😆 , but looks like it's because of this, so we can leave it.

That was the idea, but also the fact that resourceBoundsMapping doesn't seem like a good argument name from UX point of view.

I think such naming convention also makes sense in this particular case:

  • ResourceBounds - l1ResourceBounds, l2ResourceBounds
  • ResourceBoundsMapping - resourceBounds

forFeeEstimate: Boolean,
): DeployAccountTransactionV3 {
val params = DeployAccountParamsV3(
nonce = Felt.ZERO,
l1ResourceBounds = l1ResourceBounds,
l2ResourceBounds = l2ResourceBounds,
)
return signDeployAccountV3(classHash, calldata, salt, params, forFeeEstimate)
}
Expand All @@ -212,17 +216,21 @@ 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 l1ResourceBounds L1 resource bounds for the transaction
* @param l2ResourceBounds L2 resource bounds for the transaction
* @return signed deploy account payload
*/
fun signDeployAccountV3(
classHash: Felt,
calldata: Calldata,
salt: Felt,
l1ResourceBounds: ResourceBounds,
l2ResourceBounds: ResourceBounds,
): DeployAccountTransactionV3 {
val params = DeployAccountParamsV3(
nonce = Felt.ZERO,
l1ResourceBounds = l1ResourceBounds,
l2ResourceBounds = l2ResourceBounds,
)
return signDeployAccountV3(classHash, calldata, salt, params, false)
}
Expand Down Expand Up @@ -334,9 +342,10 @@ interface Account {
*
* @param calls a list of calls to be executed.
* @param l1ResourceBounds L1 resource bounds for the transaction.
* @param l2ResourceBounds 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>, l1ResourceBounds: ResourceBounds, l2ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse>

/**
* Execute single call using version 1 invoke transaction.
Expand All @@ -356,9 +365,10 @@ interface Account {
*
* @param call a call to be executed.
* @param l1ResourceBounds L1 resource bounds for the transaction.
* @param l2ResourceBounds 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, l1ResourceBounds: ResourceBounds, l2ResourceBounds: ResourceBounds): 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,12 @@ class StandardAccount @JvmOverloads constructor(
}
}

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

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

Expand All @@ -363,16 +364,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.l1Gas, resourceBounds.l2Gas)
}
}

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, l1ResourceBounds: ResourceBounds, l2ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse> {
return executeV3(listOf(call), l1ResourceBounds, l2ResourceBounds)
}

override fun executeV1(call: Call, estimateFeeMultiplier: Double): Request<InvokeFunctionResponse> {
Expand Down Expand Up @@ -542,6 +543,7 @@ class StandardAccount @JvmOverloads constructor(
val executionParams = InvokeParamsV3(
nonce = nonce,
l1ResourceBounds = ResourceBounds.ZERO,
l2ResourceBounds = ResourceBounds.ZERO,
)
val payload = signV3(calls, executionParams, true)

Expand Down
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("key")
val key: Felt,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.swmansion.starknet.data.types

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

@Serializable
data class ExecutionResources(
@SerialName("l1_gas")
val l1Gas: Int,

@SerialName("l1_data_gas")
val l1DataGas: Int,

@SerialName("l2_gas")
val l2Gas: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ data class InvokeParamsV3 private constructor(
override val nonceDataAvailabilityMode: DAMode,
override val feeDataAvailabilityMode: DAMode,
) : ParamsV3() {
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds) : this(
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds, l2ResourceBounds: ResourceBounds) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
l2Gas = l2ResourceBounds,
),
tip = Uint64.ZERO,
paymasterData = emptyList(),
Expand All @@ -66,10 +67,11 @@ data class DeclareParamsV3 private constructor(
override val nonceDataAvailabilityMode: DAMode,
override val feeDataAvailabilityMode: DAMode,
) : ParamsV3() {
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds) : this(
constructor(nonce: Felt, l1ResourceBounds: ResourceBounds, l2ResourceBounds: ResourceBounds) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
l2Gas = l2ResourceBounds,
),
tip = Uint64.ZERO,
paymasterData = emptyList(),
Expand All @@ -96,10 +98,12 @@ data class DeployAccountParamsV3 private constructor(
constructor(
nonce: Felt = Felt.ZERO,
l1ResourceBounds: ResourceBounds,
l2ResourceBounds: ResourceBounds,
) : this(
nonce = nonce,
resourceBounds = ResourceBoundsMapping(
l1Gas = l1ResourceBounds,
l2Gas = l2ResourceBounds,
),
tip = Uint64.ZERO,
paymasterData = emptyList(),
Expand Down
18 changes: 18 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,18 @@ internal data class GetNoncePayload(
override val blockId: BlockId,
) : PayloadWithBlockId()

@Serializable
internal data class GetStorageProofPayload @JvmOverloads constructor(
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
98 changes: 0 additions & 98 deletions lib/src/main/kotlin/com/swmansion/starknet/data/types/Resources.kt

This file was deleted.

Loading
Loading