github.com/baptiste-b-pegasys/quorum/v22@v22.4.2/core/mps/types.go (about) 1 package mps 2 3 import ( 4 "fmt" 5 6 "github.com/ethereum/go-ethereum/core/types" 7 ) 8 9 var ( 10 // DefaultPrivateStateMetadata is the metadata for the single private state being used 11 // when MPS is disabled 12 DefaultPrivateStateMetadata = NewPrivateStateMetadata( 13 types.DefaultPrivateStateIdentifier, 14 "private", 15 "legacy private state", 16 Resident, 17 nil, 18 ) 19 // EmptyPrivateStateMetadata is the metadata for the empty private state being used 20 // when MPS is enabled 21 EmptyPrivateStateMetadata = NewPrivateStateMetadata( 22 types.EmptyPrivateStateIdentifier, 23 "empty", 24 "empty state metadata", 25 Resident, 26 nil, 27 ) 28 ) 29 30 type PrivateStateType uint64 31 32 const ( 33 Resident PrivateStateType = iota // 0 34 Legacy PrivateStateType = 1 << PrivateStateType(iota-1) // 1 35 Pantheon PrivateStateType = 1 << PrivateStateType(iota-1) // 2 36 ) 37 38 // PrivateStateMetadata is the domain model in Quorum which maps with 39 // PrivacyGroup domain in Tessera 40 type PrivateStateMetadata struct { 41 ID types.PrivateStateIdentifier 42 Name string 43 Description string 44 Type PrivateStateType 45 // Addresses stores the public keys in the SAME ORDER being configured 46 // in Tessera 47 Addresses []string 48 // addressIndex is to facilitate fast searching 49 addressIndex map[string]struct{} 50 } 51 52 func (psm *PrivateStateMetadata) NotIncludeAny(addresses ...string) bool { 53 for _, addr := range addresses { 54 if _, found := psm.addressIndex[addr]; found { 55 return false 56 } 57 } 58 return true 59 } 60 61 func (psm *PrivateStateMetadata) FilterAddresses(addresses ...string) []string { 62 result := make([]string, 0) 63 for _, addr := range addresses { 64 if _, found := psm.addressIndex[addr]; found { 65 result = append(result, addr) 66 } 67 } 68 return result 69 } 70 71 func (psm *PrivateStateMetadata) String() string { 72 return fmt.Sprintf("ID=%s,Name=%s,Desc=%s,Type=%d,Addresses=%v", psm.ID, psm.Name, psm.Description, psm.Type, psm.Addresses) 73 } 74 75 func NewPrivateStateMetadata(id types.PrivateStateIdentifier, name, desc string, t PrivateStateType, addresses []string) *PrivateStateMetadata { 76 index := make(map[string]struct{}, len(addresses)) 77 for _, a := range addresses { 78 index[a] = struct{}{} 79 } 80 return &PrivateStateMetadata{ 81 ID: id, 82 Name: name, 83 Description: desc, 84 Type: t, 85 Addresses: addresses[:], 86 addressIndex: index, 87 } 88 }