Module: Bitcoin

Extended by:
Util
Included in:
Network::ConnectionHandler, Wallet::Wallet
Defined in:
lib/bitcoin.rb,
lib/bitcoin/key.rb,
lib/bitcoin/config.rb,
lib/bitcoin/builder.rb,
lib/bitcoin/version.rb,
lib/bitcoin/protocol.rb,
lib/bitcoin/connection.rb,
lib/bitcoin/protocol/tx.rb,
lib/bitcoin/ffi/openssl.rb,
lib/bitcoin/protocol/txin.rb,
lib/bitcoin/protocol/block.rb,
lib/bitcoin/protocol/txout.rb,
lib/bitcoin/protocol/alert.rb,
lib/bitcoin/protocol/parser.rb,
lib/bitcoin/protocol/version.rb,
lib/bitcoin/protocol/handler.rb,
lib/bitcoin/protocol/aux_pow.rb,
lib/bitcoin/protocol/address.rb,
lib/bitcoin/logger.rb

Defined Under Namespace

Modules: BinaryExtensions, Builder, Config, ConnectionHandler, Gui, Logger, Namecoin, Network, OpenSSL_EC, Protocol, Storage, Util, Validation, Wallet Classes: Connection, Key, Script

Constant Summary

VERSION =
"0.0.4"
P =
Protocol
CENT =
1_000_000
COIN =
100_000_000
MAX_BLOCK_SIZE =
1_000_000
MAX_BLOCK_SIZE_GEN =
MAX_BLOCK_SIZE/2
MAX_BLOCK_SIGOPS =
MAX_BLOCK_SIZE/50
MAX_ORPHAN_TRANSACTIONS =
MAX_BLOCK_SIZE/100
MIN_FEE_MODE =
[ :block, :relay, :send ]
NETWORKS =
{

  :bitcoin => {
    :project => :bitcoin,
    :magic_head => "\xF9\xBE\xB4\xD9",
    :address_version => "00",
    :p2sh_version => "05",
    :privkey_version => "80",
    :default_port => 8333,
    :protocol_version => 70001,
    :coinbase_maturity => 100,
    :retarget_interval => 2016,
    :retarget_time => 1209600, # 2 weeks
    :max_money => 21_000_000 * COIN,
    :min_tx_fee => 10_000,
    :min_relay_tx_fee => 10_000,
    :dns_seeds => [
      "seed.bitcoin.sipa.be",
      "dnsseed.bluematt.me",
      "dnsseed.bitcoin.dashjr.org",
      "bitseed.xf2.org",
    ],
    :genesis_hash => "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
    :proof_of_work_limit => 0x1d00ffff,
    :alert_pubkeys => ["04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"],
    :known_nodes => [
      'relay.eligius.st',
      'mining.bitcoin.cz',
      'blockchain.info',
      'blockexplorer.com',
    ],
    :checkpoints => {
       11111 => "0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d",
       33333 => "000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6",
       74000 => "0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20",
      105000 => "00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97",
      134444 => "00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe",
      168000 => "000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763",
      193000 => "000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317",
      210000 => "000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e",
      216116 => "00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e",
      225430 => "00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932",
    }
  },

  :testnet => {
    :project => :bitcoin,
    :magic_head => "\xFA\xBF\xB5\xDA",
    :address_version => "6f",
    :p2sh_version => "c4",
    :privkey_version => "ef",
    :default_port => 18333,
    :max_money => 21_000_000 * COIN,
    :dns_seeds => [ "testseed.bitcoin.interesthings.de" ],
    :genesis_hash => "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008",
    :proof_of_work_limit => 0x1d07fff8,
    :alert_pubkeys => ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"],
    :known_nodes => [],
    :checkpoints => {},
    :coinbase_maturity => 100,
    :retarget_interval => 2016,
    :retarget_time => 1209600, # 2 weeks
    :max_money => 21_000_000 * COIN,
    :min_tx_fee => 10_000,
    :min_relay_tx_fee => 10_000,
  },

  :testnet3 => {
    :project => :bitcoin,
    :magic_head => "\x0b\x11\x09\x07",
    :address_version => "6f",
    :p2sh_version => "c4",
    :privkey_version => "ef",
    :default_port => 18333,
    :protocol_version => 70001,
    :coinbase_maturity => 100,
    :retarget_interval => 2016,
    :retarget_time => 1209600, # 2 weeks
    :max_money => 21_000_000 * COIN,
    :min_tx_fee => 10_000,
    :min_relay_tx_fee => 10_000,
    :dns_seeds => [
      "testnet-seed.bitcoin.petertodd.org",
      "testnet-seed.bluematt.me",
    ],
    :genesis_hash => "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
    :proof_of_work_limit => 0x1d07fff8,
    :alert_pubkeys => ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"],
    :known_nodes => [],
    :checkpoints => {
      # 542 contains invalid transaction
      542 => "0000000083c1f82cf72c6724f7a317325806384b06408bce7a4327f418dfd5ad",
      71018 => "000000000010dd93dc55541116b2744eb8f4c3b706df6e8512d231a03fb9e435",
    }
  },

  :litecoin => {
    :project => :litecoin,
    :magic_head => "\xfb\xc0\xb6\xdb",
    :address_version => "30",
    :p2sh_version => "05",
    :privkey_version => "b0",
    :default_port => 9333,
    :protocol_version => 60002,
    :max_money => 84_000_000 * COIN,
    :min_tx_fee => 2_000_000,
    :coinbase_maturity => 100,
    :retarget_interval => 2016,
    :retarget_time => 302400, # 3.5 days
    :min_relay_tx_fee => 1_000_000,
    :dns_seeds => [
      "dnsseed.litecointools.com",
      "dnsseed.litecoinpool.org",
      "dnsseed.ltc.xurious.com",
      "dnsseed.koin-project.com",
      "dnsseed.weminemnc.com",
    ],
    :genesis_hash => "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",
    :proof_of_work_limit => 0,
    :alert_pubkeys => [],
    :known_nodes => [],
    :checkpoints => {
           1 => "80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f",
           2 => "13957807cdd1d02f993909fa59510e318763f99a506c4c426e3b254af09f40d7",
        1500 => "841a2965955dd288cfa707a755d05a54e45f8bd476835ec9af4402a2b59a2967",
        4032 => "9ce90e427198fc0ef05e5905ce3503725b80e26afd35a987965fd7e3d9cf0846",
        8064 => "eb984353fc5190f210651f150c40b8a4bab9eeeff0b729fcb3987da694430d70",
       16128 => "602edf1859b7f9a6af809f1d9b0e6cb66fdc1d4d9dcd7a4bec03e12a1ccd153d",
       23420 => "d80fdf9ca81afd0bd2b2a90ac3a9fe547da58f2530ec874e978fce0b5101b507",
       50000 => "69dc37eb029b68f075a5012dcc0419c127672adb4f3a32882b2b3e71d07a20a6",
       80000 => "4fcb7c02f676a300503f49c764a89955a8f920b46a8cbecb4867182ecdb2e90a",
      120000 => "bd9d26924f05f6daa7f0155f32828ec89e8e29cee9e7121b026a7a3552ac6131",
      161500 => "dbe89880474f4bb4f75c227c77ba1cdc024991123b28b8418dbbf7798471ff43",
      179620 => "2ad9c65c990ac00426d18e446e0fd7be2ffa69e9a7dcb28358a50b2b78b9f709",
      240000 => "7140d1c4b4c2157ca217ee7636f24c9c73db39c4590c4e6eab2e3ea1555088aa",
      383640 => "2b6809f094a9215bafc65eb3f110a35127a34be94b7d0590a096c3f126c6f364",
    }
  },

  :litecoin_testnet => {
    :project => :litecoin,
    :magic_head => "\xfc\xc1\xb7\xdc",
    :address_version => "6f",
    :p2sh_version => "c4",
    :privkey_version => "ef",
    :default_port => 19333,
    :protocol_version => 60002,
    :min_tx_fee => 2_000_000,
    :min_relay_tx_fee => 1_000_000,
    :coinbase_maturity => 100,
    :retarget_interval => 2016,
    :retarget_time => 302400, # 3.5 days
    :max_money => 84_000_000 * COIN,
    :dns_seeds => [
      "testnet-seed.litecointools.com",
      "testnet-seed.weminemnc.com",
    ],
    :genesis_hash => "f5ae71e26c74beacc88382716aced69cddf3dffff24f384e1808905e0188f68f",
    :proof_of_work_limit => 0,
    :alert_pubkeys => [],
    :known_nodes => [],
    :checkpoints => {}
  },


  :freicoin => {
    :project => :freicoin,
    :magic_head => "\x2c\xfe\x7e\x6d",
    :address_version => "00",
    :p2sh_version => "05",
    :privkey_version => "80",
    :default_port => 8639,
    :protocol_version => 60002,
    :max_money => 21_000_000 * COIN,
    :min_tx_fee => 50_000,
    :min_relay_tx_fee => 10_000,
    :dns_seeds => [ "seed.freico.in", "fledge.freico.in" ],
    :genesis_hash => "000000005b1e3d23ecfd2dd4a6e1a35238aa0392c0a8528c40df52376d7efe2c",
    :proof_of_work_limit => 0,
    :alert_pubkeys => [],
    :known_nodes => [],
    :checkpoints => {
      10080 => "00000000003ff9c4b806639ec4376cc9acafcdded0e18e9dbcc2fc42e8e72331",
      15779 => "000000000003eb31742b35f5efd8ffb5cdd19dcd8e82cdaad90e592c450363b6",
    }
  },

  :namecoin => {
    :project => :namecoin,
    :magic_head => "\xF9\xBE\xB4\xFE",
    :address_version => "34",
    :default_port => 8334,
    :protocol_version => 35000,
    :max_money => 21_000_000 * COIN,
    :min_tx_fee => 50_000,
    :min_relay_tx_fee => 10_000,
    :dns_seeds => [],
    :genesis_hash => "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770",
    :proof_of_work_limit => 0x1d00ffff,
    :known_nodes => ["bitcoin.tunl.in", "webbtc.com", "178.32.31.41",
                    "78.47.86.43", "69.164.206.88", ""],
    :checkpoints => {
      0 => "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770",
      19200 => "d8a7c3e01e1e95bcee015e6fcc7583a2ca60b79e5a3aa0a171eddd344ada903d",
      24000 => "425ab0983cf04f43f346a4ca53049d0dc2db952c0a68eb0b55c3bb64108d5371",
      97778 => "7553b1e43da01cfcda4335de1caf623e941d43894bd81c2af27b6582f9d83c6f",
    }
  },

  :namecoin_testnet => {
    :project => :namecoin,
    :magic_head => "\xFA\xBF\xB5\xFE",
    :address_version => "34",
    :default_port => 18334,
    :protocol_version => 35000,
    :min_tx_fee => 50_000,
    :min_relay_tx_fee => 10_000,
    :max_money => 21_000_000 * COIN,
    :dns_seeds => [],
    :genesis_hash => "00000001f8ab0d14bceaeb50d163b0bef15aecf62b87bd5f5c864d37f201db97",
    :proof_of_work_limit => 0x1d00ffff,
    :known_nodes => ["178.32.31.41"],
    :checkpoints => {
      0 => "000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770",

    }
  },
}

