-
Notifications
You must be signed in to change notification settings - Fork 10
/
helpers.go
51 lines (44 loc) · 869 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package lightning
import (
"encoding/hex"
"errors"
"strconv"
)
func toFloat(val interface{}) (float64, error) {
switch v := val.(type) {
case int:
return float64(v), nil
case int64:
return float64(v), nil
case int32:
return float64(v), nil
case uint32:
return float64(v), nil
case float64:
return v, nil
case string:
return strconv.ParseFloat(v, 64)
}
return 0, errors.New("Can't convert to float.")
}
func as32(v []byte) (res [32]byte) {
for i := 0; i < 32; i++ {
res[i] = v[i]
}
return
}
func asByte32(hexstr string) (res [32]byte, err error) {
v, err := hex.DecodeString(hexstr)
if err != nil {
return
}
return as32(v), nil
}
func hasTLVOnionFeature(featurehex string) bool {
features, err := strconv.ParseInt(featurehex, 16, 64)
if err != nil {
return false
}
and := 515 & features
return and == 513 || and == 514
}