-
Notifications
You must be signed in to change notification settings - Fork 85
/
operation.go
60 lines (50 loc) · 1.66 KB
/
operation.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
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
)
// decodeOperationRawShortTermOrderPlacementBytes performs stateless validation
// on a short term order placement given its underlying raw tx bytes. It also
// runs the transaction through an antehandler. The antehandler is needed to
// do signature validation. Returns an Operation if successful.
func decodeOperationRawShortTermOrderPlacementBytes(
ctx sdk.Context,
bytes []byte,
decoder sdk.TxDecoder,
anteHandler sdk.AnteHandler,
) (*InternalOperation, error) {
tx, err := decoder(bytes)
if err != nil {
return nil, err
}
if _, err := anteHandler(ctx, tx, false); err != nil {
return nil, err
}
msgs := tx.GetMsgs()
if len(msgs) != 1 {
return nil, fmt.Errorf("expected 1 msg, got %d", len(msgs))
}
msg, ok := msgs[0].(*MsgPlaceOrder)
if !ok {
return nil, fmt.Errorf("expected MsgPlaceOrder, got %T", msgs[0])
}
return &InternalOperation{
Operation: &InternalOperation_ShortTermOrderPlacement{
ShortTermOrderPlacement: msg,
},
}, nil
}
// GetInternalOperationTextString returns the text string representation of this operation.
// TODO(DEC-1772): Add method for encoding operation protos as JSON to make debugging easier.
func (o *InternalOperation) GetInternalOperationTextString() string {
return proto.MarshalTextString(o)
}
// GetOperationsQueueString returns a string representation of the provided operations.
func GetInternalOperationsQueueTextString(operations []InternalOperation) string {
var result string
for _, operation := range operations {
result += operation.GetInternalOperationTextString() + "\n"
}
return result
}