Skip to content

Instantly share code, notes, and snippets.

@devzer01
Last active November 3, 2017 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devzer01/f7092b8d9a4fd27e6132db7862e5b68a to your computer and use it in GitHub Desktop.
Save devzer01/f7092b8d9a4fd27e6132db7862e5b68a to your computer and use it in GitHub Desktop.
#!/bin/bash
# i wrote this in 10-15 minutes, it works feel free to improve it and do whatever u want with it :)
# you can use any api to publish the transaction.
# the idea is you traverse back to the the input that is confirmed and boradcast the transaction to the network.
# if you are luckly you can broadcast about 25-30 per block, if you are running multiple wallets then you can increase this
# limit (but i haven't verified this
# call the script with your transaction waiting to confirm
# hash-push.sh acaf309bdded0746253fadbde42ded0a06f73c57059a1690cbc259b5469086d3
# THIS SCRIPT IS PROVIDED AS IS I WILL HOLD NO RESPONSIBILITY, HOWEVER IF YOU HAVE QUESTIONS
# ABOUT IT YOU CAN ASK IN reddit.com/r/hashflair
# donations: 18vgdFLPG2QhLFYFX97nNzmavEk9f1Ntm8 (BTC)
PREFIX="jshon -F tx.txt -e data"
txid=$1
echo "got transaction $txid"
confirm="0" #change this to 1 if you want to force part 2
while [ $confirm == "0" ]
do
tmd5=$(echo $txid | md5sum | cut -d- -f1 | tr -d ' ')
trans=$tmd5.trans
status=`wget https://chain.so/api/v2/tx/BTC/$txid -O $tmd5.txt 2>&1 | grep HTTP | grep -o "\.\.\. ..." | sed -e "s/\.//g" | tr -d ' '`
if [ "$status" == "200" ]
then
cp $tmd5.txt tx.txt
txid=`$PREFIX -e inputs -e 0 -e received_from -e txid | sed -e "s/\"//g"`
confirm=`$PREFIX -e confirmations`
current=`$PREFIX -e txid`
xtime=`$PREFIX -e time`
txhex=`$PREFIX -e tx_hex`
echo "INPUT: $current FROM $txid Time $xtime Confirmations $confirm"
echo $txhex > $trans
echo $current >> proc.log
sleep 2
else
echo "throttle ....... sleeping 10"
sleep 10
fi
done
PREFIX="jshon -e data"
CURRENTHASH=`wget -q -O- https://blockchain.info/q/latesthash`
for txid in `tac proc.log | sed -e "s/\"//g"` #notice tac here (not cat) we need to replay backwards
do
fname="$(echo $txid | md5sum | cut -d- -f1 | tr -d ' ').txt" #i have placed the raw transaction in .trans and full json in txt you can use which ever
txhex=`cat $fname | $PREFIX -e tx_hex | tr -d '"' `
echo -ne "submitting $txid => "
statusf=$fname.xstat
electrum broadcast $txhex | tee $statusf
xstatus=`jshon -F $statusf -e 0`
xtxn=`jshon -F $statusf -e 1 | sed -e "s/\"//g"`
if [ $xstatus == "true" ]; then
if [ $xtxn == $txid ]; then
echo "Success"
else
echo "txid didn't match"
fi
else
echo "error $xtxn " | cut -c1-45
NOWHASH=`wget -q -O- https://blockchain.info/q/latesthash`
if [ $CURRENTHASH == $NOWHASH ]; then
echo "still same block"
while [ $CURRENTHASH == $NOWHASH ]; do
NOWHASH=`wget -q -O- https://blockchain.info/q/latesthash`
sleep 10;
done
echo "new block found"
echo "trying resend "
electrum broadcast $txhex
fi
echo "resend using $txhex"
fi
sleep 1
done
@devzer01
Copy link
Author

devzer01 commented Oct 17, 2017

starting

