code: func upgradeStateV1ToV2(old *stateV1) (*stateV2, error) {
  	log.Printf("[TRACE] statefile.Read: upgrading format from v1 to v2")
  	if old == nil {
  		return nil, nil
  	}
  
  	remote, err := old.Remote.upgradeToV2()
  	if err != nil {
  		return nil, fmt.Errorf("Error upgrading State V1: %v", err)
  	}
  
  	modules := make([]*moduleStateV2, len(old.Modules))
  	for i, module := range old.Modules {
  		upgraded, err := module.upgradeToV2()
  		if err != nil {
  			return nil, fmt.Errorf("Error upgrading State V1: %v", err)
  		}
  		modules[i] = upgraded
  	}
  	if len(modules) == 0 {
  		modules = nil
  	}
  
  	newState := &stateV2{
  		Version: 2,
  		Serial:  old.Serial,
  		Remote:  remote,
  		Modules: modules,
  	}
  
  	return newState, nil
  }
docs: // upgradeStateV1ToV2 is used to upgrade a V1 state representation
  // into a V2 state representation