Sha256: d0d45ac60be63d78125fa8de4bb3c0fc0e2b5d584fcd9962c77fbe01def70ce9

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

#!/usr/bin/env ruby
require 'thor'
require 'bitcoin'
require 'bitcoin/nodes/spv/daemon'

class Bitcoinrbd < Thor

  option :mode, default: 'spv'
  option :network, default: 'mainnet'
  desc 'start', 'start bitcoinrbd daemon process'
  def start
    raise ArgumentError, 'currently only support spv mode.' unless options[:mode] == 'spv'
    execute_daemon(setup_base_dir(options[:network]), ['start'])
  end

  option :mode, default: 'spv'
  option :network, default: 'mainnet'
  desc 'stop', 'start bitcoinrbd daemon process'
  def stop
    execute_daemon(setup_base_dir(options[:network]), ['stop'])
  end

  def execute_daemon(base_dir, cmd_args)
    Bitcoin::Nodes::SPV::Daemon.spawn!({working_dir: base_dir,
                                     log_file: "#{base_dir}/bitcoinrbd.log",
                                     pid_file: "#{base_dir}/bitcoinrbd.pid",
                                     sync_log: true,
                                     singleton: true}, cmd_args)
  end

  private

  def setup_base_dir(network)
    case network
    when 'mainnet'
      base_dir = Bitcoin.base_dir
    when 'testnet'
      base_dir = "#{Bitcoin.base_dir}/testnet3"
    when 'regtest'
      base_dir = "#{Bitcoin.base_dir}/regtest"
    else
      raise ArgumentError, 'Unsupported network specified.'
    end
    FileUtils.mkdir_p(base_dir)
    base_dir
  end
end

Bitcoinrbd.start(ARGV)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bitcoinrb-0.1.1 exe/bitcoinrbd
bitcoinrb-0.0.1 exe/bitcoinrbd