-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.go
54 lines (42 loc) · 1.32 KB
/
utils.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
package db
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/fissionlabsio/juno/codec"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
)
// parseTxs parses a set of transactions returned by Tendermint into StdTx
// transactions. It returns an error if any unmarshalling fails.
func parseTxs(txs []*tmctypes.ResultTx) ([]auth.StdTx, error) {
stdTxs := make([]auth.StdTx, len(txs))
for i, tx := range txs {
var stdTx auth.StdTx
err := codec.Codec.UnmarshalBinaryLengthPrefixed(tx.Tx, &stdTx)
if err != nil {
return nil, err
}
stdTxs[i] = stdTx
}
return stdTxs, nil
}
// findValidatorByAddr finds a validator by a HEX address given a set of
// Tendermint validators for a particular block. If no validator is found, nil
// is returned.
func findValidatorByAddr(addrHex string, vals *tmctypes.ResultValidators) *tmtypes.Validator {
for _, val := range vals.Validators {
if strings.ToLower(addrHex) == strings.ToLower(val.Address.String()) {
return val
}
}
return nil
}
// sumGasTxs returns the total gas consumed by a set of transactions.
func sumGasTxs(txs []sdk.TxResponse) uint64 {
var totalGas uint64
for _, tx := range txs {
totalGas += uint64(tx.GasUsed)
}
return totalGas
}