forked from bnb-chain/tss-lib
/
slice.go
52 lines (46 loc) · 1.17 KB
/
slice.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
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package common
import (
"math/big"
)
func BigIntsToBytes(bigInts []*big.Int) [][]byte {
bzs := make([][]byte, len(bigInts))
for i := range bzs {
if bigInts[i] == nil {
continue
}
bzs[i] = bigInts[i].Bytes()
}
return bzs
}
func MultiBytesToBigInts(bytes [][]byte) []*big.Int {
ints := make([]*big.Int, len(bytes))
for i := range ints {
ints[i] = new(big.Int).SetBytes(bytes[i])
}
return ints
}
// Returns true when the byte slice is non-nil and non-empty
func NonEmptyBytes(bz []byte) bool {
return bz != nil && 0 < len(bz)
}
// Returns true when all of the slices in the multi-dimensional byte slice are non-nil and non-empty
func NonEmptyMultiBytes(bzs [][]byte, expectLen ...int) bool {
if len(bzs) == 0 {
return false
}
// variadic (optional) arg test
if 0 < len(expectLen) && expectLen[0] != len(bzs) {
return false
}
for _, bz := range bzs {
if !NonEmptyBytes(bz) {
return false
}
}
return true
}