rbsx 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -1
- data/lib/rbsx.rb +13 -6
- data/lib/rbsx/client.rb +9 -3
- data/lib/rbsx/version.rb +1 -1
- data/spec/config.yml.sample +2 -0
- data/spec/rbsx/client_spec.rb +11 -3
- data/spec/rbsx_spec.rb +23 -17
- data/spec/spec_helper.rb +1 -0
- metadata +13 -13
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0bb8f400f6822621041fde468fade496e7910303
         | 
| 4 | 
            +
              data.tar.gz: 9c285eb093357043ca2f6fe98e64d260d07f6cae
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: cc1206a483949527575b38cec2ecb994ed001086a9431864a553571bb8a102f587b2c8491781f2a4ec87a226ce8e935564216cf3192f67193d4e40c7dbbc8cdb
         | 
| 7 | 
            +
              data.tar.gz: 37db148af6e5c31304a59af2ed63c5e317cd0c54058ea7c268dc452ab20d3527c89ceb4745672b99217a3ff94c9c95c5f364a90f8b327cd065adde99e3f9c72c
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -29,10 +29,16 @@ end | |
| 29 29 | 
             
            ```
         | 
| 30 30 |  | 
| 31 31 | 
             
            ```
         | 
| 32 | 
            -
            rbsx = Rbsx.new(sx_path: "/path/to_sx") # you can optionally set the path here too
         | 
| 32 | 
            +
            rbsx = Rbsx.new(sx_path: "/path/to_sx", other: "opts") # you can optionally set the path here too
         | 
| 33 33 | 
             
            rbsx.bci_fetch_last_height # 32132131
         | 
| 34 | 
            +
            rbsx.generate_address(3) # 3rd address based on `master_public_key`
         | 
| 34 35 | 
             
            ```
         | 
| 35 36 |  | 
| 37 | 
            +
            All the options:
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            - `sx_path`
         | 
| 40 | 
            +
            - `master_public_key`
         | 
| 41 | 
            +
             | 
| 36 42 | 
             
            ## Contributing
         | 
| 37 43 |  | 
| 38 44 | 
             
            1. Fork it ( https://github.com/[my-github-username]/rbsx/fork )
         | 
    
        data/lib/rbsx.rb
    CHANGED
    
    | @@ -1,15 +1,18 @@ | |
| 1 1 | 
             
            require "active_support/core_ext/module/attribute_accessors"
         | 
| 2 2 | 
             
            require "active_support/core_ext/hash/indifferent_access"
         | 
| 3 | 
            -
            require " | 
| 4 | 
            -
            require "rbsx/client"
         | 
| 5 | 
            -
            require "rbsx/exceptions"
         | 
| 3 | 
            +
            require "active_support/core_ext/hash/slice"
         | 
| 6 4 |  | 
| 7 5 | 
             
            module Rbsx
         | 
| 8 6 |  | 
| 9 | 
            -
               | 
| 7 | 
            +
              CONFIG_ATTRS = %i[sx_path master_public_key]
         | 
| 8 | 
            +
              mattr_accessor(*CONFIG_ATTRS)
         | 
| 10 9 |  | 
| 11 | 
            -
              def self.new( | 
| 12 | 
            -
                 | 
| 10 | 
            +
              def self.new(args={})
         | 
| 11 | 
            +
                config = CONFIG_ATTRS.inject({}) do |hash, config_attr|
         | 
| 12 | 
            +
                  hash[config_attr] = args[config_attr] || Rbsx.send(config_attr)
         | 
| 13 | 
            +
                  hash
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
                Client.new(config)
         | 
| 13 16 | 
             
              end
         | 
| 14 17 |  | 
| 15 18 | 
             
              def self.configure(&block)
         | 
| @@ -17,3 +20,7 @@ module Rbsx | |
| 17 20 | 
             
              end
         | 
| 18 21 |  | 
| 19 22 | 
             
            end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            require "rbsx/version"
         | 
| 25 | 
            +
            require "rbsx/client"
         | 
| 26 | 
            +
            require "rbsx/exceptions"
         | 
    
        data/lib/rbsx/client.rb
    CHANGED
    
    | @@ -1,16 +1,22 @@ | |
| 1 1 | 
             
            module Rbsx
         | 
| 2 2 | 
             
              class Client
         | 
| 3 3 |  | 
| 4 | 
            -
                attr_accessor | 
| 4 | 
            +
                attr_accessor(*Rbsx::CONFIG_ATTRS)
         | 
| 5 5 |  | 
| 6 | 
            -
                def initialize( | 
| 7 | 
            -
                   | 
| 6 | 
            +
                def initialize(config={})
         | 
| 7 | 
            +
                  Rbsx::CONFIG_ATTRS.each do |attr|
         | 
| 8 | 
            +
                    self.send :"#{attr}=", config[attr]
         | 
| 9 | 
            +
                  end
         | 
| 8 10 | 
             
                end
         | 
| 9 11 |  | 
| 10 12 | 
             
                def bci_fetch_last_height
         | 
| 11 13 | 
             
                  sx("bci-fetch-last-height").to_i
         | 
| 12 14 | 
             
                end
         | 
| 13 15 |  | 
| 16 | 
            +
                def generate_address(n)
         | 
| 17 | 
            +
                  sx("echo #{master_public_key} | sx genaddr #{n}").chomp
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 14 20 | 
             
                def sx(command)
         | 
| 15 21 | 
             
                  full_command = [sx_path, command].join(" ")
         | 
| 16 22 | 
             
                  `#{full_command}`
         | 
    
        data/lib/rbsx/version.rb
    CHANGED
    
    
    
        data/spec/config.yml.sample
    CHANGED
    
    
    
        data/spec/rbsx/client_spec.rb
    CHANGED
    
    | @@ -4,9 +4,11 @@ module Rbsx | |
