-
Notifications
You must be signed in to change notification settings - Fork 36
/
tx_ops.go
62 lines (55 loc) · 1.61 KB
/
tx_ops.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
package pchain
import "github.com/coinbase/rosetta-sdk-go/types"
// txOps collects all balance-changing information within a transaction
type txOps struct {
isConstruction bool
Ins []*types.Operation
Outs []*types.Operation
StakeOuts []*types.Operation
ImportIns []*types.Operation
ExportOuts []*types.Operation
}
func newTxOps(isConstruction bool) *txOps {
return &txOps{isConstruction: isConstruction}
}
func (t *txOps) IncludedOperations() []*types.Operation {
ops := []*types.Operation{}
ops = append(ops, t.Ins...)
ops = append(ops, t.Outs...)
ops = append(ops, t.StakeOuts...)
return ops
}
// Used to populate operation identifier
func (t *txOps) Len() int {
return len(t.Ins) + len(t.Outs) + len(t.StakeOuts)
}
// Used to populate coin identifier
func (t *txOps) OutputLen() int {
return len(t.Outs) + len(t.StakeOuts)
}
func (t *txOps) Append(op *types.Operation, metaType string) {
switch metaType {
case OpTypeImport:
if t.isConstruction {
t.Ins = append(t.Ins, op)
} else {
// removing operation identifier as these will be skipped in the final operations list
op.OperationIdentifier = nil
t.ImportIns = append(t.ImportIns, op)
}
case OpTypeExport:
if t.isConstruction {
t.Outs = append(t.Outs, op)
} else {
// removing operation identifier as these will be skipped in the final operations list
op.OperationIdentifier = nil
t.ExportOuts = append(t.ExportOuts, op)
}
case OpTypeStakeOutput, OpTypeReward:
t.StakeOuts = append(t.StakeOuts, op)
case OpTypeOutput:
t.Outs = append(t.Outs, op)
case OpTypeInput:
t.Ins = append(t.Ins, op)
}
}