-
Notifications
You must be signed in to change notification settings - Fork 1
/
utxo.go
73 lines (62 loc) · 1.89 KB
/
utxo.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
package types
import (
"github.com/AdityaSripal/plasma-mvp-sidechain/x/utxo"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
amino "github.com/tendermint/go-amino"
)
const (
// Only allowed Denomination on this plasma chain
Denom = "Ether"
)
//----------------------------------------
// Position
type PlasmaPosition struct {
Blknum uint64
TxIndex uint16
Oindex uint8
DepositNum uint64
}
func ProtoPosition() utxo.Position {
return &PlasmaPosition{}
}
func NewPlasmaPosition(blknum uint64, txIndex uint16, oIndex uint8, depositNum uint64) PlasmaPosition {
return PlasmaPosition{
Blknum: blknum,
TxIndex: txIndex,
Oindex: oIndex,
DepositNum: depositNum,
}
}
func (position PlasmaPosition) Get() []sdk.Uint {
return []sdk.Uint{sdk.NewUint(position.Blknum), sdk.NewUint(uint64(position.TxIndex)), sdk.NewUint(uint64(position.Oindex)), sdk.NewUint(position.DepositNum)}
}
// check that the position is formatted correctly
// Implements Position
func (position PlasmaPosition) IsValid() bool {
// If position is a regular tx, output index must be 0 or 1 and depositnum must be 0
if position.Blknum != 0 {
return position.Oindex < 2 && position.DepositNum == 0
} else {
// If position represents deposit, depositnum is not 0 and txindex and oindex are 0.
return position.DepositNum != 0 && position.TxIndex == 0 && position.Oindex == 0
}
}
func (position PlasmaPosition) IsDeposit() bool {
if !position.IsValid() {
return false
}
return position.DepositNum != 0
}
type Deposit struct {
Owner common.Address
Amount sdk.Uint
BlockNum sdk.Uint
}
//-------------------------------------------------------
// misc
func RegisterAmino(cdc *amino.Codec) {
cdc.RegisterConcrete(PlasmaPosition{}, "types/PlasmaPosition", nil)
cdc.RegisterConcrete(BaseTx{}, "types/BaseTX", nil)
cdc.RegisterConcrete(SpendMsg{}, "types/SpendMsg", nil)
}