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

Open
wants to merge 4 commits into
base: v0.8.0
Choose a base branch
from

Conversation

thiagodeev
Copy link
Collaborator

@thiagodeev thiagodeev commented Oct 29, 2024

#623

This PR aims to implement some RPC v0.8.0 updates to starknet.go. The ones addressed by this PR are:

Methods
starknet_getCompiledCasm

Components
CASM_COMPILED_CONTRACT_CLASS
CASM_ENTRY_POINT
CellRef
Deref
DoubleDeref
Immediate
BinOp
ResOperand
HINT
DEPRECATED_HINT
CORE_HINT
STARKNET_HINT

Errors
COMPILATION_ERROR

Note: As the RPC v0.8.0 has not yet been released, we can't fully test these changes as the nodes haven't implemented them yet. They will be updated before merging into main

Also, there's the creation of a new utility to get a typed field from a map representing a JSON

@thiagodeev thiagodeev marked this pull request as ready for review October 30, 2024 20:09
type CasmCompiledContractClass struct {
EntryPointsByType CasmEntryPointsByType `json:"entry_points_by_type"`
ByteCode []*felt.Felt `json:"bytecode"`
Prime []*felt.Felt `json:"prime"`
Copy link
Contributor

@rianhughes rianhughes Oct 31, 2024

Choose a reason for hiding this comment

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

Why not NumAsHex for prime?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch, thanks!

ByteCode []*felt.Felt `json:"bytecode"`
Prime []*felt.Felt `json:"prime"`
CompilerVersion string `json:"compiler_version"`
Hints Hints `json:"hints"`
Copy link
Contributor

@rianhughes rianhughes Oct 31, 2024

Choose a reason for hiding this comment

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

I think this should be [2]Hints

Copy link
Collaborator Author

@thiagodeev thiagodeev Oct 31, 2024

Choose a reason for hiding this comment

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

I did that because hints is a tuple of [intenger, []hint] and Golang doesn't allow an array of multiple types. So I created a struct having these two fields and two helper methods for getting the values: the Values() that returns both values the way Golang usually does (int, []Hint) and the Tuple() that returns an [2]any array in case someone needs it in this format

@@ -16,3 +19,18 @@ func UnwrapJSON(data map[string]interface{}, tag string) (map[string]interface{}
}
return data, nil
}

func GetTypedFieldFromJSON[T any](data map[string]interface{}, tag string) (T, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was using it in previous commits but not now, I'll remove it then

Comment on lines +35 to +41
func (hints *Hints) Values() (int, []Hint) {
return hints.Int, hints.HintArr
}

func (hints *Hints) Tuple() [2]any {
return [2]any{hints.Int, hints.HintArr}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these functions for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#642 (comment)

Answered here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants