Inside Bitcoin's Proof-of-Work / Waste 10-Minute Mining Lottery - The Ruby Edition by Example

Hello,

  I've put together a step-by-step article that breaks down the
"magic" of Bitcoin's proof-of-work / waste 10-minute mining lottery
[1].

  Follow (or read) along with with many ready-to-run examples (in ruby)
  including what's your hash rate per seconds [2] and many more.

Example:

```
require "digest"

def sha256( msg )
  Digest::SHA256.hexdigest( msg )
end

···

#################
# Let's calculate 10 million, that is, 10 000 000 hashes.
# e.g. "Hello, world!0"
# "Hello, world!1"
# "Hello, world!2"
# "Hello, world!3"
# and on and on and on

t1 = Time.now
10_000_000.times do |i|
  sha256( "Hello, world!#{i}")

  # bonus: print a dot (.) for progress for every one hundred thousand
hashes calculated
  print "." if i % 100_000 == 0
end
t2 = Time.now

delta = t2 - t1
puts ""
puts "Elapsed Time: %.4f seconds" % delta

hashrate = Float( 10_000_000 / delta )
puts "Hash Rate: %d hashes/second" % hashrate
```

   Happy hashing and block chaining with ruby.

Bonus: Learn the secret How to Buy Bitcoin (The CO₂-Friendly Way)
       by Trolly McTrollface.

[1] https://github.com/openblockchains/awesome-blockchains/tree/master/bitcoin_proof_of_work.rb
[2] https://github.com/openblockchains/awesome-blockchains/blob/master/bitcoin_proof_of_work.rb/hashrate.rb

Gerald,

Thanks for this stuff! I have been interested in doing something with Ruby and BTC for a while but so far have not made the time / effort - I will go through this in more detail!

Regards,

Phil.

···

On 2020-01-23 06:50, Gerald Bauer wrote:

Hello,

  I've put together a step-by-step article that breaks down the
"magic" of Bitcoin's proof-of-work / waste 10-minute mining lottery
[1].

  Follow (or read) along with with many ready-to-run examples (in ruby)
  including what's your hash rate per seconds [2] and many more.

Example:

require "digest"

def sha256( msg )
  Digest::SHA256.hexdigest( msg )
end

#################
# Let's calculate 10 million, that is, 10 000 000 hashes.
#    e.g. "Hello, world!0"
#         "Hello, world!1"
#         "Hello, world!2"
#         "Hello, world!3"
#         and on and on and on

t1 = Time.now
10_000_000.times do |i|
  sha256( "Hello, world!#{i}")

  # bonus: print a dot (.) for progress for every one hundred thousand
hashes calculated
  print "."    if i % 100_000 == 0
end
t2 = Time.now

delta = t2 - t1
puts ""
puts "Elapsed Time: %.4f seconds" % delta

hashrate = Float( 10_000_000 / delta )
puts "Hash Rate: %d hashes/second" % hashrate

   Happy hashing and block chaining with ruby.

Bonus: Learn the secret How to Buy Bitcoin (The CO₂-Friendly Way)
       by Trolly McTrollface.

[1] https://github.com/openblockchains/awesome-blockchains/tree/master/bitcoin_proof_of_work.rb
[2] https://github.com/openblockchains/awesome-blockchains/blob/master/bitcoin_proof_of_work.rb/hashrate.rb

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--
Philip Rhoades

PO Box 896
Cowra NSW 2794
Australia
E-mail: phil@pricom.com.au

Hello,

> interested in doing something with Ruby and BTC

   FYI: Learn Me A Bitcoin [1] by Greg Walker is the ultimate (free)
in-depth resource
about learning bitcoin and the best - all (or almost all) sample code
snippets are in ruby [2].

  And from my humble self you might read / browse the two (free) ruby
guides / booklets
  titled:

  o Programming Blockchains Step-by-Step Book / Guide [3]
    Let's build blockchains from scratch (zero) step by step. Let's
start with crypto hashes ...

  o Programming Bitcoin Script Transaction (Crypto) Contracts Step-by-Step [4]
Let's start with building your own bitcoin stack machine from zero /
scratch and let's run your own bitcoin ops (operations)...

  Happy block chaining and (secure) crypto programming with ruby.
Cheers. Prost.

[1] https://learnmeabitcoin.com
[2] https://github.com/in3rsha/learnmeabitcoin-code
[3] https://github.com/openblockchains/programming-blockchains
[4] https://github.com/openblockchains/programming-bitcoin-script