-
Notifications
You must be signed in to change notification settings - Fork 664
/
atomic_tx_executor.go
60 lines (51 loc) · 2 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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
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{}
// 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
vm *VM
parentState state.Chain
tx *txs.Tx
// outputs
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 (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 {
e.onAccept = state.NewDiff(
e.parentState,
e.parentState.CurrentStakers(),
e.parentState.PendingStakers(),
)
executor := standardTxExecutor{
vm: e.vm,
state: e.onAccept,
tx: e.tx,
}
err := tx.Visit(&executor)
e.inputs = executor.inputs
e.atomicRequests = executor.atomicRequests
return err
}