Skip to content

Commit

Permalink
fix: Fix method BigmapTypeDetection (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili authored Sep 9, 2024
1 parent 9c08fd0 commit cd5b76a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
49 changes: 28 additions & 21 deletions micheline/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,39 +367,46 @@ func DetectBigmapTypes(typ Prim) map[string]Type {
}
_ = typ.Walk(func(p Prim) error {
switch p.OpCode {
case T_BIG_MAP:
named[uniqueName(p.GetVarAnnoAny())] = NewType(p)
return PrimSkip
case K_STORAGE:
// The root node of the storage primitive; do nothing and continue
return nil

case T_MAP:
if p.Args[1].OpCode != T_BIG_MAP {
return PrimSkip
key := p.Args[0].String
if key == "" {
key = fmt.Sprint(p.Args[0].Hash64())
}
name := p.GetVarAnnoAny()
if n := p.Args[1].GetVarAnnoAny(); n != "" {
name = n
// Map's value type definition is in its second argument
for _, v := range DetectBigmapTypes(p.Args[1]) {
named[uniqueName(key)] = v
}
named[uniqueName(name)] = NewType(p.Args[1])
return PrimSkip
case T_LIST:
if p.Args[0].OpCode != T_BIG_MAP {
return PrimSkip
}
name := p.GetVarAnnoAny()
if n := p.Args[0].GetVarAnnoAny(); n != "" {
name = n

case T_BIG_MAP:
named[uniqueName(p.GetVarAnnoAny())] = NewType(p)
return PrimSkip

case T_LIST, T_OPTION:
// Type definition of list items and option values is in the
// first (and the only) argument of the primitive
for n, v := range DetectBigmapTypes(p.Args[0]) {
named[uniqueName(n)] = v
}
named[uniqueName(name)] = NewType(p.Args[0])
return PrimSkip

case T_LAMBDA:
case T_OR, T_PAIR:
// OR candidates are defined in the arguments of the OR primitive
for _, arg := range p.Args {
for n, v := range DetectBigmapTypes(arg) {
named[uniqueName(n)] = v
}
}
return PrimSkip

default:
// return PrimSkip
return nil
return PrimSkip
}
})

return named
}

Expand Down
Loading

0 comments on commit cd5b76a

Please sign in to comment.