/
tx_error.go
140 lines (130 loc) · 4.21 KB
/
tx_error.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package events
import (
"context"
"fmt"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
)
type TxErr struct {
*Base
evt *eventspb.TxErrorEvent
}
func NewTxErrEvent(ctx context.Context, err error, partyID string, tx interface{}, cmd string) *TxErr {
evt := &TxErr{
Base: newBase(ctx, TxErrEvent),
evt: &eventspb.TxErrorEvent{
PartyId: partyID,
ErrMsg: fmt.Sprintf("%v - %v", cmd, err.Error()),
},
}
switch tv := tx.(type) {
case *commandspb.OrderSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_OrderSubmission{
OrderSubmission: tv,
}
case *commandspb.OrderCancellation:
evt.evt.Transaction = &eventspb.TxErrorEvent_OrderCancellation{
OrderCancellation: tv,
}
case *commandspb.OrderAmendment:
evt.evt.Transaction = &eventspb.TxErrorEvent_OrderAmendment{
OrderAmendment: tv,
}
case *commandspb.VoteSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_VoteSubmission{
VoteSubmission: tv,
}
case *commandspb.WithdrawSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_WithdrawSubmission{
WithdrawSubmission: tv,
}
case *commandspb.LiquidityProvisionSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_LiquidityProvisionSubmission{
LiquidityProvisionSubmission: tv,
}
case *commandspb.LiquidityProvisionCancellation:
evt.evt.Transaction = &eventspb.TxErrorEvent_LiquidityProvisionCancellation{
LiquidityProvisionCancellation: tv,
}
case *commandspb.LiquidityProvisionAmendment:
evt.evt.Transaction = &eventspb.TxErrorEvent_LiquidityProvisionAmendment{
LiquidityProvisionAmendment: tv,
}
case *commandspb.ProposalSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_Proposal{
Proposal: tv,
}
case *commandspb.DelegateSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_DelegateSubmission{
DelegateSubmission: tv,
}
case *commandspb.UndelegateSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_UndelegateSubmission{
UndelegateSubmission: tv,
}
case *commandspb.Transfer:
evt.evt.Transaction = &eventspb.TxErrorEvent_Transfer{
Transfer: tv,
}
case *commandspb.CancelTransfer:
evt.evt.Transaction = &eventspb.TxErrorEvent_CancelTransfer{
CancelTransfer: tv,
}
case *commandspb.AnnounceNode:
evt.evt.Transaction = &eventspb.TxErrorEvent_AnnounceNode{
AnnounceNode: tv,
}
case *commandspb.OracleDataSubmission:
evt.evt.Transaction = &eventspb.TxErrorEvent_OracleDataSubmission{
OracleDataSubmission: tv,
}
case *commandspb.ProtocolUpgradeProposal:
evt.evt.Transaction = &eventspb.TxErrorEvent_ProtocolUpgradeProposal{
ProtocolUpgradeProposal: tv,
}
case *commandspb.IssueSignatures:
evt.evt.Transaction = &eventspb.TxErrorEvent_IssueSignatures{
IssueSignatures: tv,
}
case *commandspb.BatchMarketInstructions:
evt.evt.Transaction = &eventspb.TxErrorEvent_BatchMarketInstructions{
BatchMarketInstructions: tv,
}
case error: // unsupported command error
evt.evt.ErrMsg = fmt.Sprintf("%v - %v", err, tv)
}
return evt
}
func (t TxErr) IsParty(id string) bool {
return t.evt.PartyId == id
}
func (t TxErr) Proto() eventspb.TxErrorEvent {
return *t.evt
}
func (t TxErr) StreamMessage() *eventspb.BusEvent {
busEvent := newBusEventFromBase(t.Base)
busEvent.Event = &eventspb.BusEvent_TxErrEvent{
TxErrEvent: t.evt,
}
return busEvent
}
func TxErrEventFromStream(ctx context.Context, be *eventspb.BusEvent) *TxErr {
return &TxErr{
Base: newBaseFromBusEvent(ctx, TxErrEvent, be),
evt: be.GetTxErrEvent(),
}
}