-
Notifications
You must be signed in to change notification settings - Fork 112
/
block_base_tx.go
46 lines (42 loc) · 1.23 KB
/
block_base_tx.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
package verifier
import (
"fmt"
"github.com/iost-official/go-iost/common"
"github.com/iost-official/go-iost/core/block"
"github.com/iost-official/go-iost/core/blockcache"
"github.com/iost-official/go-iost/core/tx"
)
// NewBaseTx is new baseTx
func NewBaseTx(blk, parent *block.Block, witnessList *blockcache.WitnessList) (*tx.Tx, error) {
acts := []*tx.Action{}
if blk.Head.Number > 0 {
txData, err := baseTxData(blk, parent, witnessList)
if err != nil {
return nil, err
}
act := tx.NewAction("base.iost", "exec", txData)
acts = append(acts, act)
}
tx := &tx.Tx{
Publisher: "base.iost",
GasLimit: 100000000,
GasRatio: 100,
Actions: acts,
Time: blk.Head.Time,
ChainID: tx.ChainID,
}
return tx, nil
}
func baseTxData(b, pb *block.Block, witnessList *blockcache.WitnessList) (string, error) {
if pb != nil {
witnessChanged := false
if witnessList != nil && !common.StringSliceEqual(witnessList.Active(), witnessList.Pending()) {
witnessChanged = true
}
return fmt.Sprintf(`[{"parent":["%v", "%v", %v]}]`, pb.Head.Witness, pb.CalculateGasUsage(), witnessChanged), nil
}
if b.Head.Number != 0 {
return "", fmt.Errorf("block dit not have parent")
}
return `[{"parent":["", "0", false]}]`, nil
}