Class: Cryptos::Connectors::Cli
- Inherits:
-
Object
- Object
- Cryptos::Connectors::Cli
- Defined in:
- lib/cryptos/connectors/cli.rb
Instance Attribute Summary collapse
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #generate(blocks: 1, run_mode: :system) ⇒ Object
- #generate_to_address(address, blocks: 101, run_mode: :system, verbose: false) ⇒ Object
- #get_block_count ⇒ Object
- #get_received_by_address(address) ⇒ Object
- #import_address(address, run_mode: :system) ⇒ Object
-
#initialize(program: 'bitcoin-cli', network: 'regtest', verbose: false) ⇒ Cli
constructor
A new instance of Cli.
- #list_unspent(address, run_mode: :inline) ⇒ Object
-
#run(args, run_mode: :system, debug: false) ⇒ Object
private.
- #send_raw_transaction(rawtx, run_mode: :system) ⇒ Object
- #test_raw_transaction(rawtx, run_mode: :inline) ⇒ Object
Constructor Details
#initialize(program: 'bitcoin-cli', network: 'regtest', verbose: false) ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 |
# File 'lib/cryptos/connectors/cli.rb', line 6 def initialize(program: 'bitcoin-cli', network: 'regtest', verbose: false) @program = program @network = network @verbose = verbose end |
Instance Attribute Details
#network ⇒ Object (readonly)
Returns the value of attribute network.
4 5 6 |
# File 'lib/cryptos/connectors/cli.rb', line 4 def network @network end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
4 5 6 |
# File 'lib/cryptos/connectors/cli.rb', line 4 def program @program end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/cryptos/connectors/cli.rb', line 4 def verbose @verbose end |
Instance Method Details
#generate(blocks: 1, run_mode: :system) ⇒ Object
20 21 22 |
# File 'lib/cryptos/connectors/cli.rb', line 20 def generate(blocks: 1, run_mode: :system) run "generate #{blocks}" end |
#generate_to_address(address, blocks: 101, run_mode: :system, verbose: false) ⇒ Object
16 17 18 |
# File 'lib/cryptos/connectors/cli.rb', line 16 def generate_to_address(address, blocks: 101, run_mode: :system, verbose: false) run "generatetoaddress #{blocks} #{address}" end |
#get_block_count ⇒ Object
36 37 38 |
# File 'lib/cryptos/connectors/cli.rb', line 36 def get_block_count run("getblockcount", run_mode: :inline).to_i end |
#get_received_by_address(address) ⇒ Object
40 41 42 43 |
# File 'lib/cryptos/connectors/cli.rb', line 40 def get_received_by_address(address) result = run "getreceivedbyaddress #{address}", run_mode: :inline result.strip end |
#import_address(address, run_mode: :system) ⇒ Object
12 13 14 |
# File 'lib/cryptos/connectors/cli.rb', line 12 def import_address(address, run_mode: :system) run "importaddress #{address} '' false", run_mode: run_mode end |
#list_unspent(address, run_mode: :inline) ⇒ Object
24 25 26 |
# File 'lib/cryptos/connectors/cli.rb', line 24 def list_unspent(address, run_mode: :inline) run "listunspent 1 9999 \"[\\\"#{address}\\\"]\"", run_mode: run_mode end |
#run(args, run_mode: :system, debug: false) ⇒ Object
private
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cryptos/connectors/cli.rb', line 47 def run(args, run_mode: :system, debug: false) cmd = "#{program} -#{network} #{args}" puts "==> #{cmd} run_mode=#{run_mode} verbose=#{debug}" if debug || verbose case run_mode when :inline output = `#{cmd}` puts output if debug || verbose output when :system success = system cmd, out: '/dev/null' fail "failed command: #{args}" unless success success when :daemon pid = spawn cmd sleep (ENV['BOOTSTRAP'] || 10).to_i pid else raise "dont know how to run #{run_mode}" end end |
#send_raw_transaction(rawtx, run_mode: :system) ⇒ Object
28 29 30 |
# File 'lib/cryptos/connectors/cli.rb', line 28 def send_raw_transaction(rawtx, run_mode: :system) run "sendrawtransaction #{rawtx}", run_mode: run_mode end |
#test_raw_transaction(rawtx, run_mode: :inline) ⇒ Object
32 33 34 |
# File 'lib/cryptos/connectors/cli.rb', line 32 def test_raw_transaction(rawtx, run_mode: :inline) run "testmempoolaccept '[\"#{rawtx}\"]'", run_mode: run_mode end |