github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/core/state/statedb_candidate.go (about) 1 package state 2 3 // ----- candidate Set 4 5 // MarkAddressCandidate adds the specified object to the dirty map 6 //func (self *StateDB) MarkAddressCandidate(addr common.Address) { 7 // if _, exist := self.GetCandidateSet()[addr]; !exist { 8 // self.candidateSet[addr] = struct{}{} 9 // self.candidateSetDirty = true 10 // } 11 //} 12 // 13 //func (self *StateDB) ClearCandidateSetByAddress(addr common.Address) { 14 // fmt.Printf("candidate set bug, clear candidate set by address, %v\n", self.candidateSet) 15 // delete(self.candidateSet, addr) 16 // self.candidateSetDirty = true 17 //} 18 // 19 //func (self *StateDB) GetCandidateSet() CandidateSet { 20 // //fmt.Printf("candidate set bug, get candidate set 1, %v\n", self.candidateSet) 21 // if len(self.candidateSet) != 0 { 22 // return self.candidateSet 23 // } 24 // // Try to get from Trie 25 // enc, err := self.trie.TryGet(candidateSetKey) 26 // if err != nil { 27 // self.setError(err) 28 // return nil 29 // } 30 // var value CandidateSet 31 // if len(enc) > 0 { 32 // err := rlp.DecodeBytes(enc, &value) 33 // if err != nil { 34 // self.setError(err) 35 // } 36 // self.candidateSet = value 37 // } 38 // //fmt.Printf("candidate set bug, get candidate set 2, %v\n", value) 39 // return value 40 //} 41 // 42 //func (self *StateDB) commitCandidateSet() { 43 // //fmt.Printf("candidate set bug, commit candidate set, %v\n", self.candidateSet) 44 // data, err := rlp.EncodeToBytes(self.candidateSet) 45 // if err != nil { 46 // panic(fmt.Errorf("can't encode candidate set : %v", err)) 47 // } 48 // self.setError(self.trie.TryUpdate(candidateSetKey, data)) 49 //} 50 // 51 //// Store the Candidate Address Set 52 // 53 //var candidateSetKey = []byte("CandidateSet") 54 // 55 //type CandidateSet map[common.Address]struct{} 56 // 57 //func (set CandidateSet) EncodeRLP(w io.Writer) error { 58 // var list []common.Address 59 // for addr := range set { 60 // list = append(list, addr) 61 // } 62 // sort.Slice(list, func(i, j int) bool { 63 // return bytes.Compare(list[i].Bytes(), list[j].Bytes()) == 1 64 // }) 65 // return rlp.Encode(w, list) 66 //} 67 // 68 //func (set *CandidateSet) DecodeRLP(s *rlp.Stream) error { 69 // var list []common.Address 70 // if err := s.Decode(&list); err != nil { 71 // return err 72 // } 73 // candidateSet := make(CandidateSet, len(list)) 74 // for _, addr := range list { 75 // candidateSet[addr] = struct{}{} 76 // } 77 // *set = candidateSet 78 // return nil 79 //}