/
transitions.go
59 lines (48 loc) · 1.39 KB
/
transitions.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
package common
import (
"github.com/ellcrys/elld/types"
"github.com/ellcrys/elld/util"
)
// Transition represents a mutation to the state of a chain
type Transition interface {
// Address returns the address this transition is to affect
Address() util.String
// Equal is used to check whether a transition operation t is similar
Equal(t Transition) bool
}
// OpBase includes common methods and fields for a transition object
type OpBase struct {
Addr util.String
}
// Address returns the address to be acted on
func (o *OpBase) Address() util.String {
return o.Addr
}
// Equal checks whether a Transition t is equal to o
func (o *OpBase) Equal(t Transition) bool {
return o.Address().Equal(t.Address())
}
// OpCreateAccount describes a transition to create an account
type OpCreateAccount struct {
*OpBase
Account types.Account
}
// Equal checks whether a Transition t is equal to o
func (o *OpCreateAccount) Equal(t Transition) bool {
if _t, yes := t.(*OpCreateAccount); yes && o.Address() == _t.Address() {
return true
}
return false
}
// OpNewAccountBalance represents a transition to a new account balance
type OpNewAccountBalance struct {
*OpBase
Account types.Account
}
// Equal checks whether a Transition t is equal to o
func (o *OpNewAccountBalance) Equal(t Transition) bool {
if _t, yes := t.(*OpNewAccountBalance); yes && o.Address() == _t.Address() {
return true
}
return false
}