Skip to content

Instantly share code, notes, and snippets.

@rhlsthrm
Last active June 1, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhlsthrm/264c487670f4752ffa3875c4b62ed902 to your computer and use it in GitHub Desktop.
Save rhlsthrm/264c487670f4752ffa3875c4b62ed902 to your computer and use it in GitHub Desktop.
-- GET NODE FREE BALANCE ACROSS ALL CHANNELS FOR TOKEN
SELECT ("latestState" #> '{balances}' -> (
SELECT array_position(
array(
SELECT jsonb_array_elements_text("latestState" #> '{tokenAddresses}')),
'0xEcFcaB0A285d3380E488A39B4BB21e777f8A4EaC' -- TOKEN ADDRESS
)::integer - 1
) #> '{0,amount,_hex}')
FROM channel INNER JOIN app_instance
ON app_instance."channelMultisigAddress" = channel."multisigAddress"
WHERE app_instance.type = 'FREE_BALANCE';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment