-
Notifications
You must be signed in to change notification settings - Fork 5
/
helpers.go
69 lines (59 loc) · 1.63 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"encoding/base64"
"encoding/hex"
"fmt"
"math/big"
"os"
"strconv"
log "github.com/sirupsen/logrus"
)
func trimPubKey(pubkey []byte) string {
N_SPLIT := 8
if len(pubkey) > N_SPLIT {
return fmt.Sprintf("%s..%s", hex.EncodeToString(pubkey)[:N_SPLIT/2], hex.EncodeToString(pubkey)[len(hex.EncodeToString(pubkey))-N_SPLIT/2:])
} else {
return hex.EncodeToString(pubkey)
}
}
func Welcome() {
log.Info("---- ⚡️ electronwall 0.4 ⚡️ ----")
}
// SetLogger will initialize the log format
func SetLogger(debug bool, json bool) {
if json {
customFormatter := new(log.JSONFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.PrettyPrint = true
log.SetFormatter(customFormatter)
return
}
log.SetOutput(os.Stdout)
if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
customFormatter := new(log.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
customFormatter.FullTimestamp = true
customFormatter.ForceColors = true
log.SetFormatter(customFormatter)
}
func intTob64(i int64) string {
return base64.RawURLEncoding.EncodeToString(big.NewInt(i).Bytes())
}
func intToHex(i int64) string {
return hex.EncodeToString(big.NewInt(i).Bytes())
}
func ParseChannelID(e uint64) string {
byte_e := big.NewInt(int64(e)).Bytes()
hexstr := hex.EncodeToString(byte_e)
if len(hexstr) < 12 {
return ""
}
int_block3, _ := strconv.ParseInt(hexstr[:6], 16, 64)
int_block2, _ := strconv.ParseInt(hexstr[6:12], 16, 64)
int_block1, _ := strconv.ParseInt(hexstr[12:], 16, 64)
return fmt.Sprintf("%dx%dx%d", int_block3, int_block2, int_block1)
}