-
Notifications
You must be signed in to change notification settings - Fork 660
/
atomic_tx_executor.go
77 lines (65 loc) · 2.55 KB
/
atomic_tx_executor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
var _ txs.Visitor = (*AtomicTxExecutor)(nil)
// atomicTxExecutor is used to execute atomic transactions pre-AP5. After AP5
// the execution was moved to be performed inside of the standardTxExecutor.
type AtomicTxExecutor struct {
// inputs, to be filled before visitor methods are called
*Backend
ParentID ids.ID
StateVersions state.Versions
Tx *txs.Tx
// outputs of visitor execution
OnAccept state.Diff
Inputs ids.Set
AtomicRequests map[ids.ID]*atomic.Requests
}
func (*AtomicTxExecutor) AddValidatorTx(*txs.AddValidatorTx) error { return errWrongTxType }
func (*AtomicTxExecutor) AddSubnetValidatorTx(*txs.AddSubnetValidatorTx) error { return errWrongTxType }
func (*AtomicTxExecutor) AddDelegatorTx(*txs.AddDelegatorTx) error { return errWrongTxType }
func (*AtomicTxExecutor) CreateChainTx(*txs.CreateChainTx) error { return errWrongTxType }
func (*AtomicTxExecutor) CreateSubnetTx(*txs.CreateSubnetTx) error { return errWrongTxType }
func (*AtomicTxExecutor) AdvanceTimeTx(*txs.AdvanceTimeTx) error { return errWrongTxType }
func (*AtomicTxExecutor) RewardValidatorTx(*txs.RewardValidatorTx) error { return errWrongTxType }
func (*AtomicTxExecutor) RemoveSubnetValidatorTx(*txs.RemoveSubnetValidatorTx) error {
return errWrongTxType
}
func (*AtomicTxExecutor) TransformSubnetTx(*txs.TransformSubnetTx) error { return errWrongTxType }
func (*AtomicTxExecutor) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error {
return errWrongTxType
}
func (*AtomicTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error {
return errWrongTxType
}
func (e *AtomicTxExecutor) ImportTx(tx *txs.ImportTx) error {
return e.atomicTx(tx)
}
func (e *AtomicTxExecutor) ExportTx(tx *txs.ExportTx) error {
return e.atomicTx(tx)
}
func (e *AtomicTxExecutor) atomicTx(tx txs.UnsignedTx) error {
onAccept, err := state.NewDiff(
e.ParentID,
e.StateVersions,
)
if err != nil {
return err
}
e.OnAccept = onAccept
executor := StandardTxExecutor{
Backend: e.Backend,
State: e.OnAccept,
Tx: e.Tx,
}
err = tx.Visit(&executor)
e.Inputs = executor.Inputs
e.AtomicRequests = executor.AtomicRequests
return err
}