-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstate.go
66 lines (56 loc) · 1.75 KB
/
state.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
package token
import (
"errors"
"github.com/hyperledger-labs/cckit/router"
"github.com/hyperledger-labs/cckit/state"
m "github.com/hyperledger-labs/cckit/state/mapping"
)
var (
ErrAmountInsuficcient = errors.New(`amount insufficient`)
StateMappings = m.StateMappings{}.
// Create mapping for Balance entity (account model)
// key will be `Balance`,`{Address}`,`{Path[0]}`..., `{Path[n]`
Add(&Balance{},
m.PKeySchema(&BalanceId{}),
m.List(&Balances{}), // Structure of result for List method
).
// Create mapping for Balance entity
// key will be `UTXO`,`{Address}`,`{symbol}`, `{group | join (",")}`, `{TXId}`
Add(&UTXO{},
//m.PKeyer(func(instance interface{}) (state.Key, error) {
// return UTXOKey(instance.(*UTXO)), nil
//}),
m.PKeySchema(&UTXOId{}),
m.List(&UTXOs{}), // Structure of result for List method
).
Add(&TokenType{},
m.PKeySchema(&TokenTypeId{}),
m.List(&TokenTypes{})).
Add(&TokenGroup{},
m.PKeySchema(&TokenGroupId{}),
m.List(&TokenGroups{})).
Add(&Config{},
m.WithConstPKey())
EventMappings = m.EventMappings{}.
Add(&Transferred{}).
Add(&TransferredBatch{}).
Add(&TokenTypeCreated{}).
Add(&TokenGroupCreated{})
)
func UTXOKey(utxo *UTXO) state.Key {
return UTXOKeyBase(utxo).Append(state.Key{utxo.TxId})
}
//func UTXOKeyBase(utxo *UTXO) state.Key {
// return state.Key{utxo.Address, utxo.Symbol, strings.Join(utxo.Group, `,`)}
//}
func UTXOKeyBase(utxo *UTXO) state.Key {
return state.Key{utxo.Symbol, utxo.Group, utxo.Address}
}
// State with chaincode mappings
func State(ctx router.Context) m.MappedState {
return m.WrapState(ctx.State(), StateMappings)
}
// Event with chaincode mappings
func Event(ctx router.Context) state.Event {
return m.WrapEvent(ctx.Event(), EventMappings)
}