当前位置: 首页 > 知识库问答 >
问题:

Hyperledger fabric未能提交交易:错误:没有可用于{“链码”:[{“名称”:“fabcar”}]}的背书计划

唐经国
2023-03-14

我正在使用hyperledger结构网络,使用结构示例中的基本网络。基本网络由一个订购方和一个对等方组成。我已经在网络上安装了fab汽车连锁码并加入了该频道。请建议我如何将背书政策添加到链码中,下面是我用来启动链码的命令

 1. peer chaincode install -n fabcar -p github.com/ -v 1.1

 2. peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -c '{"Args":[]}'  -n fabcar -v 1.1 -P "OR('Org1MSP.peer','Org1MSP.admin','Org1MSP.member')"

我正在使用fabric sdk查询fabcar,它运行良好。但如果我试图调用链码,它会给我错误声明

未能提交交易:错误:{“链码”:[{“名称”:“fabcar”}]}没有可用的背书计划

配置Tx

 Organizations:

# SampleOrg defines an MSP using the sampleconfig.  It should never be used
# in production but may be used as a template for other definitions
- &OrdererOrg
    # DefaultOrg defines the organization which is used in the sampleconfig
    # of the fabric.git development environment
    Name: OrdererOrg

    # ID to load the MSP definition as
    ID: OrdererMSP

    # MSPDir is the filesystem path which contains the MSP configuration
    MSPDir: crypto-config/ordererOrganizations/example.com/msp

- &Org1
    # DefaultOrg defines the organization which is used in the sampleconfig
    # of the fabric.git development environment
    Name: Org1MSP

    # ID to load the MSP definition as
    ID: Org1MSP

    MSPDir: crypto-config/peerOrganizations/org1.example.com/msp

    AnchorPeers:
        # AnchorPeers defines the location of peers which can be used
        # for cross org gossip communication.  Note, this value is only
        # encoded in the genesis block in the Application section context
        - Host: peer0.org1.example.com
          Port: 7051

     Application: &ApplicationDefaults

    # Organizations is the list of orgs which are defined as participants on
    # the application side of the network
    Organizations:

    Orderer: &OrdererDefaults

# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo

Addresses:
    - orderer.example.com:7050

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s

# Batch Size: Controls the number of messages batched into a block
BatchSize:

    # Max Message Count: The maximum number of messages to permit in a batch
    MaxMessageCount: 10

    # Absolute Max Bytes: The absolute maximum number of bytes allowed for
    # the serialized messages in a batch.
    AbsoluteMaxBytes: 99 MB

    # Preferred Max Bytes: The preferred maximum number of bytes allowed for
    # the serialized messages in a batch. A message larger than the preferred
    # max bytes will result in a batch larger than preferred max bytes.
    PreferredMaxBytes: 512 KB

Kafka:
    # Brokers: A list of Kafka brokers to which the orderer connects
    # NOTE: Use IP:port notation
    Brokers:
        - 127.0.0.1:9092

# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network
Organizations:

Profiles:

OneOrgOrdererGenesis:
    Orderer:
        <<: *OrdererDefaults
        Organizations:
            - *OrdererOrg
    Consortiums:
        SampleConsortium:
            Organizations:
                - *Org1
OneOrgChannel:
    Consortium: SampleConsortium
    Application:
        <<: *ApplicationDefaults
        Organizations:
            - *Org1

加密配置

OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
  # ---------------------------------------------------------------------------
  # "Specs" - See PeerOrgs below for complete description
  # ---------------------------------------------------------------------------
  Specs:
  - Hostname: orderer

   PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
   Domain: org1.example.com

    Template:
    Count: 1
    Users:
    Count: 1

调用函数

异步函数调用(userwallet、usename、channelName、chaincodeName){try{

    // Create a new file system based wallet for managing 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(userwallet);
    if (!userExists) {
        console.log('An identity for the user "user1" does not exist in the wallet');
        console.log('Run the registerUser.js application before retrying');
        return;
    }

    // Create a new gateway for connecting to our peer node.
    const gateway = new Gateway();
    await gateway.connect(ccp, { wallet, identity: usename, discovery: { enabled: true, asLocalhost: true} });

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

    // Get the contract from the network.
    const contract = network.getContract(chaincodeName);

    // Submit the specified transaction.
    // createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
    // changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR10', 'Dave')
    await contract.submitTransaction('createCar','CAR12', 'Honda', 'Accord', 'Black', 'Tom');
    //await contract.submitTransaction('changeCarOwner', 'CAR10', 'Dave');
    console.log('Transaction has been submitted');


    // Disconnect from the gateway.
    await gateway.disconnect();

} catch (error) {
    console.error(`Failed to submit transaction: ${error}`);
    process.exit(1);
}
}

 module.exports.Invoke = Invoke

共有1个答案

凤伟泽
2023-03-14

这很奇怪,让我们做一些尝试和错误

尝试在下面的片段中进行更改。这将删除策略,不要担心默认策略将适用

peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -c '{"Args":[]}'  -n fabcar -v 1.1 
 类似资料:
  • composer transaction submit命令将交易提交给业务网络。 句法 composer transaction submit composer transaction submit [options] Options: --help Show help [boolean] -v, --version

  • 本文向大家介绍脱链交易和链上交易有什么区别?相关面试题,主要包含被问及脱链交易和链上交易有什么区别?时的应答技巧和注意事项,需要的朋友参考一下 回答:** 链上交易:这些交易在区块链上可用,并且对区块链网络上的所有节点都是可见的。它包括由一定数量的参与者对交易进行身份验证和确认。 链下交易:这些交易处理区块链外部的值,可以使用多种方法进行。

  • 我有一个理论问题。 假设我们有一笔交易需要两位同行的认可。但这两位同行对背书交易有不同的要求。例如,如果我们想改变数字N的值,对于1号节点,只有当值大于5时,它才会认可它,而对于2号节点,只有当值大于10时,它才会认可它(我知道这个例子没有多大意义,但是……假设是这样的)。 在链码中拆分逻辑的方法是什么?如何理解当前在哪个对等机上执行链码,以便我可以检查值是否应该大于5或大于10,以便对其进行背书

  • 问题内容: 我发生了繁重的数据库操作,这使我的数据库增加了大约10,000条记录。由于这可能需要很长时间,因此最好使用事务。 现在,我在事务内部进行了一些读取操作,并且由于直到endTransaction才提交插入操作,因此不会获取这些记录。我听说过一种叫做“事务隔离级别”的东西,它使我们也可以读取脏的(未提交的)记录。任何想法如何做到这一点? 问题答案: 我发现默认情况下,您将能够读取尚未提交的

  • 我正在使用超分类帐链码将证书签名请求转换为自签名证书。但是在存储有关证书的信息时,事务处理没有成功,并且没有给我任何分类帐上下文错误。 Nodejs版本:8.9.4 我的链码函数是: 虽然事务是我在peer docker日志中得到的: HandleTransaction->ERRO 09F[ddc81d1b]无法处理put_state。错误:没有分类帐上下文runtime.goexit/opt/g

  • 我提交了一个交易,但没有被开采。 创建和发送交易后,会收到交易hash,但是调用eth_getTransactionReceipt却总是返回空值,指示交易未被挖掘,代码如下: String transactionHash = sendTransaction(...); // you loop through the following expecting to eventually get a