filecoin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d03183ddc001622fb243e928ca9258cb3c8771439b9dbfdb745146e3d5197b31
4
+ data.tar.gz: 3f3e4cc8ca7a6bd4eef92dcb0055849147bd8c67ba730648a72a13b51f0410e5
5
+ SHA512:
6
+ metadata.gz: ccd108d4b698c768f773c912cce6b14802ccd7b3d21e084b75c4ba0ff394b43329c21d7c1c48576ceec70ffee11727dd8debd9413343f1224716415fed3083c8
7
+ data.tar.gz: 1b736355b8757696ab368d4815bdf263d0a3414c04cbc2c6453a686bf0f1aa1deca77756a8b9f184adee877a5872ecac26bbf52163dbc37d52811fde563b5099
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,99 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Include
4
+ - Exclude
5
+
6
+ require:
7
+ - rubocop-performance
8
+ - rubocop-rspec
9
+
10
+ AllCops:
11
+ NewCops: enable
12
+ TargetRubyVersion: 2.7.1
13
+
14
+ Layout/DotPosition:
15
+ EnforcedStyle: trailing
16
+
17
+ Layout/LineLength:
18
+ Enabled: false
19
+
20
+ Layout/MultilineOperationIndentation:
21
+ EnforcedStyle: indented
22
+
23
+ Layout/MultilineMethodCallIndentation:
24
+ EnforcedStyle: indented
25
+
26
+ Layout/ParameterAlignment:
27
+ EnforcedStyle: with_fixed_indentation
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - spec/**/*.rb
32
+
33
+ Naming/PredicateName:
34
+ ForbiddenPrefixes:
35
+ - is_
36
+ - have_
37
+
38
+ # `described_class` makes tests harder to read. When using tools that allow
39
+ # jumping between definitions and the respective tests in a Rails project, or
40
+ # using global search, the class `described_class` refers to might not be clear
41
+ # to the reader. By avoiding the shortcut, we make sure the test stands on its
42
+ # own with as much information as possible.
43
+ RSpec/DescribedClass:
44
+ Enabled: false
45
+
46
+ # Examples should be informative and explicit. While longer examples are
47
+ # generally hard to read, the value should be adjusted as reasonable for a
48
+ # project.
49
+ RSpec/ExampleLength:
50
+ Max: 10
51
+
52
+ # Examples should focus on testing one thing, but that does not necessarily
53
+ # translate into a single expectation. For instance, testing validations in
54
+ # a Rails model should assert (1) the model is invalid, (2) the model has
55
+ # validation errors, and (3) these errors not only include the target field
56
+ # but also the target error message. Another example would be testing
57
+ # side-effects are contained.
58
+ #
59
+ # Similarly, not limiting the number of expectations in an example invites
60
+ # colaborators (and consequently reviewers) to forget the rule of testing one
61
+ # thing only, or to simply ignore it due over the "simplicity" and comfort of
62
+ # checking for everything in a single test.
63
+ #
64
+ # Therefore, this cop should remain enabled, but its value should be adjusted
65
+ # as reasonable for the project.
66
+ #
67
+ RSpec/MultipleExpectations:
68
+ Max: 3
69
+
70
+ Style/ClassAndModuleChildren:
71
+ Enabled: false
72
+
73
+ Style/Documentation:
74
+ Enabled: false
75
+
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: false
78
+
79
+ Style/IfUnlessModifier:
80
+ Enabled: false
81
+
82
+ Style/NumericLiterals:
83
+ Enabled: false
84
+
85
+ Style/SingleLineBlockParams:
86
+ Enabled: false
87
+
88
+ Style/StringLiterals:
89
+ EnforcedStyle: double_quotes
90
+
91
+ Style/TrailingCommaInArguments:
92
+ EnforcedStyleForMultiline: comma
93
+
94
+ Style/TrailingCommaInArrayLiteral:
95
+ EnforcedStyleForMultiline: comma
96
+
97
+ Style/TrailingCommaInHashLiteral:
98
+ EnforcedStyleForMultiline: comma
99
+
@@ -0,0 +1 @@
1
+ ruby 2.7.1
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,19 @@
1
+ Changelog
2
+ =========
3
+
4
+ All notable changes to this project will be documented in this file.
5
+
6
+ The format is based on [Keep a Changelog], and this project adheres to
7
+ [Semantic Versioning].
8
+
9
+
10
+ Unreleased
11
+ ----------
12
+
13
+ - Add `Filecoin::Client` with `#chain_head` matching the `Filecoin.ChainHead`
14
+ method in the Filecoin Lotus Node API.
15
+
16
+
17
+ [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
18
+ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
19
+
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in filecoin.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+
8
+ group :test do
9
+ gem "faker", "~> 2.12"
10
+ gem "permafrost", "~> 1.0"
11
+ gem "rspec", "~> 3.0"
12
+ gem "rubocop", "~> 0.84.0"
13
+ gem "rubocop-performance", "~> 1.6.0"
14
+ gem "rubocop-rspec", "~> 1.39.0"
15
+ end
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ filecoin (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ concurrent-ruby (1.1.6)
11
+ diff-lcs (1.3)
12
+ faker (2.12.0)
13
+ i18n (>= 1.6, < 2)
14
+ i18n (1.8.2)
15
+ concurrent-ruby (~> 1.0)
16
+ parallel (1.19.1)
17
+ parser (2.7.1.3)
18
+ ast (~> 2.4.0)
19
+ permafrost (1.0.0)
20
+ rainbow (3.0.0)
21
+ rake (12.3.3)
22
+ rexml (3.2.4)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.2)
28
+ rspec-support (~> 3.9.3)
29
+ rspec-expectations (3.9.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.3)
36
+ rubocop (0.84.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.7.0.1)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ rexml
41
+ rubocop-ast (>= 0.0.3)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 2.0)
44
+ rubocop-ast (0.0.3)
45
+ parser (>= 2.7.0.1)
46
+ rubocop-performance (1.6.0)
47
+ rubocop (>= 0.71.0)
48
+ rubocop-rspec (1.39.0)
49
+ rubocop (>= 0.68.1)
50
+ ruby-progressbar (1.10.1)
51
+ unicode-display_width (1.7.0)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ faker (~> 2.12)
58
+ filecoin!
59
+ permafrost (~> 1.0)
60
+ rake (~> 12.0)
61
+ rspec (~> 3.0)
62
+ rubocop (~> 0.84.0)
63
+ rubocop-performance (~> 1.6.0)
64
+ rubocop-rspec (~> 1.39.0)
65
+
66
+ BUNDLED WITH
67
+ 2.1.4
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Subvisual, Lda
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,97 @@
1
+ filecoin-ruby
2
+ =============
3
+
4
+ Interface to the Filecoin network APIs in Ruby.
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "filecoin", "~> 0.1.0"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install filecoin
23
+
24
+
25
+ Usage
26
+ -----
27
+
28
+ Clients are initialized with the URI to the target API server. This URI can be
29
+ provided as a `URI` object, or as a `String`. If omitted, `Filecoin::Client`
30
+ defaults to the value of the `FILECOIN_URL` environment variable.
31
+
32
+ ```ruby
33
+ # with a URI object
34
+ Filecoin::Client.new(uri: URI("https://filecoin.example.com:1234"))
35
+
36
+ # with a String
37
+ Filecoin::Client.new(uri: "https://filecoin.example.com:1234")
38
+
39
+ # from the FILECOIN_URL environment variable
40
+ Filecoin::Client.new
41
+ ```
42
+
43
+ For each available method in the [Filecoin Node API] use the respective method
44
+ in `Filecoin::Client`. For instance, to call `Filecoin.ChainHead` use
45
+ `Filecoin::Client#chain_head`.
46
+
47
+ ```ruby
48
+ client = Filecoin::Client.new
49
+ client.chain_head # => => {"jsonrpc"=>"2.0", "result"=>{...}, ...}
50
+ ```
51
+
52
+ All methods return the server's JSON parsed response as a plain `Hash`.
53
+
54
+
55
+ Development
56
+ -----------
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
59
+ `rake` to run the linter and tests. You can also run `bin/console` for an
60
+ interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To
63
+ release a new version, update the version number in `version.rb`, and then run
64
+ `bundle exec rake release`, which will create a git tag for the version, push
65
+ git commits and tags, and push the `.gem` file to [rubygems.org].
66
+
67
+
68
+ Contributing
69
+ ------------
70
+
71
+ Bug reports and pull requests are welcome on GitHub at
72
+ https://github.com/subvisual/filecoin-ruby.
73
+
74
+
75
+ License
76
+ -----
77
+
78
+ filecoin-ruby is copyright &copy; 2020 Subvisual, Lda.
79
+
80
+ It is open-source, made available for free, and is subject to the terms in
81
+ its [license].
82
+
83
+
84
+ About
85
+ -----
86
+
87
+ filecoin-ruby was created and is maintained with :heart: by
88
+ [Subvisual][subvisual].
89
+
90
+ [![Subvisual][subvisual-logo]][subvisual]
91
+
92
+
93
+ [license]: ./LICENSE.txt
94
+ [rubygems.org]: https://rubygems.org
95
+ [subvisual]: http://subvisual.com
96
+ [subvisual-logo]: https://raw.githubusercontent.com/subvisual/guides/master/github/templates/logos/blue.png
97
+
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:lint)
7
+
8
+ task default: %i[lint spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "filecoin"
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__)
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+
3
+ # Exit if any command fails
4
+ set -e
5
+
6
+ # Install the required languages
7
+ asdf install
8
+ asdf reshim
9
+
10
+ # Install the Ruby dependencies
11
+ bundle install
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/filecoin/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "filecoin"
7
+ spec.version = Filecoin::VERSION
8
+ spec.authors = ["Pedro Costa"]
9
+ spec.email = ["pedro@subvisual.co"]
10
+
11
+ spec.summary = "Interact with the Filecoin network"
12
+ spec.description = <<~DESCRIPTION
13
+ Filecoin (https://filecoin.io/) is a distributed storage network based on a
14
+ blockchain mechanism. Filecoin miners provide storage capacity for the
15
+ network, earning FIL by periodically prooving the specified capacity is
16
+ provided to the network.
17
+
18
+ The Filecoin blockchain maintains the ledger for FIL transactions, and
19
+ implements the Filecoin VM for the execution of contracts and market
20
+ mechanisms. These include storage deals, where clients pay miners to store
21
+ data in the network.
22
+
23
+ This gem makes use of the JSON RPC API made available by Lotus
24
+ (https://lotu.sh/), the official implementation of the network.
25
+ DESCRIPTION
26
+ spec.homepage = "https://github.com/subvisual/filecoin-ruby"
27
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
28
+
29
+ spec.metadata["homepage_uri"] = spec.homepage
30
+ spec.metadata["source_code_uri"] = "https://github.com/subvisual/filecoin-ruby"
31
+ spec.metadata["changelog_uri"] = "https://github.com/subvisual/filecoin-ruby/blob/master/CHANGELOG.md"
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
36
+ `git ls-files -z`.split("\x0").reject { |f| f.start_with?("spec/") }
37
+ end
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+ end
@@ -0,0 +1,4 @@
1
+ require "filecoin/version"
2
+
3
+ module Filecoin
4
+ end
@@ -0,0 +1,38 @@
1
+ require "filecoin/client/node"
2
+ require "filecoin/http"
3
+
4
+ module Filecoin
5
+ class Client
6
+ include Filecoin::Client::Node
7
+
8
+ attr_reader :uri
9
+
10
+ def initialize(uri: nil)
11
+ @uri = initialize_uri(uri)
12
+ end
13
+
14
+ private
15
+
16
+ def initialize_uri(uri)
17
+ uri ||= ENV["FILECOIN_URL"]
18
+
19
+ return if uri.nil?
20
+
21
+ URI(uri)
22
+ end
23
+
24
+ def json_rpc_call(method, *params)
25
+ @json_rpc_call_id ||= 0
26
+ @json_rpc_call_id += 1
27
+
28
+ body = {
29
+ jsonrpc: "2.0",
30
+ method: method,
31
+ params: params,
32
+ id: @json_rpc_call_id,
33
+ }
34
+
35
+ Http.post(uri, body)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module Filecoin
2
+ class Client
3
+ module Node
4
+ def chain_head
5
+ json_rpc_call "Filecoin.ChainHead"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ require "json"
2
+ require "net/http"
3
+
4
+ module Filecoin
5
+ module Http
6
+ module ClassMethods
7
+ def post(uri, data)
8
+ return if uri.nil?
9
+
10
+ req = Net::HTTP::Post.new(uri)
11
+ req["Content-Type"] = "application/json"
12
+ req.body = data.to_json
13
+
14
+ response = request(req)
15
+ JSON.parse(response.body)
16
+ end
17
+
18
+ def request(request)
19
+ uri = request.uri
20
+
21
+ return if uri.nil?
22
+
23
+ Net::HTTP.new(uri.host, uri.port).request(request)
24
+ end
25
+ end
26
+
27
+ extend ClassMethods
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Filecoin
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filecoin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Costa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Filecoin (https://filecoin.io/) is a distributed storage network based on a
15
+ blockchain mechanism. Filecoin miners provide storage capacity for the
16
+ network, earning FIL by periodically prooving the specified capacity is
17
+ provided to the network.
18
+
19
+ The Filecoin blockchain maintains the ledger for FIL transactions, and
20
+ implements the Filecoin VM for the execution of contracts and market
21
+ mechanisms. These include storage deals, where clients pay miners to store
22
+ data in the network.
23
+
24
+ This gem makes use of the JSON RPC API made available by Lotus
25
+ (https://lotu.sh/), the official implementation of the network.
26
+ email:
27
+ - pedro@subvisual.co
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - ".gitignore"
33
+ - ".rspec"
34
+ - ".rubocop.yml"
35
+ - ".tool-versions"
36
+ - ".travis.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - filecoin.gemspec
46
+ - lib/filecoin.rb
47
+ - lib/filecoin/client.rb
48
+ - lib/filecoin/client/node.rb
49
+ - lib/filecoin/http.rb
50
+ - lib/filecoin/version.rb
51
+ homepage: https://github.com/subvisual/filecoin-ruby
52
+ licenses: []
53
+ metadata:
54
+ homepage_uri: https://github.com/subvisual/filecoin-ruby
55
+ source_code_uri: https://github.com/subvisual/filecoin-ruby
56
+ changelog_uri: https://github.com/subvisual/filecoin-ruby/blob/master/CHANGELOG.md
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.4.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Interact with the Filecoin network
76
+ test_files: []