private Protos.Common.CollectionConfigPackage Parse(JArray jsonConfig) { Protos.Common.CollectionConfigPackage ls = new Protos.Common.CollectionConfigPackage(); foreach (JToken j in jsonConfig) { JObject scf = j["StaticCollectionConfig"] as JObject; if (scf == null) { throw new ChaincodeCollectionConfigurationException($"Expected StaticCollectionConfig to be Object type but got: {j.Type.ToString()}"); } StaticCollectionConfig ssc = new StaticCollectionConfig(); ssc.Name = scf["name"].Value <string>(); ssc.BlockToLive = scf["blockToLive"].Value <ulong>(); ssc.MaximumPeerCount = scf["maximumPeerCount"].Value <int>(); CollectionPolicyConfig cpc = new CollectionPolicyConfig(); cpc.SignaturePolicy = ParseSignaturePolicyEnvelope(scf); ssc.MemberOrgsPolicy = cpc; ssc.RequiredPeerCount = scf["requiredPeerCount"].Value <int>(); Protos.Common.CollectionConfig cf = new Protos.Common.CollectionConfig(); cf.StaticCollectionConfig = ssc; ls.Config.Add(cf); } return(ls); }
public void TestLoadFromConfigFileYamlBasic() { ChaincodeCollectionConfiguration config = ChaincodeCollectionConfiguration.FromYamlFile("Fixture/collectionProperties/testCollection.yaml".Locate()); Assert.IsNotNull(config); byte[] configAsBytes = config.GetAsBytes(); Assert.IsNotNull(configAsBytes); Assert.AreEqual(configAsBytes.Length, 137); CollectionConfigPackage collectionConfigPackage = CollectionConfigPackage.Parser.ParseFrom(configAsBytes); Assert.AreEqual(collectionConfigPackage.Config.Count, 1); CollectionConfig colConfig = collectionConfigPackage.Config.FirstOrDefault(); Assert.IsNotNull(colConfig); StaticCollectionConfig staticCollectionConfig = colConfig.StaticCollectionConfig; Assert.IsNotNull(staticCollectionConfig); Assert.AreEqual(staticCollectionConfig.BlockToLive, (ulong)3); Assert.AreEqual(staticCollectionConfig.Name, "rick"); Assert.AreEqual(staticCollectionConfig.MaximumPeerCount, 9); Assert.AreEqual(staticCollectionConfig.RequiredPeerCount, 7); CollectionPolicyConfig memberOrgsPolicy = staticCollectionConfig.MemberOrgsPolicy; Assert.IsNotNull(memberOrgsPolicy); SignaturePolicyEnvelope signaturePolicy = memberOrgsPolicy.SignaturePolicy; Assert.IsNotNull(signaturePolicy); Assert.AreEqual(signaturePolicy.Version, 0); SignaturePolicy rule = signaturePolicy.Rule; Assert.IsNotNull(rule); Assert.AreEqual(rule.TypeCase, SignaturePolicy.TypeOneofCase.NOutOf); SignaturePolicy.Types.NOutOf nOutOf = rule.NOutOf; Assert.IsNotNull(nOutOf); Assert.AreEqual(2, nOutOf.N); List <MSPPrincipal> identitiesList = signaturePolicy.Identities?.ToList(); Assert.IsNotNull(identitiesList); Assert.AreEqual(3, identitiesList.Count); }
public CollectionConfig(Protos.Common.CollectionConfig cConfig) { collectionConfig = cConfig; getStaticCollectionConfig = collectionConfig.StaticCollectionConfig; }