HLF 2.2 不再支持 client.setUserContext
如果您正在使用 HLF 2.2 并且需要列出从属关系,则可以使用以下代码段
const { Wallets } = require('fabric-network');
const FabricCAServices = require('fabric-ca-client');
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8'));
// Create a new CA client for interacting with the CA.
const caInfo = connectionProfile.certificateAuthorities['ca.org2.example.com'];
const caTLSCACerts = caInfo.tlsCACerts.pem;
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
const provider = wallet.getProviderRegistry().getProvider(adminIdentity.type);
const adminUser = await provider.getUserContext(adminIdentity, 'admin');
let affiliationService = ca.newAffiliationService();
let registeredAffiliations = await affiliationService.getAll(adminUser);
console.dir(registeredAffiliations, { depth: null })
有关其他方法的文档,请访问AffiliationService 类文档