dpay-ruby 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23e94a17964a441a5b98383fc3946f6643a0c94d93a958bbc59a72bd1b2323d9
4
+ data.tar.gz: 9cb30fe0becefc5553244ae21dbb3ce3e6c676f4be47454a7d30ca7c42b72ffe
5
+ SHA512:
6
+ metadata.gz: 520176a45c078bd306c3a9fa37cb8b2433ab56fe2161d8b3dd08262133f73eae1f0d9c2f6e211b45b0d58ef1f2b3b4033fbc80d4997e394fcc3316ddbd156fb0
7
+ data.tar.gz: 20730173de19fa99069dc2a6512a6e79ae13fbbea2e1a99c16594ea4ead05fa5a82467d2039aa9fdc6a51999a7b79e8e3be461437c0d976b6d3eb07f1d8e3281
data/.gitignore ADDED
@@ -0,0 +1,54 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/fixtures/vcr_cassettes/*.yml
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+
53
+ # gource output
54
+ output.mp4
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,79 @@
1
+
2
+ # Contributing
3
+
4
+ Everyone is welcome to contribute code to dPay DAO projects. We have a Code of Conduct;
5
+ we ask that you please follow it in all your interactions with our team and your fellow
6
+ contributors.
7
+
8
+ Please note that this contributing guide only applies to our development presence.
9
+
10
+ ## How to contribute
11
+
12
+ 1. File an issue describing the problem you would like to
13
+ solve or the feature you would like to add. It saves unnecessary work on your part,
14
+ in case there's a nontechnical reason we can't accept a particular change.
15
+ Please note that we can and will _automatically close all pull requests that do not refer to
16
+ an issue_.
17
+ 2. Learn the conventions of the project you are submitting code to, even implicit ones,
18
+ and follow them. In case you have a question about a project's conventions, please
19
+ ask on the issue you filed. This includes writing tests, formatting code, and documentation.
20
+ 3. File a pull request against your Github issue and fill out the pull request template.
21
+ Remember, you are agreeing to license your code and any intellectual property associated
22
+ with your code under the same terms as the repository you are contributing to.
23
+ 4. If one of our teammates asks you to make changes, please make them. Our rule is that all
24
+ requests for changes in code review are resolved in favor of the reviewer. Our teammates
25
+ follow this rule too!
26
+
27
+ ## Code of Conduct
28
+
29
+ Again, please note that this Code of Conduct _only applies to our development presence_.
30
+
31
+ ### Our Pledge
32
+
33
+ We welcome your membership in our project and community under the rules that we have set below.
34
+
35
+ In the interest of fostering an open and welcoming environment, we as
36
+ contributors and maintainers will work to make your participation in
37
+ our project and community as fulfilling as possible.
38
+
39
+ ### Our Rules
40
+
41
+ All members of our project and community must:
42
+
43
+ 1. Show empathy toward other project and community members
44
+ 2. Use welcoming and inclusive language
45
+ 3. Respect differing viewpoints and experiences
46
+ 4. Gracefully accept constructive criticism
47
+
48
+ All members of our project and community must not:
49
+
50
+ 1. Harm our project and community, or advocate harm to our project and community
51
+ 2. Insult or make derogatory comments about others
52
+ 3. Interact with others after they have withdrawn permission to do so
53
+
54
+ ### Our Responsibilities
55
+
56
+ We will use any and all lawful means at our disposal to enforce our rules. This includes
57
+ but is not limited to:
58
+
59
+ 1. Rejecting contributions
60
+ 2. Removing comments, commits, code, wiki edits, and issues
61
+ 3. Banning abusers
62
+
63
+ We will clarify standards of acceptable behavior and we will take appropriate
64
+ and fair corrective action in response to any instances of unacceptable behavior.
65
+
66
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
67
+ reported by contacting us at github.abuse@dpays.io. All
68
+ complaints will be reviewed and investigated and will result in a response that
69
+ is deemed necessary and appropriate to the circumstances. We
70
+ maintain strict confidentiality with regard to the reporter of an incident.
71
+ Further details of specific enforcement policies may be posted separately.
72
+
73
+ ### Attribution
74
+
75
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
76
+ available at [http://contributor-covenant.org/version/1/4][version]
77
+
78
+ [homepage]: http://contributor-covenant.org
79
+ [version]: http://contributor-covenant.org/version/1/4/gg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dpay-ruby (0.1.1)
5
+ bitcoin-ruby (~> 0.0, >= 0.0.18)
6
+ ffi (~> 1.9, >= 1.9.23)
7
+ hashie (~> 3.5, >= 3.5.7)
8
+ json (~> 2.1, >= 2.1.0)
9
+ logging (~> 2.2, >= 2.2.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.5.2)
15
+ public_suffix (>= 2.0.2, < 4.0)
16
+ awesome_print (1.8.0)
17
+ bitcoin-ruby (0.0.18)
18
+ coderay (1.1.2)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ docile (1.3.1)
22
+ ffi (1.9.25)
23
+ hashdiff (0.3.7)
24
+ hashie (3.5.7)
25
+ json (2.1.0)
26
+ little-plugger (1.1.4)
27
+ logging (2.2.2)
28
+ little-plugger (~> 1.1)
29
+ multi_json (~> 1.10)
30
+ method_source (0.9.0)
31
+ minitest (5.11.3)
32
+ minitest-line (0.6.5)
33
+ minitest (~> 5.0)
34
+ minitest-proveit (1.0.0)
35
+ minitest (> 5, < 7)
36
+ multi_json (1.13.1)
37
+ pry (0.11.3)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ public_suffix (3.0.2)
41
+ rake (12.3.1)
42
+ safe_yaml (1.0.4)
43
+ simplecov (0.16.1)
44
+ docile (~> 1.1)
45
+ json (>= 1.8, < 3)
46
+ simplecov-html (~> 0.10.0)
47
+ simplecov-html (0.10.2)
48
+ vcr (4.0.0)
49
+ webmock (3.4.2)
50
+ addressable (>= 2.3.6)
51
+ crack (>= 0.3.2)
52
+ hashdiff
53
+ yard (0.9.15)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ awesome_print (~> 1.8, >= 1.8.0)
60
+ bundler (~> 1.16, >= 1.16.1)
61
+ dpay-ruby!
62
+ minitest (~> 5.10, >= 5.10.3)
63
+ minitest-line (~> 0.6, >= 0.6.4)
64
+ minitest-proveit (~> 1.0, >= 1.0.0)
65
+ pry (~> 0.11, >= 0.11.3)
66
+ rake (~> 12.3, >= 12.3.0)
67
+ simplecov (~> 0.15, >= 0.15.1)
68
+ vcr (~> 4.0, >= 4.0.0)
69
+ webmock (~> 3.3, >= 3.3.0)
70
+ yard (~> 0.9, >= 0.9.12)
71
+
72
+ BUNDLED WITH
73
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 dpay-ruby
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
+
data/README.md ADDED
@@ -0,0 +1,250 @@
1
+ [![Gem Version](https://badge.fury.io/rb/dpay-ruby.svg)](https://badge.fury.io/rb/dpay-ruby)
2
+ [![Inline docs](http://inch-ci.org/github/dpays/dpay-ruby.svg?branch=master&style=shields)](http://inch-ci.org/github/dpays/dpay-ruby)
3
+
4
+ # `dpay-ruby`
5
+
6
+ DPay-ruby the Ruby API for DPay blockchain.
7
+
8
+ Full documentation: http://www.rubydoc.info/gems/dpay-ruby
9
+
10
+ **Note:** *This library depends on AppBase methods that are a work in progress.*
11
+
12
+ ## `radiator` vs. `dpay-ruby`
13
+
14
+ The `dpay-ruby` gem was written from the ground up by `@inertia`, who is also the author of [`radiator`](https://github.com/inertia186/radiator).
15
+
16
+ > "I intend to continue work on `radiator` indefinitely. But in `radiator-0.5`, I intend to refactor `radiator` so that is uses `dpay-ruby` as its core. This means that some features of `radiator` like Serialization will become redundant. I think it's still useful for radiator to do its own serialization because it reduces the number of API requests." - @inertia
17
+
18
+ | `radiator` | `dpay-ruby` |
19
+ |-|-|
20
+ | Has internal failover logic | Can have failover delegated externally |
21
+ | Passes `error` responses to the caller | Handles `error` responses and raises exceptions |
22
+ | Supports tx signing, does its own serialization | Also supports tx signing, but delegates serialization to `database_api.get_transaction_hex` |
23
+ | All apis and methods are hardcoded | Asks `jsonrpc` what apis and methods are available from the node |
24
+ | (`radiator-0.4.x`) Only supports AppBase but relies on `condenser_api` | Only supports AppBase but does not rely on `condenser_api` **(WIP)**
25
+ | Small list of helper methods for select ops (in addition to build your own transaction) | Complete implementation of helper methods for every op (in addition to build your own transaction) |
26
+ | Does not (yet) support `json-rpc-batch` requests | Supports `json-rpc-batch` requests |
27
+
28
+ ## Getting Started
29
+
30
+ The dpay-ruby gem is compatible with Ruby 2.2.5 or later.
31
+
32
+ ### Install the gem for your project
33
+
34
+ *(Assuming that [Ruby is installed](https://www.ruby-lang.org/en/downloads/) on your computer, as well as [RubyGems](http://rubygems.org/pages/download))*
35
+
36
+ To install the gem on your computer, run in shell:
37
+
38
+ ```bash
39
+ gem install dpay-ruby
40
+ ```
41
+
42
+ ... then add in your code:
43
+
44
+ ```ruby
45
+ require 'dpay'
46
+ ```
47
+
48
+ To add the gem as a dependency to your project with [Bundler](http://bundler.io/), you can add this line in your Gemfile:
49
+
50
+ ```ruby
51
+ gem 'dpay-ruby', require: 'dpay'
52
+ ```
53
+
54
+ ## Examples
55
+
56
+ ### Broadcast Vote
57
+
58
+ ```ruby
59
+ params = {
60
+ voter: voter,
61
+ author: author,
62
+ permlink: permlink,
63
+ weight: weight
64
+ }
65
+
66
+ DPay::Broadcast.vote(wif: wif, params: params) do |result|
67
+ puts result
68
+ end
69
+ ```
70
+
71
+ *See: [Broadcast](https://www.rubydoc.info/gems/dpay-ruby/DPay/Broadcast)*
72
+
73
+ ### Streaming
74
+
75
+ The value passed to the block is an object, with the keys: `:type` and `:value`.
76
+
77
+ ```ruby
78
+ stream = DPay::Stream.new
79
+
80
+ stream.operations do |op|
81
+ puts "#{op.type}: #{op.value}"
82
+ end
83
+ ```
84
+
85
+ To start a stream from a specific block number, pass it as an argument:
86
+
87
+ ```ruby
88
+ stream = DPay::Stream.new
89
+
90
+ stream.operations(at_block_num: 9001) do |op|
91
+ puts "#{op.type}: #{op.value}"
92
+ end
93
+ ```
94
+
95
+ You can also grab the related transaction id and block number for each operation:
96
+
97
+ ```ruby
98
+ stream = DPay::Stream.new
99
+
100
+ stream.operations do |op, trx_id, block_num|
101
+ puts "#{block_num} :: #{trx_id}"
102
+ puts "#{op.type}: #{op.value}"
103
+ end
104
+ ```
105
+
106
+ To stream only certain operations:
107
+
108
+ ```ruby
109
+ stream = DPay::Stream.new
110
+
111
+ stream.operations(types: :vote_operation) do |op|
112
+ puts "#{op.type}: #{op.value}"
113
+ end
114
+ ```
115
+
116
+ Or pass an array of certain operations:
117
+
118
+ ```ruby
119
+ stream = DPay::Stream.new
120
+
121
+ stream.operations(types: [:comment_operation, :vote_operation]) do |op|
122
+ puts "#{op.type}: #{op.value}"
123
+ end
124
+ ```
125
+
126
+ Or (optionally) just pass the operation(s) you want as the only arguments. This is semantic sugar for when you want specific types and take all of the defaults.
127
+
128
+ ```ruby
129
+ stream = DPay::Stream.new
130
+
131
+ stream.operations(:vote_operation) do |op|
132
+ puts "#{op.type}: #{op.value}"
133
+ end
134
+ ```
135
+
136
+ To also include virtual operations:
137
+
138
+ ```ruby
139
+ stream = DPay::Stream.new
140
+
141
+ stream.operations(include_virtual: true) do |op|
142
+ puts "#{op.type}: #{op.value}"
143
+ end
144
+ ```
145
+
146
+ ### Multisig
147
+
148
+ You can use multisignature to broadcast an operation.
149
+
150
+ ```ruby
151
+ params = {
152
+ voter: voter,
153
+ author: author,
154
+ permlink: permlink,
155
+ weight: weight
156
+ }
157
+
158
+ DPay::Broadcast.vote(wif: [wif1, wif2], params: params) do |result|
159
+ puts result
160
+ end
161
+ ```
162
+
163
+ In addition to signing with multiple `wif` private keys, it is possible to also export a partially signed transaction to have signing completed by someone else.
164
+
165
+ ```ruby
166
+ builder = DPay::TransactionBuilder.new(wif: wif1)
167
+
168
+ builder.put(vote: {
169
+ voter: voter,
170
+ author: author,
171
+ permlink: permlink,
172
+ weight: weight
173
+ })
174
+
175
+ trx = builder.sign.to_json
176
+
177
+ File.open('trx.json', 'w') do |f|
178
+ f.write(trx)
179
+ end
180
+ ```
181
+
182
+ Then send the contents of `trx.json` to the other signing party so they can privately sign and broadcast the transaction.
183
+
184
+ ```ruby
185
+ trx = open('trx.json').read
186
+ builder = DPay::TransactionBuilder.new(wif: wif2, trx: trx)
187
+ api = DPay::CondenserApi.new
188
+ trx = builder.transaction
189
+ api.broadcast_transaction_synchronous(trx: trx)
190
+ ```
191
+
192
+ ### Get Accounts
193
+
194
+ ```ruby
195
+ api = DPay::DatabaseApi.new
196
+
197
+ api.find_accounts(accounts: ['dsite', 'alice']) do |result|
198
+ puts result.accounts
199
+ end
200
+ ```
201
+
202
+ *See: [Api](https://www.rubydoc.info/gems/dpay-ruby/DPay/Api)*
203
+
204
+ ### Reputation Formatter
205
+
206
+ ```ruby
207
+ rep = DPay::Formatter.reputation(account.reputation)
208
+ puts rep
209
+ ```
210
+
211
+ ### Tests
212
+
213
+ * Clone the client repository into a directory of your choice:
214
+ * `git clone https://github.com/dpays/dpay-ruby.git`
215
+ * Navigate into the new folder
216
+ * `cd dpay-ruby`
217
+ * All tests can be invoked as follows:
218
+ * `bundle exec rake test`
219
+ * To run `static` tests:
220
+ * `bundle exec rake test:static`
221
+ * To run `broadcast` tests (broadcast is simulated, only `verify` is actually used):
222
+ * `bundle exec rake test:broadcast`
223
+ * To run `threads` tests (which quickly verifies thread safety):
224
+ * `bundle exec rake test:threads`
225
+ * To run `testnet` tests (which does actual broadcasts)
226
+ * `TEST_NODE=https://testnet.dpays.io bundle exec rake test:testnet`
227
+
228
+ You can also run other tests that are not part of the above `test` execution:
229
+
230
+ * To run `block_range`, which streams blocks (using `json-rpc-batch`)
231
+ * `bundle exec rake stream:block_range`
232
+
233
+
234
+ If you want to point to any node for tests, instead of letting the test suite pick the default, set the environment variable to `TEST_NODE`, e.g.:
235
+
236
+ ```bash
237
+ $ TEST_NODE=https://testapi.dpays.io bundle exec rake test
238
+ ```
239
+
240
+ ## Contributions
241
+
242
+ Patches are welcome! Contributors are listed in the `dpay-ruby.gemspec` file. Please run the tests (`rake test`) before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list.
243
+
244
+ ## Issues
245
+
246
+ When you find issues, please report them!
247
+
248
+ ## License
249
+
250
+ MIT