Research Article

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

Algorithm 3

The chaincode about the insert algorithm of the cuckoo filter.
1: Procedure func (s SmartContract) Insert(ctx contractapi.TransactionContextInterface, id string, item string) error
2: cfJSON, err: = ctx.GetStub().GetState(id)
3: If err! = nil then
4:  Return shim.Error(err.Error())
5: End if
6: var cf CFilter
7: err = json.Unmarshal(cfJSON, &cf)
8: If err! = nil then
9:  Return shim.Error(err.Error())
10:   End if
11:   f := fprint([]byte(item), cf.FpSize, Hashfn)
12:   j: = hashfp([]byte(item))
13:   k := (j XOR hashfp(f)) % cf.Size
14:   If cf.Buckets[j].insert(f) || cf.Buckets[k].insert(f) then
15:  cf.Count++
16:   Else
17:  i: = [2]uint{j, k}[rand.Intn(2)]
18:
19:  For n := uint(0); n<cf.Kicks; n++ do
20:   f = cf.Buckets[i].swap(f)
21:   i = (i XOR hashfp(f)) % cf.Size
22:
23:   If cf.Buckets[i].insert(f) then
24:    cf.Count++
25:   End if
26:  End for
27:   End if
28:   cfJSON, err = json.Marshal(&cf)
29:    If err! = nil then
30:  Return shim.Error(err.Error())
31:   End if
32:   CF_: = CF{id: Id, cfilter: cfJSON}
33:   err = ctx.GetStub().PutState(cf_.id, cf_.cfilter)
34:   If err! = nil then
35:  Return shim.Error(err.Error())
36:   End if
37:   Return nil
38: End procedure