Skip to content

Commit d0fa00d

Browse files
authored
v0.3.1
Command options for min & max
1 parent ce82801 commit d0fa00d

File tree

1 file changed

+55
-41
lines changed

1 file changed

+55
-41
lines changed

getxchtx.sh

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ usage () {
99
echo " -s INTERGER Index of starting transaction Default: 0"
1010
echo " -e INTERGER Index of ending transaction Default: 999999"
1111
echo " -o INTERGER 0 for ascending, 1 for descending Default: 0"
12+
echo " -min AMOUNT Only transactions greater than AMOUNT Default: 0"
13+
echo " -max AMOUNT Only transactions less than AMOUNT Default: 999999"
1214
echo " -t INTERGER -1 for all transaction types Default: -1"
1315
echo " 0 for INCOMING_TX"
1416
echo " 1 for OUTGOING_TX"
@@ -55,6 +57,8 @@ trx_start=0
5557
trx_end=999999
5658
trx_order=0
5759
desired_type=-1
60+
trx_max=999999
61+
trx_min=0
5862

5963
# Handle the command line options. Set variable based on input
6064
# be sure not to shift after an option that is only has one term
@@ -67,6 +71,8 @@ do
6771
-e) trx_end=$2 && shift ;;
6872
-o) trx_order=$2 && shift ;;
6973
-t) desired_type=$2 && shift ;;
74+
-min) trx_min=$2 && shift ;;
75+
-max) trx_max=$2 && shift ;;
7076
-v) verbose="true" ;;
7177
-h) usage && exit 1 ;;
7278
--) shift && break ;;
@@ -75,9 +81,6 @@ do
7581
shift
7682
done
7783

78-
# DEBUG
79-
# echo "WalletID=$wallet_id, Year=$year, Verbose=$verbose, Start=$trx_start, End=$trx_end, Sort=$trx_order, Desired Type = $desired_type"
80-
8184
# Make a call against the chia wallet_rpc_api to get transactions, then use jq to write the json to a file
8285
query_parameters="{\"wallet_id\":$wallet_id,\"start\":$trx_start,\"end\":$trx_end,\"reverse\":$trx_order}"
8386
curl -s -X POST --insecure \
@@ -120,16 +123,31 @@ jq -c '.transactions[]' alltxs.json | while read trx; do
120123
tx_type=`echo "$trx" | jq -r '.type'`
121124
tx_wallet_id=`echo "$trx" | jq -r '.wallet_id'`
122125

126+
# If there was a desired type, lets limit the results down to only that transaction type
127+
if [[ $desired_type -ge 0 ]] && [[ $desired_type -ne $tx_type ]]; then
128+
continue
129+
fi
130+
123131
# placeholder for the current price of XCH
124132
current_price=0
125133

126134
# call function to switch amount from mojo to xch
127135
mojo2xch && tx_amount=$xch
128136

137+
# filter based on min/max
138+
if [[ "$tx_amount" > "$trx_max" ]] || [[ "$tx_amount" < "$trx_min" ]]; then
139+
continue
140+
fi
141+
129142
# build datetime from epoch
130143
tx_datetime=$(date --date=@$tx_created_at_time +"%Y-%m-%d %T")
131144
tx_year=`echo $tx_datetime | cut -c1-4`
132145

146+
# jump to next record if we want a specific year and the transaction doesn't match
147+
if [ "$year" != "all" ] && [ "$year" != "$tx_year" ]; then
148+
continue
149+
fi
150+
133151
# set a good description for the transaction type
134152
case $tx_type in
135153
0) tx_typedesc="INCOMING_TX" ;;
@@ -161,49 +179,45 @@ jq -c '.transactions[]' alltxs.json | while read trx; do
161179
mojo2xch && tx_amount=$xch
162180
fi
163181

