sila-ruby 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +90 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/bin/console +21 -0
- data/bin/setup +8 -0
- data/lib/deep_symbolize.rb +66 -0
- data/lib/sila-ruby.rb +1 -0
- data/lib/sila-ruby/accounts.rb +92 -0
- data/lib/sila-ruby/api_helpers.rb +92 -0
- data/lib/sila-ruby/banks.rb +46 -0
- data/lib/sila-ruby/transactions.rb +101 -0
- data/lib/sila-ruby/version.rb +3 -0
- data/lib/sila_ruby.rb +51 -0
- data/sila-ruby.gemspec +36 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae32e01d27c73fa7f96d8a7d382aceb1f46a9bec408e710043d9e7df7b288efc
|
4
|
+
data.tar.gz: 64fc5670f6804dc35068635e37dc48b17eb60e3b791d1507c10b23906a2990db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7380f0eadf6cdf35866751e46706eaa8da80319dfef16b254fef80e41b91800330677d8847df10d2448c13c5f309bfa1cf3a0e237c7d0457981d23ef82c961e
|
7
|
+
data.tar.gz: 3e20c25997dccd399fc3a9006049cfe978cd175a3ae63f3a8ff30dd6e4657ca0341a8d0bc3cdca8e3feccc9c2fa5f570828e754f7f1a16b98c845a4f250f0b15
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sila-ruby (0.0.2)
|
5
|
+
addressable (~> 2.6)
|
6
|
+
dotenv (~> 2.7)
|
7
|
+
eth
|
8
|
+
httparty (~> 0.17)
|
9
|
+
json (~> 2.2)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.7.0)
|
15
|
+
public_suffix (>= 2.0.2, < 5.0)
|
16
|
+
ansi (1.5.0)
|
17
|
+
coderay (1.1.2)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
digest-sha3 (1.1.0)
|
20
|
+
docile (1.3.2)
|
21
|
+
dotenv (2.7.5)
|
22
|
+
eth (0.4.10)
|
23
|
+
digest-sha3 (~> 1.1)
|
24
|
+
ffi (~> 1.0)
|
25
|
+
money-tree (~> 0.10.0)
|
26
|
+
rlp (~> 0.7.3)
|
27
|
+
scrypt (~> 3.0.6)
|
28
|
+
ffi (1.11.1)
|
29
|
+
ffi-compiler (1.0.1)
|
30
|
+
ffi (>= 1.0.0)
|
31
|
+
rake
|
32
|
+
httparty (0.17.0)
|
33
|
+
mime-types (~> 3.0)
|
34
|
+
multi_xml (>= 0.5.2)
|
35
|
+
json (2.2.0)
|
36
|
+
method_source (0.9.2)
|
37
|
+
mime-types (3.3)
|
38
|
+
mime-types-data (~> 3.2015)
|
39
|
+
mime-types-data (3.2019.0904)
|
40
|
+
money-tree (0.10.0)
|
41
|
+
ffi
|
42
|
+
multi_xml (0.6.0)
|
43
|
+
pry (0.12.2)
|
44
|
+
coderay (~> 1.1.0)
|
45
|
+
method_source (~> 0.9.0)
|
46
|
+
public_suffix (4.0.1)
|
47
|
+
rake (10.5.0)
|
48
|
+
rlp (0.7.3)
|
49
|
+
rspec (3.8.0)
|
50
|
+
rspec-core (~> 3.8.0)
|
51
|
+
rspec-expectations (~> 3.8.0)
|
52
|
+
rspec-mocks (~> 3.8.0)
|
53
|
+
rspec-core (3.8.1)
|
54
|
+
rspec-support (~> 3.8.0)
|
55
|
+
rspec-expectations (3.8.4)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.8.0)
|
58
|
+
rspec-mocks (3.8.1)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.8.0)
|
61
|
+
rspec-support (3.8.2)
|
62
|
+
scrypt (3.0.6)
|
63
|
+
ffi-compiler (>= 1.0, < 2.0)
|
64
|
+
simplecov (0.16.1)
|
65
|
+
docile (~> 1.1)
|
66
|
+
json (>= 1.8, < 3)
|
67
|
+
simplecov-html (~> 0.10.0)
|
68
|
+
simplecov-console (0.5.0)
|
69
|
+
ansi
|
70
|
+
simplecov
|
71
|
+
terminal-table
|
72
|
+
simplecov-html (0.10.2)
|
73
|
+
terminal-table (1.8.0)
|
74
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
75
|
+
unicode-display_width (1.6.0)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
bundler (~> 1.16)
|
82
|
+
pry (~> 0.12.2)
|
83
|
+
rake (~> 10.0)
|
84
|
+
rspec (~> 3.0)
|
85
|
+
sila-ruby!
|
86
|
+
simplecov (~> 0.16.0)
|
87
|
+
simplecov-console (~> 0.5.0)
|
88
|
+
|
89
|
+
BUNDLED WITH
|
90
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Vertbase
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# SilaRuby
|
2
|
+
|
3
|
+
A simple Ruby gem for the Sila API protocol.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sila-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sila-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Load the gem
|
24
|
+
```
|
25
|
+
require 'sila-ruby'
|
26
|
+
```
|
27
|
+
|
28
|
+
### Setup your Sila API keys
|
29
|
+
|
30
|
+
```
|
31
|
+
SilaRuby.setup do |config|
|
32
|
+
config.handle = 'SILA_HANDLE'
|
33
|
+
config.address = 'SILA_ADDRESS'
|
34
|
+
config.private_key = "SILA_PRIVATE_KEY"
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### Use the gem
|
39
|
+
|
40
|
+
The gem methods are named after the official Sila API Documentation: https://docs.silamoney.com/?plaintext#endpoints
|
data/bin/console
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'dotenv/load'
|
5
|
+
require 'sila-ruby'
|
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
|
+
SilaRuby.setup do |config|
|
15
|
+
config.address = ENV['SILA_ADDRESS']
|
16
|
+
config.handle = ENV['SILA_HANDLE']
|
17
|
+
config.private_key = ENV['SILA_PRIVATE_KEY']
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'irb'
|
21
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# ================================================
|
2
|
+
# DEEP-SYMBOLIZE =================================
|
3
|
+
# ================================================
|
4
|
+
module DeepSymbolizable
|
5
|
+
|
6
|
+
# ----------------------------------------------
|
7
|
+
# DEEP-SYMBOLIZE -------------------------------
|
8
|
+
# ----------------------------------------------
|
9
|
+
def deep_symbolize(&block)
|
10
|
+
method = self.class.to_s.downcase.to_sym
|
11
|
+
syms = DeepSymbolizable::Symbolizers
|
12
|
+
syms.respond_to?(method) ? syms.send(method, self, &block) : self
|
13
|
+
end
|
14
|
+
|
15
|
+
# ----------------------------------------------
|
16
|
+
# SYMBOLIZERS ----------------------------------
|
17
|
+
# ----------------------------------------------
|
18
|
+
# Used to symbolize hashes
|
19
|
+
module Symbolizers
|
20
|
+
module_function
|
21
|
+
|
22
|
+
# --------------------------------------------
|
23
|
+
# HASH ---------------------------------------
|
24
|
+
# --------------------------------------------
|
25
|
+
# The primary method - symbolizes keys of the given hash, preprocessing them with a block if one was given, and recursively going into all nested enumerables
|
26
|
+
def hash(hash, &block)
|
27
|
+
hash.each_with_object({}) do |(key, value), result|
|
28
|
+
# Recursively deep-symbolize subhashes
|
29
|
+
value = _recurse_(value, &block)
|
30
|
+
# Pre-process the key with a block if it was given
|
31
|
+
key = yield key if block_given?
|
32
|
+
# Symbolize the key string if it responds to to_sym
|
33
|
+
sym_key = begin
|
34
|
+
key.to_sym
|
35
|
+
rescue StandardError
|
36
|
+
key
|
37
|
+
end
|
38
|
+
# Write it back into the result and return the updated hash
|
39
|
+
result[sym_key] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# --------------------------------------------
|
44
|
+
# ARRAY --------------------------------------
|
45
|
+
# --------------------------------------------
|
46
|
+
# Walking over arrays and symbolizing all nested elements
|
47
|
+
def array(ary, &block)
|
48
|
+
ary.map { |v| _recurse_(v, &block) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# --------------------------------------------
|
52
|
+
# RECURSE ------------------------------------
|
53
|
+
# --------------------------------------------
|
54
|
+
# Handling recursion - any Enumerable elements (except String) is being extended with the module, and then symbolized
|
55
|
+
def _recurse_(value, &block)
|
56
|
+
if value.is_a?(Enumerable) && !value.is_a?(String)
|
57
|
+
# Support for a use case without extended core Hash
|
58
|
+
unless value.class.include?(DeepSymbolizable)
|
59
|
+
value.extend DeepSymbolizable
|
60
|
+
end
|
61
|
+
value = value.deep_symbolize(&block)
|
62
|
+
end
|
63
|
+
value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/sila-ruby.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'sila_ruby.rb')
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# ================================================
|
2
|
+
# SILA-RUBY ======================================
|
3
|
+
# ================================================
|
4
|
+
module SilaRuby
|
5
|
+
|
6
|
+
# ==============================================
|
7
|
+
# ACCOUNTS =====================================
|
8
|
+
# ==============================================
|
9
|
+
class Accounts
|
10
|
+
|
11
|
+
# --------------------------------------------
|
12
|
+
# INCLUDES -----------------------------------
|
13
|
+
# --------------------------------------------
|
14
|
+
include ApiHelpers
|
15
|
+
|
16
|
+
# --------------------------------------------
|
17
|
+
# CHECK-HANDLE -------------------------------
|
18
|
+
# --------------------------------------------
|
19
|
+
# Check if a specific handle is taken
|
20
|
+
def self.check_handle(handle)
|
21
|
+
header = { user_handle: handle }
|
22
|
+
message = 'header_msg'
|
23
|
+
post_signed('check_handle', header, message, nil, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
# --------------------------------------------
|
27
|
+
# REGISTER -----------------------------------
|
28
|
+
# --------------------------------------------
|
29
|
+
# Attaches KYC and blockchain address to user handle
|
30
|
+
def self.register(handle, params={})
|
31
|
+
header = { user_handle: handle }
|
32
|
+
message = 'entity_msg'
|
33
|
+
|
34
|
+
# Example of params passed
|
35
|
+
#
|
36
|
+
# params = {
|
37
|
+
# address: {
|
38
|
+
# address_alias: "home",
|
39
|
+
# street_address_1: "1265 Lombardi Ave",
|
40
|
+
# city: "Green Bay",
|
41
|
+
# state: "WI",
|
42
|
+
# country: "US",
|
43
|
+
# postal_code: "54304"
|
44
|
+
# },
|
45
|
+
# identity: {
|
46
|
+
# identity_alias: "SSN",
|
47
|
+
# identity_value: "123452222"
|
48
|
+
# },
|
49
|
+
# contact: {
|
50
|
+
# contact_alias: "",
|
51
|
+
# phone: "503-123-4567",
|
52
|
+
# email: "example@silamoney.com"
|
53
|
+
# },
|
54
|
+
# crypto_entry: {
|
55
|
+
# crypto_alias: "Address 1",
|
56
|
+
# crypto_address: "0x1234567890abcdef1234567890abcdef12345678",
|
57
|
+
# crypto_code: "ETH"
|
58
|
+
# },
|
59
|
+
# entity: {
|
60
|
+
# birthdate: "1900-01-31",
|
61
|
+
# entity_name: "Example User",
|
62
|
+
# first_name: "Example",
|
63
|
+
# last_name: "User",
|
64
|
+
# relationship: "user"
|
65
|
+
# }
|
66
|
+
# }
|
67
|
+
|
68
|
+
post_signed('register', header, message, params, nil)
|
69
|
+
end
|
70
|
+
|
71
|
+
# --------------------------------------------
|
72
|
+
# REQUEST-KYC --------------------------------
|
73
|
+
# --------------------------------------------
|
74
|
+
# Start KYC verification process on a registered user handle
|
75
|
+
def self.request_kyc(handle, user_key)
|
76
|
+
header = { user_handle: handle }
|
77
|
+
message = 'header_msg'
|
78
|
+
post_signed('request_kyc', header, message, nil, user_key)
|
79
|
+
end
|
80
|
+
|
81
|
+
# --------------------------------------------
|
82
|
+
# CHECK-KYC ----------------------------------
|
83
|
+
# --------------------------------------------
|
84
|
+
# Whether entity attached to user handle is verified, not valid, or pending
|
85
|
+
def self.check_kyc(handle, user_key)
|
86
|
+
header = { user_handle: handle }
|
87
|
+
message = 'header_msg'
|
88
|
+
post_signed('check_kyc', header, message, nil, user_key)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# ================================================
|
2
|
+
# SILA-RUBY->API-HELPERS =========================
|
3
|
+
# ================================================
|
4
|
+
module ApiHelpers
|
5
|
+
|
6
|
+
# ==============================================
|
7
|
+
# INCLUDED =====================================
|
8
|
+
# ==============================================
|
9
|
+
def self.included(base)
|
10
|
+
base.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
# ==============================================
|
14
|
+
# HTTPHEADER ===================================
|
15
|
+
# ==============================================
|
16
|
+
# Sila's API doesn't allow lowercase headers
|
17
|
+
module Net::HTTPHeader
|
18
|
+
def capitalize(name)
|
19
|
+
name
|
20
|
+
end
|
21
|
+
private :capitalize
|
22
|
+
end
|
23
|
+
|
24
|
+
# ==============================================
|
25
|
+
# CLASS-METHODS ================================
|
26
|
+
# ==============================================
|
27
|
+
module ClassMethods
|
28
|
+
|
29
|
+
# --------------------------------------------
|
30
|
+
# BASE-URI -----------------------------------
|
31
|
+
# --------------------------------------------
|
32
|
+
def base_uri
|
33
|
+
ENV['environment'] == 'production' ? 'https://api.silamoney.com' : 'https://sandbox.silamoney.com'
|
34
|
+
end
|
35
|
+
|
36
|
+
# --------------------------------------------
|
37
|
+
# POST-SIGNED --------------------------------
|
38
|
+
# --------------------------------------------
|
39
|
+
def post_signed(api_group, header={}, message={}, params={}, user_key)
|
40
|
+
# Set the post URL
|
41
|
+
url = "#{base_uri}/0.2/#{api_group}"
|
42
|
+
# Create the header
|
43
|
+
header = header.merge({reference: SecureRandom.uuid, created: Time.now.to_i, auth_handle: SilaRuby.configuration.handle, version: '0.2', crypto: 'ETH'})
|
44
|
+
# Put together the body in JSON
|
45
|
+
body = {
|
46
|
+
header: header,
|
47
|
+
message: message
|
48
|
+
}
|
49
|
+
unless params.nil?
|
50
|
+
body = body.merge(params)
|
51
|
+
end
|
52
|
+
bodyJSON = body.to_json
|
53
|
+
# Sign the authorization request
|
54
|
+
auth_key = Eth::Key.new priv: SilaRuby.configuration.private_key
|
55
|
+
auth_signature = sila_personal_sign(auth_key, bodyJSON)
|
56
|
+
# Sign the user request
|
57
|
+
unless user_key.nil?
|
58
|
+
user_key = Eth::Key.new priv: user_key
|
59
|
+
user_signature = sila_personal_sign(user_key, bodyJSON)
|
60
|
+
end
|
61
|
+
# Post to the API endpoint
|
62
|
+
begin
|
63
|
+
response = HTTParty.post(url, { "body": bodyJSON, "headers": { "authsignature": auth_signature, "usersignature": user_signature }})
|
64
|
+
res_hash(response)
|
65
|
+
rescue => e
|
66
|
+
e.inspect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# ============================================
|
71
|
+
# PRIVATE ====================================
|
72
|
+
# ============================================
|
73
|
+
private
|
74
|
+
|
75
|
+
# --------------------------------------------
|
76
|
+
# SILA-PERSONAL-SIGNED -----------------------
|
77
|
+
# --------------------------------------------
|
78
|
+
def sila_personal_sign(key, message)
|
79
|
+
Eth::Utils.bin_to_hex(key.sign(message).bytes.rotate(1).pack('c*'))
|
80
|
+
end
|
81
|
+
|
82
|
+
# --------------------------------------------
|
83
|
+
# RES-HASH -----------------------------------
|
84
|
+
# --------------------------------------------
|
85
|
+
def res_hash(res)
|
86
|
+
data = JSON.parse(res.body)
|
87
|
+
data.extend DeepSymbolizable
|
88
|
+
{ data: data.deep_symbolize }
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# ================================================
|
2
|
+
# SILA-RUBY ======================================
|
3
|
+
# ================================================
|
4
|
+
module SilaRuby
|
5
|
+
|
6
|
+
# ==============================================
|
7
|
+
# BANKS ========================================
|
8
|
+
# ==============================================
|
9
|
+
class Banks
|
10
|
+
|
11
|
+
# --------------------------------------------
|
12
|
+
# INCLUDES -----------------------------------
|
13
|
+
# --------------------------------------------
|
14
|
+
include ApiHelpers
|
15
|
+
|
16
|
+
# --------------------------------------------
|
17
|
+
# LINK-ACCOUNT -------------------------------
|
18
|
+
# --------------------------------------------
|
19
|
+
# Uses a provided Plaid public token to link a bank account to a verified entity
|
20
|
+
def self.link_account(handle, params={}, user_key)
|
21
|
+
header = { user_handle: handle }
|
22
|
+
message = 'link_account_msg'
|
23
|
+
|
24
|
+
# Example of params passed
|
25
|
+
#
|
26
|
+
# params = {
|
27
|
+
# public_token: "public-xxx-xxx",
|
28
|
+
# account_name: "Custom Account Name",
|
29
|
+
# selected_account_id: "optional_selected_account_id"
|
30
|
+
# }
|
31
|
+
|
32
|
+
post_signed('link_account', header, message, params, user_key)
|
33
|
+
end
|
34
|
+
|
35
|
+
# --------------------------------------------
|
36
|
+
# GET-ACCOUNTS -------------------------------
|
37
|
+
# --------------------------------------------
|
38
|
+
# Gets basic bank account names linked to user handle
|
39
|
+
def self.get_accounts(handle, user_key)
|
40
|
+
header = { user_handle: handle }
|
41
|
+
message = 'get_accounts_msg'
|
42
|
+
post_signed('get_accounts', header, message, nil, user_key)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# ================================================
|
2
|
+
# SILA-RUBY ======================================
|
3
|
+
# ================================================
|
4
|
+
module SilaRuby
|
5
|
+
|
6
|
+
# ==============================================
|
7
|
+
# TRANSACTIONS =================================
|
8
|
+
# ==============================================
|
9
|
+
class Transactions
|
10
|
+
|
11
|
+
# --------------------------------------------
|
12
|
+
# INCLUDES -----------------------------------
|
13
|
+
# --------------------------------------------
|
14
|
+
include ApiHelpers
|
15
|
+
|
16
|
+
# --------------------------------------------
|
17
|
+
# ISSUE-SILA ---------------------------------
|
18
|
+
# --------------------------------------------
|
19
|
+
# Debits a specified account and issues tokens to the address belonging to the requested handle
|
20
|
+
def self.issue_sila(handle, params={}, user_key)
|
21
|
+
header = { user_handle: handle }
|
22
|
+
message = 'issue_msg'
|
23
|
+
|
24
|
+
# Example of params passed
|
25
|
+
#
|
26
|
+
# params = {
|
27
|
+
# amount: 1000,
|
28
|
+
# account_name: "default"
|
29
|
+
# }
|
30
|
+
|
31
|
+
post_signed('issue_sila', header, message, params, user_key)
|
32
|
+
end
|
33
|
+
|
34
|
+
# --------------------------------------------
|
35
|
+
# TRANSFER-SILA ------------------------------
|
36
|
+
# --------------------------------------------
|
37
|
+
# Starts a transfer of the requested amount of SILA to the requested destination handle
|
38
|
+
def self.transfer_sila(handle, params={}, user_key)
|
39
|
+
header = { user_handle: handle }
|
40
|
+
message = 'transfer_msg'
|
41
|
+
|
42
|
+
# Example of params passed
|
43
|
+
#
|
44
|
+
# params = {
|
45
|
+
# amount: 1000,
|
46
|
+
# destination: "user2.silamoney.eth"
|
47
|
+
# }
|
48
|
+
|
49
|
+
post_signed('transfer_sila', header, message, params, user_key)
|
50
|
+
end
|
51
|
+
|
52
|
+
# --------------------------------------------
|
53
|
+
# REDEEM-SILA --------------------------------
|
54
|
+
# --------------------------------------------
|
55
|
+
# Burns given amount of SILA at the handle's blockchain address and credits their named bank account in the equivalent monetary amount
|
56
|
+
def self.redeem_sila(handle, params={}, user_key)
|
57
|
+
header = { user_handle: handle }
|
58
|
+
message = 'redeem_msg'
|
59
|
+
|
60
|
+
# Example of params passed
|
61
|
+
#
|
62
|
+
# params = {
|
63
|
+
# amount: 1000,
|
64
|
+
# account_name: "default"
|
65
|
+
# }
|
66
|
+
|
67
|
+
post_signed('redeem_sila', header, message, params, user_key)
|
68
|
+
end
|
69
|
+
|
70
|
+
# --------------------------------------------
|
71
|
+
# GET-TRANSACTIONS ---------------------------
|
72
|
+
# --------------------------------------------
|
73
|
+
# Gets array of user handle's transactions with detailed status information
|
74
|
+
def self.get_transactions(handle, params={}, user_key)
|
75
|
+
header = { user_handle: handle }
|
76
|
+
message = 'get_transactions_msg'
|
77
|
+
|
78
|
+
# Example of params passed
|
79
|
+
#
|
80
|
+
# params = {
|
81
|
+
# search_filters: {
|
82
|
+
# transaction_id: "some UUID string assigned by Sila",
|
83
|
+
# reference_id: "the reference string sent in the header object when transaction request was made",
|
84
|
+
# show_timelines: true,
|
85
|
+
# sort_ascending: false,
|
86
|
+
# max_sila_amount: 1300,
|
87
|
+
# min_sila_amount: 1000,
|
88
|
+
# statuses: ["pending", "successful", "failed", "complete"],
|
89
|
+
# start_epoch: 1234567860,
|
90
|
+
# end_epoch: 1234567891,
|
91
|
+
# page: 1,
|
92
|
+
# per_page: 20,
|
93
|
+
# transaction_types: ["issue", "redeem", "transfer"]
|
94
|
+
# }
|
95
|
+
# }
|
96
|
+
|
97
|
+
post_signed('get_transactions', header, message, params, user_key)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
data/lib/sila_ruby.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
require 'digest/sha3'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'openssl'
|
5
|
+
require 'addressable/uri'
|
6
|
+
require 'deep_symbolize'
|
7
|
+
require 'json'
|
8
|
+
require 'httparty'
|
9
|
+
require 'pry'
|
10
|
+
require 'eth'
|
11
|
+
|
12
|
+
require 'sila-ruby/version'
|
13
|
+
require 'sila-ruby/api_helpers'
|
14
|
+
require 'sila-ruby/accounts'
|
15
|
+
require 'sila-ruby/banks'
|
16
|
+
require 'sila-ruby/transactions'
|
17
|
+
|
18
|
+
# ================================================
|
19
|
+
# SILA-RUBY ======================================
|
20
|
+
# ================================================
|
21
|
+
module SilaRuby
|
22
|
+
|
23
|
+
# ----------------------------------------------
|
24
|
+
# SELF -----------------------------------------
|
25
|
+
# ----------------------------------------------
|
26
|
+
class << self
|
27
|
+
attr_accessor :configuration
|
28
|
+
end
|
29
|
+
|
30
|
+
# ----------------------------------------------
|
31
|
+
# SETUP ----------------------------------------
|
32
|
+
# ----------------------------------------------
|
33
|
+
def self.setup
|
34
|
+
@configuration ||= Configuration.new
|
35
|
+
yield(configuration)
|
36
|
+
end
|
37
|
+
|
38
|
+
# ----------------------------------------------
|
39
|
+
# CONFIGURATION --------------------------------
|
40
|
+
# ----------------------------------------------
|
41
|
+
class Configuration
|
42
|
+
attr_accessor :address, :handle, :private_key
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@address = ''
|
46
|
+
@handle = ''
|
47
|
+
@pkey = ''
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/sila-ruby.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sila-ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'sila-ruby'
|
8
|
+
spec.version = SilaRuby::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ['Vertbase']
|
11
|
+
spec.email = ['dev@vertbase.com']
|
12
|
+
|
13
|
+
spec.summary = 'Ruby implementation of the Sila API'
|
14
|
+
spec.description = 'Ruby implementation of the Sila API'
|
15
|
+
spec.homepage = 'https://github.com/vertbase/sila-ruby'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'addressable', '~> 2.6'
|
25
|
+
spec.add_dependency 'json', '~> 2.2'
|
26
|
+
spec.add_dependency 'httparty', '~> 0.17'
|
27
|
+
spec.add_dependency 'dotenv', '~> 2.7'
|
28
|
+
spec.add_dependency 'eth'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.0'
|
34
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.5.0'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.12.2'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sila-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vertbase
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.17'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: eth
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.16'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.16.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.16.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov-console
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.5.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.5.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.12.2
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.12.2
|
167
|
+
description: Ruby implementation of the Sila API
|
168
|
+
email:
|
169
|
+
- dev@vertbase.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- Gemfile
|
177
|
+
- Gemfile.lock
|
178
|
+
- LICENSE
|
179
|
+
- README.md
|
180
|
+
- bin/console
|
181
|
+
- bin/setup
|
182
|
+
- lib/deep_symbolize.rb
|
183
|
+
- lib/sila-ruby.rb
|
184
|
+
- lib/sila-ruby/accounts.rb
|
185
|
+
- lib/sila-ruby/api_helpers.rb
|
186
|
+
- lib/sila-ruby/banks.rb
|
187
|
+
- lib/sila-ruby/transactions.rb
|
188
|
+
- lib/sila-ruby/version.rb
|
189
|
+
- lib/sila_ruby.rb
|
190
|
+
- sila-ruby.gemspec
|
191
|
+
homepage: https://github.com/vertbase/sila-ruby
|
192
|
+
licenses:
|
193
|
+
- MIT
|
194
|
+
metadata: {}
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
requirements: []
|
210
|
+
rubygems_version: 3.0.4
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: Ruby implementation of the Sila API
|
214
|
+
test_files: []
|