Bitcoin Forum
December 09, 2016, 01:47:46 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1] 2 3 4 »  All
  Print  
Author Topic: A full shell script implementation of bitcoin ?  (Read 13037 times)
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
December 26, 2010, 12:38:42 PM
 #1

The thread
http://bitcointalk.org/index.php?topic=2459.0

make me feel like suggesting a full shell implementation of bitcoin.  I've actually been thinking about this for some time but I'd like to see if other people would be interested in such a crazy project.

Here is the kind of architecture I'd like to see :

- nodes communicate transactions via IRC, XMPP or similar (a shell script communicating with such a protocol should be easy to implement) ;
- each node publishes its blocks via its own http server (possibly via a TOR hidden service to avoid NAT traversal problems) ;
- each node also publishes the list of nodes it is currently connected to ;
- nodes store their blocks using GnuNet or maybe a NoSQL database such as MongoDB  (easily scripted) ;
- cryptographic functions are performed via the openssl command line ;
- blocks and wallets are stored in an human readable ASCII format ;
1481291266
Hero Member
*
Offline Offline

Posts: 1481291266

View Profile Personal Message (Offline)

Ignore
1481291266
Reply with quote  #2

1481291266
Report to moderator
1481291266
Hero Member
*
Offline Offline

Posts: 1481291266

View Profile Personal Message (Offline)

Ignore
1481291266
Reply with quote  #2

1481291266
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481291266
Hero Member
*
Offline Offline

Posts: 1481291266

View Profile Personal Message (Offline)

Ignore
1481291266
Reply with quote  #2

1481291266
Report to moderator
BioMike
Legendary
*
Offline Offline

Activity: 1259


View Profile
December 27, 2010, 03:10:28 PM
 #2

That would be one big dependency hell...
MoonShadow
Legendary
*
Offline Offline

Activity: 1666



View Profile
December 27, 2010, 03:16:58 PM
 #3

At least it would be trivial to have small CL tools to perform bitcoin operations in this system, such as tools to import and export transactions, blocks and keypairs to/from normal files.  *nix CL shells, such as Bash, are centered around the manipulation of data streams as files, and it's an incredibly powerful model.

"The powers of financial capitalism had another far-reaching aim, nothing less than to create a world system of financial control in private hands able to dominate the political system of each country and the economy of the world as a whole. This system was to be controlled in a feudalist fashion by the central banks of the world acting in concert, by secret agreements arrived at in frequent meetings and conferences. The apex of the systems was to be the Bank for International Settlements in Basel, Switzerland, a private bank owned and controlled by the world's central banks which were themselves private corporations. Each central bank...sought to dominate its government by its ability to control Treasury loans, to manipulate foreign exchanges, to influence the level of economic activity in the country, and to influence cooperative politicians by subsequent economic rewards in the business world."

- Carroll Quigley, CFR member, mentor to Bill Clinton, from 'Tragedy And Hope'
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
December 27, 2010, 09:34:55 PM
 #4

At least it would be trivial to have small CL tools to perform bitcoin operations in this system, such as tools to import and export transactions, blocks and keypairs to/from normal files.  *nix CL shells, such as Bash, are centered around the manipulation of data streams as files, and it's an incredibly powerful model.

Exactly.

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.
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1470


View Profile
December 27, 2010, 10:35:14 PM
 #5

Shell script would be fine for a connect-work-disconnect method of working.

But it is grossly ineffective for maintaining a long-running P2P network node, where long-lasting TCP connections are preferred.

Jeff Garzik, bitcoin core dev team and BitPay engineer; opinions are my own, not my employer.
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
December 28, 2010, 03:04:15 AM
 #6

also, Kademlia network works fine without kickstarters and other things like this

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1470


View Profile
December 28, 2010, 04:30:38 AM
 #7

also, Kademlia network works fine without kickstarters and other things like this

Do you mean bootstrapping?  Kademlia network needs bootstrapping, just like other P2P networks.

Jeff Garzik, bitcoin core dev team and BitPay engineer; opinions are my own, not my employer.
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
MoonShadow
Legendary
*
Offline Offline

Activity: 1666



View Profile
December 28, 2010, 04:32:26 AM
 #8

Shell script would be fine for a connect-work-disconnect method of working.


There is a growing demand for a client that can function disconnected from the Internet.  This might be a step in this direction.

"The powers of financial capitalism had another far-reaching aim, nothing less than to create a world system of financial control in private hands able to dominate the political system of each country and the economy of the world as a whole. This system was to be controlled in a feudalist fashion by the central banks of the world acting in concert, by secret agreements arrived at in frequent meetings and conferences. The apex of the systems was to be the Bank for International Settlements in Basel, Switzerland, a private bank owned and controlled by the world's central banks which were themselves private corporations. Each central bank...sought to dominate its government by its ability to control Treasury loans, to manipulate foreign exchanges, to influence the level of economic activity in the country, and to influence cooperative politicians by subsequent economic rewards in the business world."

- Carroll Quigley, CFR member, mentor to Bill Clinton, from 'Tragedy And Hope'
pj
Newbie
*
Offline Offline

Activity: 24


View Profile
December 28, 2010, 11:49:39 AM
 #9

Shell script would be fine for a connect-work-disconnect method of working.

But it is grossly ineffective for maintaining a long-running P2P network node, where long-lasting TCP connections are preferred.
One could work around that inefficiency in at least a couple of ways:
 1) Background a task that has a file descriptor open back to the active shell, that can manipulate and communicate with sockets, or
 2) Use a shell that provides this builtin, such as the net/socket module in zsh as described at  http://www.cims.nyu.edu/cgi-systems/info2html?%28zsh%29The%2520zsh%2Fnet%2Fsocket%2520Module
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
December 28, 2010, 12:40:26 PM
 #10

Could anyone educate me about the interest of coding a bitcoin client in shell script ? (protip : "just for fun" is a valid answer:) )

pj
Newbie
*
Offline Offline

Activity: 24


View Profile
December 28, 2010, 12:50:11 PM
 #11

Could anyone educate me about the interest of coding a bitcoin client in shell script ? (protip : "just for fun" is a valid answer:) )

Someone else asked the question, so I can just guess from what they said.

My guess is that the interest is not so much in coding the guts of the client in shell script (not exactly a high performance engine for computationally intensive tasks), but rather in exposing the data flows and stores to shell script manipulation.

In other words, as I have often done myself in other tasks, write several tools that each have specific capabilities, and which have interfaces that work well when combined in shell scripts with each other and other *nix utilities.  One shot commands are handled in that environment by forking/execing a command that is passed command line arguments, environment variables and files or file descriptors to read or write.  Higher performance for repetitive tasks is obtained by using commands in a series of filters, operating on a stream of line oriented text.  The new, individual tools would each be written in C or Python or some other such language that provided adequate performance and library support for their particular purpose.
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 06, 2011, 02:16:42 AM
 #12


I'm trying to implement the base58 functions.  I'm almost there but I have difficulties with the checksum.


Code:
#!/bin/bash

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

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
}

Hash160ToAddress() {
    ADDRESSVERSION=00
    EncodeBase58 "${ADDRESSVERSION}$1$(Checksum "$1")"
}

Checksum() {
    xxd -p -r <<<"$1" |
    openssl dgst -sha256 -binary |
    openssl dgst -sha256 -hex |
    cut -d\  -f2 |
    sed -r "s/^.*((..){4})/\1/"
}

Hash160() {
    echo -n "$1" |
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -hex |
    cut -d\  -f2
}

H=0057b0dc5aac7c215a9a458d6c3c85cd21089af8
Hash160ToAddress $H
# I should get     112p3sLidyEptFEfx3C2RCvFoRPK89HyBT
# I actually get     2p3sLidyEptFEfx3C2RCvFoRPK7JQWdq
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 06, 2011, 02:52:51 AM
 #13

Yes !  It works  Cheesy

Code:
#!/bin/bash
#
# Requires bc, openssl, xxd
#

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

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
}

Hash160ToAddress() {
    printf %34s $(EncodeBase58 "00$1$(checksum "00$1")")|
    sed "s/ /1/g"
}

checksum() {
    xxd -p -r <<<"$1" |
    openssl dgst -sha256 -binary |
    openssl dgst -sha256 -hex |
    cut -d\  -f2 |
    sed -r "s/^((..){4}).*/\1/"
}

Hash160() {
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -hex |
    cut -d\  -f2
}

PubKeyToAdress() { Hash160ToAddress $(tail -c 65 |Hash160) ; }
davux
Sr. Member
****
Offline Offline

Activity: 289


Firstbits.com/1davux


View Profile WWW
January 06, 2011, 05:16:48 PM
 #14

I like the idea: having a series of small tools that do one task, do it well, and can work together through stdin/stdout, the filesystem, sockets, etc.

I'd start off with strict sh compatibility, though, not bash, unless there's really a big advantage of requiring bash over lighter posix-compliant sh implementations (e.g. dash).

1DavuxH9tLqU4c7zvG387aTG4mA7BcRpp2
México (Oaxaca) – France - Leeds
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 06, 2011, 05:47:09 PM
 #15

I'd start off with strict sh compatibility, though, not bash, unless there's really a big advantage of requiring bash over lighter posix-compliant sh implementations (e.g. dash).

Writing in POSIX is much less fun.  To me GNU is a better standard de facto.

Also, what's the point of those excellent GNU tools if we can never use them ?
mikegogulski
Sr. Member
****
Offline Offline

Activity: 360



View Profile WWW
January 06, 2011, 07:39:31 PM
 #16

I'd start off with strict sh compatibility, though, not bash, unless there's really a big advantage of requiring bash over lighter posix-compliant sh implementations (e.g. dash).

Not that I've got any skin in this game, but it would be worth considering targeting the more limited toolset offered by Busybox:

http://busybox.net/

The profusion of embedded linux devices these days means Busybox is everywhere.

FREE ROSS ULBRICHT, allegedly one of the Dread Pirates Roberts of the Silk Road
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 07, 2011, 04:20:10 AM
 #17

I've added two functions : decodeBase68 and checkBitcoinAddress.

I think it might be usefull to check the validity of a bitcoin address in pure bash.

Requires "dc", the unix desk calculator.  Few people use this reverse polish notation calcultor but it's much easier to handle in scripts.


Code:
#!/bin/bash
#
# Requires bc, dc, openssl, xxd
#

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})
bitcoinregex="^[$(printf "%s" "${base58[@]}")]{34}$"

decodeBase58() {
    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 -hex |
    sed 's/^.* //' |
    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() {
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -hex |
    sed 's/^.* //'
}

hash160ToAddress() {
    printf %34s "$(encodeBase58 "00$1$(checksum "00$1")")" |
    sed "y/ /1/"
}

publicKeyToAddress() {
    hash160ToAddress $(
    openssl ec -pubin -pubout -outform DER 2>/dev/null |
    tail -c 65 |
    hash160
    )
}
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
January 15, 2011, 01:51:54 PM
 #18

I have modified dirtyfilthy's program so that it can export the whole wallet in an ascii format.

http://github.com/grondilu/bc_key


Just use "ALL" instead of a particular bitcoin address.

Be careful with this command, for it shows all your private keys in clear !  In particular, you should never redirect the output of this program to a file.  Unless you use an encrypted file system.

Anyway, I'll add a few bash functions that can be used to create a new address, sign a transaction, and so on...

Here is a function to create a new address already :

Code:
#!/bin/bash

. base58.sh

wallet="$HOME/.bitcoin-bash/wallet.dat"

generateNewAddress() {

    privkey="$(openssl ecparam -name secp256k1 -genkey)"

    openssl ec -pubout <<<"$privkey" 2>&- |
    publicKeyToAddress 2>&- |
    if [[ -f "$wallet" ]]
    then
        tee -a "$wallet"  # storing and showing the address
        printf "%s" "$privkey" >> "$wallet"  # storing the private key
    else
        # showing address and private key
        cat
        printf "%s" "$privkey"
    fi

}
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
February 24, 2011, 11:30:27 AM
 #19


I know a bit about this software and I think it's pretty cool.  I really would like to see an implementation of bitcoin using this as a database handler.


One of the reason why I think it would fit bitcoin nicely is the fact that mongodb uses JSON directly to represent data.   An other reason is that it is very easy to connect to an other mongodb on the net.  Thus, the network handling would be easy.

Also, it's very easy to handle from a bash script.


www.mongodb.org
Nefario
Hero Member
*****
Offline Offline

Activity: 602


GLBSE Support support@glbse.com


View Profile WWW
February 24, 2011, 01:34:59 PM
 #20

What is it with you and bash scripts?  Roll Eyes
Can you do nothing else?

PGP key id at pgp.mit.edu 0xA68F4B7C

To get help and support for GLBSE please email support@glbse.com
Pages: [1] 2 3 4 »  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!