-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
64 lines (53 loc) · 1.33 KB
/
types.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
package utxo
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/go-amino"
)
// UTXO is a standard unspent transaction output
// When spent, it becomes invalid and spender keys are filled in
type UTXO struct {
Address []byte
Amount uint64
Denom string
Valid bool
Position Position
}
func NewUTXO(owner []byte, amount uint64, denom string, position Position) UTXO {
return UTXO{
Address: owner,
Amount: amount,
Denom: denom,
Position: position,
Valid: true,
}
}
func (utxo UTXO) StoreKey(cdc *amino.Codec) []byte {
encPos := cdc.MustMarshalBinaryBare(utxo.Position)
return append(utxo.Address, encPos...)
}
// Create a prototype Position.
// Must return pointer to struct implementing Position
type ProtoPosition func() Position
// Positions must be unqiue or a collision may result when using mapper.go
type Position interface {
// Position is a uint slice
Get() []sdk.Uint // get position int slice. Return nil if unset.
// returns true if the position is valid, false otherwise
IsValid() bool
}
// SpendMsg is an interface that wraps sdk.Msg with additional information
// for the UTXO spend handler.
type SpendMsg interface {
sdk.Msg
Inputs() []Input
Outputs() []Output
}
type Input struct {
Owner []byte
Position
}
type Output struct {
Owner []byte
Denom string
Amount uint64
}