-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: check balance with polling
- Loading branch information
1 parent
30525bb
commit 1c6e448
Showing
3 changed files
with
92 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: 'Check Token Balance With Polling' | ||
|
||
inputs: | ||
url: | ||
description: 'API endpoint for fetching a balance for a wallet' | ||
required: true | ||
address: | ||
description: 'Wallet address to check the balance' | ||
required: true | ||
denom: | ||
description: 'Denom whose amount has to be extracted from the JSON response' | ||
required: true | ||
file: | ||
description: 'Name of the file to place extracted amount of denom' | ||
required: true | ||
comparison_type: | ||
description: 'Type of comparison to perform ("greater" or "lesser")' | ||
required: true | ||
default: 'greater' | ||
polling_seconds: | ||
description: 'Polling time in seconds' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Check token balance and validate | ||
shell: bash | ||
run: | | ||
timeout ${{ inputs.polling_seconds }} bash -c "\ | ||
OLD_BALANCE=\$(cat ${{ inputs.file }}) | ||
NEW_BALANCE=\$(curl -s ${{ inputs.url }}/${{ inputs.address }} | jq -r --arg denom '${{ inputs.denom }}' '.balances[] | select(.denom == \$denom) | .amount') | ||
COMPARISON_OP='-gt' | ||
if [[ ${{ inputs.comparison_type }} == 'lesser' ]]; then | ||
COMPARISON_OP='-lt' | ||
fi | ||
until [[ \$NEW_BALANCE \$COMPARISON_OP \$OLD_BALANCE ]]; do | ||
echo \"Old Balance: \$OLD_BALANCE\" | ||
echo \"New Balance: \$NEW_BALANCE\" | ||
NEW_BALANCE=\$(curl -s ${{ inputs.url }}/${{ inputs.address }} | jq -r --arg denom '${{ inputs.denom }}' '.balances[] | select(.denom == \$denom) | .amount') | ||
done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters