// manageDeletion removes applications tied to the target account, if they
// don't fulfil the specs of the Algorand buffer (e.g. wrong schema). If
// the account has several valid applications, then the one with the smallest
// CreatedAtRound-parameter will be kept. All others will be deleted.
manageDeletion removes applications tied to the target account, if they
don't fulfil the specs of the Algorand buffer . If
the account has several valid applications, then the one with the smallest
CreatedAtRound-parameter will be kept. All others will be deleted.
// manageDeletion removes applications tied to the target account if they // don ' t fulfil the specs of the Algorand buffer ( e . g . wrong schema ) . If // the account has several valid applications then the one with the smallest // CreatedAtRound - parameter will be kept . All others will be deleted .
func (ab *AlgorandBuffer) manageDeletion() error {
	info, err := ab.Client.AccountInformation(ab.AccountCrypt.Address.String(), context.Background())
	if err != nil {
		return err
	}
	if len(info.CreatedApps) == 0 {
		return nil
	}
	validApp := -1
	earliestValidApp := uint64(math.MaxUint64)
	for i, val := range info.CreatedApps {
		if client.FulfillsSchema(val) && val.CreatedAtRound < earliestValidApp {
			validApp = i
			earliestValidApp = val.CreatedAtRound
		}
	}
	if !client.ValidAccount(info) {
		for i := len(info.CreatedApps) - 1; i >= 0; i-- {
			if i == validApp {
				continue
			}
			err := ab.Client.DeleteApplication(ab.AccountCrypt, info.CreatedApps[i].Id)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
func ( ab * AlgorandBuffer ) manageDeletion ( ) error { info , err := ab . Client . AccountInformation ( ab . AccountCrypt . Address . String ( ) , context . Background ( ) ) if err != nil { return err } if len ( info . CreatedApps ) == 0 { return nil } validApp := - 1 earliestValidApp := uint64 ( math . MaxUint64 ) for i , val := range info . CreatedApps { if client . FulfillsSchema ( val ) && val . CreatedAtRound < earliestValidApp { validApp = i earliestValidApp = val . CreatedAtRound } } if ! client . ValidAccount ( info ) { for i := len ( info . CreatedApps ) - 1 ; i >= 0 ; i -- { if i == validApp { continue } err := ab . Client . DeleteApplication ( ab . AccountCrypt , info . CreatedApps [ i ] . Id ) if err != nil { return err } } } return nil }
manageDeletion removes applications tied to the target account, if they
don't fulfil the specs of the Algorand buffer .
manageDeletion removes applications tied to the target account if they don ' t fulfil the specs of the Algorand buffer .
// If no apps exist, no deletion necessary // Find out if there exists an app that's already "valid" (i.e. right schema) // Delete apps if there's at least one incorrect app