From what I read, it’s possible to selectively block specific numbers (i.e. a block list), but no mention of an allow list.
It looks like you can block anonymous/hidden numbers, which are most likely to be spam:
Regarding other numbers, since there is talk of incoming calls being recorded to a log, it might be possible for a program to watch that log for a new incoming call, check it against your contact list, and if not recognised then add it to the block list. (Not sure if this would block the current incoming call, or just future calls from that number.)
Someone could probably use the source code of the following program as a basis for what you want:
(It blocks all numbers from some public list.)