github.com/s7techlab/cckit@v0.10.5/examples/token/service/balance/state.go (about) 1 package balance 2 3 import ( 4 "errors" 5 6 "github.com/s7techlab/cckit/router" 7 "github.com/s7techlab/cckit/state" 8 m "github.com/s7techlab/cckit/state/mapping" 9 ) 10 11 var ( 12 ErrAmountInsuficcient = errors.New(`amount insufficient`) 13 14 StateMappings = m.StateMappings{}. 15 // Create mapping for Balance entity 16 // key will be `Balance`,`{Address}`,`{Path[0]}`..., `{Path[n]` 17 Add(&Balance{}, 18 m.PKeySchema(&BalanceId{}), 19 m.List(&Balances{}), // Structure of result for List method 20 ) 21 22 EventMappings = m.EventMappings{}. 23 Add(&Transferred{}) 24 ) 25 26 // State with chaincode mappings 27 func State(ctx router.Context) m.MappedState { 28 return m.WrapState(ctx.State(), StateMappings) 29 } 30 31 // Event with chaincode mappings 32 func Event(ctx router.Context) state.Event { 33 return m.WrapEvent(ctx.Event(), EventMappings) 34 }