Skip to content

Instantly share code, notes, and snippets.

@halink0803
Last active April 4, 2019 08:13
Show Gist options
  • Select an option

  • Save halink0803/497cbd165fc84b73f89fee7021104de0 to your computer and use it in GitHub Desktop.

Select an option

Save halink0803/497cbd165fc84b73f89fee7021104de0 to your computer and use it in GitHub Desktop.
	CREATE OR REPLACE FUNCTION get_erc20_transfer(text, text, integer, integer) RETURNS text AS 
$$
DECLARE
query_final text;
wallet ALIAS FOR $1;
token ALIAS FOR $2;
from_time ALIAS FOR $3;
to_time ALIAS FOR $4;
BEGIN
query_final = "SELECT data FROM wallet_erc_20txs WHERE ((data->>'timestamp')>=from_time::text AND (data->>'timestamp')<to_time::text) ";
IF (wallet <> '') THEN
	 query_final = query_final || "AND (data->>'from'=wallet OR data->>'to'=wallet) ";
END IF;
IF (token <> '') THEN
	query_final = query_final || "AND data->>'contractAddress'=$2";
END IF;
RETURN query_final;
END;
$$ LANGUAGE PLPGSQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment