github.com/mavryk-network/mvgo@v1.19.9/micheline/constant.go (about) 1 // Copyright (c) 2020-2021 Blockwatch Data Inc. 2 // Author: alex@blockwatch.cc 3 4 package micheline 5 6 import "github.com/mavryk-network/mvgo/mavryk" 7 8 type ConstantDict map[string]Prim 9 10 func (d *ConstantDict) Add(address mavryk.ExprHash, value Prim) { 11 if *d == nil { 12 *d = make(ConstantDict) 13 } 14 (*d)[address.String()] = value 15 } 16 17 func (d ConstantDict) Has(address mavryk.ExprHash) bool { 18 if d == nil { 19 return false 20 } 21 _, ok := d[address.String()] 22 return ok 23 } 24 25 func (d ConstantDict) Get(address mavryk.ExprHash) (Prim, bool) { 26 if d == nil { 27 return InvalidPrim, false 28 } 29 p, ok := d[address.String()] 30 return p, ok 31 } 32 33 func (d ConstantDict) GetString(address string) (Prim, bool) { 34 if d == nil { 35 return InvalidPrim, false 36 } 37 p, ok := d[address] 38 return p, ok 39 } 40 41 func (p Prim) Constants() []mavryk.ExprHash { 42 c := make([]mavryk.ExprHash, 0) 43 p.Walk(func(p Prim) error { 44 if p.IsConstant() { 45 if h, err := mavryk.ParseExprHash(p.Args[0].String); err == nil { 46 c = append(c, h) 47 } 48 } 49 return nil 50 }) 51 return c 52 }