164-
# If year is passed in as an option we only want to print that year
165-
if [ "$year" == "all" ] || [ "$year" == "$tx_year" ]; then
166-
167-
# If there was a desired type, lets limit the results down to only that transaction type
168-
if [[ $desired_type -lt 0 ]] || [[ $desired_type -eq $tx_type ]]; then
169-
170-
# write out to screen
171-
# to save to file the user must use redirection on the command line
172-
if [ "$verbose" == "true" ]; then
173-
row="$tx_name,$tx_datetime,$tx_typedesc,$tx_amount,$current_price,$tx_additions,$tx_confirmed,$tx_confirmed_at_height,$tx_fee_amount,$tx_memos,$tx_removals,$tx_sent,$tx_sent_to,$tx_spend_bundle,$tx_to_address,$tx_to_puzzle_hash,$tx_trade_id,$tx_wallet_id"
174-
else
175-
row="$tx_name,$tx_datetime,$tx_typedesc,$tx_amount,$current_price"
176-
fi
177-
echo "$row"
178-
fi
182+
# write out to screen
183+
# to save to file the user must use redirection on the command line
184+
if [ "$verbose" == "true" ]; then
185+
row="$tx_name,$tx_datetime,$tx_typedesc,$tx_amount,$current_price,$tx_additions,$tx_confirmed,$tx_confirmed_at_height,$tx_fee_amount,$tx_memos,$tx_removals,$tx_sent,$tx_sent_to,$tx_spend_bundle,$tx_to_address,$tx_to_puzzle_hash,$tx_trade_id,$tx_wallet_id"
186+
else
187+
row="$tx_name,$tx_datetime,$tx_typedesc,$tx_amount,$current_price"
179188
fi
189+
echo "$row"
190+
180191
done
181192

182193
# Version History
183194
#
184-
# v0.1 - Initial Release:
185-
# - Basic functionality. Will generate a list of transactions for Chia (XCH) and
186-
# put into a CSV file. Pulls only a list of transaction ids from wallet then looped on those
187-
# ids and used Chia commands to get more details for each transaction.
188-
# - Output was sent to the screen and also saved to a file. This required defaults for path &
189-
# filenames and also command options from user to specify each as well.
195+
# v0.1.0 - Initial Release:
196+
# - Basic functionality. Will generate a list of transactions for Chia (XCH) and
197+
# put into a CSV file. Pulls only a list of transaction ids from wallet then looped on those
198+
# ids and used Chia commands to get more details for each transaction.
199+
# - Output was sent to the screen and also saved to a file. This required defaults for path &
200+
# filenames and also command options from user to specify each as well.
190201
#
191-
# v0.2 - Changes:
192-
# - Rebuilt the query against the wallet db to pull all the transaction data and write into a
193-
# json file that can be used in the rest of the script without having to run Chia commands.
194-
# - Changed output to screen only and updated Usage to tell user how to redirect to a file from
195-
# the command line.
196-
# New features:
197-
# - Added command option to specify a year for the transactions. If the transacion year doesn't
198-
# match the value from the command option, then it doesn't get writtent to the CSV.
199-
# - Added command option for verbose which will include all fields in the CSV. The default is now
200-
# a condensed version with fewer fields.
202+
# v0.2.0 - Changes:
203+
# - Rebuilt the query against the wallet db to pull all the transaction data and write into a
204+
# json file that can be used in the rest of the script without having to run Chia commands.
205+
# - Changed output to screen only and updated Usage to tell user how to redirect to a file from
206+
# the command line.
207+
# New features:
208+
# - Added command option to specify a year for the transactions. If the transacion year doesn't
209+
# match the value from the command option, then it doesn't get writtent to the CSV.
210+
# - Added command option for verbose which will include all fields in the CSV. The default is now
211+
# a condensed version with fewer fields.
201212
#
202-
# v0.3 - New features:
203-
# - Add a command option for sorting. Either ASC for ascending (oldest to newest) or DESC for
204-
# descending (newest to oldest).
205-
# - Add a command option for selecting wallet id to pull transactions from.
206-
# - Add a command option for start & end indexes for transactions to pull out of the wallet db.
207-
# - Add a command option for selecting a specific Transaction Type to filter the list by.
213+
# v0.3.0 - New features:
214+
# - Add a command option for sorting. Either ASC for ascending (oldest to newest) or DESC for
215+
# descending (newest to oldest).
216+
# - Add a command option for selecting wallet id to pull transactions from.
217+
# - Add a command option for start & end indexes for transactions to pull out of the wallet db.
218+
# - Add a command option for selecting a specific Transaction Type to filter the list by.
208219
#
209-
220+
# v0.3.1 - Changes
221+
# - Rewrite so filters are in a big nested if statement. Use continue to jump to next iteration instead.
222+
# New features:
223+
# - Add a command option for filtering based on transaction amount.

0 commit comments

Comments
 (0)