glueby 0.2.0 → 0.4.2
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 +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/Gemfile +1 -0
- data/README.md +224 -16
- data/glueby.gemspec +2 -2
- data/lib/generators/glueby/contract/block_syncer_generator.rb +26 -0
- data/lib/generators/glueby/contract/reissuable_token_generator.rb +26 -0
- data/lib/generators/glueby/contract/templates/initializer.rb.erb +4 -2
- data/lib/generators/glueby/contract/templates/key_table.rb.erb +4 -3
- data/lib/generators/glueby/contract/templates/reissuable_token_table.rb.erb +10 -0
- data/lib/generators/glueby/contract/templates/system_information_table.rb.erb +12 -0
- data/lib/generators/glueby/contract/templates/timestamp_table.rb.erb +1 -1
- data/lib/generators/glueby/contract/templates/utxo_table.rb.erb +3 -2
- data/lib/generators/glueby/contract/templates/wallet_table.rb.erb +2 -2
- data/lib/glueby.rb +28 -11
- data/lib/glueby/active_record.rb +8 -0
- data/lib/glueby/active_record/system_information.rb +15 -0
- data/lib/glueby/block_syncer.rb +98 -0
- data/lib/glueby/configuration.rb +62 -0
- data/lib/glueby/contract.rb +2 -2
- data/lib/glueby/contract/active_record.rb +1 -0
- data/lib/glueby/contract/active_record/reissuable_token.rb +26 -0
- data/lib/glueby/contract/fee_estimator.rb +38 -0
- data/lib/glueby/contract/payment.rb +10 -6
- data/lib/glueby/contract/timestamp.rb +8 -6
- data/lib/glueby/contract/timestamp/syncer.rb +13 -0
- data/lib/glueby/contract/token.rb +78 -26
- data/lib/glueby/contract/tx_builder.rb +23 -20
- data/lib/glueby/fee_provider.rb +73 -0
- data/lib/glueby/fee_provider/tasks.rb +141 -0
- data/lib/glueby/generator/migrate_generator.rb +1 -1
- data/lib/glueby/internal/wallet.rb +56 -13
- data/lib/glueby/internal/wallet/abstract_wallet_adapter.rb +25 -6
- data/lib/glueby/internal/wallet/active_record/utxo.rb +1 -0
- data/lib/glueby/internal/wallet/active_record/wallet.rb +15 -5
- data/lib/glueby/internal/wallet/active_record_wallet_adapter.rb +25 -8
- data/lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb +14 -0
- data/lib/glueby/internal/wallet/errors.rb +3 -0
- data/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb +42 -14
- data/lib/glueby/railtie.rb +14 -0
- data/lib/glueby/version.rb +1 -1
- data/lib/glueby/wallet.rb +3 -2
- data/lib/tasks/glueby/block_syncer.rake +29 -0
- data/lib/tasks/glueby/contract/timestamp.rake +4 -26
- data/lib/tasks/glueby/fee_provider.rake +18 -0
- metadata +26 -11
- data/.travis.yml +0 -7
- data/lib/glueby/contract/fee_provider.rb +0 -21
- data/lib/tasks/glueby/contract/wallet_adapter.rake +0 -42
@@ -0,0 +1,14 @@
|
|
1
|
+
module Glueby
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "glueby.register_syncers" do
|
4
|
+
BlockSyncer.register_syncer(Contract::Timestamp::Syncer)
|
5
|
+
end
|
6
|
+
|
7
|
+
rake_tasks do
|
8
|
+
load "tasks/glueby/contract.rake"
|
9
|
+
load "tasks/glueby/contract/timestamp.rake"
|
10
|
+
load "tasks/glueby/block_syncer.rake"
|
11
|
+
load "tasks/glueby/fee_provider.rake"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/glueby/version.rb
CHANGED
data/lib/glueby/wallet.rb
CHANGED
@@ -13,6 +13,7 @@ module Glueby
|
|
13
13
|
new(Glueby::Internal::Wallet.load(wallet_id))
|
14
14
|
end
|
15
15
|
|
16
|
+
# @deprecated - Use Glueby.configure instead
|
16
17
|
def configure(config)
|
17
18
|
case config[:adapter]
|
18
19
|
when 'core'
|
@@ -32,8 +33,8 @@ module Glueby
|
|
32
33
|
end
|
33
34
|
|
34
35
|
# @return [HashMap] hash of balances which key is color_id or empty string, and value is amount
|
35
|
-
def balances
|
36
|
-
utxos = @internal_wallet.list_unspent
|
36
|
+
def balances(only_finalized = true)
|
37
|
+
utxos = @internal_wallet.list_unspent(only_finalized)
|
37
38
|
utxos.inject({}) do |balances, output|
|
38
39
|
key = output[:color_id] || ''
|
39
40
|
balances[key] ||= 0
|
@@ -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::
|
16
|
-
|
17
|
-
|
18
|
-
|
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.2
|
4
|
+
version: 0.4.2
|
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-
|
11
|
+
date: 2021-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
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.
|
26
|
+
version: 0.2.9
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -59,11 +59,11 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/ruby.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
64
65
|
- ".ruby-gemset"
|
65
66
|
- ".ruby-version"
|
66
|
-
- ".travis.yml"
|
67
67
|
- CODE_OF_CONDUCT.md
|
68
68
|
- Gemfile
|
69
69
|
- LICENSE.txt
|
@@ -72,24 +72,36 @@ files:
|
|
72
72
|
- bin/console
|
73
73
|
- bin/setup
|
74
74
|
- glueby.gemspec
|
75
|
+
- lib/generators/glueby/contract/block_syncer_generator.rb
|
75
76
|
- lib/generators/glueby/contract/initializer_generator.rb
|
77
|
+
- lib/generators/glueby/contract/reissuable_token_generator.rb
|
76
78
|
- lib/generators/glueby/contract/templates/initializer.rb.erb
|
77
79
|
- lib/generators/glueby/contract/templates/key_table.rb.erb
|
80
|
+
- lib/generators/glueby/contract/templates/reissuable_token_table.rb.erb
|
81
|
+
- lib/generators/glueby/contract/templates/system_information_table.rb.erb
|
78
82
|
- lib/generators/glueby/contract/templates/timestamp_table.rb.erb
|
79
83
|
- lib/generators/glueby/contract/templates/utxo_table.rb.erb
|
80
84
|
- lib/generators/glueby/contract/templates/wallet_table.rb.erb
|
81
85
|
- lib/generators/glueby/contract/timestamp_generator.rb
|
82
86
|
- lib/generators/glueby/contract/wallet_adapter_generator.rb
|
83
87
|
- lib/glueby.rb
|
88
|
+
- lib/glueby/active_record.rb
|
89
|
+
- lib/glueby/active_record/system_information.rb
|
90
|
+
- lib/glueby/block_syncer.rb
|
91
|
+
- lib/glueby/configuration.rb
|
84
92
|
- lib/glueby/contract.rb
|
85
93
|
- lib/glueby/contract/active_record.rb
|
94
|
+
- lib/glueby/contract/active_record/reissuable_token.rb
|
86
95
|
- lib/glueby/contract/active_record/timestamp.rb
|
87
96
|
- lib/glueby/contract/errors.rb
|
88
|
-
- lib/glueby/contract/
|
97
|
+
- lib/glueby/contract/fee_estimator.rb
|
89
98
|
- lib/glueby/contract/payment.rb
|
90
99
|
- lib/glueby/contract/timestamp.rb
|
100
|
+
- lib/glueby/contract/timestamp/syncer.rb
|
91
101
|
- lib/glueby/contract/token.rb
|
92
102
|
- lib/glueby/contract/tx_builder.rb
|
103
|
+
- lib/glueby/fee_provider.rb
|
104
|
+
- lib/glueby/fee_provider/tasks.rb
|
93
105
|
- lib/glueby/generator.rb
|
94
106
|
- lib/glueby/generator/migrate_generator.rb
|
95
107
|
- lib/glueby/internal.rb
|
@@ -101,13 +113,16 @@ files:
|
|
101
113
|
- lib/glueby/internal/wallet/active_record/utxo.rb
|
102
114
|
- lib/glueby/internal/wallet/active_record/wallet.rb
|
103
115
|
- lib/glueby/internal/wallet/active_record_wallet_adapter.rb
|
116
|
+
- lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb
|
104
117
|
- lib/glueby/internal/wallet/errors.rb
|
105
118
|
- lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb
|
119
|
+
- lib/glueby/railtie.rb
|
106
120
|
- lib/glueby/version.rb
|
107
121
|
- lib/glueby/wallet.rb
|
122
|
+
- lib/tasks/glueby/block_syncer.rake
|
108
123
|
- lib/tasks/glueby/contract.rake
|
109
124
|
- lib/tasks/glueby/contract/timestamp.rake
|
110
|
-
- lib/tasks/glueby/
|
125
|
+
- lib/tasks/glueby/fee_provider.rake
|
111
126
|
homepage: https://github.com/chaintope/glueby
|
112
127
|
licenses:
|
113
128
|
- MIT
|
@@ -115,7 +130,7 @@ metadata:
|
|
115
130
|
homepage_uri: https://github.com/chaintope/glueby
|
116
131
|
source_code_uri: https://github.com/chaintope/glueby
|
117
132
|
changelog_uri: https://github.com/chaintope/glueby
|
118
|
-
post_install_message:
|
133
|
+
post_install_message:
|
119
134
|
rdoc_options: []
|
120
135
|
require_paths:
|
121
136
|
- lib
|
@@ -131,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
146
|
version: '0'
|
132
147
|
requirements: []
|
133
148
|
rubygems_version: 3.2.3
|
134
|
-
signing_key:
|
149
|
+
signing_key:
|
135
150
|
specification_version: 4
|
136
151
|
summary: A Ruby library of smart contracts that can be used on Tapyrus.
|
137
152
|
test_files: []
|
data/.travis.yml
DELETED
@@ -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,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
|