hyperledger_cli 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d6b42ce90eacccb6414235200c7751ab5011f54
4
+ data.tar.gz: ce4b4c9d8dd46862393e68b604eeaf716ffd9219
5
+ SHA512:
6
+ metadata.gz: e8096533978aaf156a137130fb7b8eae618004c7825c5469ecbce3641186afd4c0678fb2acc43e01246aa9ef28f0d8e88db7f7f1c33d3859c7676bfc257c6350
7
+ data.tar.gz: e6d91278ce36c457757b20bec6c1b3f4cd9593229b605835e937b640b5e7e6fd702bb8bd31698e08b50235552dad110d38551c41474e6c735c04e540fb8d7615
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hyperledger_cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Feichtinger
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # HyperledgerCli
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hyperledger_cli'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hyperledger_cli
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/hyperledger_cli/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/hyperledger ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'fileutils'
5
+ require 'openssl'
6
+ require 'rest_client'
7
+ require 'base64'
8
+ require 'json'
9
+
10
+ module ErrorPrinter
11
+ def print_error(err)
12
+ puts 'There seems to have been a problem... :-/'
13
+ puts "Error: #{err}"
14
+ errors = JSON.parse(err.response, symbolize_names: true)[:errors]
15
+ if errors
16
+ errors.each do |k, v| puts "#{k}:\t#{v.join(', ')}" end
17
+ end
18
+ end
19
+ end
20
+
21
+ class Ledger < Thor
22
+ include ErrorPrinter
23
+
24
+ desc 'list', 'List all known ledgers'
25
+ def list
26
+ response = RestClient.get "#{options[:server]}/currencies", content_type: :json
27
+ data = JSON.parse(response.body, symbolize_names: true)
28
+ data[:currencies].each do |c| puts c[:name] end
29
+ end
30
+
31
+ desc 'register <name> <url>', 'Registers a new ledger. The name must be unique, and the URL should contain more information about the ledger.'
32
+ def register(name, url)
33
+ key = OpenSSL::PKey::RSA.new 2048
34
+ data = { public_key: key.public_key.to_pem, name: name, url: url }
35
+
36
+ begin
37
+ response = RestClient.post "#{options[:server]}/currencies", data, content_type: :json
38
+ currency = JSON.parse(response.body, symbolize_names: true)[:currency]
39
+ puts 'New ledger created'
40
+ puts "name:\t#{currency[:name]}"
41
+ puts "url:\t#{currency[:url]}"
42
+ puts "primary account code:\t#{currency[:primary_account][:code]}"
43
+
44
+ # Write key
45
+ FileUtils.mkdir_p "#{ENV['HOME']}/.mintet"
46
+ open "#{ENV['HOME']}/.mintet/#{currency[:primary_account][:code]}.pem", 'w' do |io| io.write key.to_pem end
47
+ open "#{ENV['HOME']}/.mintet/#{name}.pem", 'w' do |io| io.write key.to_pem end
48
+ rescue => e
49
+ print_error(e)
50
+ end
51
+ end
52
+ end
53
+
54
+ class Account < Thor
55
+ include ErrorPrinter
56
+
57
+ desc 'list', 'List all known accounts'
58
+ def list
59
+ response = RestClient.get "#{options[:server]}/accounts", content_type: :json
60
+ data = JSON.parse(response.body, symbolize_names: true)
61
+ data[:accounts].each do |a|
62
+ a.each do |k, v|
63
+ puts "#{k}:\t#{v}"
64
+ end
65
+ puts "\n"
66
+ end
67
+ end
68
+
69
+ desc 'register <ledger>', 'Registers a new account in <ledger>.'
70
+ def register(currency)
71
+ key = OpenSSL::PKey::RSA.new 2048
72
+ data = { public_key: key.public_key.to_pem, currency: currency }
73
+
74
+ begin
75
+ resp = RestClient.post "#{options.server}/accounts", data, content_type: :json
76
+ account = JSON.parse(resp.body, symbolize_names: true)[:account]
77
+ puts 'New account created'
78
+ puts "code:\t\t#{account[:code]}"
79
+ puts "balance:\t#{account[:balance]}"
80
+
81
+ # Write key
82
+ FileUtils.mkdir_p "#{ENV['HOME']}/.mintet"
83
+ open "#{ENV['HOME']}/.mintet/#{account[:code]}.pem", 'w' do |io| io.write key.to_pem end
84
+ rescue => e
85
+ print_error(e)
86
+ end
87
+ end
88
+ end
89
+
90
+ class Hyperledger < Thor
91
+ include ErrorPrinter
92
+
93
+ class_option :server, type: :string, default: 'http://still-depths-9447.herokuapp.com'
94
+
95
+ desc 'ledger SUBCOMMAND', 'Subcommands relating to ledgers.'
96
+ subcommand 'ledger', Ledger
97
+
98
+ desc 'account SUBCOMMAND', 'Subcommands relating to accounts.'
99
+ subcommand 'account', Account
100
+
101
+ desc 'issue <amount> <ledger>', 'Issue <amount> new units to <ledger>.'
102
+ def issue(amount, currency)
103
+ data = { currency: currency, amount: amount }
104
+
105
+ key = OpenSSL::PKey::RSA.new File.read("#{ENV['HOME']}/.mintet/#{currency.downcase}.pem")
106
+ sign = Base64.encode64 key.sign(OpenSSL::Digest::SHA256.new, data.to_json)
107
+
108
+ begin
109
+ resp = RestClient.post "#{options[:server]}/issues", { issue: data, signature: sign }, content_type: :json
110
+ puts "#{amount} new units issued to #{ledger}"
111
+ rescue => e
112
+ print_error(e)
113
+ end
114
+ end
115
+
116
+ desc 'transfer <amount> <source> <destination>', 'Transfer <amount> of units from <source> to <destination>'
117
+ def transfer(amount, source, destination)
118
+ key = OpenSSL::PKey::RSA.new File.read("#{ENV['HOME']}/.mintet/#{source}.pem")
119
+
120
+ data = { source: source, destination: destination, amount: amount }
121
+ sign = Base64.encode64 key.sign(OpenSSL::Digest::SHA256.new, data.to_json)
122
+
123
+ begin
124
+ resp = RestClient.post "#{options.server}/transfers", { transfer: data, signature: sign }, content_type: :json
125
+ puts 'Transfer completed!'
126
+ rescue => e
127
+ print_error(e)
128
+ end
129
+ end
130
+ end
131
+
132
+ Hyperledger.start(ARGV)
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hyperledger_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hyperledger_cli"
8
+ spec.version = HyperledgerCli::VERSION
9
+ spec.authors = ["Daniel Feichtinger"]
10
+ spec.email = ["df@hyperledger.org"]
11
+ spec.summary = "A sample CLI for the Hyperledger protocol."
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 10.3"
21
+ spec.add_runtime_dependency "rest_client", "~> 1.7"
22
+ spec.add_runtime_dependency "thor", "~> 0.19"
23
+ end
@@ -0,0 +1,4 @@
1
+ require "hyperledger_cli/version"
2
+
3
+ module HyperledgerCli
4
+ end
@@ -0,0 +1,3 @@
1
+ module HyperledgerCli
2
+ VERSION = "0.0.5"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyperledger_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Feichtinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest_client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ description:
70
+ email:
71
+ - df@hyperledger.org
72
+ executables:
73
+ - hyperledger
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/hyperledger
83
+ - hyperledger_cli.gemspec
84
+ - lib/hyperledger_cli.rb
85
+ - lib/hyperledger_cli/version.rb
86
+ homepage:
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A sample CLI for the Hyperledger protocol.
110
+ test_files: []