forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
76 lines (62 loc) · 1.35 KB
/
tx.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
package main
import (
"bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
)
// An sdk.Tx which is its own sdk.Msg.
type dummyTx struct {
key []byte
value []byte
bytes []byte
}
func (tx dummyTx) Get(key interface{}) (value interface{}) {
switch k := key.(type) {
case string:
switch k {
case "key":
return tx.key
case "value":
return tx.value
}
}
return nil
}
func (tx dummyTx) Type() string {
return "dummy"
}
func (tx dummyTx) GetMsg() sdk.Msg {
return tx
}
func (tx dummyTx) GetSignBytes() []byte {
return tx.bytes
}
// Should the app be calling this? Or only handlers?
func (tx dummyTx) ValidateBasic() sdk.Error {
return nil
}
func (tx dummyTx) GetSigners() []crypto.Address {
return nil
}
func (tx dummyTx) GetSignatures() []sdk.StdSignature {
return nil
}
func (tx dummyTx) GetFeePayer() crypto.Address {
return nil
}
// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has
// all the signatures and can be used to authenticate.
func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
var tx sdk.Tx
split := bytes.Split(txBytes, []byte("="))
if len(split) == 1 {
k := split[0]
tx = dummyTx{k, k, txBytes}
} else if len(split) == 2 {
k, v := split[0], split[1]
tx = dummyTx{k, v, txBytes}
} else {
return nil, sdk.ErrTxParse("too many =")
}
return tx, nil
}