ark-ruby 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
+ SHA1:
3
+ metadata.gz: 0f28f16827b49ac19e4ddfc7cc6e4399b4438920
4
+ data.tar.gz: db3e3fe62e47272fd7a9398cd2bc6d6904c8ab0c
5
+ SHA512:
6
+ metadata.gz: cae824d9dc90e24d7e0b5b049384b73d82f44902ae86803bb9a5cca785d364f8d9b9c3ea135953674df6a57160a59d9307ca1c79cd3c82374bab4031d3350768
7
+ data.tar.gz: 190320eb38bfbf6b6de546849b5e5454983d1a8ef193274fd4840597c0be960196b9a8918b0f06d94a2747df0002b7d0c3dfe0c3a307e5ce778feb1bc19fefcc
@@ -0,0 +1,10 @@
1
+ IP=
2
+ PORT=
3
+ NETHASH=
4
+ VERSION=
5
+
6
+ ADDRESS=
7
+ PUBLIC_KEY=
8
+
9
+ SECRET=
10
+ SECOND_SECRET=
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /.env
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -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.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ark-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Brian Faust
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.
@@ -0,0 +1,32 @@
1
+ # Ark::Ruby
2
+
3
+ ## Table of contents
4
+
5
+ * [Installation](docs/Installation.md)
6
+ * [Usage](docs/Usage.md)
7
+ * [Initialization](docs/Initialization.md)
8
+ * [Account](docs/Account.md)
9
+ * [Block](docs/Block.md)
10
+ * [Delegate](docs/Delegate.md)
11
+ * [Loader](docs/Loader.md)
12
+ * [MultiSignature](docs/MultiSignature.md)
13
+ * [Peer](docs/Peer.md)
14
+ * [Signature](docs/Signature.md)
15
+ * [Transaction](docs/Transaction.md)
16
+ * [Development](#development)
17
+ * [Contributing](#contributing)
18
+ * [License](#license)
19
+
20
+ ## Development
21
+
22
+ 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.
23
+
24
+ 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).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faustbrian/ark-ruby.
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ark/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ark-ruby"
8
+ spec.version = Ark::VERSION
9
+ spec.authors = ["Brian Faust"]
10
+ spec.email = ["hello@brianfaust.me"]
11
+
12
+ spec.summary = "An Ark Client for Ruby"
13
+ spec.description = "An Ark Client for Ruby"
14
+ spec.homepage = "https://github.com/faustbrian/Ark-Ruby"
15
+ spec.license = "MIT"
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["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "webmock", "3.0.1"
37
+ spec.add_development_dependency "dotenv", "2.2.1"
38
+
39
+ spec.add_dependency 'faraday', "~> 0.12.2"
40
+ spec.add_dependency 'faraday_middleware', "~> 0.12.2"
41
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ark"
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,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
@@ -0,0 +1,55 @@
1
+ # Account
2
+
3
+ ## Get the balance of an account.
4
+
5
+ ```ruby
6
+ client.account_balance(address)
7
+ ```
8
+
9
+ ## Get the public key of an account.
10
+
11
+ ```ruby
12
+ client.account_publickey(address)
13
+ ```
14
+
15
+ ## Get the delegates of an account.
16
+
17
+ ```ruby
18
+ client.account_delegates(address)
19
+ ```
20
+
21
+ ## Get the delegate fee of an account.
22
+
23
+ ```ruby
24
+ client.account_delegates_fee(address)
25
+ ```
26
+
27
+ ## Add a new delegate to an account.
28
+
29
+ ```ruby
30
+ client.create_account_delegates(secret, publicKey, secondSecret)
31
+ ```
32
+
33
+ ## Returns account information of an address.
34
+
35
+ ```ruby
36
+ client.account(address)
37
+ ```
38
+
39
+ ## Get a list of accounts.
40
+
41
+ ```ruby
42
+ client.accounts
43
+ ```
44
+
45
+ ## Get a list of top accounts.
46
+
47
+ ```ruby
48
+ client.top_accounts
49
+ ```
50
+
51
+ ## Get the count of accounts.
52
+
53
+ ```ruby
54
+ client.count_accounts
55
+ ```
@@ -0,0 +1,67 @@
1
+ # Block
2
+
3
+ ## Get block by id.
4
+
5
+ ```ruby
6
+ client.block(id)
7
+ ```
8
+
9
+ ## Get all blocks.
10
+
11
+ ```ruby
12
+ client.blocks(parameters: {})
13
+ ```
14
+
15
+ ## Get the blockchain epoch.
16
+
17
+ ```ruby
18
+ client.block_epoch
19
+ ```
20
+
21
+ ## Get the blockchain height.
22
+
23
+ ```ruby
24
+ client.block_height
25
+ ```
26
+
27
+ ## Get the blockchain nethash.
28
+
29
+ ```ruby
30
+ client.block_nethash
31
+ ```
32
+
33
+ ## Get the transaction fee for sending "normal" transactions.
34
+
35
+ ```ruby
36
+ client.block_fee
37
+ ```
38
+
39
+ ## Get the network fees.
40
+
41
+ ```ruby
42
+ client.block_fees
43
+ ```
44
+
45
+ ## Get the blockchain milestone.
46
+
47
+ ```ruby
48
+ client.block_milestone
49
+ ```
50
+
51
+ ## Get the blockchain reward.
52
+
53
+ ```ruby
54
+ client.block_reward
55
+ ```
56
+
57
+ ## Get the blockchain supply.
58
+
59
+ ```ruby
60
+ client.block_supply
61
+ ```
62
+
63
+ ## Get the blockchain status.
64
+
65
+ ```ruby
66
+ client.block_status
67
+ ```
@@ -0,0 +1,80 @@
1
+ # Delegate
2
+
3
+ ## count
4
+
5
+ ```ruby
6
+ client.count_delegates
7
+ ```
8
+
9
+ ## search
10
+
11
+ ```ruby
12
+ client.search_delegates(q, parameters: {})
13
+ ```
14
+
15
+ ## voters
16
+
17
+ ```ruby
18
+ client.delegate_voters(publicKey, parameters: {})
19
+ ```
20
+
21
+ ## delegate
22
+
23
+ ```ruby
24
+ client.delegate(parameters: {})
25
+ ```
26
+
27
+ ## delegates
28
+
29
+ ```ruby
30
+ client.delegates(parameters: {})
31
+ ```
32
+
33
+ ## fee
34
+
35
+ ```ruby
36
+ client.delegate_fee
37
+ ```
38
+
39
+ ## forgedByAccount
40
+
41
+ ```ruby
42
+ client.forged_by_account(generatorPublicKey)
43
+ ```
44
+
45
+ ## create
46
+
47
+ ```ruby
48
+ client.create_delegate(secret, username, secondSecret: nil)
49
+ ```
50
+
51
+
52
+ ## vote
53
+
54
+ ```ruby
55
+ client.vote_for_delegate(secret, delegates, secondSecret: nil)
56
+ ```
57
+
58
+ ## nextForgers
59
+
60
+ ```ruby
61
+ client.next_forgers
62
+ ```
63
+
64
+ ## enableForging
65
+
66
+ ```ruby
67
+ client.enable_forging(secret, parameters: {})
68
+ ```
69
+
70
+ ## disableForging
71
+
72
+ ```ruby
73
+ client.disable_forging(secret, parameters: {})
74
+ ```
75
+
76
+ ## forgingStatus
77
+
78
+ ```ruby
79
+ client.forging_status(publicKey, parameters: {})
80
+ ```
@@ -0,0 +1,14 @@
1
+ # Initialization
2
+
3
+ ## Initialize Client
4
+
5
+ ```ruby
6
+ require 'ark'
7
+
8
+ client = Ark::Client.new(
9
+ :ip => 'your-ip',
10
+ :port => 4001,
11
+ :nethash => '6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988',
12
+ :version => '1.0.1'
13
+ )
14
+ ```
@@ -0,0 +1,25 @@
1
+ # Installation
2
+
3
+ ## Prerequisites
4
+
5
+ Before starting to use [ARK-Ruby](https://github.com/faustbrian/Ark-Ruby) make sure you have [NUCLeId](https://github.com/ArkEcosystem/nucleid) and [ARK JS](https://github.com/ArkEcosystem/ark-js) installed globally with [npm](https://www.npmjs.com/):
6
+
7
+ ```
8
+ npm install -g nucleid arkjs
9
+ ```
10
+
11
+ ## Bundler
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'ark-ruby'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install ark-ruby
@@ -0,0 +1,19 @@
1
+ ## Loader
2
+
3
+ ## Get the blockchain status.
4
+
5
+ ```ruby
6
+ client.status
7
+ ```
8
+
9
+ ## Get the synchronisation status of the client.
10
+
11
+ ```ruby
12
+ client.sync
13
+ ```
14
+
15
+ ## Auto-configure the client loader.
16
+
17
+ ```ruby
18
+ client.autoconfigure
19
+ ```
@@ -0,0 +1,25 @@
1
+ # Multi Signature
2
+
3
+ ## Get pending multi signature transactions.
4
+
5
+ ```ruby
6
+ client.pending_multi_signatures(publicKey)
7
+ ```
8
+
9
+ ## Sign a new multi signature.
10
+
11
+ ```ruby
12
+ client.multi_signature_sign(transactionId, secret, parameters: {})
13
+ ```
14
+
15
+ ## Create a new multi signature.
16
+
17
+ ```ruby
18
+ client.create_multi_signature(secret, secondSecret, keysgroup, lifetime, min)
19
+ ```
20
+
21
+ ## Get a list of accounts.
22
+
23
+ ```ruby
24
+ client.multi_signature_accounts(publicKey)
25
+ ```
@@ -0,0 +1,17 @@
1
+ # Peer
2
+
3
+ ## Get a single peer.
4
+
5
+ ```ruby
6
+ client.peer(ip, port)
7
+ ```
8
+ ## Get all peers.
9
+
10
+ ```ruby
11
+ client.peers(parameters: {})
12
+ ```
13
+ ## Get the peer version.
14
+
15
+ ```ruby
16
+ client.version
17
+ ```
@@ -0,0 +1,13 @@
1
+ # Signature
2
+
3
+ ## Get the fee for a signature.
4
+
5
+ ```ruby
6
+ client.signature_fee
7
+ ```
8
+
9
+ ## Create a new signature.
10
+
11
+ ```ruby
12
+ client.create_signature(secret, secondSecret)
13
+ ```
@@ -0,0 +1,31 @@
1
+ # Transactions
2
+
3
+ ## Get a single transaction.
4
+
5
+ ```ruby
6
+ client.transaction(id)
7
+ ```
8
+
9
+ ## Get all transactions.
10
+
11
+ ```ruby
12
+ client.transactions(parameters: {})
13
+ ```
14
+
15
+ ## Get a single unconfirmed transaction.
16
+
17
+ ```ruby
18
+ client.unconfirmed_transaction(id)
19
+ ```
20
+
21
+ ## Get all unconfirmed transactions.
22
+
23
+ ```ruby
24
+ client.unconfirmed_transactions(parameters: {})
25
+ ```
26
+
27
+ ## Create a new transaction.
28
+
29
+ ```ruby
30
+ client.create_transaction(recipientId, amount, vendorField, secret, secondSecret)
31
+ ```
@@ -0,0 +1,14 @@
1
+ ## Usage
2
+
3
+ ```ruby
4
+ require 'ark'
5
+
6
+ client = Ark::Client.new(
7
+ :ip => 'your-ip',
8
+ :port => 4001,
9
+ :nethash => '6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988',
10
+ :version => '1.0.1'
11
+ )
12
+
13
+ print client.version
14
+ ```
@@ -0,0 +1,12 @@
1
+ require 'ark/client'
2
+
3
+ module Ark
4
+ class << self
5
+ include Ark::Configurable
6
+
7
+ def client
8
+ return @client if defined?(@client) && @client.same_options?(options)
9
+ @client = Ark::Client.new(options)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ require 'ark/connection'
2
+ require 'ark/configurable'
3
+ require 'ark/nucleid'
4
+ require 'ark/client/account'
5
+ require 'ark/client/block'
6
+ require 'ark/client/delegate'
7
+ require 'ark/client/loader'
8
+ require 'ark/client/multisignature'
9
+ require 'ark/client/peer'
10
+ require 'ark/client/signature'
11
+ require 'ark/client/transaction'
12
+
13
+ module Ark
14
+ class Client
15
+ include Ark::Configurable
16
+ include Ark::Connection
17
+ include Ark::Nucleid
18
+ include Ark::Client::Account
19
+ include Ark::Client::Block
20
+ include Ark::Client::Delegate
21
+ include Ark::Client::Loader
22
+ include Ark::Client::MultiSignature
23
+ include Ark::Client::Peer
24
+ include Ark::Client::Signature
25
+ include Ark::Client::Transaction
26
+
27
+ def initialize(options = {})
28
+ Ark::Configurable.keys.each do |key|
29
+ instance_variable_set(:"@#{key}", options[key] || Ark.instance_variable_get(:"@#{key}"))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Ark
2
+ class Client
3
+ module Account
4
+ def account_balance(address)
5
+ get('api/accounts/getBalance', {address: address})
6
+ end
7
+
8
+ def account_publickey(address)
9
+ get('api/accounts/getPublickey', {address: address})
10
+ end
11
+
12
+ def account_delegates(address)
13
+ get('api/accounts/delegates', {address: address})
14
+ end
15
+
16
+ def account_delegates_fee(address)
17
+ get('api/accounts/delegates/fee', {address: address})
18
+ end
19
+
20
+ def create_account_delegates(secret, publicKey, secondSecret)
21
+ put('api/accounts/delegates', {
22
+ :secret => secret,
23
+ :publicKey => publicKey,
24
+ :secondSecret => secondSecret
25
+ })
26
+ end
27
+
28
+ def account(address)
29
+ get('api/accounts', {address: address})
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ module Ark
2
+ class Client
3
+ module Block
4
+ def block(id)
5
+ get('api/blocks/get', {:id => id})
6
+ end
7
+
8
+ def blocks(parameters: {})
9
+ get('api/blocks', parameters)
10
+ end
11
+
12
+ def block_epoch
13
+ get('api/blocks/getEpoch')
14
+ end
15
+
16
+ def block_height
17
+ get('api/blocks/getHeight')
18
+ end
19
+
20
+ def block_nethash
21
+ get('api/blocks/getNethash')
22
+ end
23
+
24
+ def block_fee
25
+ get('api/blocks/getFee')
26
+ end
27
+
28
+ def block_fees
29
+ get('api/blocks/getFees')
30
+ end
31
+
32
+ def block_milestone
33
+ get('api/blocks/getMilestone')
34
+ end
35
+
36
+ def block_reward
37
+ get('api/blocks/getReward')
38
+ end
39
+
40
+ def block_supply
41
+ get('api/blocks/getSupply')
42
+ end
43
+
44
+ def block_status
45
+ get('api/blocks/getStatus')
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,71 @@
1
+ module Ark
2
+ class Client
3
+ module Delegate
4
+ def count_delegates
5
+ get('api/delegates/count')
6
+ end
7
+
8
+ def search_delegates(q, parameters: {})
9
+ get('api/delegates/search', {q: q}.merge(parameters))
10
+ end
11
+
12
+ def delegate_voters(publicKey, parameters: {})
13
+ get('api/delegates/voters', {publicKey: publicKey}.merge(parameters))
14
+ end
15
+
16
+ def delegate(parameters: {})
17
+ get('api/delegates/get', parameters)
18
+ end
19
+
20
+ def delegates(parameters: {})
21
+ get('api/delegates', parameters)
22
+ end
23
+
24
+ def delegate_fee
25
+ get('api/delegates/fee')
26
+ end
27
+
28
+ def forged_by_account(generatorPublicKey)
29
+ get('api/delegates/forging/getForgedByAccount', {generatorPublicKey: generatorPublicKey})
30
+ end
31
+
32
+ def create_delegate(secret, username, secondSecret: nil)
33
+ transaction = buildTransaction(
34
+ 'delegate.createDelegate', {
35
+ :secret => secret,
36
+ :username => username,
37
+ :secondSecret => secondSecret
38
+ })
39
+
40
+ post('peer/transactions', {:transactions => [transaction]})
41
+ end
42
+
43
+ def vote_for_delegate(secret, delegates, secondSecret: nil)
44
+ transaction = buildTransaction(
45
+ 'vote.createVote', {
46
+ :secret => secret,
47
+ :delegates => delegates,
48
+ :secondSecret => secondSecret
49
+ })
50
+
51
+ post('peer/transactions', {:transactions => [transaction]})
52
+ end
53
+
54
+ def next_forgers
55
+ get('api/delegates/getNextForgers')
56
+ end
57
+
58
+ def enable_forging(secret, parameters: {})
59
+ post('api/delegates/forging/enable', {:secret => secret}.merge(parameters))
60
+ end
61
+
62
+ def disable_forging(secret, parameters: {})
63
+ post('api/delegates/forging/disable', {:secret => secret}.merge(parameters))
64
+ end
65
+
66
+ def forging_status(publicKey, parameters: {})
67
+ post('api/delegates/forging/disable', {:publicKey => publicKey}.merge(parameters))
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ module Ark
2
+ class Client
3
+ module Loader
4
+ def status
5
+ get('api/loader/status')
6
+ end
7
+
8
+ def sync
9
+ get('api/loader/status/sync')
10
+ end
11
+
12
+ def autoconfigure
13
+ get('api/loader/autoconfigure')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Ark
2
+ class Client
3
+ module MultiSignature
4
+ def pending_multi_signatures(publicKey)
5
+ get('api/multisignatures/pending', {:publicKey => publicKey})
6
+ end
7
+
8
+ def multi_signature_sign(transactionId, secret, parameters: {})
9
+ post('api/multisignatures/sign', {:transactionId => transactionId, :secret => secret}.merge(parameters))
10
+ end
11
+
12
+ def create_multi_signature(secret, secondSecret, keysgroup, lifetime, min)
13
+ transaction = buildTransaction(
14
+ 'multisignature.createMultisignature', {
15
+ :secret => secret,
16
+ :secondSecret => secondSecret,
17
+ :keysgroup => keysgroup,
18
+ :lifetime => lifetime,
19
+ :min => min
20
+ })
21
+
22
+ post('peer/transactions', {:transactions => [transaction]})
23
+ end
24
+
25
+ def multi_signature_accounts(publicKey)
26
+ get('api/multisignatures/accounts', {:publicKey => publicKey})
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ module Ark
2
+ class Client
3
+ module Peer
4
+ def peer(ip, port)
5
+ get('api/peers/get', {:ip => ip, :port => port})
6
+ end
7
+
8
+ def peers(parameters: {})
9
+ get('api/peers', parameters)
10
+ end
11
+
12
+ def version
13
+ get('api/peers/version')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Ark
2
+ class Client
3
+ module Signature
4
+ def signature_fee
5
+ get('api/signatures/fee')
6
+ end
7
+
8
+ def create_signature(secret, secondSecret)
9
+ transaction = buildTransaction(
10
+ 'signature.createSignature', {
11
+ :secret => secret,
12
+ :secondSecret => secondSecret
13
+ })
14
+
15
+ post('peer/transactions', {:transactions => [transaction]})
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module Ark
2
+ class Client
3
+ module Transaction
4
+ def transaction(id)
5
+ get('api/transactions/get', {:id => id})
6
+ end
7
+
8
+ def transactions(parameters: {})
9
+ get('api/transactions', parameters)
10
+ end
11
+
12
+ def unconfirmed_transaction(id)
13
+ get('api/transactions/unconfirmed/get', {:id => id})
14
+ end
15
+
16
+ def unconfirmed_transactions(parameters: {})
17
+ get('api/transactions/unconfirmed', parameters)
18
+ end
19
+
20
+ def create_transaction(recipientId, amount, vendorField, secret, secondSecret)
21
+ transaction = buildTransaction(
22
+ 'transaction.createTransaction', {
23
+ :recipientId => recipientId,
24
+ :amount => amount,
25
+ :vendorField => vendorField,
26
+ :secret => secret,
27
+ :secondSecret => secondSecret,
28
+ })
29
+
30
+ transaction['amount'] = transaction['amount'].to_i
31
+
32
+ post('peer/transactions', {:transactions => [transaction]})
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module Ark
2
+ module Configurable
3
+ attr_accessor :ip, :port, :nethash, :version
4
+ attr_writer :ip, :port, :nethash, :version
5
+
6
+ class << self
7
+ def keys
8
+ @keys ||= [
9
+ :ip,
10
+ :port,
11
+ :nethash,
12
+ :version
13
+ ]
14
+ end
15
+ end
16
+
17
+ # Set configuration options using a block
18
+ def configure
19
+ yield self
20
+ end
21
+
22
+ # Reset configuration options to default values
23
+ def reset!
24
+ Ark::Configurable.keys.each do |key|
25
+ instance_variable_set(:"@#{key}", Ark::Default.options[key])
26
+ end
27
+ self
28
+ end
29
+ alias setup reset!
30
+
31
+ # Compares client options to a Hash of requested options
32
+ #
33
+ # @param opts [Hash] Options to compare with current client options
34
+ # @return [Boolean]
35
+ def same_options?(opts)
36
+ opts.hash == options.hash
37
+ end
38
+
39
+ private
40
+
41
+ def options
42
+ Hash[Ark::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,61 @@
1
+ require 'json'
2
+ require 'faraday_middleware'
3
+
4
+ module Ark
5
+ module Connection
6
+ def get(url, options = {})
7
+ request :get, url, options
8
+ end
9
+
10
+ def post(url, options = {})
11
+ request :post, url, options
12
+ end
13
+
14
+ def put(url, options = {})
15
+ request :put, url, options
16
+ end
17
+
18
+ def delete(url, options = {})
19
+ request :delete, url, options
20
+ end
21
+
22
+ def root
23
+ "http://#{@ip}:#{@port}/"
24
+ end
25
+
26
+ def last_response
27
+ @last_response if defined? @last_response
28
+ end
29
+
30
+ private
31
+
32
+ def request(method, path, data)
33
+ request = http.send(method, path, data)
34
+
35
+ @last_response = response = JSON.parse request.body
36
+
37
+ if response['success'] == false
38
+ raise response['error']
39
+ end
40
+
41
+ if response['status'] == false
42
+ raise response['error']
43
+ end
44
+
45
+ response
46
+ end
47
+
48
+ def http
49
+ connection = Faraday.new root do |conn|
50
+ conn.headers['Content-Type'] = 'application/json'
51
+ conn.headers[:nethash] = @nethash
52
+ conn.headers[:version] = @version
53
+ conn.headers[:port] = "1"
54
+
55
+ conn.request :json
56
+
57
+ conn.adapter Faraday.default_adapter
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ module Ark
4
+ module Nucleid
5
+ def buildTransaction(method, arguments)
6
+ arguments = buildTransactionArguments(arguments)
7
+
8
+ output = `nucleid -r arkjs -e #{method} #{arguments} --ojson`
9
+
10
+ JSON.parse output
11
+ end
12
+
13
+ def buildTransactionArguments(arguments)
14
+ result = ""
15
+
16
+ arguments.each do |key, value|
17
+ if value.is_a? String
18
+ result.concat('"' + value.to_s + '" ')
19
+ else
20
+ result.concat(value.to_s + ' ')
21
+ end
22
+ end
23
+
24
+ result
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Ark
2
+ # Current major release.
3
+ MAJOR = 0
4
+
5
+ # Current minor release.
6
+ MINOR = 1
7
+
8
+ # Current patch level.
9
+ PATCH = 0
10
+
11
+ # Full release version.
12
+ VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
13
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ark-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Faust
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-16 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: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.1
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.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.2.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.2.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.12.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.12.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.12.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.12.2
111
+ description: An Ark Client for Ruby
112
+ email:
113
+ - hello@brianfaust.me
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.example"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - ark-ruby.gemspec
127
+ - bin/console
128
+ - bin/setup
129
+ - docs/Account.md
130
+ - docs/Block.md
131
+ - docs/Delegate.md
132
+ - docs/Initialization.md
133
+ - docs/Installation.md
134
+ - docs/Loader.md
135
+ - docs/MultiSignature.md
136
+ - docs/Peer.md
137
+ - docs/Signature.md
138
+ - docs/Transaction.md
139
+ - docs/Usage.md
140
+ - lib/ark.rb
141
+ - lib/ark/client.rb
142
+ - lib/ark/client/account.rb
143
+ - lib/ark/client/block.rb
144
+ - lib/ark/client/delegate.rb
145
+ - lib/ark/client/loader.rb
146
+ - lib/ark/client/multisignature.rb
147
+ - lib/ark/client/peer.rb
148
+ - lib/ark/client/signature.rb
149
+ - lib/ark/client/transaction.rb
150
+ - lib/ark/configurable.rb
151
+ - lib/ark/connection.rb
152
+ - lib/ark/nucleid.rb
153
+ - lib/ark/version.rb
154
+ homepage: https://github.com/faustbrian/Ark-Ruby
155
+ licenses:
156
+ - MIT
157
+ metadata:
158
+ allowed_push_host: https://rubygems.org
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.6.11
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: An Ark Client for Ruby
179
+ test_files: []