glueby 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/Gemfile +1 -0
  4. data/README.md +227 -16
  5. data/glueby.gemspec +3 -2
  6. data/lib/generators/glueby/contract/reissuable_token_generator.rb +26 -0
  7. data/lib/generators/glueby/contract/templates/initializer.rb.erb +7 -2
  8. data/lib/generators/glueby/contract/templates/key_table.rb.erb +4 -3
  9. data/lib/generators/glueby/contract/templates/reissuable_token_table.rb.erb +10 -0
  10. data/lib/generators/glueby/contract/templates/system_information_table.rb.erb +2 -2
  11. data/lib/generators/glueby/contract/templates/timestamp_table.rb.erb +1 -1
  12. data/lib/generators/glueby/contract/templates/utxo_table.rb.erb +3 -2
  13. data/lib/generators/glueby/contract/templates/wallet_table.rb.erb +2 -2
  14. data/lib/glueby/block_syncer.rb +98 -0
  15. data/lib/glueby/configuration.rb +62 -0
  16. data/lib/glueby/contract/active_record/reissuable_token.rb +26 -0
  17. data/lib/glueby/contract/active_record.rb +1 -0
  18. data/lib/glueby/contract/fee_estimator.rb +38 -0
  19. data/lib/glueby/contract/payment.rb +4 -4
  20. data/lib/glueby/contract/timestamp/syncer.rb +13 -0
  21. data/lib/glueby/contract/timestamp.rb +8 -6
  22. data/lib/glueby/contract/token.rb +70 -22
  23. data/lib/glueby/contract/tx_builder.rb +22 -19
  24. data/lib/glueby/contract.rb +2 -2
  25. data/lib/glueby/fee_provider/tasks.rb +141 -0
  26. data/lib/glueby/fee_provider.rb +73 -0
  27. data/lib/glueby/generator/migrate_generator.rb +1 -1
  28. data/lib/glueby/internal/wallet/abstract_wallet_adapter.rb +25 -6
  29. data/lib/glueby/internal/wallet/active_record/utxo.rb +1 -0
  30. data/lib/glueby/internal/wallet/active_record/wallet.rb +15 -5
  31. data/lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb +14 -0
  32. data/lib/glueby/internal/wallet/active_record_wallet_adapter.rb +25 -8
  33. data/lib/glueby/internal/wallet/errors.rb +3 -0
  34. data/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb +42 -14
  35. data/lib/glueby/internal/wallet.rb +56 -13
  36. data/lib/glueby/railtie.rb +10 -0
  37. data/lib/glueby/version.rb +1 -1
  38. data/lib/glueby/wallet.rb +3 -2
  39. data/lib/glueby.rb +27 -12
  40. data/lib/tasks/glueby/block_syncer.rake +29 -0
  41. data/lib/tasks/glueby/contract/timestamp.rake +4 -26
  42. data/lib/tasks/glueby/fee_provider.rake +18 -0
  43. metadata +40 -16
  44. data/.travis.yml +0 -7
  45. data/lib/glueby/contract/fee_provider.rb +0 -21
  46. data/lib/tasks/glueby/contract/block_syncer.rake +0 -36
  47. data/lib/tasks/glueby/contract/wallet_adapter.rake +0 -42
@@ -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
@@ -12,10 +12,10 @@ module Glueby
12
12
  begin
13
13
  ::ActiveRecord::Base.transaction do
14
14
  wallet = Glueby::Wallet.load(t.wallet_id)
15
- tx = create_tx(wallet, t.prefix, t.content_hash, Glueby::Contract::FixedFeeProvider.new)
16
- t.update(txid: tx.txid, status: :unconfirmed)
17
-
18
- wallet.internal_wallet.broadcast(tx)
15
+ tx = create_tx(wallet, t.prefix, t.content_hash, Glueby::Contract::FixedFeeEstimator.new)
16
+ wallet.internal_wallet.broadcast(tx) do |tx|
17
+ t.update(txid: tx.txid, status: :unconfirmed)
18
+ end
19
19
  puts "broadcasted (id=#{t.id}, txid=#{tx.txid})"
20
20
  end
21
21
  rescue => e
@@ -23,23 +23,6 @@ module Glueby
23
23
  end
24
24
  end
25
25
  end
26
-
27
- def confirm
28
- timestamps = Glueby::Contract::AR::Timestamp.where(status: :unconfirmed)
29
- timestamps.each do |t|
30
- begin
31
- ::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']})"
36
- end
37
- end
38
- rescue => e
39
- puts "failed to confirm (id=#{t.id}, reason=#{e.message})"
40
- end
41
- end
42
- end
43
26
  end
44
27
  end
45
28
  end
@@ -52,11 +35,6 @@ namespace :glueby do
52
35
  task :create, [] => [:environment] do |_, _|
53
36
  Glueby::Contract::Task::Timestamp.create
54
37
  end
55
-
56
- desc 'confirm glueby timestamp tx'
57
- task :confirm, [] => [:environment] do |_, _|
58
- Glueby::Contract::Task::Timestamp.confirm
59
- end
60
38
  end
61
39
  end
62
40
  end
@@ -0,0 +1,18 @@
1
+ namespace :glueby do
2
+ namespace :fee_provider do
3
+ desc 'Manage the UTXO pool in Glueby::FeeProvider. Creates outputs for paying fee if the outputs is less than configured pool size by :utxo_pool_size'
4
+ task :manage_utxo_pool, [] => [:environment] do |_, _|
5
+ Glueby::FeeProvider::Tasks.new.manage_utxo_pool
6
+ end
7
+
8
+ desc 'Show the status of the UTXO pool in Glueby::FeeProvider'
9
+ task :status, [] => [:environment] do |_, _|
10
+ Glueby::FeeProvider::Tasks.new.status
11
+ end
12
+
13
+ desc 'Show the address of the Glueby::FeeProvider'
14
+ task :address, [] => [:environment] do |_, _|
15
+ Glueby::FeeProvider::Tasks.new.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.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-23 00:00:00.000000000 Z
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.6
19
+ version: 0.2.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.6
26
+ version: 0.2.9
27
27
  - !ruby/object:Gem::Dependency
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'
34
- type: :development
33
+ version: 6.1.3
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
@@ -59,11 +73,11 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".github/workflows/ruby.yml"
62
77
  - ".gitignore"
63
78
  - ".rspec"
64
79
  - ".ruby-gemset"
65
80
  - ".ruby-version"
66
- - ".travis.yml"
67
81
  - CODE_OF_CONDUCT.md
68
82
  - Gemfile
69
83
  - LICENSE.txt
@@ -74,8 +88,10 @@ files:
74
88
  - glueby.gemspec
75
89
  - lib/generators/glueby/contract/block_syncer_generator.rb
76
90
  - lib/generators/glueby/contract/initializer_generator.rb
91
+ - lib/generators/glueby/contract/reissuable_token_generator.rb
77
92
  - lib/generators/glueby/contract/templates/initializer.rb.erb
78
93
  - lib/generators/glueby/contract/templates/key_table.rb.erb
94
+ - lib/generators/glueby/contract/templates/reissuable_token_table.rb.erb
79
95
  - lib/generators/glueby/contract/templates/system_information_table.rb.erb
80
96
  - lib/generators/glueby/contract/templates/timestamp_table.rb.erb
81
97
  - lib/generators/glueby/contract/templates/utxo_table.rb.erb
@@ -85,15 +101,21 @@ files:
85
101
  - lib/glueby.rb
86
102
  - lib/glueby/active_record.rb
87
103
  - lib/glueby/active_record/system_information.rb
104
+ - lib/glueby/block_syncer.rb
105
+ - lib/glueby/configuration.rb
88
106
  - lib/glueby/contract.rb
89
107
  - lib/glueby/contract/active_record.rb
108
+ - lib/glueby/contract/active_record/reissuable_token.rb
90
109
  - lib/glueby/contract/active_record/timestamp.rb
91
110
  - lib/glueby/contract/errors.rb
92
- - lib/glueby/contract/fee_provider.rb
111
+ - lib/glueby/contract/fee_estimator.rb
93
112
  - lib/glueby/contract/payment.rb
94
113
  - lib/glueby/contract/timestamp.rb
114
+ - lib/glueby/contract/timestamp/syncer.rb
95
115
  - lib/glueby/contract/token.rb
96
116
  - lib/glueby/contract/tx_builder.rb
117
+ - lib/glueby/fee_provider.rb
118
+ - lib/glueby/fee_provider/tasks.rb
97
119
  - lib/glueby/generator.rb
98
120
  - lib/glueby/generator/migrate_generator.rb
99
121
  - lib/glueby/internal.rb
@@ -105,14 +127,16 @@ files:
105
127
  - lib/glueby/internal/wallet/active_record/utxo.rb
106
128
  - lib/glueby/internal/wallet/active_record/wallet.rb
107
129
  - lib/glueby/internal/wallet/active_record_wallet_adapter.rb
130
+ - lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb
108
131
  - lib/glueby/internal/wallet/errors.rb
109
132
  - lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb
133
+ - lib/glueby/railtie.rb
110
134
  - lib/glueby/version.rb
111
135
  - lib/glueby/wallet.rb
136
+ - lib/tasks/glueby/block_syncer.rake
112
137
  - lib/tasks/glueby/contract.rake
113
- - lib/tasks/glueby/contract/block_syncer.rake
114
138
  - lib/tasks/glueby/contract/timestamp.rake
115
- - lib/tasks/glueby/contract/wallet_adapter.rake
139
+ - lib/tasks/glueby/fee_provider.rake
116
140
  homepage: https://github.com/chaintope/glueby
117
141
  licenses:
118
142
  - MIT
@@ -120,7 +144,7 @@ metadata:
120
144
  homepage_uri: https://github.com/chaintope/glueby
121
145
  source_code_uri: https://github.com/chaintope/glueby
122
146
  changelog_uri: https://github.com/chaintope/glueby
123
- post_install_message:
147
+ post_install_message:
124
148
  rdoc_options: []
125
149
  require_paths:
126
150
  - lib
@@ -136,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
160
  version: '0'
137
161
  requirements: []
138
162
  rubygems_version: 3.2.3
139
- signing_key:
163
+ signing_key:
140
164
  specification_version: 4
141
165
  summary: A Ruby library of smart contracts that can be used on Tapyrus.
142
166
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.6
6
- - 2.7.2
7
- - 3.0.0
@@ -1,21 +0,0 @@
1
- module Glueby
2
- module Contract
3
- module FeeProvider
4
- # @return fee by tapyrus(not TPC).
5
- def fee(_tx); end
6
- end
7
-
8
- class FixedFeeProvider
9
- include FeeProvider
10
-
11
- def initialize(fixed_fee: 10_000)
12
- @fixed_fee = fixed_fee
13
- end
14
-
15
- # @return fee by tapyrus(not TPC).
16
- def fee(_tx)
17
- @fixed_fee
18
- end
19
- end
20
- end
21
- end
@@ -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