-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactions.go
44 lines (35 loc) · 1021 Bytes
/
transactions.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
// Copyright (c) 2018 The VeChainThor developers
// Copyright (c) 2019 The PlayMaker developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package tx
import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/playmakerchain/powerplay/powerplay"
"github.com/playmakerchain/powerplay/trie"
)
var (
emptyRoot = trie.DeriveRoot(&derivableTxs{})
)
// Transactions a slice of transactions.
type Transactions []*Transaction
// RootHash computes merkle root hash of transactions.
func (txs Transactions) RootHash() powerplay.Bytes32 {
if len(txs) == 0 {
// optimized
return emptyRoot
}
return trie.DeriveRoot(derivableTxs(txs))
}
// implements types.DerivableList
type derivableTxs Transactions
func (txs derivableTxs) Len() int {
return len(txs)
}
func (txs derivableTxs) GetRlp(i int) []byte {
data, err := rlp.EncodeToBytes(txs[i])
if err != nil {
panic(err)
}
return data
}