// ============================================================
// createAuthScene - create a new auth scene, store into chaincode state
// ============================================================
create a new auth scene, store into chaincode state
// ============================================================ // createAuthScene - create a new auth scene store into chaincode state // ============================================================
func (t *AuthChaincode) createAuthScene(stub shim.ChaincodeStubInterface, args []string) pb.Response {
	var err error
	if len(args) != 18 {
		return shim.Error("Incorrect number of arguments. Expecting 18")
	}
	fmt.Println("- start create auth scene")
	if len(args[0]) <= 0 {
		return shim.Error("1st argument must be a non-empty string")
	}
	if len(args[1]) <= 0 {
		return shim.Error("2nd argument must be a non-empty string")
	}
	if len(args[2]) <= 0 {
		return shim.Error("3rd argument must be a non-empty string")
	}
	if len(args[3]) <= 0 {
		return shim.Error("4th argument must be a non-empty string")
	}
	if len(args[4]) <= 0 {
                return shim.Error("4th argument must be a non-empty string")
        }
	if len(args[5]) <= 0 {
                return shim.Error("4th argument must be a non-empty string")
        }
	authId := args[0]
	authName := args[1]
	grantorType := args[2]
	grantorId := args[3]
	grantorName := args[4]
	grantorIdCard := args[5]
	cnname := args[6]
	socialCreditCode := args[7]
	granteeId := args[8]
	granteeName := args[9]
	sceneId := args[10]
	sceneName := args[11]
 	period := args[12]
	protocolFile := args[13]
	authDate := args[14]
	authBeginTime := args[15]
	authEndTime := args[16]
	authStatus := args[17]
	authSceneAsBytes, err := stub.GetState(authId)
	if err != nil {
		return shim.Error("Failed to get auth scene: " + err.Error())
	} else if authSceneAsBytes != nil {
		fmt.Println("This auth scene already exists: " + authId)
		return shim.Error("This auth scene already exists: " + authId)
	}
	authScene := &AuthScene{authId, authName, grantorType, grantorId, grantorName, grantorIdCard, cnname, socialCreditCode, granteeId, granteeName, sceneId, sceneName, period, protocolFile, authDate, authBeginTime, authEndTime, authStatus}
	authSceneJSONasBytes, err := json.Marshal(authScene)
	if err != nil {
		return shim.Error(err.Error())
	}
	err = stub.PutState(authId, authSceneJSONasBytes)
	if err != nil {
		return shim.Error(err.Error())
	}
	indexName := "grantorId~granteeId~sceneId"
	indexKey, err := stub.CreateCompositeKey(indexName, []string{authScene.GrantorId, authScene.GranteeId, authScene.SceneId})
	if err != nil {
		return shim.Error(err.Error())
	}
	value := []byte{0x00}
	stub.PutState(indexKey, value)
	fmt.Println("- end create auth scene")
	return shim.Success(nil)
}
func ( t * AuthChaincode ) createAuthScene ( stub shim . ChaincodeStubInterface , args [ ] string ) pb . Response { var err error if len ( args ) != 18 { return shim . Error ( " " ) } fmt . Println ( " " ) if len ( args [ 0 ] ) <= 0 { return shim . Error ( " " ) } if len ( args [ 1 ] ) <= 0 { return shim . Error ( " " ) } if len ( args [ 2 ] ) <= 0 { return shim . Error ( " " ) } if len ( args [ 3 ] ) <= 0 { return shim . Error ( " " ) } if len ( args [ 4 ] ) <= 0 { return shim . Error ( " " ) } if len ( args [ 5 ] ) <= 0 { return shim . Error ( " " ) } authId := args [ 0 ] authName := args [ 1 ] grantorType := args [ 2 ] grantorId := args [ 3 ] grantorName := args [ 4 ] grantorIdCard := args [ 5 ] cnname := args [ 6 ] socialCreditCode := args [ 7 ] granteeId := args [ 8 ] granteeName := args [ 9 ] sceneId := args [ 10 ] sceneName := args [ 11 ] period := args [ 12 ] protocolFile := args [ 13 ] authDate := args [ 14 ] authBeginTime := args [ 15 ] authEndTime := args [ 16 ] authStatus := args [ 17 ] authSceneAsBytes , err := stub . GetState ( authId ) if err != nil { return shim . Error ( " " + err . Error ( ) ) } else if authSceneAsBytes != nil { fmt . Println ( " " + authId ) return shim . Error ( " " + authId ) } authScene := & AuthScene { authId , authName , grantorType , grantorId , grantorName , grantorIdCard , cnname , socialCreditCode , granteeId , granteeName , sceneId , sceneName , period , protocolFile , authDate , authBeginTime , authEndTime , authStatus } authSceneJSONasBytes , err := json . Marshal ( authScene ) if err != nil { return shim . Error ( err . Error ( ) ) } err = stub . PutState ( authId , authSceneJSONasBytes ) if err != nil { return shim . Error ( err . Error ( ) ) } indexName := " " indexKey , err := stub . CreateCompositeKey ( indexName , [ ] string { authScene . GrantorId , authScene . GranteeId , authScene . SceneId } ) if err != nil { return shim . Error ( err . Error ( ) ) } value := [ ] byte { 0x00 } stub . PutState ( indexKey , value ) fmt . Println ( " " ) return shim . Success ( nil ) }
create a new auth scene, store into chaincode state
create a new auth scene store into chaincode state
// ==== Input sanitation ==== // ==== Check if auth scene already exists ==== // ==== Create auth scene object and marshal to JSON ==== // === Save auth scene to state === //  ==== Index the marble to enable color-based range queries, e.g. return all blue marbles ==== //  An 'index' is a normal key/value entry in state. //  The key is a composite key, with the elements that you want to range query on listed first. //  In our case, the composite key is based on indexName~color~name. //  This will enable very efficient state range queries based on composite keys matching indexName~color~* //  Save index entry to state. Only the key name is needed, no need to store a duplicate copy of the marble. //  Note - passing a 'nil' value will effectively delete the key from state, therefore we pass null character as value // ==== Auth info saved and indexed. Return success ====