nayana@rebeast:~/Desktop/replay.log$ ./hash-push.sh baafbe548330f7fb7ce04181d0b6da4209a63646c280fd1dc6f31d162ba142a9
got transaction baafbe548330f7fb7ce04181d0b6da4209a63646c280fd1dc6f31d162ba142a9
INPUT: "baafbe548330f7fb7ce04181d0b6da4209a63646c280fd1dc6f31d162ba142a9" FROM 92eb42bbeb9b769e853104720fa798e595ec75ff48f081cd6c70789799c00ff7 Time 1508251042 Confirmations 0
INPUT: "92eb42bbeb9b769e853104720fa798e595ec75ff48f081cd6c70789799c00ff7" FROM 6ea7932eb8c4df185d18a1212217da668e17ab4d5af343b0c24ff385eef0e93c Time 1508251045 Confirmations 0
INPUT: "6ea7932eb8c4df185d18a1212217da668e17ab4d5af343b0c24ff385eef0e93c" FROM 5ff79867579061d72b6d58af41afb2516ca32a14a6c016bad1dab1cecc5752e6 Time 1508251047 Confirmations 0
INPUT: "5ff79867579061d72b6d58af41afb2516ca32a14a6c016bad1dab1cecc5752e6" FROM 41e049db7ceb31262c4b76579bcc73192bc7008ffad00af56f2ac0b018b0e57c Time 1508251050 Confirmations 0
INPUT: "41e049db7ceb31262c4b76579bcc73192bc7008ffad00af56f2ac0b018b0e57c" FROM a2b15bea03cd811550700f2900660d914e6bf64c2b77aa1c79f79f5ff0619a04 Time 1508251052 Confirmations 0
INPUT: "a2b15bea03cd811550700f2900660d914e6bf64c2b77aa1c79f79f5ff0619a04" FROM 5459081aedca251b98625fc2f0830bfade0d6e27d101a03c878dbb11c86e13c9 Time 1508251055 Confirmations 0
INPUT: "5459081aedca251b98625fc2f0830bfade0d6e27d101a03c878dbb11c86e13c9" FROM 571a9cbd0514633b35a29d0fb445ef53ccaf1d00c4c9ba90c455e7c187423e90 Time 1508251057 Confirmations 0
INPUT: "571a9cbd0514633b35a29d0fb445ef53ccaf1d00c4c9ba90c455e7c187423e90" FROM 06b8e26f328b166b6d3308337b1e3aa8a9440f1bf4a93676ab67233ba9349fa8 Time 1508251060 Confirmations 0
INPUT: "06b8e26f328b166b6d3308337b1e3aa8a9440f1bf4a93676ab67233ba9349fa8" FROM 91033b820eec966c0858696c318a327bb4eb5546124b60dc4657b4569600caf1 Time 1508251063 Confirmations 0
INPUT: "91033b820eec966c0858696c318a327bb4eb5546124b60dc4657b4569600caf1" FROM dda2f4a81ce2f289d9e22d828b528d6461786e2d124aeb6df6cb6c867e9050f3 Time 1508251065 Confirmations 0
throttle ....... sleeping 10
throttle ....... sleeping 10
INPUT: "dda2f4a81ce2f289d9e22d828b528d6461786e2d124aeb6df6cb6c867e9050f3" FROM 8160c0490f7ea1d53379d56b005c291384145a3d2866b828228d098368762a31 Time 1508251089 Confirmations 0
INPUT: "8160c0490f7ea1d53379d56b005c291384145a3d2866b828228d098368762a31" FROM e44cef0503949043e2ac6f140152a64604f8e5f89544930f8b3371b41b8508a6 Time 1508251092 Confirmations 0

when the confirmed input is found it goes forward

INPUT: "fc4532b8475266efccd545f62f2e4e117085f02f2adc12272897e3547d5fbfc9" FROM d1e310d2b8cc151502011986cf263f42ff2d8218bcfdf0bda0388f77d34c8b56 Time 1508253254 Confirmations 0
INPUT: "d1e310d2b8cc151502011986cf263f42ff2d8218bcfdf0bda0388f77d34c8b56" FROM ec753137d0b67cf364b8ed5e3daa9231c0a86788cc5bdba17520095e63324833 Time 1508252265 Confirmations 2
submitting ec753137d0b67cf364b8ed5e3daa9231c0a86788cc5bdba17520095e63324833 =>

Submitting Transactions Looks like this

submitting fc4532b8475266efccd545f62f2e4e117085f02f2adc12272897e3547d5fbfc9 => [
    true, 
    "fc4532b8475266efccd545f62f2e4e117085f02f2adc12272897e3547d5fbfc9"
]
Success
submitting 9a46dae193726074560ca92f717a1871e2269d7364cf1e2b315da7f7687c468d => [
    true, 
    "9a46dae193726074560ca92f717a1871e2269d7364cf1e2b315da7f7687c468d"
]
Success
submitting b6c75b7e945f101adeba500d619039bc6f5bbfe0f1d81619f468a4f11f57901c => [
    true, 
    "b6c75b7e945f101adeba500d619039bc6f5bbfe0f1d81619f468a4f11f57901c"
]

When mempool limit is reached it waits for the next block

Success
submitting acaf309bdded0746253fadbde42ded0a06f73c57059a1690cbc259b5469086d3 => [
    false, 
    "error: the transaction was rejected by network rules.\n\n64: too-long-mempool-chain\n[01000000014d265c787dc8e3a92980c23e561b860348cb94a56ccdfb5e47238757d0299e5401000000d90047304402203d2b54acd8fa584c0fe954a4ea2eca5aa00e07c7b270f5617a41a83a2b81fb87022066e394341a55c94e7cc92e348219119b88ecf585e29508ff5ad7416fc9e351fb014730440220379fc858353dbef47756689f7a5e700740bfee7636140b53d75f8d0f26da0e2c02201da4a212212a25563b0f02fe74f519de489fd275543cc2ae6985694653a82d9301475221022647ed8ed0e12371a08cf0d4c0c1acb27e858423d103ddd0611610c6d6f425e521027a900cf1bc28805f5747fd9d4b9fd3ff8ff10c0ba15b8caba8dd750f1e22db0452aeffffffff02b9760200000000001976a914054f2c3c9d4397ee1be9753ff28ee219e13b2f5088ac3d4701f90000000017a914cb93febf21c9652a640b8a10820bb7f0f6274fda8700000000]"
]
error error: the transaction was rejected by 
still same block

if things got half way done or if you get a message saying transaction already in chain, then you will have to manually seek forward and adjust the inputfile

other

  • it doesn't clean up after it self, so you will end up having lot of files in the directory u run it, i didn't add any deletes because i was still sort of debuging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment