grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 01, 2011, 10:04:56 PM |
|
How about { bigEndianHex2littleEndianHex <<<"$a" | xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" | xxd -p -r ; } \ | openssl dgst -sha256 -binary \ | openssl dgst -sha256 -hex \ | bigEndianHex2littleEndianHex
That would give the third hash, wouldn't it? It does indeed! But you have to get rid of the annoying 'std(...)= ': I didn't know that there were actually 2 sha256 passes, just like for the hash of the block itself. { bigEndianHex2littleEndianHex <<<"$a" | xxd -p -r ; bigEndianHex2littleEndianHex <<<"$b" | xxd -p -r ; } | openssl dgst -sha256 -binary | openssl dgst -sha256 -hex | sed 's/.* //' | bigEndianHex2littleEndianHex
(also, you can use '|' at the end of line without using '\') Now how to deal with blocks with a number of transactions that are not a power of 2?
|
|
|
|
kseistrup
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 01, 2011, 10:18:33 PM |
|
But you have to get rid of the annoying 'std(...)= ':
Huh? I don't get you… I didn't know that there were actually 2 sha256 passes, just like for the hash of the block itself.
Neither did I, but it was worth a try. (also, you can use '|' at the end of line without using '\')
(I know, but I think explicit line continuations are more legible.) Now how to deal with blocks with a number of transactions that are not a power of 2?
You tell me. ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) Cheers,
|
Klaus Alexander Seistrup
|
|
|
TiagoTiago
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2011, 08:07:08 PM |
|
(just subscribing to the thread)
|
(I dont always get new reply notifications, pls send a pm when you think it has happened) Wanna gimme some BTC/BCH for any or no reason? 1FmvtS66LFh6ycrXDwKRQTexGJw4UWiqDX ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) The more you believe in Bitcoin, and the more you show you do to other people, the faster the real value will soar!
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2011, 08:32:34 PM |
|
But you have to get rid of the annoying 'std(...)= ':
Huh? I don't get you… Well, when I run openssl dgst -sha1 -hex <<<"hello, world", I get an annoying: (stdin)= cd50d19784897085a8d0e3e413f8612b097c03f1 I wish there was an option not to display this "(...)= " before my result. Anyway that's why I had to add a 'sed "s/^.* //"'.
|
|
|
|
kseistrup
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2011, 08:42:27 PM |
|
Well, when I run openssl dgst -sha1 -hex <<<"hello, world", I get an annoying:
(stdin)= cd50d19784897085a8d0e3e413f8612b097c03f1
I wish there was an option not to display this "(...)= " before my result. Anyway that's why I had to add a 'sed "s/^.* //"'.
Ah, this doesn't happen here — I only see that SHA256 digest: $ openssl dgst -sha256 -hex <<< "hello, world" 853ff93762a06ddbf722c4ebe9ddd66d8f63ddaea97f521c3ecc20da7c976020 $
Cheers,
|
Klaus Alexander Seistrup
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2011, 08:53:35 PM |
|
$ openssl dgst -sha256 -hex <<< "hello, world" 853ff93762a06ddbf722c4ebe9ddd66d8f63ddaea97f521c3ecc20da7c976020 $
Cheers, different version of openssl I guess. $ openssl version OpenSSL 1.0.0c 2 Dec 2010
|
|
|
|
kseistrup
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2011, 09:02:16 PM |
|
different version of openssl I guess.
$ openssl version OpenSSL 1.0.0c 2 Dec 2010
Yes, I'm running OpenSSL 0.9.8k 25 Mar 2009 (from Ubuntu Lucid). Cheers,
|
Klaus Alexander Seistrup
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 04, 2011, 07:25:33 PM |
|
Here is the Merkle tree for block 95002, which had three transactions: "mrkl_tree":[ "4fa598026d9be1ca0c2bff1b531e566b7ea7f90b72e75fda0c1795bc2dfa375c", "186640daf908156e2616790d7c816235b0c43f668c3c38351b348c08ca44d457", "ef3928700309b4deceac9a992a19a7481b4e520cbc0b1ab74e2645eee39c8da0", "688c53517f62f7a65c0e87519c18a4de98f2ccafbf389b269d0bb867f88d166a", "01889506f7fe9210045f588361881e2d16a034a62bc48ebd7b6b0a3edeaf5a6d", "74f3a7df861d6a58957b84a3e425a8cf57e1e2e3a3def046dd200baeb8714f00" ]
I rewrote the two bash functions: bigEndianHex2littleEndianHex() { local s='' while read -n 2 char do s=$char$s done echo $s }
bitcoinHash() { bigEndianHex2littleEndianHex | xxd -p -r | openssl dgst -sha256 -binary | openssl dgst -sha256 -binary | xxd -p -c 80 | bigEndianHex2littleEndianHex }
The fourth entry of the Merkle tree is easy to reconstitute. It's obviously made out of the first two. bitcoinHash <<<"186640daf908156e2616790d7c816235b0c43f668c3c38351b348c08ca44d457 4fa598026d9be1ca0c2bff1b531e566b7ea7f90b72e75fda0c1795bc2dfa375c" But then, I don't know how to get the fith out of the third.
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13296
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 04, 2011, 08:38:02 PM |
|
The last hash is doubled.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 04, 2011, 09:02:11 PM |
|
The last hash is doubled.
Indeed. I thought I had tried that but I guess I did it wrong. Thanks.
|
|
|
|
TiagoTiago
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 16, 2011, 06:37:07 AM |
|
how far are we from a total implementation?
|
(I dont always get new reply notifications, pls send a pm when you think it has happened) Wanna gimme some BTC/BCH for any or no reason? 1FmvtS66LFh6ycrXDwKRQTexGJw4UWiqDX ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) The more you believe in Bitcoin, and the more you show you do to other people, the faster the real value will soar!
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 16, 2011, 06:41:48 AM |
|
how far are we from a total implementation?
Very far.
|
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 15, 2011, 01:39:27 PM |
|
Connecting to IRC is actually much easier than I thought. I still have to request my IP and format my nick, though. #!/bin/bash # # This is free and unencumbered software released into the public domain. # # Anyone is free to copy, modify, publish, use, compile, sell, or # distribute this software, either in source code form or as a compiled # binary, for any purpose, commercial or non-commercial, and by any # means. # # In jurisdictions that recognize copyright laws, the author or authors # of this software dedicate any and all copyright interest in the # software to the public domain. We make this dedication for the benefit # of the public at large and to the detriment of our heirs and # successors. We intend this dedication to be an overt act of # relinquishment in perpetuity of all present and future rights to this # software under copyright law. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # #
################################################################################ # # BASE 58 encoding/decoding # # Requires bc, dc, openssl, xxd ################################################################################
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z}) bitcoinregex="^[$(printf "%s" "${base58[@]}")]{34}$"
decodeBase58() { local s=$1 for i in {0..57} do s="${s//${base58[i]}/ $i}" done dc <<< "16o0d${s// /+58*}+f" }
encodeBase58() { # 58 = 0x3A bc <<<"ibase=16; n=${1^^}; while(n>0) { n%3A ; n/=3A }" | tac | while read n do echo -n ${base58[n]} done }
checksum() { xxd -p -r <<<"$1" | openssl dgst -sha256 -binary | openssl dgst -sha256 -binary | xxd -p -c 80 | head -c 8 }
checkBitcoinAddress() { if [[ "$1" =~ $bitcoinregex ]] then h=$(decodeBase58 "$1") checksum "00${h::${#h}-8}" | grep -qi "^${h: -8}$" else return 2 fi }
hash160() { # binary data expected on stdin openssl dgst -sha256 -binary | openssl dgst -rmd160 -binary | xxd -p -c 80 }
hash160ToAddress() { printf "%34s\n" "$(encodeBase58 "00$1$(checksum "00$1")")" | sed "y/ /1/" }
publicKeyToAddress() { hash160ToAddress $( openssl ec -pubin -pubout -outform DER 2>/dev/null | tail -c 65 | hash160 ) }
bigEndianHex2littleEndianHex() { local s while read -n 2 c do s=$c$s done echo $s }
bitcoinHash() { bigEndianHex2littleEndianHex | xxd -p -r | openssl dgst -sha256 -binary | openssl dgst -sha256 -binary | xxd -p -c 80 | bigEndianHex2littleEndianHex }
################################################################################ # # IRC communication # # most of this comes from http://shudder.daemonette.org/source/BashNP-Guide.txt ################################################################################
host="irc.lfnet.org" port=6667 channel="#bitcoinTEST" mode="+i"
nick="$USER$$" name="$USER's bitcoin bot script"
if # try to connect ! exec 3<> /dev/tcp/$host/$port then echo "$(basename $0): unable to connect to $host:$port" 1>&2 exit 1 else # duplicate standard input and output with the newly created socket exec 0<&3 1>&3-
# register to the server echo "USER $nick ${mode:-+iw} $nick :$name" echo "NICK $nick" # join channel echo "JOIN $channel"
while read do set -- ${REPLY//$'\r'/}
# answer the critical ping request # otherwise the server will disconnect us [[ "$1" == "PING" ]] && echo "PONG $2"
echo $REPLY >&2
done
exec 1<&- fi
|
|
|
|
kripz
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 17, 2011, 12:00:30 PM |
|
Subscribing, very interesting ![Wink](https://bitcointalk.org/Smileys/default/wink.gif)
|
|
|
|
macman31
Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 83
Merit: 10
The French Pool
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 27, 2011, 09:28:22 PM |
|
Hi,
Warning ! "/dev/tcp/" is not available everywhere ! Disabled on some new Linux OS (Debian 6, ...) for more security.
You should use the wildly available "netcat" ("nc") to connect to the IRC server !
By the way, your script is very interesting !
(Sorry for my English, I'm french)
macman31
|
Feel free to donate to 13cyb1gvVcu6q8F1ysLhEDM4UwzZR9MvNx ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) Rejoignez la 1ère pool Française : The French Pool ! https://frenchpool.fr
|
|
|
hamdi
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 27, 2011, 11:13:47 PM |
|
nice development. cant wait to see all the tools finished
|
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 28, 2011, 11:44:04 AM |
|
You should use the wildly available "netcat" ("nc") to connect to the IRC server !
Thanks for the tip about netcat, I didn't know about it. So many things to know and only one life ;(
|
|
|
|
macman31
Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 83
Merit: 10
The French Pool
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 28, 2011, 11:53:02 AM |
|
|
Feel free to donate to 13cyb1gvVcu6q8F1ysLhEDM4UwzZR9MvNx ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) Rejoignez la 1ère pool Française : The French Pool ! https://frenchpool.fr
|
|
|
marcus_of_augustus
Legendary
Offline
Activity: 3920
Merit: 2349
Eadem mutata resurgo
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 28, 2011, 09:04:21 PM |
|
Post #35 in this thread. grondilu: Quote I also wonder if all communications could not be done using HTTP. Blocks would be published via http GET method (giving the hash of the preceding block), and transactions could be sent via POST method.
One advantage of using http would be that it would be very hard for governments to forbid.
Where did you get to with the network connection side of this, netcat could be an option.
|
|
|
|
grondilu (OP)
Legendary
Offline
Activity: 1288
Merit: 1080
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 29, 2011, 11:45:22 AM |
|
Could someone write a C/C++ program that could allow me to test this portion of code in irc.cpp ? #pragma pack(push, 1) struct ircaddr { int ip; short port; }; #pragma pack(pop)
string EncodeAddress(const CAddress& addr) { struct ircaddr tmp; tmp.ip = addr.ip; tmp.port = addr.port;
vector<unsigned char> vch(UBEGIN(tmp), UEND(tmp)); return string("u") + EncodeBase58Check(vch); }
I need to do some trial and error testing of the bash equivalent.
|
|
|
|
|