MCPcopy Index your code
hub / github.com/hyperledger/fabric / HandleInvokeChaincode

Method HandleInvokeChaincode

core/chaincode/handler.go:1339–1421  ·  view source on GitHub ↗

Handles requests that modify ledger state

(msg *pb.ChaincodeMessage, txContext *TransactionContext)

Source from the content-addressed store, hash-verified

1337
1338// Handles requests that modify ledger state
1339func (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 {

Callers 1

handler_test.goFile · 0.80

Calls 14

checkACLMethod · 0.95
DoneMethod · 0.95
ParseNameFunction · 0.85
DebugfMethod · 0.80
WrapMethod · 0.80
shorttxidFunction · 0.70
UnmarshalMethod · 0.65
ErrorfMethod · 0.65
GetLedgerMethod · 0.65
NewTxSimulatorMethod · 0.65
InvokeMethod · 0.65

Tested by

no test coverage detected