lisk 0.2.0

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: 5ae0ec3ce26db828b0aae312d3caaa44a0c4dce7
4
+ data.tar.gz: ea7aab7e631ce1324b4be92fd364392c7dbc1b5c
5
+ SHA512:
6
+ metadata.gz: 1602e278569adf67a0219260721333fd93218c4d8249f5c076647bf6719353f6a1e1004708f40c7ffff64a1138efbc696e750d8b798716f7123c2de95a1f1469
7
+ data.tar.gz: ce32d974e5623ca732af30f88813ca5734c6e01be2097cf9791386f9b67321c856d6e7a06220a248be6e544090858e7c731598aba7966d1097f5e8bc444ac221
data/.gitignore ADDED
@@ -0,0 +1,64 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # bundle
53
+ /.bundle/
54
+ /.yardoc
55
+ /Gemfile.lock
56
+ /_yardoc/
57
+ /coverage/
58
+ /doc/
59
+ /pkg/
60
+ /spec/reports/
61
+ /tmp/
62
+
63
+ # rspec failure tracking
64
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 4fryn@users.noreply.github.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in lisk.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 4fryn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Lisk.rb
2
+
3
+ A simple Ruby wrapper for the Lisk API. 💎
4
+
5
+ ## Note before using
6
+
7
+ This is very early work-in-progress. The idea is to publish this `gem` as soon as it is fully compatible with Lisk Core 1.0.0, which, however, is not released yet. The current implementation of the lisk.rb gem is pure minimal by design and barely allows checking the node status.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'lisk'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```bash
26
+ $ gem install lisk
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Make sure to include lisk.rb in your scripts.
32
+
33
+ ```ruby
34
+ require 'lisk'
35
+ ```
36
+
37
+ To get started, point the lisk.rb to any Lisk-API endpoint. By default, lisk.rb assumes a running Lisk node on localhost port 8000.
38
+
39
+ ```ruby
40
+ client = Lisk::Client.new "127.0.0.1", 8000
41
+ ```
42
+
43
+ For convenience, check if the Lisk node is connected, fully synchronized, and active by pinging it.
44
+
45
+ ```ruby
46
+ if client.ping
47
+ # only do stuff if client is connected, fully synchronized, and active ...
48
+ end
49
+ ```
50
+
51
+ Get the version of the connected Lisk node.
52
+
53
+ ```ruby
54
+ version = client.version
55
+ p "Lisk node version #{version["version"]} build #{version["build"]}..."
56
+ ```
57
+
58
+ Get the status of the connected Lisk node.
59
+
60
+ ```ruby
61
+ status = client.status
62
+ p "Lisk node is connected: #{status["success"]}... Blockchain loaded: #{status["loaded"]}..."
63
+ ```
64
+
65
+ Figure out if the node is still synchronizing.
66
+
67
+ ```ruby
68
+ syncing = client.sync
69
+ p "Lisk node is syncing: #{syncing["syncing"]}... #{syncing["blocks"]} remaining blocks to latest block #{syncing["height"]}..."
70
+ ```
71
+
72
+ Let's have a look at the connected peers.
73
+
74
+ ```ruby
75
+ peers = client.peers
76
+ cond = 0
77
+ disd = 0
78
+ band = 0
79
+ peers.each do | peer |
80
+ case peer["state"]
81
+ when 0
82
+ band += 1
83
+ when 1
84
+ disd += 1
85
+ when 2
86
+ cond += 1
87
+ end
88
+ end
89
+ p "Lisk node saw #{peers.count} peers... #{cond} connected, #{disd} disconnected, #{band} banned..."
90
+ ```
91
+
92
+ Get some global Lisk blockchain stats.
93
+
94
+ ```ruby
95
+ chain = client.chain
96
+ p "Lisk chain latest block: #{chain["height"]}... total supply: #{chain["supply"] / 1e8}... block reward: #{chain["reward"] / 1e8}"
97
+ ```
98
+
99
+ To be continued, see `example.rb` for some examples.
100
+
101
+ ## Development
102
+
103
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
+
105
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/4fryn/lisk.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
114
+
115
+ ## Code of Conduct
116
+
117
+ Everyone interacting in the Lisk.rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/4fryn/lisk.rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lisk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/debug ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ echo $PWD
4
+
5
+ gem uninstall lisk
6
+ rm pkg/*.gem
7
+ git add -A
8
+ bundle exec rake install
9
+ ruby example.rb
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/example.rb ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lisk'
4
+
5
+ # Try to connect a local Lisk client
6
+ client = Lisk::Client.new
7
+
8
+ # Configure host and port of the Lisk client
9
+ client.configure "127.0.0.1", 8000
10
+
11
+ # Same as above, just in one line
12
+ client = Lisk::Client.new "127.0.0.1", 8000
13
+
14
+ if client.ping
15
+ version = client.version
16
+ p "Lisk node version #{version["version"]} build #{version["build"]}..."
17
+
18
+ status = client.status
19
+ p "Lisk node is connected: #{status["success"]}... Blockchain loaded: #{status["loaded"]}..."
20
+
21
+ syncing = client.sync
22
+ p "Lisk node is syncing: #{syncing["syncing"]}... #{syncing["blocks"]} remaining blocks to latest block #{syncing["height"]}..."
23
+
24
+ peers = client.peers
25
+ cond = 0
26
+ disd = 0
27
+ band = 0
28
+ peers.each do | peer |
29
+ case peer["state"]
30
+ when 0
31
+ band += 1
32
+ when 1
33
+ disd += 1
34
+ when 2
35
+ cond += 1
36
+ end
37
+ end
38
+ p "Lisk node saw #{peers.count} peers... #{cond} connected, #{disd} disconnected, #{band} banned..."
39
+
40
+ chain = client.chain
41
+ p "Lisk chain latest block: #{chain["height"]}... total supply: #{chain["supply"] / 1e8}... block reward: #{chain["reward"] / 1e8}"
42
+ else
43
+ p 'Lisk node disconnected or inactive ...'
44
+ end
45
+
46
+ #account = Lisk::Account.new("14524922419337843943L")
47
+ #client.get_address(account)
48
+ #block = Lisk::Block.new("11145685198263496703")
49
+ #delegate = Lisk::Delegate.new("lightcurve")
50
+ #client.get_address(delegate)
51
+ #client.get_voters(delegate)
52
+ #transaction = Lisk::Transaction.new("10153999325502978458")
@@ -0,0 +1,73 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ module Lisk
6
+ class Client
7
+
8
+ attr_accessor :host, :port
9
+
10
+ def initialize host = "127.0.0.1", port = 8000
11
+ @host = host
12
+ @port = port
13
+ end
14
+
15
+ def configure host, port
16
+ if not host.empty? or not port.empty?
17
+ @host = host
18
+ @port = port
19
+ end
20
+ end
21
+
22
+ def query endpoint
23
+ node = ::Net::HTTP.new @host, @port
24
+ uri = URI.parse "http://#{host}:#{port}/api/#{endpoint}"
25
+ request = ::Net::HTTP::Get.new uri
26
+ response = node.request request
27
+ result = JSON::parse response.body
28
+ end
29
+
30
+ # Get the status of last received block.
31
+ # Returns true if block was received in the past 120 seconds.
32
+ def ping
33
+ ping = self.query "loader/status/ping"
34
+ ping["success"]
35
+ end
36
+
37
+ # Returns the sync status of the blockchain.
38
+ def status
39
+ status = self.query "loader/status"
40
+ end
41
+
42
+ # Get the synchronization status of the client.
43
+ def sync
44
+ sync = self.query "loader/status/sync"
45
+ end
46
+
47
+ # Gets list of peers.
48
+ def peers
49
+ peers = self.query "peers"
50
+ if peers["success"]
51
+ return peers["peers"]
52
+ else
53
+ return peers
54
+ end
55
+ end
56
+
57
+ # Gets version and build time.
58
+ def version
59
+ version = self.query "peers/version"
60
+ end
61
+
62
+ # Gets status of height, fee, milestone, blockreward and supply.
63
+ def chain
64
+ chain = self.query "blocks/getStatus"
65
+ end
66
+
67
+ # Unimplemented methods
68
+ def method_missing(name, *args, &block)
69
+ todo "#{self}::#{name} METHOD MISSING"
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Lisk
2
+ VERSION = "0.2.0"
3
+ end
data/lib/lisk.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "lisk/version"
2
+ require "todonotes"
3
+
4
+ module Lisk
5
+ require "lisk/client"
6
+
7
+ # Unimplemented methods
8
+ def self.method_missing
9
+ todo "#{self}::#{__method__} METHOD MISSING"
10
+ end
11
+ end
data/lisk.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "lisk/version"
5
+
6
+ Gem::Specification.new do |lisk|
7
+ lisk.name = "lisk"
8
+ lisk.version = Lisk::VERSION
9
+ lisk.authors = ["4fryn Dings"]
10
+ lisk.email = ["ruby@4fry.net"]
11
+
12
+ lisk.description = 'A Ruby wrapper for the Lisk blockchain platform API.'
13
+ lisk.homepage = 'https://github.com/4fryn/lisk.rb'
14
+ lisk.summary = 'Lisk API Ruby wrapper.'
15
+ lisk.license = "MIT"
16
+
17
+ lisk.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ lisk.bindir = "exe"
21
+ lisk.executables = lisk.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ lisk.require_paths = ["lib", "bin"]
23
+
24
+ lisk.add_development_dependency "bundler", "~> 1.15"
25
+ lisk.add_development_dependency "rake", "~> 10.0"
26
+ lisk.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ lisk.add_dependency "todonotes", "~> 0.2.2"
29
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lisk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - 4fryn Dings
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-26 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: todonotes
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.2
69
+ description: A Ruby wrapper for the Lisk blockchain platform API.
70
+ email:
71
+ - ruby@4fry.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/debug
86
+ - bin/setup
87
+ - example.rb
88
+ - lib/lisk.rb
89
+ - lib/lisk/client.rb
90
+ - lib/lisk/version.rb
91
+ - lisk.gemspec
92
+ homepage: https://github.com/4fryn/lisk.rb
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ - bin
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.11
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Lisk API Ruby wrapper.
117
+ test_files: []