Hyperledger fabric 调用合同形成HYPERLEDGER结构中链码中的另一个合同

Hyperledger fabric 调用合同形成HYPERLEDGER结构中链码中的另一个合同,hyperledger-fabric,hyperledger,smartcontracts,Hyperledger Fabric,Hyperledger,Smartcontracts,我试图在一个通道内调用contract,形成另一个contract,并部署在一个链码(“cc”)上。HLF 1.4的版本 class Contract1 extends Contract { constructor() { super('Contract1'); } async testContract2(ctx) { const res = await ctx.stub.invokeChaincode('cc', ['test']); return JS

我试图在一个通道内调用contract,形成另一个contract,并部署在一个链码(“cc”)上。HLF 1.4的版本

class Contract1  extends Contract {
  constructor() {
    super('Contract1');
  }

  async testContract2(ctx) {
    const res = await ctx.stub.invokeChaincode('cc', ['test']);
    return JSON.stringify(res);
  }
}

class Contract2  extends Contract {
  constructor() {
    super('Contract2');
  }

  async test(ctx) {
    // some logic
  }
}
和获取错误:

[Query]: evaluate: Query ID "[object Object]" of peer "peer0.org1.example.com:7051" failed:
 message=transaction returned with failure: Error: INVOKE_CHAINCODE failed: 
transaction ID: 82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7: 
execute failed: error sending: txid: 82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7(some-channel) exists,
 stack=Error: transaction returned with failure: Error: INVOKE_CHAINCODE failed: transaction ID:
 82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7: 
execute failed: error sending: txid: 82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7(some-channel) exists


(/hyperledger-fabric/javascript/node_modules/grpc/src/client_interceptors.js:845:24),status=500,
url=grpcs://localhost:7051, name=peer0.org1.example.com:7051,
grpc.max_receive_message_length=-1, grpc.max_send_message_length=-1, 
grpc.keepalive_time_ms=120000, grpc.http2.min_time_between_pings_ms=120000, 
grpc.keepalive_timeout_ms=20000, grpc.http2.max_pings_without_data=0, 
grpc.keepalive_permit_without_calls=1, name=peer0.org1.example.com:7051, 
grpc.ssl_target_name_override=peer0.org1.example.com, 
grpc.default_authority=peer0.org1.example.com, isProposalResponse=true

Failed to evaluate transaction: Error: transaction returned with failure: Error: 
INVOKE_CHAINCODE failed: transaction ID: 
82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7: execute failed: error sending: 
txid: 82c10988ad2c7cef468cae937d2e0d0bfe649f7f9c5406498733d7ef20d387f7(some-channel) exists
其他一切都按预期工作(从客户端调用方法、保存状态等)。我做错了什么?是否不可能在同一链码中从一个合同中调用另一个合同中的方法??

TL;博士

class Contract1  extends Contract {
  constructor() {
    super('Contract1');
  }

  async testContract2(ctx) {
    let contract2 = new Contract2();
    const res = await contract2.test(ctx)
    .....
  }
}

class Contract2  extends Contract {
  constructor() {
    super('Contract2');
  }

  async test(ctx) {
    // some logic
  }
}
ctx.stub.invokeChaincode
设计用于实际调用另一个链码。部分混淆在于
合同
链码
并不完全相同

在您的例子中,您已经在一个链码中实现了两个
合同。
合同
是更高级别的抽象,一个或多个
合同
可以打包在同一个
链码


因此,您实际上希望
合同
在同一链码内调用
合同
,而不是跨越两个不同的链码。

谢谢。我认为这种方法行不通,因为合同需要某种特定的初始化)