Constants included from Util

Util::RETARGET_INTERVAL

Class Method Summary (collapse)

Methods included from Util

address_type, address_version, base58_checksum?, base58_to_int, bitcoin_byte_hash, bitcoin_elliptic_curve, bitcoin_hash, bitcoin_mrkl, bitcoin_signed_message_hash, block_average_hashing_time, block_average_mining_time, block_creation_reward, block_difficulty, block_hash, block_hashes_to_win, block_next_retarget, block_probability, blockchain_total_btc, checksum, decode_base58, decode_compact_bits, decode_target, encode_address, encode_base58, encode_compact_bits, generate_address, generate_key, hash160, hash160_from_address, hash160_to_address, hash160_to_p2sh_address, hash_mrkl_branch, hash_mrkl_tree, inspect_key, int_to_base58, mrkl_branch_root, open_key, p2sh_version, pubkey_to_address, regenerate_public_key, sha256, sign_data, sign_message, valid_address?, verify_message, verify_signature

Class Method Details

+ (Object) network



411
412
413
# File 'lib/bitcoin.rb', line 411

def self.network
  NETWORKS[@network]
end

+ (Object) network=(name)



423
424
425
426
427
428
429
# File 'lib/bitcoin.rb', line 423

def self.network= name
  raise "Network descriptor '#{name}' not found."  unless NETWORKS[name.to_sym]
  @network = name.to_sym
  @network_project = network[:project] rescue nil
  Bitcoin::Namecoin.load  if namecoin?
  @network
end

+ (Object) network_name



415
416
417
# File 'lib/bitcoin.rb', line 415

def self.network_name
  @network
end

+ (Object) network_project



419
420
421
# File 'lib/bitcoin.rb', line 419

def self.network_project
  @network_project
end

+ (Object) require_dependency(name, opts = {})



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bitcoin.rb', line 46

def self.require_dependency name, opts = {}
  begin
    require name.to_s
  rescue LoadError
    return false if name.to_s == "log4r"
    print "Cannot load #{opts[:exit] == false ? 'optional' : 'required'} dependency '#{name}'"
    (opts[:gem] == false) ? puts("") :
      puts(" - install with `gem install #{opts[:gem] || name}`")
    puts opts[:message]  if opts[:message]
    exit 1  unless opts[:exit] == false
    return false
  end
  true
end