Last active
March 28, 2023 17:50
-
-
Save rithvikvibhu/4aa5885da70eeca3a8627c1718f0d2ca to your computer and use it in GitHub Desktop.
test-tx-for-swap.sh
This file contains hidden or 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
# Check if a tx is an atomic name swap (Bob atomic swap, Shakedex sale, FxWallet marketplace sale) | |
# Bob swap (HIP-4) hints: | |
# - in0.witness[0] ends with 84 | |
# - last output value = price | |
# - out0 = FINALIZE | |
# Shakedex (HIP-1) transfer hints: | |
# - in0.witness[0] ends with 84 | |
# - last output value = price | |
# - out0 = TRANSFER | |
# Txs examples: | |
# irrelevant transaction: 4befa3c3aafa043b3bafd01bed0530f314a0804df281fd6e693a76dfa00398b8 | |
# normal transfer (no payment): b80481b397f561468fcd0b09bb8274e36bc7bfacfc2a5d01accd9f1581eeeb78 | |
# i_the_magician (hip1 shakedex): b89eeaa38733d2d14a93397d42a0ec3773af1b53ace85dbebed9b3dbf63d9e8c | |
# pinkieswear (hip4 atomic swap): 32227eb2dab16dbb3debc873ff40cfeba299eb2cf1554ffd098fa968bc88c6cd | |
for txid in 4befa3c3aafa043b3bafd01bed0530f314a0804df281fd6e693a76dfa00398b8 b80481b397f561468fcd0b09bb8274e36bc7bfacfc2a5d01accd9f1581eeeb78 b89eeaa38733d2d14a93397d42a0ec3773af1b53ace85dbebed9b3dbf63d9e8c 32227eb2dab16dbb3debc873ff40cfeba299eb2cf1554ffd098fa968bc88c6cd; do | |
echo -e "\nTransaction: $txid" | |
tx=$(hsd-cli tx $txid) | |
#echo $tx | |
data=$(echo $tx | jq '{ | |
flag_match: (.inputs[0].witness[0] | endswith("84")), | |
is_transfer: (.outputs[0].covenant.type == 9), | |
is_finalize: (.outputs[0].covenant.type == 10), | |
price: (.outputs | last.value / 1e6), | |
} | if (.flag_match and (.is_transfer or .is_finalize)) then { | |
hip4: .is_finalize, | |
hip1: .is_transfer, | |
price: .price | |
} else {} end') | |
echo $data | |
done | |
# Example output: | |
# Transaction: 4befa3c3aafa043b3bafd01bed0530f314a0804df281fd6e693a76dfa00398b8 | |
# {} | |
# | |
# Transaction: b80481b397f561468fcd0b09bb8274e36bc7bfacfc2a5d01accd9f1581eeeb78 | |
# {} | |
# | |
# Transaction: b89eeaa38733d2d14a93397d42a0ec3773af1b53ace85dbebed9b3dbf63d9e8c | |
# { "hip4": false, "hip1": true, "price": 598.848641 } | |
# | |
# Transaction: 32227eb2dab16dbb3debc873ff40cfeba299eb2cf1554ffd098fa968bc88c6cd | |
# { "hip4": true, "hip1": false, "price": 123.654321 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment