Handles requests that modify ledger state
(msg *pb.ChaincodeMessage, txContext *TransactionContext)
| 1337 | |
| 1338 | // Handles requests that modify ledger state |
| 1339 | func (h *Handler) HandleInvokeChaincode(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) { |
| 1340 | chaincodeLogger.Debugf("[%s] C-call-C", shorttxid(msg.Txid)) |
| 1341 | |
| 1342 | chaincodeSpec := &pb.ChaincodeSpec{} |
| 1343 | err := proto.Unmarshal(msg.Payload, chaincodeSpec) |
| 1344 | if err != nil { |
| 1345 | return nil, errors.Wrap(err, "unmarshal failed") |
| 1346 | } |
| 1347 | |
| 1348 | // Get the chaincodeID to invoke. The chaincodeID to be called may |
| 1349 | // contain composite info like "chaincode-name:version/channel-name". |
| 1350 | // We are not using version now but default to the latest. |
| 1351 | targetInstance := ParseName(chaincodeSpec.ChaincodeId.Name) |
| 1352 | chaincodeSpec.ChaincodeId.Name = targetInstance.ChaincodeName |
| 1353 | if targetInstance.ChannelID == "" { |
| 1354 | // use caller's channel as the called chaincode is in the same channel |
| 1355 | targetInstance.ChannelID = txContext.ChannelID |
| 1356 | } |
| 1357 | chaincodeLogger.Debugf("[%s] C-call-C %s on channel %s", shorttxid(msg.Txid), targetInstance.ChaincodeName, targetInstance.ChannelID) |
| 1358 | |
| 1359 | err = h.checkACL(txContext.SignedProp, txContext.Proposal, targetInstance) |
| 1360 | if err != nil { |
| 1361 | chaincodeLogger.Errorf( |
| 1362 | "[%s] C-call-C %s on channel %s failed check ACL [%v]: [%s]", |
| 1363 | shorttxid(msg.Txid), |
| 1364 | targetInstance.ChaincodeName, |
| 1365 | targetInstance.ChannelID, |
| 1366 | txContext.SignedProp, |
| 1367 | err, |
| 1368 | ) |
| 1369 | return nil, errors.WithStack(err) |
| 1370 | } |
| 1371 | |
| 1372 | // Set up a new context for the called chaincode if on a different channel |
| 1373 | // We grab the called channel's ledger simulator to hold the new state |
| 1374 | txParams := &ccprovider.TransactionParams{ |
| 1375 | TxID: msg.Txid, |
| 1376 | ChannelID: targetInstance.ChannelID, |
| 1377 | SignedProp: txContext.SignedProp, |
| 1378 | Proposal: txContext.Proposal, |
| 1379 | TXSimulator: txContext.TXSimulator, |
| 1380 | HistoryQueryExecutor: txContext.HistoryQueryExecutor, |
| 1381 | } |
| 1382 | |
| 1383 | if targetInstance.ChannelID != txContext.ChannelID { |
| 1384 | lgr := h.LedgerGetter.GetLedger(targetInstance.ChannelID) |
| 1385 | if lgr == nil { |
| 1386 | return nil, errors.Errorf("failed to find ledger for channel: %s", targetInstance.ChannelID) |
| 1387 | } |
| 1388 | |
| 1389 | sim, err := lgr.NewTxSimulator(msg.Txid) |
| 1390 | if err != nil { |
| 1391 | return nil, errors.WithStack(err) |
| 1392 | } |
| 1393 | defer sim.Done() |
| 1394 | |
| 1395 | hqe, err := lgr.NewHistoryQueryExecutor() |
| 1396 | if err != nil { |
no test coverage detected