如何在 peer cli 中调用不同合约的方法

How inkoke a different contract's method in peer cli

在 Hyperledger Fabric 中,我在同一个链代码(两个控制器)中加载了两个合约。在对等 CLI 上,我设法调用了我在代码中加载的第一个合同方法。

"Calling chaincode Invoke() returned error response [Error: You've asked to invoke a function that does not exist: createPost]. Sending ERROR message back to peer"

我的index.ts(打字稿): 导出常量合同:any[] = [stController, PostController];

2019-03-25T21:11:23.217Z INFO [contracts-spi/chaincodefromcontract.js] Metadata is : 
 { contracts: 
   { stController: 
      { name: 'stController',
        contractInstance: { name: 'stController', default: true },
        transactions: 
         [ { name: 'initLedger' },
           { name: 'queryStDoc' },
           { name: 'createStDoc' },
           { name: 'queryAllStDocs' },
           { name: 'queryStByOwner' },
           { name: 'changeStOwner' },
           { name: 'cancel' } ],
        info: { title: '', version: '' } },
     PostController: 
      { name: 'PostController',
        contractInstance: { name: 'PostController' },
        transactions: [ { name: 'createPost' }, { name: 'deletePost' } ],
        info: { title: '', version: '' } },
     'org.hyperledger.fabric': 
      { name: 'org.hyperledger.fabric',
        contractInstance: { name: 'org.hyperledger.fabric' },
        transactions: [ { name: 'GetMetadata' } ],
        info: { title: '', version: '' } } },
  info: { version: '1.0.0', title: 'sget' },
  components: { schemas: {} } } 

我没有在 Typescript 中这样做,但我在 JavaScript 中做了同样的事情 - 我在两个合同中都使用了一个超类型来获得一个命名空间来区分合同。 (在我的示例中,我有重复的函数名称 - Fabcar 的 2 个副本。)

    constructor() {
    super('org.example.car');
    }


    constructor() {
    super('org.example.rob');
    }

然后我从 cli 调用函数如下:

peer chaincode invoke -o orderer.example.com:7050 -C mychannel -c '{"Args":["org.example.car:queryCar","CAR2"]}' -n fcnstest

peer chaincode invoke -o orderer.example.com:7050 -C mychannel -c '{"Args":["org.example.rob:changeCarOwner","CAR2","Rob"]}' -n fcnstest

Commercial Paper tutorial 有一个使用 namespace/supertype 的例子。但它也是 Javascript 而不是打字稿。