glueby 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/glueby.rb CHANGED
@@ -9,27 +9,18 @@ module Glueby
9
9
  autoload :AR, 'glueby/active_record'
10
10
  autoload :FeeProvider, 'glueby/fee_provider'
11
11
  autoload :Configuration, 'glueby/configuration'
12
+ autoload :BlockSyncer, 'glueby/block_syncer'
13
+ autoload :UtxoProvider, 'glueby/utxo_provider'
14
+
15
+ if defined? ::Rails::Railtie
16
+ require 'glueby/railtie'
17
+ end
12
18
 
13
19
  # Add prefix to activerecord table names
14
20
  def self.table_name_prefix
15
21
  'glueby_'
16
22
  end
17
23
 
18
- begin
19
- class Railtie < ::Rails::Railtie
20
- rake_tasks do
21
- load "tasks/glueby/contract.rake"
22
- load "tasks/glueby/contract/timestamp.rake"
23
- load "tasks/glueby/contract/wallet_adapter.rake"
24
- load "tasks/glueby/contract/block_syncer.rake"
25
- load "tasks/glueby/fee_provider.rake"
26
- end
27
- end
28
- rescue
29
- # Rake task is unavailable
30
- puts "Rake task is unavailable"
31
- end
32
-
33
24
  # Returns the global [Configuration](RSpec/Core/Configuration) object.
34
25
  def self.configuration
35
26
  @configuration ||= Glueby::Configuration.new
@@ -0,0 +1,29 @@
1
+ namespace :glueby do
2
+ namespace :contract do
3
+ namespace :block_syncer do
4
+ desc '[Deprecated use glueby:block_syncer:start instead] sync block into database'
5
+ task :start, [] => [:environment] do |_, _|
6
+ puts '[Deprecated] glueby:contract:block_syncer:start is deprecated. Use \'glueby:block_syncer:start\''
7
+ Rake::Task['glueby:block_syncer:start'].execute
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+
14
+ namespace :glueby do
15
+ namespace :block_syncer do
16
+ desc 'sync block into database'
17
+ task :start, [] => [:environment] do |_, _|
18
+ latest_block_num = Glueby::Internal::RPC.client.getblockcount
19
+ synced_block = Glueby::AR::SystemInformation.synced_block_height
20
+ (synced_block.int_value + 1..latest_block_num).each do |height|
21
+ ::ActiveRecord::Base.transaction do
22
+ Glueby::BlockSyncer.new(height).run
23
+ synced_block.update(info_value: height.to_s)
24
+ end
25
+ puts "success in synchronization (block height=#{height})"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -8,35 +8,25 @@ module Glueby
8
8
 
9
9
  def create
10
10
  timestamps = Glueby::Contract::AR::Timestamp.where(status: :init)
11
+ utxo_provider = Glueby::UtxoProvider.new if Glueby.configuration.use_utxo_provider?
11
12
  timestamps.each do |t|
12
13
  begin
13
- ::ActiveRecord::Base.transaction do
14
- wallet = Glueby::Wallet.load(t.wallet_id)
15
- tx = create_tx(wallet, t.prefix, t.content_hash, Glueby::Contract::FixedFeeEstimator.new)
16
- t.update(txid: tx.txid, status: :unconfirmed)
17
-
18
- wallet.internal_wallet.broadcast(tx)
19
- puts "broadcasted (id=#{t.id}, txid=#{tx.txid})"
14
+ wallet = Glueby::Wallet.load(t.wallet_id)
15
+ funding_tx, tx = create_txs(wallet, t.prefix, t.content_hash, Glueby::Contract::FixedFeeEstimator.new, utxo_provider)
16
+ if funding_tx
17
+ ::ActiveRecord::Base.transaction do
18
+ wallet.internal_wallet.broadcast(funding_tx)
19
+ puts "funding tx was broadcasted(id=#{t.id}, funding_tx.txid=#{funding_tx.txid})"
20
+ end
20
21
  end
21
- rescue => e
22
- puts "failed to broadcast (id=#{t.id}, reason=#{e.message})"
23
- end
24
- end
25
- end
26
-
27
- def confirm
28
- timestamps = Glueby::Contract::AR::Timestamp.where(status: :unconfirmed)
29
- timestamps.each do |t|
30
- begin
31
22
  ::ActiveRecord::Base.transaction do
32
- tx = get_transaction(t)
33
- if tx['confirmations'] && tx['confirmations'] > 0
34
- t.update(status: :confirmed)
35
- puts "confirmed (id=#{t.id}, txid=#{tx['txid']})"
23
+ wallet.internal_wallet.broadcast(tx) do |tx|
24
+ t.update(txid: tx.txid, status: :unconfirmed)
36
25
  end
26
+ puts "timestamp tx was broadcasted (id=#{t.id}, txid=#{tx.txid})"
37
27
  end
38
28
  rescue => e
39
- puts "failed to confirm (id=#{t.id}, reason=#{e.message})"
29
+ puts "failed to broadcast (id=#{t.id}, reason=#{e.message})"
40
30
  end
41
31
  end
42
32
  end
@@ -52,11 +42,6 @@ namespace :glueby do
52
42
  task :create, [] => [:environment] do |_, _|
53
43
  Glueby::Contract::Task::Timestamp.create
54
44
  end
55
-
56
- desc 'confirm glueby timestamp tx'
57
- task :confirm, [] => [:environment] do |_, _|
58
- Glueby::Contract::Task::Timestamp.confirm
59
- end
60
45
  end
61
46
  end
62
47
  end
@@ -9,5 +9,10 @@ namespace :glueby do
9
9
  task :status, [] => [:environment] do |_, _|
10
10
  Glueby::FeeProvider::Tasks.new.status
11
11
  end
12
+
13
+ desc 'Show the address of the Glueby::FeeProvider'
14
+ task :address, [] => [:environment] do |_, _|
15
+ Glueby::FeeProvider::Tasks.new.print_address
16
+ end
12
17
  end
13
18
  end
@@ -0,0 +1,18 @@
1
+ namespace :glueby do
2
+ namespace :utxo_provider do
3
+ desc 'Manage the UTXO pool in Glueby::UtxoProvider. Creates outputs for paying utxo if the outputs is less than configured pool size by :utxo_pool_size'
4
+ task :manage_utxo_pool, [] => [:environment] do |_, _|
5
+ Glueby::UtxoProvider::Tasks.new.manage_utxo_pool
6
+ end
7
+
8
+ desc 'Show the status of the UTXO pool in Glueby::UtxoProvider'
9
+ task :status, [] => [:environment] do |_, _|
10
+ Glueby::UtxoProvider::Tasks.new.status
11
+ end
12
+
13
+ desc 'Show the address of the Glueby::UtxoProvider'
14
+ task :address, [] => [:environment] do |_, _|
15
+ Glueby::UtxoProvider::Tasks.new.print_address
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glueby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 6.1.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 6.1.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.1.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.1.3
55
69
  description: A Ruby library of smart contracts that can be used on Tapyrus.
56
70
  email:
57
71
  - azuchi@chaintope.com
@@ -87,6 +101,7 @@ files:
87
101
  - lib/glueby.rb
88
102
  - lib/glueby/active_record.rb
89
103
  - lib/glueby/active_record/system_information.rb
104
+ - lib/glueby/block_syncer.rb
90
105
  - lib/glueby/configuration.rb
91
106
  - lib/glueby/contract.rb
92
107
  - lib/glueby/contract/active_record.rb
@@ -96,6 +111,7 @@ files:
96
111
  - lib/glueby/contract/fee_estimator.rb
97
112
  - lib/glueby/contract/payment.rb
98
113
  - lib/glueby/contract/timestamp.rb
114
+ - lib/glueby/contract/timestamp/syncer.rb
99
115
  - lib/glueby/contract/token.rb
100
116
  - lib/glueby/contract/tx_builder.rb