| 4 4 | 
             
              describe Client do
         | 
| 5 5 |  | 
| 6 6 | 
             
                describe "initialization" do
         | 
| 7 | 
            -
                   | 
| 8 | 
            -
                     | 
| 9 | 
            -
             | 
| 7 | 
            +
                  Rbsx::CONFIG_ATTRS.each do |attr|
         | 
| 8 | 
            +
                    it "accepts #{attr}" do
         | 
| 9 | 
            +
                      client = described_class.new(attr => "localval")
         | 
| 10 | 
            +
                      expect(client.send(attr)).to eq "localval"
         | 
| 11 | 
            +
                    end
         | 
| 10 12 | 
             
                  end
         | 
| 11 13 | 
             
                end
         | 
| 12 14 |  | 
| @@ -40,6 +42,12 @@ module Rbsx | |
| 40 42 | 
             
                  end
         | 
| 41 43 | 
             
                end
         | 
| 42 44 |  | 
| 45 | 
            +
                describe "#generate_address" do
         | 
| 46 | 
            +
                  it "generates an address based on the master public key" do
         | 
| 47 | 
            +
                    client = described_class.new(CONFIG.slice(:master_public_key))
         | 
| 48 | 
            +
                    expect(client.generate_address(0)).to eq CONFIG[:address_0]
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 43 51 |  | 
| 44 52 | 
             
              end
         | 
| 45 53 | 
             
            end
         | 
    
        data/spec/rbsx_spec.rb
    CHANGED
    
    | @@ -12,29 +12,35 @@ describe Rbsx do | |
| 12 12 | 
             
                end
         | 
| 13 13 | 
             
              end
         | 
| 14 14 |  | 
| 15 | 
            -
               | 
| 16 | 
            -
                 | 
| 17 | 
            -
                   | 
| 18 | 
            -
             | 
| 15 | 
            +
              described_class::CONFIG_ATTRS.each do |attr|
         | 
| 16 | 
            +
                describe ".#{attr}" do
         | 
| 17 | 
            +
                  it "is a setter/getter" do
         | 
| 18 | 
            +
                    Rbsx.send :"#{attr}=", "a"
         | 
| 19 | 
            +
                    expect(Rbsx.send(attr)).to eq "a"
         | 
| 20 | 
            +
                  end
         | 
| 19 21 | 
             
                end
         | 
| 20 22 | 
             
              end
         | 
