Skip to content

Commit

Permalink
partially finished parse_full_abi_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
rishikpulhani3106 committed Sep 24, 2024
1 parent ec0c25c commit 1b3d6c3
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 42 deletions.
16 changes: 16 additions & 0 deletions athena_abi/abi.go

Large diffs are not rendered by default.

42 changes: 39 additions & 3 deletions athena_abi/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package athena_abi

import (
"errors"
"fmt"
"log"
)

Expand Down Expand Up @@ -34,7 +35,11 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class
groupedAbi := GroupAbiByType(abiJson)

// Parse defined types (structs and enums)
fmt.Println("hello")
fmt.Println("grouped abi", groupedAbi["type_def"])
definedTypes, err := ParseEnumsAndStructs(groupedAbi["type_def"])
fmt.Println("defined types Map contents:", definedTypes)
fmt.Println("is there error", err)
if err != nil {
sortedDefs, errDef := TopoSortTypeDefs(groupedAbi["type_def"])
if errDef == nil {
Expand All @@ -50,6 +55,7 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse interfaces
var definedInterfaces []AbiInterface
fmt.Println("now parsing interfaces")
for _, iface := range groupedAbi["interface"] {
functions := []AbiFunction{}
for _, funcData := range iface["items"].([]interface{}) {
Expand All @@ -67,6 +73,7 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse functions
functions := make(map[string]AbiFunction)
fmt.Println("now parsing functions")
for _, functionData := range groupedAbi["function"] {
funcName := functionData["name"].(string)
abiFunc, errParsingFunctions := ParseAbiFunction(functionData, definedTypes)
Expand All @@ -85,15 +92,28 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse events
parsedAbiEvents := []AbiEvent{}
fmt.Println("now parsing events")
for _, eventData := range groupedAbi["event"] {
fmt.Println("eventdata is ", eventData)
parsedEvent, errParsingEvent := ParseAbiEvent(eventData, definedTypes)
fmt.Println("parsed event is ", parsedEvent)
fmt.Println("the err is ", errParsingEvent)

if errParsingEvent != nil {
return nil, errParseEvents
}
parsedAbiEvents = append(parsedAbiEvents, *parsedEvent)
//parsedAbiEvents = append(parsedAbiEvents, *parsedEvent)
if parsedEvent != nil {
parsedAbiEvents = append(parsedAbiEvents, *parsedEvent)
} else {
// Handle the nil case if necessary
//return nil, errors.New("parsed event is nil")
continue
}
}

events := make(map[string]AbiEvent)
fmt.Println("parsedabievents are ", parsedAbiEvents)
for _, event := range parsedAbiEvents {
if event.name != "" {
events[event.name] = event
Expand All @@ -102,6 +122,7 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse constructor
var constructor []AbiParameter
fmt.Println("now parsing constructor")
if len(groupedAbi["constructor"]) == 1 {
for _, paramData := range groupedAbi["constructor"][0]["inputs"].([]interface{}) {
param := paramData.(map[string]interface{})
Expand All @@ -120,6 +141,7 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse L1 handler
var l1Handler *AbiFunction
fmt.Println("now parsing l1handler")
if len(groupedAbi["l1_handler"]) == 1 {
handler, errorParsingFunction := ParseAbiFunction(groupedAbi["l1_handler"][0], definedTypes)
if errorParsingFunction != nil {
Expand All @@ -132,9 +154,11 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class

// Parse implemented interfaces
implementedInterfaces := make(map[string]AbiInterface)
fmt.Println("now parsing implemented interfaces")
implArray, ok := groupedAbi["impl"]
if !ok {
return nil, errParseImplementedInterfaces
//return nil, errParseImplementedInterfaces
//this if block is not required
}
for _, implData := range implArray {
implMap := implData
Expand All @@ -146,7 +170,19 @@ func StarknetAbiFromJSON(abiJson []map[string]interface{}, abiName string, class
}
}
}

fmt.Println("abi name : ", abiName)
fmt.Println("classhash is : ", classHash)
fmt.Println()
fmt.Println("functions is : ", functions)
fmt.Println()
fmt.Println("events is : ", events)
fmt.Println()
fmt.Println("constructor is : ", constructor)
fmt.Println()
fmt.Println("l1handles is ", l1Handler)
fmt.Println()
fmt.Println("implemented interfaces is : ", implementedInterfaces)
fmt.Println()
// Return the populated StarknetAbi struct
return &StarknetABI{
ABIName: &abiName,
Expand Down
Loading

0 comments on commit 1b3d6c3

Please sign in to comment.