Skip to content

Commit 41f8496

Browse files
committed
web3.eth.alchemy.api.detect allows for optional checks (for unwarranted airdrop and/or spam contract)
1 parent 2045d44 commit 41f8496

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

Diff for: web3.eth.alchemy.api.pas

+27-7
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ procedure simulate(
5050
Airdrop, // probably an unwarranted airdrop. most of the owners are honeypots, or a significant chunk of the usual honeypot addresses own this token.
5151
Spam // probably spam. this contract contains a lot of duplicate NFTs, or the contract lies about its own token supply. running totalSupply() on the contract is vastly different from the empirical number of tokens in circulation.
5252
);
53+
TContractTypes = set of TContractType;
5354

5455
// spam detection
5556
procedure detect(
5657
const apiKey : string;
5758
const chain : TChain;
5859
const contract: TAddress;
60+
const checkFor: TContractTypes;
5961
const callback: TProc<TContractType, IError>);
6062

6163
// simulate transaction, return incoming assets that are honeypots (eg. you cannot sell)
@@ -407,19 +409,37 @@ procedure detect(
407409
const apiKey : string;
408410
const chain : TChain;
409411
const contract: TAddress;
412+
const checkFor: TContractTypes;
410413
const callback: TProc<TContractType, IError>);
411414
begin
412-
isAirdrop(apiKey, chain, contract, procedure(response: Boolean; err: IError)
415+
( // step #1: check for unwarranted airdrop or skip this check
416+
procedure(callback: TProc<Boolean, IError>)
413417
begin
414-
if response then
415-
callback(Airdrop, nil)
418+
if TContractType.Airdrop in checkFor then
419+
isAirdrop(apiKey, chain, contract, callback)
416420
else
417-
isSpam(apiKey, chain, contract, procedure(response: TJsonValue; err: IError)
421+
callback(False, nil);
422+
end)(procedure(response1: Boolean; err1: IError)
423+
begin
424+
if response1 and not Assigned(err1) then
425+
callback(TContractType.Airdrop, nil)
426+
else
427+
( // step #2: check for spam contract or skip this check
428+
procedure(callback: TProc<Boolean, IError>)
429+
begin
430+
if not(TContractType.Spam in checkFor) then
431+
callback(False, nil)
432+
else
433+
isSpam(apiKey, chain, contract, procedure(response: TJsonValue; err: IError)
434+
begin
435+
callback(Assigned(response) and (response is TJsonTrue), err);
436+
end);
437+
end)(procedure(response2: Boolean; err2: IError)
418438
begin
419-
if Assigned(response) and (response is TJsonTrue) then
420-
callback(Spam, nil)
439+
if response2 and not Assigned(err2) then
440+
callback(TContractType.Spam, nil)
421441
else
422-
callback(Good, err);
442+
callback(TContractType.Good, err2);
423443
end);
424444
end);
425445
end;

0 commit comments

Comments
 (0)