MCPcopy
hub / github.com/canopy-network/canopy / addPaymentPercent

Method addPaymentPercent

controller/result.go:162–183  ·  view source on GitHub ↗

addPaymentPercent() is a helper function to add a payment percent to the certificate result

(toAdd *lib.LotteryWinner, results *lib.CertificateResult, chainId uint64)

Source from the content-addressed store, hash-verified

160
161// addPaymentPercent() is a helper function to add a payment percent to the certificate result
162func (c *Controller) addPaymentPercent(toAdd *lib.LotteryWinner, results *lib.CertificateResult, chainId uint64) {
163 // don't add 0% cuts
164 if toAdd.Cut == 0 {
165 return
166 }
167 // check if the winner's address is already in the reward recipients list for the root chain
168 // if found, update their reward percentage - else add them as a new recipient
169 if !slices.ContainsFunc(results.RewardRecipients.PaymentPercents, func(pp *lib.PaymentPercents) (has bool) {
170 // if the address and chain id matches
171 if bytes.Equal(pp.Address, toAdd.Winner) && pp.ChainId == chainId {
172 // mark as found
173 has = true
174 // increase their reward percentage by 'cut'
175 pp.Percent += toAdd.Cut
176 }
177 return
178 }) {
179 // if the winner is not found in the list, add them as a new recipient
180 results.RewardRecipients.PaymentPercents = append(results.RewardRecipients.PaymentPercents,
181 &lib.PaymentPercents{Address: toAdd.Winner, Percent: toAdd.Cut, ChainId: chainId})
182 }
183}
184
185// HandleSwaps() handles the 'buy' side of the sell orders
186func (c *Controller) HandleSwaps(fsm *fsm.StateMachine, blockResult *lib.BlockResult, results *lib.CertificateResult, rootChainHeight uint64) {

Callers 1

AddPaymentPercentMethod · 0.95

Calls 1

EqualMethod · 0.80

Tested by

no test coverage detected