|
| 1 | +package canton |
| 2 | + |
| 3 | +// LedgerQueryParties builds the party list for ledger ACS reads (GetActiveContracts, etc.). |
| 4 | +// |
| 5 | +// The operator participant may ActAs one party while holding CanReadAs for others (for example |
| 6 | +// CCIP owner parties under MCMS). Contract visibility is per-party: an MCMS instance might only |
| 7 | +// be readable via ReadAs party B even when ActAs party A cannot see it. |
| 8 | +// |
| 9 | +// Order is ActAs party first, then ReadAs parties in config order. Duplicates and empty strings |
| 10 | +// are omitted. |
| 11 | +func LedgerQueryParties(participant Participant) []string { |
| 12 | + parties := make([]string, 0, 1+len(participant.ReadAsPartyIDs)) |
| 13 | + seen := make(map[string]struct{}, 1+len(participant.ReadAsPartyIDs)) |
| 14 | + add := func(party string) { |
| 15 | + if party == "" { |
| 16 | + return |
| 17 | + } |
| 18 | + if _, ok := seen[party]; ok { |
| 19 | + return |
| 20 | + } |
| 21 | + seen[party] = struct{}{} |
| 22 | + parties = append(parties, party) |
| 23 | + } |
| 24 | + add(participant.PartyID) |
| 25 | + for _, party := range participant.ReadAsPartyIDs { |
| 26 | + add(party) |
| 27 | + } |
| 28 | + |
| 29 | + return parties |
| 30 | +} |
| 31 | + |
| 32 | +// MCMSPartiesForChain returns the deduplicated party list for MCMS ledger queries across all |
| 33 | +// chain participants. |
| 34 | +func MCMSPartiesForChain(ch Chain) []string { |
| 35 | + parties := make([]string, 0) |
| 36 | + seen := make(map[string]struct{}) |
| 37 | + for _, participant := range ch.Participants { |
| 38 | + for _, party := range LedgerQueryParties(participant) { |
| 39 | + if _, ok := seen[party]; ok { |
| 40 | + continue |
| 41 | + } |
| 42 | + seen[party] = struct{}{} |
| 43 | + parties = append(parties, party) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + return parties |
| 48 | +} |
0 commit comments