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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 079da0f7d67f6bb68f4f44ae7315a667da1bf41e
4
- data.tar.gz: 2d140fa5de0cbdca0c8d9c8524493eb91938abcd
3
+ metadata.gz: 0bb8f400f6822621041fde468fade496e7910303
4
+ data.tar.gz: 9c285eb093357043ca2f6fe98e64d260d07f6cae
5
5
  SHA512:
6
- metadata.gz: e24f1a80a80b210c1429b8fe8a196f01a17abde7c1247f5cc99514f839a80e6b8b51d9f2d562496abeff508808a69a1583896d18ce3d0bc74abb675f01286c48
7
- data.tar.gz: 6fcebcb0c952a2e4df79208d1a0b1721d04e5294bd0393b63b8d52c6c3d1d68fb08a5dfdc44323c6b37ac9f877d698de8622352a7cb0b29fdcd91dcebdc25b1f
6
+ metadata.gz: cc1206a483949527575b38cec2ecb994ed001086a9431864a553571bb8a102f587b2c8491781f2a4ec87a226ce8e935564216cf3192f67193d4e40c7dbbc8cdb
7
+ data.tar.gz: 37db148af6e5c31304a59af2ed63c5e317cd0c54058ea7c268dc452ab20d3527c89ceb4745672b99217a3ff94c9c95c5f364a90f8b327cd065adde99e3f9c72c
@@ -1,3 +1,7 @@
1
+ # 0.1.0
2
+
3
+ - Generate address from master public key
4
+
1
5
  # 0.0.2
2
6
 
3
7
  - Allow overriding of `sx_path` when instantiating: `Rbsx.new(sx_path: "/sx/path")`
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 )
@@ -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 "rbsx/version"
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
- mattr_accessor :sx_path
7
+ CONFIG_ATTRS = %i[sx_path master_public_key]
8
+ mattr_accessor(*CONFIG_ATTRS)
10
9
 
11
- def self.new(sx_path: Rbsx.sx_path)
12
- Client.new(sx_path: sx_path)
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"
@@ -1,16 +1,22 @@
1
1
  module Rbsx
2
2
  class Client
3
3
 
4
- attr_accessor :sx_path
4
+ attr_accessor(*Rbsx::CONFIG_ATTRS)
5
5
 
6
- def initialize(sx_path: sx_path)
7
- self.sx_path = sx_path
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}`
@@ -1,3 +1,3 @@
1
1
  module Rbsx
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1 +1,3 @@
1
1
  sx_path: "/usr/local/bin/sx"
2
+ master_public_key: "mpkhere"
3
+ address_0: "address0here"
@@ -4,9 +4,11 @@ module Rbsx
4
4
  describe Client do
5
5
 
6
6
  describe "initialization" do
7
- it "accepts sx_path" do
8
- client = described_class.new(sx_path: "/path/to")
9
- expect(client.sx_path).to eq "/path/to"
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
@@ -12,29 +12,35 @@ describe Rbsx do
12
12
  end
13
13
  end
14
14
 
15
- describe ".sx_path" do
16
- it "is a setter/getter" do
17
- Rbsx.sx_path = "a"
18
- expect(Rbsx.sx_path).to eq "a"
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
- it "returns an instance of Client" do
24
- Rbsx.sx_path = "/sx/path"
25
- client = double(Rbsx::Client)
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).with(sx_path: "/sx/path").
29
+ allow(Rbsx::Client).to receive(:new).
30
+ with(hash_including(attr => "globalval")).
36
31
  and_return(client)
37
- expect(described_class.new(sx_path: "/sx/path")).to eq client
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
@@ -9,6 +9,7 @@ RSpec.configure do |c|
9
9
  c.before(:each) do
10
10
  Rbsx.configure do |config|
11
11
  config.sx_path = CONFIG.fetch(:sx_path)
12
+ config.master_public_key = CONFIG.fetch(:master_public_key)
12
13
  end
13
14
  end
14
15
 
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.2
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-09-28 00:00:00.000000000 Z
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: []