Skip to content

Commit ad3b726

Browse files
committed
[FAB-14324] add Channel accessors and use them
- create accessors on the Channel struct - use accessors instead of field access when appropriate Change-Id: I8bf5acc90505002b90c142ae9e6c37b441bdb1e7 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 784212e commit ad3b726

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

core/peer/peer.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ func (c *Channel) Ledger() ledger.PeerLedger {
103103
return c.ledger
104104
}
105105

106+
func (c *Channel) Resources() channelconfig.Resources {
107+
return c.resources
108+
}
109+
110+
func (c *Channel) ConfigBlock() *common.Block {
111+
return c.cb
112+
}
113+
114+
func (c *Channel) setConfigBlock(cb *common.Block) {
115+
c.cb = cb
116+
}
117+
118+
func (c *Channel) BundleSource() *channelconfig.BundleSource {
119+
return c.bundleSource
120+
}
121+
122+
func (c *Channel) Store() transientstore.Store {
123+
return c.store
124+
}
125+
106126
func (c *Channel) Reader() blockledger.Reader {
107127
return fileledger.NewFileLedger(fileLedgerBlockStore{c.ledger})
108128
}
@@ -176,10 +196,6 @@ func (c *Channel) MSPManager() msp.MSPManager {
176196
return c.resources.MSPManager()
177197
}
178198

179-
func (c *Channel) Store() transientstore.Store {
180-
return c.store
181-
}
182-
183199
func getCurrConfigBlockFromLedger(ledger ledger.PeerLedger) (*common.Block, error) {
184200
peerLogger.Debugf("Getting config block")
185201

@@ -316,7 +332,7 @@ func buildTrustedRootsForChain(cm channelconfig.Resources) {
316332
// setCurrConfigBlock sets the current config block of the specified channel
317333
func (p *Peer) setCurrConfigBlock(block *common.Block, cid string) error {
318334
if c := p.Channel(cid); c != nil {
319-
c.cb = block // TODO: serialization?
335+
c.setConfigBlock(block)
320336
return nil
321337
}
322338
return errors.Errorf("[channel %s] channel not associated with this peer", cid)
@@ -379,7 +395,7 @@ func (*configSupport) GetChannelConfig(cid string) cc.Config {
379395
peerLogger.Errorf("[channel %s] channel not associated with this peer", cid)
380396
return nil
381397
}
382-
return channel.bundleSource.ConfigtxValidator()
398+
return channel.BundleSource().ConfigtxValidator()
383399
}
384400

385401
// Operations exposes an interface to the package level functions that operated
@@ -600,7 +616,7 @@ func (p *Peer) Channel(cid string) *Channel {
600616

601617
func (p *Peer) StoreForChannel(cid string) transientstore.Store {
602618
if c := p.Channel(cid); c != nil {
603-
return c.store
619+
return c.Store()
604620
}
605621
return nil
606622
}
@@ -609,7 +625,7 @@ func (p *Peer) StoreForChannel(cid string) transientstore.Store {
609625
// call returns nil if channel cid has not been created.
610626
func (p *Peer) GetChannelConfig(cid string) channelconfig.Resources {
611627
if c := p.Channel(cid); c != nil {
612-
return c.resources
628+
return c.Resources()
613629
}
614630
return nil
615631
}
@@ -632,7 +648,7 @@ func (p *Peer) GetChannelsInfo() []*pb.ChannelInfo {
632648
// Note that this call returns nil if channel cid has not been created.
633649
func (p *Peer) GetStableChannelConfig(cid string) channelconfig.Resources {
634650
if c := p.Channel(cid); c != nil {
635-
return c.bundleSource.StableBundle()
651+
return c.BundleSource().StableBundle()
636652
}
637653
return nil
638654
}
@@ -641,7 +657,7 @@ func (p *Peer) GetStableChannelConfig(cid string) channelconfig.Resources {
641657
// Note that this call returns nil if channel cid has not been created.
642658
func (p *Peer) GetCurrConfigBlock(cid string) *common.Block {
643659
if c := p.Channel(cid); c != nil {
644-
return c.cb
660+
return c.ConfigBlock()
645661
}
646662
return nil
647663
}
@@ -650,7 +666,7 @@ func (p *Peer) GetCurrConfigBlock(cid string) *common.Block {
650666
// call returns nil if channel cid has not been created.
651667
func (p *Peer) GetLedger(cid string) ledger.PeerLedger {
652668
if c := p.Channel(cid); c != nil {
653-
return c.ledger
669+
return c.Ledger()
654670
}
655671
return nil
656672
}
@@ -667,7 +683,7 @@ func (p *Peer) GetMSPIDs(cid string) []string {
667683
// call returns nil if channel cid has not been created.
668684
func (p *Peer) GetPolicyManager(cid string) policies.Manager {
669685
if c := p.Channel(cid); c != nil {
670-
return c.resources.PolicyManager()
686+
return c.Resources().PolicyManager()
671687
}
672688
return nil
673689
}

0 commit comments

Comments
 (0)