Skip to content

Commit

Permalink
starknet_getCompiledCasm (#642)
Browse files Browse the repository at this point in the history
* implement starknet_getCompiledCasm for RPCv8
  • Loading branch information
thiagodeev committed Dec 4, 2024
1 parent 98d2b5c commit 9007483
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 3 deletions.
15 changes: 15 additions & 0 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ var (
Code: 63,
Message: "An unexpected error occurred",
}
ErrCompilationError = &RPCError{
Code: 9999, //placeholder number as this error has no code so far. TODO: change this with the next updates
Message: "More data about the compilation failure",
}
)
24 changes: 24 additions & 0 deletions rpc/executables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rpc

import (
"context"

"github.com/NethermindEth/juno/core/felt"
)

// Get the contract class definition in the given block associated with the given hash
//
// Parameters:
// - ctx: The context.Context used for the request
// - classHash: The hash of the contract class whose CASM will be returned
// Returns:
// - CasmCompiledContractClass: The compiled contract class
// - error: An error if any occurred during the execution
func (provider *Provider) CompiledCasm(ctx context.Context, classHash *felt.Felt) (*CasmCompiledContractClass, error) {
var result CasmCompiledContractClass
if err := do(ctx, provider.c, "starknet_getCompiledCasm", &result, classHash); err != nil {

return nil, tryUnwrapToRPCErr(err, ErrClassHashNotFound, ErrCompilationError)
}
return &result, nil
}
7 changes: 7 additions & 0 deletions rpc/executables_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package rpc

import "testing"

func TestCompiledCasm(t *testing.T) {
t.Skip("TODO: create a test before merge")
}
1 change: 1 addition & 0 deletions rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type RpcProvider interface {
Class(ctx context.Context, blockID BlockID, classHash *felt.Felt) (ClassOutput, error)
ClassAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (ClassOutput, error)
ClassHashAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error)
CompiledCasm(ctx context.Context, classHash *felt.Felt) (*CasmCompiledContractClass, error)
EstimateFee(ctx context.Context, requests []BroadcastTxn, simulationFlags []SimulationFlag, blockID BlockID) ([]FeeEstimation, error)
EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimation, error)
Events(ctx context.Context, input EventsInput) (*EventChunk, error)
Expand Down
4 changes: 2 additions & 2 deletions rpc/types_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type ContractClass struct {
// The version of the contract class object. Currently, the Starknet OS supports version 0.1.0
ContractClassVersion string `json:"contract_class_version"`

EntryPointsByType EntryPointsByType `json:"entry_points_by_type"`
EntryPointsByType SierraEntryPointsByType `json:"entry_points_by_type"`

ABI string `json:"abi,omitempty"`
}
Expand Down Expand Up @@ -285,7 +285,7 @@ type SierraEntryPoint struct {
Selector *felt.Felt `json:"selector"`
}

type EntryPointsByType struct {
type SierraEntryPointsByType struct {
Constructor []SierraEntryPoint `json:"CONSTRUCTOR"`
External []SierraEntryPoint `json:"EXTERNAL"`
L1Handler []SierraEntryPoint `json:"L1_HANDLER"`
Expand Down
Loading

0 comments on commit 9007483

Please sign in to comment.