101
117
  - lib/glueby/fee_provider.rb
@@ -111,15 +127,19 @@ files:
111
127
  - lib/glueby/internal/wallet/active_record/utxo.rb
112
128
  - lib/glueby/internal/wallet/active_record/wallet.rb
113
129
  - lib/glueby/internal/wallet/active_record_wallet_adapter.rb
130
+ - lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb
114
131
  - lib/glueby/internal/wallet/errors.rb
115
132
  - lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb
133
+ - lib/glueby/railtie.rb
134
+ - lib/glueby/utxo_provider.rb
135
+ - lib/glueby/utxo_provider/tasks.rb
116
136
  - lib/glueby/version.rb
117
137
  - lib/glueby/wallet.rb
138
+ - lib/tasks/glueby/block_syncer.rake
118
139
  - lib/tasks/glueby/contract.rake
119
- - lib/tasks/glueby/contract/block_syncer.rake
120
140
  - lib/tasks/glueby/contract/timestamp.rake
121
- - lib/tasks/glueby/contract/wallet_adapter.rake
122
141
  - lib/tasks/glueby/fee_provider.rake
142
+ - lib/tasks/glueby/utxo_provider.rake
123
143
  homepage: https://github.com/chaintope/glueby
124
144
  licenses:
125
145
  - MIT
@@ -1,36 +0,0 @@
1
- module Glueby
2
- module Contract
3
- module Task
4
- module BlockSyncer
5
-
6
- def sync_block
7
- latest_block_num = Glueby::Internal::RPC.client.getblockcount
8
- synced_block = Glueby::AR::SystemInformation.synced_block_height
9
- (synced_block.int_value + 1..latest_block_num).each do |i|
10
- ::ActiveRecord::Base.transaction do
11
- block_hash = Glueby::Internal::RPC.client.getblockhash(i)
12
- import_block(block_hash)
13
- synced_block.update(info_value: i.to_s)
14
- puts "success in synchronization (block height=#{i.to_s})"
15
- end
16
- end
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
23
-
24
- namespace :glueby do
25
- namespace :contract do
26
- namespace :block_syncer do
27
- include Glueby::Contract::Task::BlockSyncer
28
-
29
- desc 'sync block into database'
30
- task :start, [] => [:environment] do |_, _|
31
- Glueby::Contract::Task::BlockSyncer.sync_block
32
- end
33
-
34
- end
35
- end
36
- end
@@ -1,42 +0,0 @@
1
- module Glueby
2
- module Contract
3
- module Task
4
- module WalletAdapter
5
- def import_block(block_hash)
6
- block = Glueby::Internal::RPC.client.getblock(block_hash, 0)
7
- block = Tapyrus::Block.parse_from_payload(block.htb)
8
- block.transactions.each { |tx| import_tx(tx.txid) }
9
- end
10
-
11
- def import_tx(txid)
12
- tx = Glueby::Internal::RPC.client.getrawtransaction(txid)
13
- tx = Tapyrus::Tx.parse_from_payload(tx.htb)
14
- Glueby::Internal::Wallet::AR::Utxo.destroy_for_inputs(tx)
15
- Glueby::Internal::Wallet::AR::Utxo.create_or_update_for_outputs(tx)
16
- end
17
- end
18
- end
19
- end
20
- end
21
-
22
- namespace :glueby do
23
- namespace :contract do
24
- namespace :wallet_adapter do
25
- include Glueby::Contract::Task::WalletAdapter
26
-
27
- desc 'import block into database'
28
- task :import_block, [:block_hash] => [:environment] do |_, args|
29
- block_hash = args[:block_hash]
30
-
31
- ::ActiveRecord::Base.transaction { import_block(block_hash) }
32
- end
33
-
34
- desc 'import transaction into database'
35
- task :import_tx, [:txid] => [:environment] do |_, args|
36
- txid = args[:txid]
37
-
38
- ::ActiveRecord::Base.transaction { import_tx(txid) }
39
- end
40
- end
41
- end
42
- end