From 89b2b0a18b5a886933cc68e898127fe9876636c4 Mon Sep 17 00:00:00 2001 From: rianhughes Date: Tue, 22 Aug 2023 12:59:26 +0300 Subject: [PATCH] both classes --- rpc/types_contract.go | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/rpc/types_contract.go b/rpc/types_contract.go index c897444a..fc1b1e2c 100644 --- a/rpc/types_contract.go +++ b/rpc/types_contract.go @@ -12,7 +12,7 @@ import ( type NumAsHex string -type EntryPoint struct { +type DeprecatedCairoEntryPoint struct { // The offset of the entry point in the program Offset NumAsHex `json:"offset"` // A unique identifier of the entry point (function) in the program @@ -21,17 +21,16 @@ type EntryPoint struct { type ABI []ABIEntry -type EntryPointsByType struct { - Constructor []EntryPoint `json:"CONSTRUCTOR"` - External []EntryPoint `json:"EXTERNAL"` - L1Handler []EntryPoint `json:"L1_HANDLER"` +type DeprecatedEntryPointsByType struct { + Constructor []DeprecatedCairoEntryPoint `json:"CONSTRUCTOR"` + External []DeprecatedCairoEntryPoint `json:"EXTERNAL"` + L1Handler []DeprecatedCairoEntryPoint `json:"L1_HANDLER"` } - type DepcreatedContractClass struct { // Program A base64 representation of the compressed program code Program string `json:"program"` - EntryPointsByType EntryPointsByType `json:"entry_points_by_type"` + EntryPointsByType DeprecatedEntryPointsByType `json:"entry_points_by_type"` ABI *ABI `json:"abi,omitempty"` } @@ -61,7 +60,7 @@ func (c *DepcreatedContractClass) UnmarshalJSON(content []byte) error { return fmt.Errorf("missing entry_points_by_type in json object") } - entryPointsByType := EntryPointsByType{} + entryPointsByType := DeprecatedEntryPointsByType{} if err := json.Unmarshal(data, &entryPointsByType); err != nil { return err } @@ -113,6 +112,32 @@ func (c *DepcreatedContractClass) UnmarshalJSON(content []byte) error { return nil } +// https://github.com/starkware-libs/starknet-specs/blob/v0.3.0/api/starknet_api_openrpc.json#L2372 +type ContractClass struct { + // The list of Sierra instructions of which the program consists + SierraProgram []*felt.Felt `json:"sierra_program"` + + // The version of the contract class object. Currently, the Starknet OS supports version 0.1.0 + Version string `json:"contract_class_version"` + + EntryPointsByType EntryPointsByType `json:"entry_points_by_type"` + + ABI string `json:"abi,omitempty"` +} + +type SierraEntryPoint struct { + // The index of the function in the program + FunctionIdx int `json:"function_idx"` + // A unique identifier of the entry point (function) in the program + Selector *felt.Felt `json:"selector"` +} + +type EntryPointsByType struct { + Constructor []SierraEntryPoint `json:"CONSTRUCTOR"` + External []SierraEntryPoint `json:"EXTERNAL"` + L1Handler []SierraEntryPoint `json:"L1_HANDLER"` +} + type ABIEntry interface { IsType() ABIType }