github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/common/config/applicationorg.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package config 18 19 import ( 20 mspconfig "github.com/inklabsfoundation/inkchain/common/config/msp" 21 pb "github.com/inklabsfoundation/inkchain/protos/peer" 22 23 logging "github.com/op/go-logging" 24 ) 25 26 // Application org config keys 27 const ( 28 // AnchorPeersKey is the key name for the AnchorPeers ConfigValue 29 AnchorPeersKey = "AnchorPeers" 30 ) 31 32 type ApplicationOrgProtos struct { 33 AnchorPeers *pb.AnchorPeers 34 } 35 36 type ApplicationOrgConfig struct { 37 *OrganizationConfig 38 protos *ApplicationOrgProtos 39 40 applicationOrgGroup *ApplicationOrgGroup 41 } 42 43 // ApplicationOrgGroup defines the configuration for an application org 44 type ApplicationOrgGroup struct { 45 *Proposer 46 *OrganizationGroup 47 *ApplicationOrgConfig 48 } 49 50 // NewApplicationOrgGroup creates a new ApplicationOrgGroup 51 func NewApplicationOrgGroup(id string, mspConfig *mspconfig.MSPConfigHandler) *ApplicationOrgGroup { 52 aog := &ApplicationOrgGroup{ 53 OrganizationGroup: NewOrganizationGroup(id, mspConfig), 54 } 55 aog.Proposer = NewProposer(aog) 56 return aog 57 } 58 59 // AnchorPeers returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver 60 func (aog *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer { 61 return aog.protos.AnchorPeers.AnchorPeers 62 } 63 64 func (aog *ApplicationOrgGroup) Allocate() Values { 65 return NewApplicationOrgConfig(aog) 66 } 67 68 func (aoc *ApplicationOrgConfig) Commit() { 69 aoc.applicationOrgGroup.ApplicationOrgConfig = aoc 70 aoc.OrganizationConfig.Commit() 71 } 72 73 func NewApplicationOrgConfig(aog *ApplicationOrgGroup) *ApplicationOrgConfig { 74 aoc := &ApplicationOrgConfig{ 75 protos: &ApplicationOrgProtos{}, 76 OrganizationConfig: NewOrganizationConfig(aog.OrganizationGroup), 77 78 applicationOrgGroup: aog, 79 } 80 var err error 81 aoc.standardValues, err = NewStandardValues(aoc.protos, aoc.OrganizationConfig.protos) 82 if err != nil { 83 logger.Panicf("Programming error: %s", err) 84 } 85 86 return aoc 87 } 88 89 func (aoc *ApplicationOrgConfig) Validate(tx interface{}, groups map[string]ValueProposer) error { 90 if logger.IsEnabledFor(logging.DEBUG) { 91 logger.Debugf("Anchor peers for org %s are %v", aoc.applicationOrgGroup.name, aoc.protos.AnchorPeers) 92 } 93 return aoc.OrganizationConfig.Validate(tx, groups) 94 }