Module: Bitcoin

Extended by:
Util
Included in:
Network::ConnectionHandler, Wallet::Wallet
Defined in:
lib/bitcoin/contracthash.rb,
lib/bitcoin.rb,
lib/bitcoin/key.rb,
lib/bitcoin/config.rb,
lib/bitcoin/version.rb,
lib/bitcoin/builder.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/txout.rb,
lib/bitcoin/protocol/block.rb,
lib/bitcoin/protocol/alert.rb,
lib/bitcoin/protocol/parser.rb,
lib/bitcoin/protocol/address.rb,
lib/bitcoin/protocol/version.rb,
lib/bitcoin/protocol/handler.rb,
lib/bitcoin/protocol/aux_pow.rb,
lib/bitcoin/logger.rb

Overview

Defined Under Namespace

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

Constant Summary

VERSION =
"0.0.6"
P =
Protocol
MAX_BLOCK_SIZE =

maximum size of a block (in bytes)

1_000_000
MAX_BLOCK_SIZE_GEN =

soft limit for new blocks

MAX_BLOCK_SIZE/2
MAX_BLOCK_SIGOPS =

maximum number of signature operations in a block

MAX_BLOCK_SIZE / 50
MAX_ORPHAN_TRANSACTIONS =

maximum number of orphan transactions to be kept in memory

MAX_BLOCK_SIZE/100
LOCKTIME_THRESHOLD =

Threshold for lock_time: below this value it is interpreted as block number, otherwise as UNIX timestamp.

500000000
UINT32_MAX =

maximum integer value

0xffffffff
INT_MAX =

deprecated name, left here for compatibility with existing users.

0xffffffff
COINBASE_MATURITY =

number of confirmations required before coinbase tx can be spent

100
RETARGET_INTERVAL =

interval (in blocks) for difficulty retarget

2016
RETARGET =

deprecated constant

2016
REWARD_DROP =

interval (in blocks) for mining reward reduction

210_000
CENT =
1_000_000
COIN =
100_000_000
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,
    reward_base: 50 * COIN,
    reward_halving: 210_000,
    retarget_interval: 2016,
    retarget_time: 1209600, # 2 weeks
    target_spacing: 600, # block interval
    max_money: 21_000_000 * COIN,
    min_tx_fee: 10_000,
    min_relay_tx_fee: 10_000,
    free_tx_bytes: 1_000,
    dust: CENT,
    per_dust_fee: false,
    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",
      290000 => "0000000000000000fa0b2badd05db0178623ebf8dd081fe7eb874c26e27d0b3b",
      300000 => "000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254",
      305000 => "0000000000000000142bb90561e1a907d500bf534a6727a63a92af5b6abc6160",
    }
  }
}

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_new_target, block_next_retarget, block_probability, block_scrypt_hash, 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, litecoin_hash, mrkl_branch_root, open_key, p2sh_version, pubkey_to_address, pubkeys_to_p2sh_multisig_address, regenerate_public_key, sha256, sign_data, sign_message, valid_address?, valid_pubkey?, verify_message, verify_signature

Class Method Details

.networkObject



490
491
492
493
# File 'lib/bitcoin.rb', line 490

def self.network
  # Store the copy of network options so we can modify them in tests without breaking the defaults
  @network_options ||= NETWORKS[@network].dup
end

.network=(name) ⇒ Object



503
504
505
506
507
508
509
510
511
# File 'lib/bitcoin.rb', line 503

def self.network=(name)
  raise "Network descriptor '#{name}' not found."  unless NETWORKS[name.to_sym]
  @network_options = nil # clear cached parameters
  @network = name.to_sym
  @network_project = network[:project] rescue nil
  Dogecoin.load  if dogecoin? || dogecoin_testnet?
  Namecoin.load  if namecoin?
  @network
end

.network_nameObject



495
496
497
# File 'lib/bitcoin.rb', line 495

def self.network_name
  @network
end

.network_projectObject



499
500
501
# File 'lib/bitcoin.rb', line 499

def self.network_project
  @network_project
end

.require_dependency(name, opts = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bitcoin.rb', line 50

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