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

starknet_getCompiledCasm #642

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading