|
| 1 | +package mspmgmt |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hyperledger/fabric/core/util" |
| 5 | + "github.com/hyperledger/fabric/msp" |
| 6 | + "github.com/hyperledger/fabric/protos/common" |
| 7 | +) |
| 8 | + |
| 9 | +func LoadLocalMsp(dir string) error { |
| 10 | + conf, err := msp.GetLocalMspConfig(dir) |
| 11 | + if err != nil { |
| 12 | + return err |
| 13 | + } |
| 14 | + |
| 15 | + return GetLocalMSP().Setup(conf) |
| 16 | +} |
| 17 | + |
| 18 | +// FIXME: this is required for now because we need a local MSP |
| 19 | +// and also the MSP mgr for the test chain; as soon as the code |
| 20 | +// to setup chains is ready, the chain should be setup using |
| 21 | +// the method below and this method should disappear |
| 22 | +func LoadFakeSetupWithLocalMspAndTestChainMsp(dir string) error { |
| 23 | + conf, err := msp.GetLocalMspConfig(dir) |
| 24 | + if err != nil { |
| 25 | + return err |
| 26 | + } |
| 27 | + |
| 28 | + err = GetLocalMSP().Setup(conf) |
| 29 | + if err != nil { |
| 30 | + return err |
| 31 | + } |
| 32 | + |
| 33 | + fakeConfig = &msp.MSPManagerConfig{MspList: []*msp.MSPConfig{conf}, Name: "MGRFORTESTCHAIN"} |
| 34 | + |
| 35 | + err = GetManagerForChain(util.GetTestChainID()).Setup(fakeConfig) |
| 36 | + if err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + |
| 40 | + return nil |
| 41 | +} |
| 42 | + |
| 43 | +// FIXME! Every chain needs an MSP config but for now, |
| 44 | +// we don't have support for that; we get around it |
| 45 | +// temporarily by storing the config the peer loaded |
| 46 | +// and using it every time we're asked to get an MSP |
| 47 | +// manager via LoadMSPManagerFromBlock |
| 48 | +var fakeConfig *msp.MSPManagerConfig |
| 49 | + |
| 50 | +func GetMSPManagerFromBlock(b *common.Block) (msp.MSPManager, error) { |
| 51 | + // FIXME! We need to extract the config item |
| 52 | + // that relates to MSP from the contig tx |
| 53 | + // inside this block, unmarshal it to extract |
| 54 | + // an *MSPManagerConfig that we can then pass |
| 55 | + // to the Setup method; for now we wing it by |
| 56 | + // passing the same config we got for the |
| 57 | + // local manager; this way chain creation tests |
| 58 | + // can proceed without being block by this |
| 59 | + |
| 60 | + // this hack is required to give us some configuration |
| 61 | + // so that we can return a valid MSP manager when |
| 62 | + // someone calls this function; it should work, provided |
| 63 | + // that this call occurs after the peer has started |
| 64 | + // and called LoadFakeSetupWithLocalMspAndTestChainMsp. |
| 65 | + // Notice that this happens very early in the peer |
| 66 | + // startup and so the assumption should be safe |
| 67 | + if fakeConfig == nil { |
| 68 | + panic("fakeConfig is nil") |
| 69 | + } |
| 70 | + |
| 71 | + mgr := msp.NewMSPManager() |
| 72 | + err := mgr.Setup(fakeConfig) |
| 73 | + if err != nil { |
| 74 | + return nil, err |
| 75 | + } else { |
| 76 | + return mgr, nil |
| 77 | + } |
| 78 | +} |
0 commit comments