Research Article

A Multi-Blockchain-Based Cross-Domain Authentication and Authorization Scheme for Energy Internet

Algorithm 1

The key chaincode about crossing chain.
1: Procedure (s SmartContract) GetCrossMessage(ctx contractapi.TransactionContextInterface, channel, chaincode, user1, user2 string) (string, error)
2: params := []string{"GetMessage", user1, user2}
3: invokeArgs: = make([][]byte, len(params))
4: For i, arg: = range params {invokeArgs[i] = []byte(arg)}
5: response := ctx.GetStub().InvokeChaincode(chaincode, invokeArgs, channel)
6: If response.Status! = shim.OK then
7:  Return shim.Error(err.Error())
8: End if
9: users := user1 + ":" + user2
10:   messages := Messages{Users: users, Message: string(response.Payload)}
11:   msgJSON, err: = json.Marshal(messages)
12:   If err! = nil then
13:  Return shim.Error(err.Error())
14:   End if
15:   Err = ctx.GetStub().PutState(users, msgJSON)
16:   If err! = nil then
17:  Return shim.Error(err.Error())
18:   End if
19:   Return string(response.Payload), nil
20: End procedure