peatio-electrum 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: 1826ed8fd6cda494ca2bbc3ff4a96c3fafb9c0424abc85dbb6b917fecb0834d0
4
+ data.tar.gz: 249fa5f632f8e32d2d467ff1b7e4bad7090ebf1afbed06200bb0730c740d6a30
5
+ SHA512:
6
+ metadata.gz: 41add4a5bc5151cf30e6babd801fc6c3351d4aaaacf0b99d84f5fd12d8f33bcc57b33e99d044b0d9dbe6bb02831a8431382b4ac1572acaee1bd5c7d17cd6a8da
7
+ data.tar.gz: 893cb8b69be5485048e9c0dbca02965c6fb53e5778a91e27e23f444aa5c8d10ed11ed1dd1f050875257608217ac1009195d05f74b2bc3958232e7dd4ec0690af
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in peatio-electrum.gemspec
8
+ gemspec
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ peatio-electrum (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.0.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2, >= 2.2.2)
15
+ ast (2.4.0)
16
+ concurrent-ruby (1.1.6)
17
+ diff-lcs (1.3)
18
+ docile (1.3.2)
19
+ i18n (1.8.2)
20
+ concurrent-ruby (~> 1.0)
21
+ io-console (0.5.6)
22
+ irb (1.2.4)
23
+ reline (>= 0.0.1)
24
+ jaro_winkler (1.5.4)
25
+ minitest (5.14.0)
26
+ parallel (1.19.1)
27
+ parser (2.7.1.2)
28
+ ast (~> 2.4.0)
29
+ rack (2.2.2)
30
+ rainbow (3.0.0)
31
+ rake (10.5.0)
32
+ reline (0.1.4)
33
+ io-console (~> 0.5)
34
+ rexml (3.2.4)
35
+ rspec (3.9.0)
36
+ rspec-core (~> 3.9.0)
37
+ rspec-expectations (~> 3.9.0)
38
+ rspec-mocks (~> 3.9.0)
39
+ rspec-core (3.9.2)
40
+ rspec-support (~> 3.9.3)
41
+ rspec-expectations (3.9.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-mocks (3.9.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-support (3.9.3)
48
+ rubocop (0.82.0)
49
+ jaro_winkler (~> 1.5.1)
50
+ parallel (~> 1.10)
51
+ parser (>= 2.7.0.1)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ rexml
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 2.0)
56
+ rubocop-github (0.15.0)
57
+ rubocop (<= 0.82.0)
58
+ rubocop-performance (~> 1.0)
59
+ rubocop-rails (~> 2.0)
60
+ rubocop-performance (1.5.2)
61
+ rubocop (>= 0.71.0)
62
+ rubocop-rails (2.5.2)
63
+ activesupport
64
+ rack (>= 1.1)
65
+ rubocop (>= 0.72.0)
66
+ ruby-progressbar (1.10.1)
67
+ simplecov (0.18.5)
68
+ docile (~> 1.1)
69
+ simplecov-html (~> 0.11)
70
+ simplecov-html (0.12.2)
71
+ thread_safe (0.3.6)
72
+ tzinfo (1.2.7)
73
+ thread_safe (~> 0.1)
74
+ unicode-display_width (1.7.0)
75
+ zeitwerk (2.3.0)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ bundler
82
+ irb
83
+ peatio-electrum!
84
+ rake (~> 10.0)
85
+ rspec (~> 3.0)
86
+ rubocop-github
87
+ simplecov
88
+
89
+ BUNDLED WITH
90
+ 1.17.3
@@ -0,0 +1,20 @@
1
+ # Peatio Electrum Blockchain Plugin
2
+
3
+ This gem is a [peatio](https://github.com/openware/peatio) plugin adding the support of Electrum blockchain.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'peatio-electrum'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install peatio-electrum
20
+
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "peatio/electrum"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "peatio/electrum"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Electrum
5
+ Error = Class.new(StandardError)
6
+
7
+ require "peatio/electrum/version"
8
+ require "peatio/electrum/hooks"
9
+ require "peatio/electrum/blockchain"
10
+ require "peatio/electrum/wallet"
11
+ end
12
+ end
13
+
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ #
5
+ # See the abstract class here:
6
+ # https://github.com/openware/peatio-core/blob/master/lib/peatio/blockchain/abstract.rb
7
+ #
8
+ class Blockchain < Peatio::Blockchain::Abstract
9
+ DEFAULT_FEATURES = {case_sensitive: true}.freeze
10
+
11
+ # You could override default features by passing them to initializer.
12
+ def initialize(custom_features = {})
13
+ @features = DEFAULT_FEATURES.merge(custom_features)
14
+ end
15
+
16
+ # Merges given configuration parameters with defined during initialization
17
+ # and returns the result.
18
+ #
19
+ # @param [Hash] settings parameters to use.
20
+ #
21
+ # @option settings [String] :server Public blockchain API endpoint.
22
+ # @option settings [Array<Hash>] :currencies List of currency hashes
23
+ # with :id,:base_factor,:options(deprecated) keys.
24
+ # Custom keys could be added by defining them in Currency #options.
25
+ #
26
+ # @return [Hash] merged settings.
27
+ #
28
+ # @note Be careful with your blockchain state after configure.
29
+ # Clean everything what could be related to other blockchain configuration.
30
+ # E.g. client state.
31
+ def configure(settings = {})
32
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
33
+ end
34
+
35
+ # Fetches blockchain block by calling API and builds block object
36
+ # from response payload.
37
+ #
38
+ # @param block_number [Integer] the block number.
39
+ # @return [Peatio::Block] the block object.
40
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
41
+ # on blockchain API call.
42
+ def fetch_block!(block_number)
43
+ method_not_implemented
44
+ end
45
+
46
+ # Fetches current blockchain height by calling API and returns it as number.
47
+ #
48
+ # @return [Integer] the current blockchain height.
49
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
50
+ # on blockchain API call.
51
+ def latest_block_number
52
+ method_not_implemented
53
+ end
54
+
55
+ # Fetches address balance of specific currency.
56
+ #
57
+ # @note Optional. Don't override this method if your blockchain
58
+ # doesn't provide functionality to get balance by address.
59
+ #
60
+ # @param address [String] the address for requesting balance.
61
+ # @param currency_id [String] which currency balance we need to request.
62
+ # @return [BigDecimal] the current address balance.
63
+ # @raise [Peatio::Blockchain::ClientError,Peatio::Blockchain::UnavailableAddressBalanceError]
64
+ # if error was raised on blockchain API call ClientError is raised.
65
+ # if blockchain API call was successful but we can't detect balance
66
+ # for address Error is raised.
67
+ def load_balance_of_address!(address, currency_id)
68
+ raise Peatio::Blockchain::UnavailableAddressBalanceError
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum::Hooks
4
+ class << self
5
+ def check_compatibility
6
+ if Peatio::Blockchain::VERSION >= '2.0'
7
+ [
8
+ "Electrum plugin was designed for work with 1.x. Blockchain.",
9
+ "You have #{Peatio::Electrum::Blockchain::VERSION}."
10
+ ].join('\n').tap { |s| Kernel.abort s }
11
+ end
12
+
13
+ if Peatio::Wallet::VERSION >= '2.0'
14
+ [
15
+ "Electrum plugin was designed for work with 1.x. Wallet.",
16
+ "You have #{Peatio::Electrum::Wallet::VERSION}."
17
+ ].join('\n').tap { |s| Kernel.abort s }
18
+ end
19
+ end
20
+
21
+ def register
22
+ Peatio::Blockchain.registry[:Electrum] = Electrum::Blockchain
23
+ Peatio::Wallet.registry[:Electrumd] = Electrum::Wallet
24
+ end
25
+ end
26
+
27
+ if defined?(Rails::Railtie)
28
+ require "peatio/Electrum/railtie"
29
+ else
30
+ check_compatibility
31
+ register
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ class Railtie < Rails::Railtie
5
+ config.before_initialize do
6
+ Hooks.check_compatibility
7
+ end
8
+
9
+ config.after_initialize do
10
+ Hooks.register
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Electrum
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ #
5
+ # See the abstract class here:
6
+ # https://github.com/openware/peatio-core/blob/master/lib/peatio/wallet/abstract.rb
7
+ #
8
+ class Wallet < Peatio::Wallet::Abstract
9
+
10
+ def initialize(settings = {})
11
+ @settings = settings
12
+ end
13
+
14
+ # Merges given configuration parameters with defined during initialization
15
+ # and returns the result.
16
+ #
17
+ # @param [Hash] settings configurations to use.
18
+ # @option settings [Hash] :wallet Wallet settings for performing API calls.
19
+ # With :address required key other settings could be customized
20
+ # using Wallet#settings.
21
+ # @option settings [Array<Hash>] :currencies List of currency hashes
22
+ # with :id,:base_factor,:options(deprecated) keys.
23
+ # Custom keys could be added by defining them in Currency #options.
24
+ #
25
+ # @return [Hash] merged settings.
26
+ #
27
+ # @note Be careful with your wallet state after configure.
28
+ # Clean everything what could be related to other wallet configuration.
29
+ # E.g. client state.
30
+ def configure(settings = {})
31
+ # Clean client state during configure.
32
+ @client = nil
33
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
34
+
35
+ @wallet = @settings.fetch(:wallet) do
36
+ raise Peatio::Wallet::MissingSettingError, :wallet
37
+ end.slice(:uri, :address, :secret)
38
+
39
+ @currency = @settings.fetch(:currency) do
40
+ raise Peatio::Wallet::MissingSettingError, :currency
41
+ end.slice(:id, :base_factor, :options)
42
+ end
43
+
44
+ # Performs API call for address creation and returns it.
45
+ #
46
+ # @param [Hash] options
47
+ # @options options [String] :uid User UID which requested address creation.
48
+ #
49
+ # @return [Hash] newly created blockchain address.
50
+ #
51
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
52
+ # on wallet API call.
53
+ #
54
+ # @example
55
+ # { address: :fake_address,
56
+ # secret: :changeme,
57
+ # details: { uid: account.member.uid } }
58
+ def create_address!(options = {})
59
+ method_not_implemented
60
+ end
61
+
62
+ # Performs API call for creating transaction and returns updated transaction.
63
+ #
64
+ # @param [Peatio::Transaction] transaction transaction with defined
65
+ # to_address, amount & currency_id.
66
+ #
67
+ # @param [Hash] options
68
+ # @options options [String] :subtract_fee Defines if you need to subtract
69
+ # fee from amount defined in transaction.
70
+ # It means that you need to deduct fee from amount declared in
71
+ # transaction and send only remaining amount.
72
+ # If transaction amount is 1.0 and estimated fee
73
+ # for sending transaction is 0.01 you need to send 0.09
74
+ # so 1.0 (0.9 + 0.1) will be subtracted from wallet balance
75
+ #
76
+ # @options options [String] custon options for wallet client.
77
+ #
78
+ # @return [Peatio::Transaction] transaction with updated hash.
79
+ #
80
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
81
+ # on wallet API call.
82
+ def create_transaction!(transaction, options = {})
83
+ method_not_implemented
84
+ end
85
+
86
+ # Fetches address balance of specific currency.
87
+ #
88
+ # @note Optional. Don't override this method if your blockchain
89
+ # doesn't provide functionality to get balance by address.
90
+ #
91
+ # @return [BigDecimal] the current address balance.
92
+ #
93
+ # @raise [Peatio::Blockchain::ClientError,Peatio::Blockchain::UnavailableAddressBalanceError]
94
+ # if error was raised on wallet API call ClientError is raised.
95
+ # if wallet API call was successful but we can't detect balance
96
+ # for address Error is raised.
97
+ def load_balance!
98
+ raise Peatio::Wallet::UnavailableAddressBalanceError
99
+ end
100
+
101
+ # Performs API call(s) for preparing for deposit collection.
102
+ # E.g deposits ETH for collecting ERC20 tokens in case of Ethereum blockchain.
103
+ #
104
+ # @note Optional. Override this method only if you need additional step
105
+ # before deposit collection.
106
+ #
107
+ # @param [Peatio::Transaction] deposit_transaction transaction which
108
+ # describes received deposit.
109
+ #
110
+ # @param [Array<Peatio::Transaction>] spread_transactions result of deposit
111
+ # spread between wallets.
112
+ #
113
+ # @return [Array<Peatio::Transaction>] transaction created for
114
+ # deposit collection preparing.
115
+ # By default return empty [Array]
116
+ def prepare_deposit_collection!(deposit_transaction, spread_transactions, deposit_currency)
117
+ # This method is mostly used for coins which needs additional fees
118
+ # to be deposited before deposit collection.
119
+ []
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "peatio/electrum/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "peatio-electrum"
9
+ spec.version = Peatio::Electrum::VERSION
10
+ spec.authors = ["Camille Meulien"]
11
+ spec.email = ["cmeulien@heliostech.fr"]
12
+
13
+ spec.summary = "Peatio Electrum Blockchain Plugin"
14
+ spec.description = "Peatio Electrum Blockchain Plugin"
15
+ spec.homepage = "https://www.openware.com"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/openware/peatio-contrib"
22
+ spec.metadata["changelog_uri"] = "https://github.com/openware/peatio-contrib/blob/master/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "irb"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "rubocop-github"
42
+ spec.add_development_dependency "simplecov"
43
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peatio-electrum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Camille Meulien
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-11 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: irb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-github
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Peatio Electrum Blockchain Plugin
98
+ email:
99
+ - cmeulien@heliostech.fr
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - README.md
107
+ - Rakefile
108
+ - bin/peatio-electrum-console
109
+ - bin/peatio-electrum-setup
110
+ - lib/peatio/electrum.rb
111
+ - lib/peatio/electrum/blockchain.rb
112
+ - lib/peatio/electrum/hooks.rb
113
+ - lib/peatio/electrum/railtie.rb
114
+ - lib/peatio/electrum/version.rb
115
+ - lib/peatio/electrum/wallet.rb
116
+ - peatio-electrum.gemspec
117
+ homepage: https://www.openware.com
118
+ licenses: []
119
+ metadata:
120
+ homepage_uri: https://www.openware.com
121
+ source_code_uri: https://github.com/openware/peatio-contrib
122
+ changelog_uri: https://github.com/openware/peatio-contrib/blob/master/CHANGELOG.md
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Peatio Electrum Blockchain Plugin
142
+ test_files: []