github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/decode/bool.go (about)

     1  package decode
     2  
     3  import (
     4  	"encoding/hex"
     5  	"errors"
     6  )
     7  
     8  // ArticulateBool translates EVM hex into Go boolean
     9  func ArticulateBool(hexStr string) (result bool, err error) {
    10  	// 0x + 64 characters
    11  	if len(hexStr) < 66 {
    12  		err = errors.New("hex string too short")
    13  		return
    14  	}
    15  	byteValue, err := hex.DecodeString(hexStr[2:])
    16  	if err != nil {
    17  		return
    18  	}
    19  	result = byteValue[len(byteValue)-1] == 1
    20  	return
    21  }