| 21 23 |  | 
| 22 24 | 
             
              describe ".new" do
         | 
| 23 | 
            -
                 | 
| 24 | 
            -
                   | 
| 25 | 
            -
             | 
| 26 | 
            -
                  allow(Rbsx::Client).to receive(:new).with(sx_path: "/sx/path").
         | 
| 27 | 
            -
                    and_return(client)
         | 
| 28 | 
            -
                  expect(described_class.new).to eq client
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                context "sx_path is given" do
         | 
| 32 | 
            -
                  it "overrides the default" do
         | 
| 33 | 
            -
                    Rbsx.sx_path = "/old/sx"
         | 
| 25 | 
            +
                described_class::CONFIG_ATTRS.each do |attr|
         | 
| 26 | 
            +
                  it "returns an instance of Client" do
         | 
| 27 | 
            +
                    Rbsx.send :"#{attr}=", "globalval"
         | 
| 34 28 | 
             
                    client = double(Rbsx::Client)
         | 
| 35 | 
            -
                    allow(Rbsx::Client).to receive(:new). | 
| 29 | 
            +
                    allow(Rbsx::Client).to receive(:new).
         | 
| 30 | 
            +
                      with(hash_including(attr => "globalval")).
         | 
| 36 31 | 
             
                      and_return(client)
         | 
| 37 | 
            -
                    expect(described_class.new | 
| 32 | 
            +
                    expect(described_class.new).to eq client
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  context "#{attr} is given" do
         | 
| 36 | 
            +
                    it "overrides the default" do
         | 
| 37 | 
            +
                      Rbsx.sx_path = "globalval"
         | 
| 38 | 
            +
                      client = double(Rbsx::Client)
         | 
| 39 | 
            +
                      allow(Rbsx::Client).to receive(:new).
         | 
| 40 | 
            +
                        with(hash_including(attr => "localval")).
         | 
| 41 | 
            +
                        and_return(client)
         | 
| 42 | 
            +
                      expect(described_class.new(attr => "localval")).to eq client
         | 
| 43 | 
            +
                    end
         | 
| 38 44 | 
             
                  end
         | 
| 39 45 | 
             
                end
         | 
| 40 46 | 
             
              end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,69 +1,69 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rbsx
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ramon Tayag
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-11-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '0'
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 24 | 
            +
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '0'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: bundler
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - ~>
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '1.6'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - - ~>
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '1.6'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: rake
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: '0'
         | 
| 48 48 | 
             
              type: :development
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '0'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: rspec
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - -  | 
| 59 | 
            +
                - - ">="
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 61 | 
             
                    version: '0'
         | 
| 62 62 | 
             
              type: :development
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - -  | 
| 66 | 
            +
                - - ">="
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '0'
         | 
| 69 69 | 
             
            description: Wrapper for sx Bitcoin command line utilities
         | 
| @@ -73,7 +73,7 @@ executables: [] | |
| 73 73 | 
             
            extensions: []
         | 
| 74 74 | 
             
            extra_rdoc_files: []
         | 
| 75 75 | 
             
            files:
         | 
| 76 | 
            -
            - .gitignore
         | 
| 76 | 
            +
            - ".gitignore"
         | 
| 77 77 | 
             
            - CHANGELOG.md
         | 
| 78 78 | 
             
            - Gemfile
         | 
| 79 79 | 
             
            - LICENSE.txt
         | 
| @@ -98,12 +98,12 @@ require_paths: | |
| 98 98 | 
             
            - lib
         | 
| 99 99 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 100 100 | 
             
              requirements:
         | 
| 101 | 
            -
              - -  | 
| 101 | 
            +
              - - ">="
         | 
| 102 102 | 
             
                - !ruby/object:Gem::Version
         | 
| 103 103 | 
             
                  version: '0'
         | 
| 104 104 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 105 105 | 
             
              requirements:
         | 
| 106 | 
            -
              - -  | 
| 106 | 
            +
              - - ">="
         | 
| 107 107 | 
             
                - !ruby/object:Gem::Version
         | 
| 108 108 | 
             
                  version: '0'
         | 
| 109 109 | 
             
            requirements: []
         |