bitsy-bitcoin 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/bitsy/v1/blockchain_notifications_controller.rb +4 -1
- data/app/jobs/bitsy/check_payments_job.rb +12 -0
- data/app/models/bitsy/blockchain_notification.rb +6 -0
- data/app/models/bitsy/payment_depot.rb +9 -0
- data/app/services/bitsy/check_for_payments.rb +14 -0
- data/app/services/bitsy/check_payment_depot_transaction.rb +19 -0
- data/app/services/bitsy/check_payment_depot_transactions.rb +17 -0
- data/app/services/bitsy/get_latest_block.rb +12 -0
- data/app/services/bitsy/process_blockchain_blockexplorer_transaction.rb +33 -0
- data/db/migrate/20141209131150_add_check_count_and_checked_at_to_payment_depot.rb +6 -0
- data/lib/bitsy/config.rb +2 -1
- data/lib/bitsy/version.rb +1 -1
- data/lib/generators/bitsy/config/templates/clock.rb +1 -0
- data/lib/generators/bitsy/config/templates/initializer.rb +5 -0
- metadata +23 -3
- data/app/services/bitsy/updating/get_latest_block.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dc9926eed4195fdde26c052f88bd3847dd612c6
|
4
|
+
data.tar.gz: c2501edd14c431e09ccc0d052dd56bf0193ab283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e4d71e5000101667f18299f2fba3dc23e9cbc242b8cb4582a18fb32e65391fb81fc230266c9f3e65f74576f95e17872bf3c47b97bbed8e6710bcce7e53251e
|
7
|
+
data.tar.gz: 25b02015f4e2b296618d5e653f4015a19cbfa2c1c0964c65c6f3cadea15ae26b003ced797228f4adc77bd8ad78e46edb635f6aff76a8af328d7db160e93d8983
|
@@ -4,7 +4,9 @@ module Bitsy
|
|
4
4
|
|
5
5
|
def index
|
6
6
|
bn = BlockchainNotification.new(blockchain_notification_params)
|
7
|
-
if bn.
|
7
|
+
if bn.test
|
8
|
+
render text: "*ok*", status: 200
|
9
|
+
elsif bn.save
|
8
10
|
BlockchainNotificationJob.perform_async(bn.id)
|
9
11
|
render text: "*ok*", status: 200
|
10
12
|
else
|
@@ -21,6 +23,7 @@ module Bitsy
|
|
21
23
|
:input_address,
|
22
24
|
:confirmations,
|
23
25
|
:secret,
|
26
|
+
:test,
|
24
27
|
)
|
25
28
|
end
|
26
29
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Bitsy
|
2
2
|
class BlockchainNotification < ActiveRecord::Base
|
3
3
|
|
4
|
+
attr_reader :test
|
5
|
+
|
4
6
|
validates(
|
5
7
|
:value,
|
6
8
|
:transaction_hash,
|
@@ -11,5 +13,9 @@ module Bitsy
|
|
11
13
|
|
12
14
|
validates(:secret, inclusion: {in: Bitsy.config.blockchain_secrets})
|
13
15
|
|
16
|
+
def test=(b)
|
17
|
+
@test = ["true", true].include?(b)
|
18
|
+
end
|
19
|
+
|
14
20
|
end
|
15
21
|
end
|
@@ -2,11 +2,13 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module Bitsy
|
4
4
|
class PaymentDepot < ActiveRecord::Base
|
5
|
+
|
5
6
|
has_many :transactions, class_name: 'PaymentTransaction'
|
6
7
|
|
7
8
|
alias_attribute :balance, :balance_cache
|
8
9
|
after_initialize :set_uuid
|
9
10
|
scope :with_balance, -> { where('balance_cache > 0.0') }
|
11
|
+
scope :checked_at_is_past, -> { where(arel_table[:checked_at].lt(Time.now)) }
|
10
12
|
validates(
|
11
13
|
:initial_tax_rate,
|
12
14
|
inclusion: {
|
@@ -24,6 +26,13 @@ module Bitsy
|
|
24
26
|
self.min_payment * (1 - self.initial_tax_rate)
|
25
27
|
end
|
26
28
|
|
29
|
+
def reset_checked_at!
|
30
|
+
self.update_attributes(
|
31
|
+
check_count: self.check_count + 1,
|
32
|
+
checked_at: (self.check_count**2).seconds.from_now,
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
27
36
|
def balance_tax_amount
|
28
37
|
ForwardTaxCalculator.calculate(self.balance,
|
29
38
|
self.min_payment,
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Bitsy
|
2
|
+
class CheckPaymentDepotTransaction
|
3
|
+
|
4
|
+
include LightService::Action
|
5
|
+
expects :latest_block, :payment_depot
|
6
|
+
|
7
|
+
executed do |ctx|
|
8
|
+
blockchain_address = Blockchain.get_address(ctx.payment_depot.address)
|
9
|
+
blockchain_address.txs.each do |tx|
|
10
|
+
ProcessBlockchainBlockexplorerTransaction.execute(
|
11
|
+
payment_depot: ctx.payment_depot,
|
12
|
+
latest_block: ctx.latest_block,
|
13
|
+
blockchain_transaction: tx,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Bitsy
|
2
|
+
class CheckPaymentDepotTransactions
|
3
|
+
|
4
|
+
include LightService::Action
|
5
|
+
expects :latest_block, :payment_depots
|
6
|
+
|
7
|
+
executed do |ctx|
|
8
|
+
ctx.payment_depots.each do |payment_depot|
|
9
|
+
CheckPaymentDepotTransaction.execute(
|
10
|
+
payment_depot: payment_depot,
|
11
|
+
latest_block: ctx.latest_block,
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bitsy
|
2
|
+
class ProcessBlockchainBlockexplorerTransaction
|
3
|
+
|
4
|
+
include LightService::Action
|
5
|
+
expects :payment_depot, :latest_block, :blockchain_transaction
|
6
|
+
|
7
|
+
executed do |ctx|
|
8
|
+
tx = ctx.blockchain_transaction
|
9
|
+
next ctx if PaymentTransaction.exists?(transaction_id: tx.hash)
|
10
|
+
payment_depot = ctx.payment_depot
|
11
|
+
output = tx.outputs.find { |o| o.address == payment_depot.address }
|
12
|
+
PaymentTransaction.create!(
|
13
|
+
payment_depot_id: payment_depot.id,
|
14
|
+
amount: output.value / 100_000_000.0,
|
15
|
+
receiving_address: output.address,
|
16
|
+
payment_type: "receive",
|
17
|
+
confirmations: confirmations_of(tx, ctx.latest_block.height),
|
18
|
+
transaction_id: tx.hash,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.confirmations_of(tx, block_height)
|
25
|
+
if tx.block_height
|
26
|
+
block_height + 1 - tx.block_height
|
27
|
+
else
|
28
|
+
0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/bitsy/config.rb
CHANGED
data/lib/bitsy/version.rb
CHANGED
@@ -22,6 +22,11 @@ Bitsy.configure do |c|
|
|
22
22
|
# WHen debug is true, no money will be forwarded. This is for testing
|
23
23
|
# purposes.
|
24
24
|
c.debug = false
|
25
|
+
|
26
|
+
# Bitsy will check the transactions of the payment depot manually if it hasn't
|
27
|
+
# been paid for yet. It will check 40 times, in approximately check count ** 2
|
28
|
+
# power intervals. Ex: check_count = 3, then it will check again in 9 seconds.
|
29
|
+
c.check_limit = 40
|
25
30
|
end
|
26
31
|
|
27
32
|
Sidekiq.configure_server do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitsy-bitcoin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -282,6 +282,20 @@ dependencies:
|
|
282
282
|
- - ">="
|
283
283
|
- !ruby/object:Gem::Version
|
284
284
|
version: '0'
|
285
|
+
- !ruby/object:Gem::Dependency
|
286
|
+
name: timecop
|
287
|
+
requirement: !ruby/object:Gem::Requirement
|
288
|
+
requirements:
|
289
|
+
- - ">="
|
290
|
+
- !ruby/object:Gem::Version
|
291
|
+
version: '0'
|
292
|
+
type: :development
|
293
|
+
prerelease: false
|
294
|
+
version_requirements: !ruby/object:Gem::Requirement
|
295
|
+
requirements:
|
296
|
+
- - ">="
|
297
|
+
- !ruby/object:Gem::Version
|
298
|
+
version: '0'
|
285
299
|
description: A mountable Rails engine to create a payment server that can handle the
|
286
300
|
money in your Bitcoin ecosystem
|
287
301
|
email:
|
@@ -301,6 +315,7 @@ files:
|
|
301
315
|
- app/controllers/bitsy/v1/truncations_controller.rb
|
302
316
|
- app/helpers/bitsy/application_helper.rb
|
303
317
|
- app/jobs/bitsy/blockchain_notification_job.rb
|
318
|
+
- app/jobs/bitsy/check_payments_job.rb
|
304
319
|
- app/jobs/bitsy/forward_job.rb
|
305
320
|
- app/jobs/bitsy/transactions_sync_job.rb
|
306
321
|
- app/models/bitsy/blockchain_notification.rb
|
@@ -312,15 +327,19 @@ files:
|
|
312
327
|
- app/services/bitsy/build_send_many_hash.rb
|
313
328
|
- app/services/bitsy/build_send_many_hash_for_transaction.rb
|
314
329
|
- app/services/bitsy/build_send_many_hash_with_transaction_fee.rb
|
330
|
+
- app/services/bitsy/check_for_payments.rb
|
331
|
+
- app/services/bitsy/check_payment_depot_transaction.rb
|
332
|
+
- app/services/bitsy/check_payment_depot_transactions.rb
|
315
333
|
- app/services/bitsy/compute_amount_for_splitting.rb
|
316
334
|
- app/services/bitsy/create_payment_depot.rb
|
317
335
|
- app/services/bitsy/forward_payments.rb
|
318
336
|
- app/services/bitsy/forward_tax_calculator.rb
|
337
|
+
- app/services/bitsy/get_latest_block.rb
|
319
338
|
- app/services/bitsy/instantiate_blockchain_wallet.rb
|
320
339
|
- app/services/bitsy/log_send_many.rb
|
340
|
+
- app/services/bitsy/process_blockchain_blockexplorer_transaction.rb
|
321
341
|
- app/services/bitsy/process_blockchain_notification.rb
|
322
342
|
- app/services/bitsy/send_payments.rb
|
323
|
-
- app/services/bitsy/updating/get_latest_block.rb
|
324
343
|
- app/services/bitsy/updating/select_transactions.rb
|
325
344
|
- app/services/bitsy/updating/sync_transactions.rb
|
326
345
|
- app/services/bitsy/updating/update_transaction.rb
|
@@ -338,6 +357,7 @@ files:
|
|
338
357
|
- db/migrate/20141109072242_change_payment_depot_balance_cache_default.rb
|
339
358
|
- db/migrate/20141115001846_add_total_received_amount_cache_to_payment_depots.rb
|
340
359
|
- db/migrate/20141129064958_change_total_received_amount_cache_to_decimal.rb
|
360
|
+
- db/migrate/20141209131150_add_check_count_and_checked_at_to_payment_depot.rb
|
341
361
|
- lib/bitsy-bitcoin.rb
|
342
362
|
- lib/bitsy.rb
|
343
363
|
- lib/bitsy/config.rb
|