如何在Hyperledger中将对等方添加到现有网络中

时间:2019-10-23 05:49:27

标签: hyperledger-fabric

我是超级账本结构的新手,并尝试了一些实践。我正在尝试使用Fabric SDK将对等方添加并加入到通道中,但是我得到““ [[Remote.js]:错误:无法在截止日期URL:grpcs:// localhost:7088”“之前连接此错误。 / p>

我使用了通道的addPeer功能,添加后我尝试使用连接通道操作将对等连接到通道。但是在运行代码后,我得到了上面提到的错误。如果有人可以建议如何使用Fabric API添加和加入对等方。

import { FileSystemWallet, Gateway } from 'fabric-network';
import * as path from 'path';
import { Peer } from 'fabric-client';
import { request } from 'https';

const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');

async function main() {
    try {

        identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        // Check to see if we've already enrolled the user.
        const userExists = await wallet.exists('user1');
        if (!userExists) {
            console.log('An identity for the user "user1" does not exist in the wallet');
            console.log('Run the registerUser.ts application before retrying');
            return;
        }


        const gateway = new Gateway();
        await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });

        // Get the network (channel) our contract is deployed to.
        const network = await gateway.getNetwork('mychannel');

        var  opts ={
            name: 'peer4.org1.example.com',
            request_timeout: '5252',
            'pem': '-----BEGIN CERTIFICATE-----\nMIICVzCCAf2gAwIBAgIQfdwd3s8+f0YvH2esgpia7TAKBggqhkjOPQQDAjB2MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxz\nY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0xOTEwMjIwNjA3MDBaFw0yOTEwMTkwNjA3\nMDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH\nEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYD\nVQQDExZ0bHNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0D\nAQcDQgAEJBq3JFLV0LdNLxOBLS/BH1jh2AMjg6awzO5fz9faB0rIBj7xZg4sCwq4\nwA5M3y5kOjVDTZaEe/t+8o4DMZmBmaNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1Ud\nJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1Ud\nDgQiBCB6UC4NGyvuVZ0Bmi7aWkju7bRm3jZvU9kNXrVgFeBa6TAKBggqhkjOPQQD\nAgNIADBFAiEArR3BiLVpA0z3K53wr+2Cjjtq0gmx2un9Nlgl352bhAoCIEh9dZCK\ny+JcrTBTWM57WZvmieVvf2uUN9UgJ2xHyK9o\n-----END CERTIFICATE-----\n',
            sslcerti: 'peer4.org1.example.com',
        }
        var peer =  new Peer('grpcs://localhost:7088', opts);

        var channel =  network.getChannel();

        channel.addPeer(peer,'Org1MSP')



        var request ={
            target:[peer],
            block :await channel.getGenesisBlock(),
            txId :gateway.getClient().newTransactionID(true)
        }

        channel.joinChannel(request, 5252)

}

1 个答案:

答案 0 :(得分:0)

在截止期限URL:grpcs:// localhost:7088 之前无法连接->定义它正在尝试使用相应的端口连接到服务器,但是失败。似乎是服务未运行或端口未正确绑定。 确保服务正常运行或启用了端口。如有任何问题,请告诉我