katapaty 0.2.0

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
+ SHA1:
3
+ metadata.gz: 1de29969082c82da63a7bc91322ec08f830c7183
4
+ data.tar.gz: '08e3b77a6356c77948d4cae047145eb7ff33aeea'
5
+ SHA512:
6
+ metadata.gz: a1d4bd553d406f8bcc716a0bbfeef7bdc4fdecf8cb9ad0d4d4921e87fd86c5f78efb9dfb1410a2d8311ce41dd7ec9e9f2a3e605b5708994dbf26896e520ee93d
7
+ data.tar.gz: 7bcce122dfc6915f66acd07131d85fe95bad06c35b372d6de1fe89b2181a256bcf7a57bec40651ecf48a32830b4c3575480a97de53580057f2f209c57bcc795e
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ *.swo
11
+ *.swp
12
+ /vendor/
13
+ # rspec failure tracking
14
+ .rspec_status
15
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in katapaty.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 longhoang.wkm
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.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Katapaty
2
+
3
+ A ruby gem for communicating with a Counterparty (Bitcoin / XCP) API server. Katapaty was inspired by counterparty_ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'katapaty'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install katapaty
20
+
21
+ Set counterparty node configuration in `config/initializers/katapaty.rb`
22
+
23
+ ```ruby
24
+ Katapaty.configure do |config|
25
+ config.username = 'rpc'
26
+ config.password = 'rpc'
27
+ config.host = '200.200.10.50'
28
+ config.port = 14000
29
+ end
30
+ ```
31
+
32
+
33
+ ## Usage Example
34
+
35
+ `Katapaty.create_send({source: "mypcUU2fYyJav7XUpPLtMVhuPupArLJtiM", destination: "mjtwweXS2u5q1Ybypb271Wmehmj9g1w2th", asset: "LONGDD", quantity: 50000})`
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/katapaty. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the Katapaty project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/katapaty/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "katapaty"
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__)
data/bin/setup ADDED
@@ -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
data/katapaty.gemspec ADDED
@@ -0,0 +1,25 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "katapaty/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "katapaty"
8
+ spec.version = Katapaty::VERSION
9
+ spec.authors = ["longhoang.wkm"]
10
+ spec.email = ["longhoang@wakumo.vn"]
11
+
12
+ spec.summary = "A ruby gem for communicating with a Counterparty (Bitcoin / XCP) API server"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
@@ -0,0 +1,12 @@
1
+ module Katapaty
2
+ class Configuration
3
+ attr_accessor :username,
4
+ :password,
5
+ :host,
6
+ :port
7
+
8
+ def api_url
9
+ "http://#{@username}:#{@password}@#{@host}:#{@port}/api/"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Katapaty
2
+ class JsonResponseError < StandardError; end
3
+
4
+ class ResponseError < StandardError
5
+ attr_reader :data_type
6
+ attr_reader :data_args
7
+ attr_reader :data_message
8
+ attr_reader :code
9
+ attr_reader :message_class
10
+
11
+ def initialize(json)
12
+ @message_class, @code = json['message'], json['code']
13
+ json['data'].each_pair do |(k,v)|
14
+ instance_variable_set '@data_%s' % k, v
15
+ end if json.has_key? 'data'
16
+ super
17
+ end
18
+
19
+ def message
20
+ "#{@message_class}:#{@data_message}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Katapaty
2
+ class Resource
3
+ class << self
4
+ def api_name
5
+ to_s.split('::').last.gsub(/[^\A]([A-Z])/, '_\\1').downcase
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,533 @@
1
+ module Katapaty::Resources
2
+ class Balance < Katapaty::Resource
3
+ attr_accessor :address,
4
+ :asset,
5
+ :quantity
6
+ end
7
+
8
+ class Send < Katapaty::Resource
9
+ attr_accessor :tx_index,
10
+ :tx_hash,
11
+ :block_index,
12
+ :source,
13
+ :destination,
14
+ :asset,
15
+ :quantity,
16
+ :validity
17
+ end
18
+
19
+ class Broadcast < Katapaty::Resource
20
+ # Value: Open Broadcast
21
+ OPEN_BROADCAST = -1.0
22
+
23
+ # (integer): The transaction index
24
+ attr_accessor :tx_index
25
+
26
+ # (string): The transaction hash
27
+ attr_accessor :tx_hash
28
+
29
+ # (integer): The block index (block number in the block chain)
30
+ attr_accessor :block_index
31
+
32
+ # (string): The address that made the broadcast
33
+ attr_accessor :source
34
+
35
+ # (string): The time the broadcast was made, in Unix time.
36
+ attr_accessor :timestamp
37
+
38
+ # (float): The numerical value of the broadcast
39
+ attr_accessor :value
40
+
41
+ # (float): How much of every bet on this feed should go to its operator;
42
+ # a fraction of 1, (i.e. .05 is five percent)
43
+ attr_accessor :fee_multiplier
44
+
45
+ # (string): The textual component of the broadcast
46
+ attr_accessor :text
47
+
48
+ # (string): Set to "valid" if a valid broadcast. Any other setting signifies
49
+ # an invalid/improper broadcast
50
+ attr_accessor :validity
51
+
52
+ # (float): How much of every bet on this feed should go to its
53
+ # operator; a fraction of 1, (i.e. .05 is five percent). Used on create.
54
+ attr_accessor :fee_fraction
55
+ end
56
+
57
+ # An object that describes an instance of a specific burn.
58
+ class Burn < Katapaty::Resource
59
+ # (integer): The transaction index
60
+ attr_accessor :tx_index
61
+
62
+ # (string): The transaction hash
63
+ attr_accessor :tx_hash
64
+
65
+ # (integer): The block index (block number in the block chain)
66
+ attr_accessor :block_index
67
+
68
+ # (string): The address the burn was performed from
69
+ attr_accessor :source
70
+
71
+ # (integer): The quantity of BTC burned
72
+ attr_accessor :burned
73
+
74
+ # (integer): The quantity of XPC actually earned from the burn (takes into
75
+ # account any bonus quantitys, 1 BTC limitation, etc)
76
+ attr_accessor :earned
77
+
78
+ # (string): Set to "valid" if a valid burn. Any other setting signifies an
79
+ # invalid/improper burn
80
+ attr_accessor :validity
81
+
82
+ # (string): Set to "valid" if a valid burn. Any other setting signifies an
83
+ # invalid/improper burn
84
+ attr_accessor :status
85
+
86
+ # (integer): The amount of BTC to burn (only used in the Create Burn)
87
+ attr_accessor :quantity
88
+ end
89
+
90
+ # An object that describes a specific asset callback (i.e. the exercising of
91
+ # a call option on an asset owned by the source address).
92
+ class Callback < Katapaty::Resource
93
+ # (integer): The transaction index
94
+ attr_accessor :tx_index
95
+
96
+ # (string): The transaction hash
97
+ attr_accessor :tx_hash
98
+
99
+ # block_index (integer): The block index (block number in the block chain)
100
+ attr_accessor :block_index
101
+
102
+ # (string): The source address of the call back (should be the current owner
103
+ # of the asset)
104
+ attr_accessor :source
105
+
106
+ # (integer): A floating point number greater than zero but less than or
107
+ # equal to 1, where 0% is for a callback of 0%
108
+ attr_accessor :fraction
109
+
110
+ # of the balance of each of the asset's holders, and 1 would be for a
111
+ # callback of 100%). For example, 0.56 would be 56%. Each holder of the
112
+ # called asset will be paid the call price for the asset, times the number
113
+ # of units of that asset that were called back from them.
114
+ attr_accessor :of
115
+
116
+ # (string): The asset being called back
117
+ attr_accessor :asset
118
+
119
+ # (string): Set to "valid" if a valid send. Any other setting signifies an
120
+ # invalid/improper send
121
+ attr_accessor :validity
122
+ end
123
+
124
+ # An object that describes a cancellation of a (previously) open order or bet.
125
+ class Cancel < Katapaty::Resource
126
+ # (integer): The transaction index
127
+ attr_accessor :tx_index
128
+
129
+ # (string): The transaction hash
130
+ attr_accessor :tx_hash
131
+
132
+ # (integer): The block index (block number in the block chain)
133
+ attr_accessor :block_index
134
+
135
+ # (string): The address with the open order or bet that was cancelled
136
+ attr_accessor :source
137
+
138
+ # (string): The transaction hash of the order or bet cancelled
139
+ attr_accessor :offer_hash
140
+
141
+ # (string): Set to "valid" if a valid burn. Any other setting signifies an
142
+ # invalid/improper burn
143
+ attr_accessor :validity
144
+ end
145
+
146
+ # An object that describes a account credit.
147
+ class Credit < Katapaty::Resource
148
+ # (integer): The transaction index
149
+ attr_accessor :tx_index
150
+
151
+ # (string): The transaction hash
152
+ attr_accessor :tx_hash
153
+
154
+ # (integer): The block index (block number in the block chain)
155
+ attr_accessor :block_index
156
+
157
+ # (string): The address debited or credited
158
+ attr_accessor :address
159
+
160
+ # (string): The asset debited or credited
161
+ attr_accessor :asset
162
+
163
+ # (integer): The quantity of the specified asset debited or credited
164
+ attr_accessor :quantity
165
+
166
+ attr_accessor :action
167
+
168
+ attr_accessor :event
169
+ end
170
+
171
+ # An object that describes a account debit or credit.
172
+ class Debit < Katapaty::Resource
173
+ # (integer): The transaction index
174
+ attr_accessor :tx_index
175
+
176
+ # (string): The transaction hash
177
+ attr_accessor :tx_hash
178
+
179
+ # (integer): The block index (block number in the block chain)
180
+ attr_accessor :block_index
181
+
182
+ # (string): The address debited or credited
183
+ attr_accessor :address
184
+
185
+ # (string): The asset debited or credited
186
+ attr_accessor :asset
187
+
188
+ # (integer): The quantity of the specified asset debited or credited
189
+ attr_accessor :quantity
190
+
191
+ attr_accessor :action
192
+
193
+ attr_accessor :event
194
+ end
195
+
196
+ # An object that describes an issuance of dividends on a specific user
197
+ # defined asset.
198
+ class Dividend < Katapaty::Resource
199
+ # (integer): The transaction index
200
+ attr_accessor :tx_index
201
+
202
+ # (string): The transaction hash
203
+ attr_accessor :tx_hash
204
+
205
+ # (integer): The block index (block number in the block chain)
206
+ attr_accessor :block_index
207
+
208
+ # (string): The address that issued the dividend
209
+ attr_accessor :source
210
+
211
+ # (string): The asset that the dividends are being rewarded on
212
+ attr_accessor :asset
213
+
214
+ # (integer): The quantity of XCP rewarded per whole unit of the asset
215
+ attr_accessor :quantity_per_unit
216
+
217
+ # (string): Set to "valid" if a valid burn. Any other setting signifies an
218
+ # invalid/improper burn
219
+ attr_accessor :validity
220
+
221
+ # (string, required): The asset that the dividends are paid in.
222
+ attr_accessor :dividend_asset
223
+ end
224
+
225
+ # An object that describes a specific occurance of a user defined asset being
226
+ # issued, or re-issued
227
+ class Issuance < Katapaty::Resource
228
+ # (integer): The transaction index
229
+ attr_accessor :tx_index
230
+
231
+ # (string): The transaction hash
232
+ attr_accessor :tx_hash
233
+
234
+ # (integer): The block index (block number in the block chain)
235
+ attr_accessor :block_index
236
+
237
+ # (string): The asset being issued, or re-issued
238
+ attr_accessor :asset
239
+
240
+ # (integer): The quantity of the specified asset being issued
241
+ attr_accessor :quantity
242
+
243
+ # (boolean): Whether or not the asset is divisible (must agree with previous
244
+ # issuances of the asset, if there are any)
245
+ attr_accessor :divisible
246
+
247
+ # issuer (string):
248
+ attr_accessor :issuer
249
+
250
+ # (boolean): Whether or not this objects marks the transfer of ownership
251
+ # rights for the specified quantity of this asset
252
+ attr_accessor :transfer
253
+
254
+ # (string): Set to "valid" if a valid issuance. Any other setting signifies
255
+ # an invalid/improper issuance
256
+ attr_accessor :validity
257
+
258
+ # (string): This is used when creating an issuance, and indicates the source
259
+ # address of the asset
260
+ attr_accessor :source
261
+
262
+ # (string): This is used when creating an issuance, and indicates
263
+ # the destination address of the asset
264
+ attr_accessor :description
265
+
266
+ # (string): This is used when creating an issuance transfer, and indicates
267
+ # the destination address of the asset
268
+ attr_accessor :transfer_destination
269
+ end
270
+
271
+ # An object that describes a specific order.
272
+ class Order < Katapaty::Resource
273
+ # (integer): The transaction index
274
+ attr_accessor :tx_index
275
+
276
+ # (string): The transaction hash
277
+ attr_accessor :tx_hash
278
+
279
+ # (integer): The block index (block number in the block chain)
280
+ attr_accessor :block_index
281
+
282
+ # (string): The address that made the order
283
+ attr_accessor :source
284
+
285
+ # (string): The asset being offered
286
+ attr_accessor :give_asset
287
+
288
+ # (integer): The quantity of the specified asset being offered
289
+ attr_accessor :give_quantity
290
+
291
+ # (integer): The quantity of the specified give asset remaining for the order
292
+ attr_accessor :give_remaining
293
+
294
+ # (string): The asset desired in exchange
295
+ attr_accessor :get_asset
296
+
297
+ # (integer): The quantity of the specified asset desired in exchange
298
+ attr_accessor :get_quantity
299
+
300
+ # (integer): The quantity of the specified get asset remaining for the order
301
+ attr_accessor :get_remaining
302
+
303
+ # (float): The given exchange rate (as an exchange ratio desired from the
304
+ # asset offered to the asset desired)
305
+ attr_accessor :price
306
+
307
+ # (integer): The number of blocks over which the order should be valid
308
+ attr_accessor :expiration
309
+
310
+ # (integer): The miners' fee provided; in BTC; required only if selling BTC
311
+ # (should not be lower than is required for acceptance in a block)
312
+ attr_accessor :fee_provided
313
+
314
+ # (integer): The miners' fee required to be paid by orders for them to match
315
+ # this one; in BTC; required only if buying BTC (may be zero, though)
316
+ attr_accessor :fee_required
317
+ end
318
+
319
+ # An object that describes a specific occurance of two orders being matched
320
+ # (either partially, or fully)
321
+ class OrderMatch < Katapaty::Resource
322
+ # (integer): The Bitcoin transaction index of the first (earlier) order
323
+ attr_accessor :tx0_index
324
+
325
+ # (string): The Bitcoin transaction hash of the first order
326
+ attr_accessor :tx0_hash
327
+
328
+ # (integer): The Bitcoin block index of the first order
329
+ attr_accessor :tx0_block_index
330
+
331
+ # (integer): The number of blocks over which the first order was valid
332
+ attr_accessor :tx0_expiration
333
+
334
+ # (string): The address that issued the first (earlier) order
335
+ attr_accessor :tx0_address
336
+
337
+ # (integer): The transaction index of the second (matching) order
338
+ attr_accessor :tx1_index
339
+
340
+ # (string): The transaction hash of the second order
341
+ attr_accessor :tx1_hash
342
+
343
+ # (integer): The block index of the second order
344
+ attr_accessor :tx1_block_index
345
+
346
+ # (string): The address that issued the second order
347
+ attr_accessor :tx1_address
348
+
349
+ # (integer): The number of blocks over which the second order was valid
350
+ attr_accessor :tx1_expiration
351
+
352
+ # (string): The asset exchanged FROM the first order to the second order
353
+ attr_accessor :forward_asset
354
+
355
+ # (integer): The quantity of the specified forward asset
356
+ attr_accessor :forward_quantity
357
+
358
+ # (string): The asset exchanged FROM the second order to the first order
359
+ attr_accessor :backward_asset
360
+
361
+ # (integer): The quantity of the specified backward asset
362
+ attr_accessor :backward_quantity
363
+
364
+ # (string): Set to "valid" if a valid order match. Any other setting
365
+ # signifies an invalid/improper order match
366
+ attr_accessor :validity
367
+ end
368
+
369
+ # An object that describes a specific event in the counterpartyd message feed
370
+ # (which can be used by 3rd party applications to track state changes to the
371
+ # counterpartyd database on a block-by-block basis).
372
+ class Message < Katapaty::Resource
373
+ # (integer): The message index (i.e. transaction index)
374
+ attr_accessor :message_index
375
+
376
+ # (integer): The block index (block number in the block chain) this event
377
+ # occurred on
378
+ attr_accessor :block_index
379
+
380
+ # (string): A string denoting the entity that the message relates to, e.g.
381
+ # "credits", "burns", "debits". The category matches the relevant table name
382
+ # in counterpartyd (see blocks.py for more info).
383
+ attr_accessor :category
384
+
385
+ # (string): The operation done to the table noted in category. This is
386
+ # either "insert", or "update".
387
+ attr_accessor :command
388
+
389
+ # (string): A JSON-encoded object containing the message data. The
390
+ # properties in this object match the columns in the table referred to by category.
391
+ attr_accessor :bindings
392
+ end
393
+
394
+ # An object that describes a specific asset callback (i.e. the exercising of
395
+ # a call option on an asset owned by the source address).
396
+ class Callback < Katapaty::Resource
397
+ # (integer): The transaction index
398
+ attr_accessor :tx_index
399
+
400
+ # (string): The transaction hash
401
+ attr_accessor :tx_hash
402
+
403
+ # (integer): The block index (block number in the block chain)
404
+ attr_accessor :block_index
405
+
406
+ # (string): The source address of the call back (should be the current owner
407
+ # of the asset)
408
+ attr_accessor :source
409
+
410
+ # (integer): A floating point number greater than zero but less than
411
+ # or equal to 1, where 0% is for a callback of 0% of the balance of each of
412
+ # the asset's holders, and 1 would be for a callback of 100%). For example,
413
+ # 0.56 would be 56%. Each holder of the called asset will be paid the call
414
+ # price for the asset, times the number of units of that asset that were
415
+ # called back from them.
416
+ attr_accessor :fraction
417
+
418
+ # asset (string): The asset being called back
419
+ attr_accessor :asset
420
+
421
+ # (string): Set to "valid" if a valid send. Any other setting signifies an
422
+ # invalid/improper send
423
+ attr_accessor :validity
424
+ end
425
+
426
+ # An object that describes the expiration of a bet created by the source
427
+ # address.
428
+ class BetExpiration < Katapaty::Resource
429
+ # (integer): The transaction index of the bet expiring
430
+ attr_accessor :bet_index
431
+
432
+ # bet_hash (string): The transaction hash of the bet expiriing
433
+ attr_accessor :bet_hash
434
+
435
+ # (integer): The block index (block number in the block chain) when this
436
+ # expiration occurred
437
+ attr_accessor :block_index
438
+
439
+ # (string): The source address that created the bet
440
+ attr_accessor :source
441
+ end
442
+
443
+ # An object that describes the expiration of an order created by the source
444
+ # address.
445
+ class OrderExpiration < Katapaty::Resource
446
+ # (integer): The transaction index of the order expiring
447
+ attr_accessor :order_index
448
+
449
+ # (string): The transaction hash of the order expiriing
450
+ attr_accessor :order_hash
451
+
452
+ # (integer): The block index (block number in the block chain) when this
453
+ # expiration occurred
454
+ attr_accessor :block_index
455
+
456
+ # (string): The source address that created the order
457
+ attr_accessor :source
458
+ end
459
+
460
+ # An object that describes the expiration of a bet match.
461
+ class BetMatchExpiration < Katapaty::Resource
462
+ # (integer): The transaction index of the bet match ID (e.g. the
463
+ # concatenation of the tx0 and tx1 hashes)
464
+ attr_accessor :bet_match_id
465
+
466
+ # (string): The tx0 (first) address for the bet match
467
+ attr_accessor :tx0_address
468
+
469
+ # (string): The tx1 (second) address for the bet match
470
+ attr_accessor :tx1_address
471
+
472
+ # (integer): The block index (block number in the block chain) when this
473
+ # expiration occurred
474
+ attr_accessor :block_index
475
+ end
476
+
477
+ # An object that describes the expiration of an order match.
478
+ class OrderMatchExpiration < Katapaty::Resource
479
+ # (integer): The transaction index of the order match ID (e.g. the
480
+ # concatenation of the tx0 and tx1 hashes)
481
+ attr_accessor :order_match_id
482
+
483
+ # (string): The tx0 (first) address for the order match
484
+ attr_accessor :tx0_address
485
+
486
+ # (string): The tx1 (second) address for the order match
487
+ attr_accessor :tx1_address
488
+
489
+ # (integer): The block index (block number in the block chain) when this
490
+ # expiration occurred
491
+ attr_accessor :block_index
492
+ end
493
+
494
+ # An object that publishes a compiled serpent contract onto the Counterparty
495
+ # network
496
+ class Publish < Katapaty::Resource
497
+ # (string) the source address
498
+ attr_accessor :source
499
+
500
+ # (integer) the price of gas
501
+ attr_accessor :gasprice
502
+
503
+ # (integer) the maximum quantity of {} to be used to pay for the execution (satoshis)
504
+ attr_accessor :startgas
505
+
506
+ # (integer) quantity of {} to be transfered to the contract (satoshis)
507
+ attr_accessor :endowment
508
+
509
+ # (string) the hex‐encoded contract (returned by 'serpent compile')
510
+ attr_accessor :code_hex
511
+ end
512
+
513
+ # An object that executes contract code in the blockchain
514
+ class Execute < Katapaty::Resource
515
+ # (string) the source address
516
+ attr_accessor :source
517
+
518
+ # (integer) the price of gas
519
+ attr_accessor :gasprice
520
+
521
+ # (integer) the maximum quantity of {} to be used to pay for the execution (satoshis
522
+ attr_accessor :startgas
523
+
524
+ # (integer) the contract ID of the contract to be executed
525
+ attr_accessor :contract_id
526
+
527
+ # (integer) quantity to be transfered to the contract (satoshis)
528
+ attr_accessor :value
529
+
530
+ # (string) data to be provided to the contract (returned by serpent encode_datalist)
531
+ attr_accessor :payload_hex
532
+ end
533
+ end
@@ -0,0 +1,3 @@
1
+ module Katapaty
2
+ VERSION = "0.2.0"
3
+ end
data/lib/katapaty.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'katapaty/version'
2
+ require 'katapaty/configuration'
3
+ require 'katapaty/resource'
4
+ require 'katapaty/resources'
5
+ require 'katapaty/errors'
6
+
7
+ module Katapaty
8
+
9
+ class << self
10
+ attr_writer :configuration
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def reset
17
+ @configuration = Configuration.new
18
+ end
19
+
20
+ def configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def request(method, params)
25
+ client = RestClient::Resource.new @configuration.api_url
26
+ request = { method: method, params: params, jsonrpc: '2.0', id: '0' }.to_json
27
+ response = JSON.parse client.post(request,
28
+ user: @configuration.username,
29
+ password: @configuration.password,
30
+ accept: 'json',
31
+ content_type: 'json' )
32
+ raise JsonResponseError.new response if response.has_key? 'code'
33
+ raise ResponseError.new response['error'] if response.has_key? 'error'
34
+ response['result']
35
+ end
36
+
37
+ Katapaty::Resources.constants.each do |c|
38
+ begin
39
+ define_method(:"get_#{c.to_s.pluralize.downcase}") do |params|
40
+ self.request((__method__).to_s, params)
41
+ end
42
+ define_method(:"create_#{c.to_s.downcase}") do |params|
43
+ self.request((__method__).to_s, params)
44
+ end
45
+ rescue NameError
46
+ next
47
+ end
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: katapaty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - longhoang.wkm
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-05 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ description:
56
+ email:
57
+ - longhoang@wakumo.vn
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - katapaty.gemspec
72
+ - lib/katapaty.rb
73
+ - lib/katapaty/configuration.rb
74
+ - lib/katapaty/errors.rb
75
+ - lib/katapaty/resource.rb
76
+ - lib/katapaty/resources.rb
77
+ - lib/katapaty/version.rb
78
+ homepage:
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.11
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A ruby gem for communicating with a Counterparty (Bitcoin / XCP) API server
102
+ test_files: []