|
|
@ -3,6 +3,8 @@ defmodule Explorer.Chain.Transaction do |
|
|
|
|
|
|
|
|
|
|
|
use Explorer.Schema |
|
|
|
use Explorer.Schema |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2, join: 5, preload: 3] |
|
|
|
|
|
|
|
|
|
|
|
alias Ecto.Changeset |
|
|
|
alias Ecto.Changeset |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain.{ |
|
|
|
alias Explorer.Chain.{ |
|
|
@ -334,78 +336,90 @@ defmodule Explorer.Chain.Transaction do |
|
|
|
to token_contract_address_hash, to_address_hash or from_address_hash from Token Transfers's table. |
|
|
|
to token_contract_address_hash, to_address_hash or from_address_hash from Token Transfers's table. |
|
|
|
""" |
|
|
|
""" |
|
|
|
def where_address_fields_match(query, address_hash, :to) do |
|
|
|
def where_address_fields_match(query, address_hash, :to) do |
|
|
|
query |
|
|
|
join( |
|
|
|
|> where( |
|
|
|
query, |
|
|
|
[t], |
|
|
|
:inner, |
|
|
|
t.hash in fragment( |
|
|
|
[transaction], |
|
|
|
|
|
|
|
matches in fragment( |
|
|
|
""" |
|
|
|
""" |
|
|
|
( |
|
|
|
WITH hashes AS ( |
|
|
|
SELECT t0.hash AS hash |
|
|
|
( |
|
|
|
FROM transactions AS t0 |
|
|
|
SELECT t0.hash AS hash |
|
|
|
WHERE t0.to_address_hash = ? OR t0.created_contract_address_hash = ? |
|
|
|
FROM transactions AS t0 |
|
|
|
) |
|
|
|
WHERE t0.to_address_hash = ? OR t0.created_contract_address_hash = ? |
|
|
|
UNION |
|
|
|
) |
|
|
|
( |
|
|
|
UNION ALL |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
( |
|
|
|
FROM token_transfers AS tt |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
WHERE tt.to_address_hash = ? |
|
|
|
FROM token_transfers AS tt |
|
|
|
) |
|
|
|
WHERE tt.to_address_hash = ? |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) SELECT * from hashes |
|
|
|
""", |
|
|
|
""", |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes |
|
|
|
^address_hash.bytes |
|
|
|
) |
|
|
|
), |
|
|
|
|
|
|
|
transaction.hash == matches.hash |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def where_address_fields_match(query, address_hash, :from) do |
|
|
|
def where_address_fields_match(query, address_hash, :from) do |
|
|
|
query |
|
|
|
join( |
|
|
|
|> where( |
|
|
|
query, |
|
|
|
[t], |
|
|
|
:inner, |
|
|
|
t.hash in fragment( |
|
|
|
[transaction], |
|
|
|
|
|
|
|
matches in fragment( |
|
|
|
""" |
|
|
|
""" |
|
|
|
( |
|
|
|
WITH hashes AS ( |
|
|
|
SELECT t0.hash AS hash |
|
|
|
( |
|
|
|
FROM transactions AS t0 |
|
|
|
SELECT t0.hash AS hash |
|
|
|
WHERE t0.from_address_hash = ? |
|
|
|
FROM transactions AS t0 |
|
|
|
) |
|
|
|
WHERE t0.from_address_hash = ? |
|
|
|
UNION |
|
|
|
) |
|
|
|
( |
|
|
|
UNION ALL |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
( |
|
|
|
FROM token_transfers AS tt |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
WHERE tt.from_address_hash = ? |
|
|
|
FROM token_transfers AS tt |
|
|
|
) |
|
|
|
WHERE tt.from_address_hash = ? |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) SELECT * from hashes |
|
|
|
""", |
|
|
|
""", |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes |
|
|
|
^address_hash.bytes |
|
|
|
) |
|
|
|
), |
|
|
|
|
|
|
|
transaction.hash == matches.hash |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def where_address_fields_match(query, address_hash, nil) do |
|
|
|
def where_address_fields_match(query, address_hash, nil) do |
|
|
|
query |
|
|
|
join( |
|
|
|
|> where( |
|
|
|
query, |
|
|
|
[t], |
|
|
|
:inner, |
|
|
|
t.hash in fragment( |
|
|
|
[transaction], |
|
|
|
|
|
|
|
matches in fragment( |
|
|
|
""" |
|
|
|
""" |
|
|
|
( |
|
|
|
WITH hashes AS ( |
|
|
|
SELECT t0.hash AS hash |
|
|
|
( |
|
|
|
FROM transactions AS t0 |
|
|
|
SELECT t0.hash AS hash |
|
|
|
WHERE t0.to_address_hash = ? OR t0.from_address_hash = ? OR t0.created_contract_address_hash = ? |
|
|
|
FROM transactions AS t0 |
|
|
|
) |
|
|
|
WHERE t0.to_address_hash = ? OR t0.from_address_hash = ? OR t0.created_contract_address_hash = ? |
|
|
|
UNION |
|
|
|
) |
|
|
|
( |
|
|
|
UNION ALL |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
( |
|
|
|
FROM token_transfers AS tt |
|
|
|
SELECT tt.transaction_hash AS hash |
|
|
|
WHERE tt.to_address_hash = ? OR tt.from_address_hash = ? |
|
|
|
FROM token_transfers AS tt |
|
|
|
) |
|
|
|
WHERE tt.to_address_hash = ? OR tt.from_address_hash = ? |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) SELECT * from hashes |
|
|
|
""", |
|
|
|
""", |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes, |
|
|
|
^address_hash.bytes |
|
|
|
^address_hash.bytes |
|
|
|
) |
|
|
|
), |
|
|
|
|
|
|
|
transaction.hash == matches.hash |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|