Created
March 18, 2014 01:36
-
-
Save wozz/9611952 to your computer and use it in GitHub Desktop.
create transaction with sx
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
| #!/bin/bash | |
| #send from single address with single input | |
| #pk1 = private key | |
| #addr1.txt = send from address (generated) | |
| #pub1 = pub key (generated) | |
| #output.txt = send to address + amount | |
| sx pubkey < pk1 > pub1 | |
| sx addr < pk1 > addr1.txt | |
| sx history < addr1.txt > hist.txt | |
| grep Unspent -B 3 hist.txt | grep output: | awk '{print $2}' > inputs.txt | |
| numtx=$(grep value hist.txt | wc -l) | |
| inval=$(grep value hist.txt | awk '{s+=$2} END {print s}') | |
| cat inputs.txt | sed 's/^/-i /' | tr '\n' ' ' > input-line.txt | |
| cat output.txt | sed 's/^/-o /' | tr '\n' ' -o ' > output-line.txt | |
| sx mktx txfile.tx `cat input-line.txt` `cat output-line.txt` --locktime 290000 | |
| outval=$(awk -F ":" '{s+=$2} END {print s}' output.txt) | |
| fee=$(sx btc $(expr $inval - $outval)) | |
| echo "fee: $fee" | |
| sx rawscript dup hash160 [ `cat addr1.txt | sx decode-addr` ] equalverify checksig > raw.script.txt | |
| for x in `seq 0 $(expr $numtx - 1)`; | |
| do | |
| cat pk1 | sx sign-input txfile.tx $x `cat raw.script.txt` | tail -n 1 > sig$x | |
| done | |
| for x in `seq 0 $(expr $numtx - 1)` | |
| do | |
| sx set-input txfile.tx $x `sx rawscript [ $(cat sig$x) ] [ $(cat pub1) ]` > txfile2.tx | |
| mv txfile2.tx txfile.tx | |
| done | |
| sx validtx txfile.tx | |
| for x in `seq 0 $(expr $numtx - 1)`; | |
| do | |
| rm sig$x | |
| done | |
| rm pub1 | |
| rm raw.script.txt | |
| rm addr1.txt | |
| rm hist.txt | |
| rm input-line.txt | |
| rm output-line.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment