glueby 0.8.0 → 0.8.1
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/glueby.gemspec +1 -1
- data/lib/glueby/contract/active_record/timestamp.rb +2 -2
- data/lib/glueby/contract/token.rb +4 -1
- data/lib/glueby/utxo_provider/tasks.rb +15 -37
- data/lib/glueby/utxo_provider.rb +19 -1
- data/lib/glueby/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0196e03513c71e992b7b126c3100a6a57bff96210479f97736a7ea1893f029ec'
|
4
|
+
data.tar.gz: f2d3fa7ec7918394054447ccbca4dff5f039a0a8ef5d431311800dcae9fdb2e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bdb76d2162a482823107ac0a61d81436599a3ce49d706c69366ac288c394546fa553e896c91a9af084a3f3991d698307a3cfcfc457b47625cef06e3f5b6c113
|
7
|
+
data.tar.gz: e1f8f4885822bc70475e99856858421e693db63b3dae96abaaac2c235d7c2fcd8ca610333a085b03a706976ffdcfffa0c4e5f9ef9f0da8e391a73ee350e93ec4
|
data/glueby.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_runtime_dependency 'tapyrus', '>= 0.2.
|
29
|
+
spec.add_runtime_dependency 'tapyrus', '>= 0.2.13'
|
30
30
|
spec.add_runtime_dependency 'activerecord', '~> 6.1.3'
|
31
31
|
spec.add_development_dependency 'sqlite3'
|
32
32
|
spec.add_development_dependency 'rails', '~> 6.1.3'
|
@@ -35,16 +35,16 @@ module Glueby
|
|
35
35
|
if funding_tx
|
36
36
|
::ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
|
37
37
|
wallet.internal_wallet.broadcast(funding_tx)
|
38
|
-
logger.info("funding tx was broadcasted(id=#{id}, funding_tx.txid=#{funding_tx.txid})")
|
39
38
|
end
|
39
|
+
logger.info("funding tx was broadcasted(id=#{id}, funding_tx.txid=#{funding_tx.txid})")
|
40
40
|
end
|
41
41
|
::ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
|
42
42
|
wallet.internal_wallet.broadcast(tx) do |tx|
|
43
43
|
assign_attributes(txid: tx.txid, status: :unconfirmed, p2c_address: p2c_address, payment_base: payment_base)
|
44
44
|
save!
|
45
45
|
end
|
46
|
-
logger.info("timestamp tx was broadcasted (id=#{id}, txid=#{tx.txid})")
|
47
46
|
end
|
47
|
+
logger.info("timestamp tx was broadcasted (id=#{id}, txid=#{tx.txid})")
|
48
48
|
true
|
49
49
|
rescue => e
|
50
50
|
logger.error("failed to broadcast (id=#{id}, reason=#{e.message})")
|
@@ -91,11 +91,14 @@ module Glueby
|
|
91
91
|
script_pubkey = funding_tx.outputs.first.script_pubkey
|
92
92
|
color_id = Tapyrus::Color::ColorIdentifier.reissuable(script_pubkey)
|
93
93
|
|
94
|
+
ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
|
95
|
+
funding_tx = issuer.internal_wallet.broadcast(funding_tx)
|
96
|
+
end
|
97
|
+
|
94
98
|
ActiveRecord::Base.transaction(joinable: false, requires_new: true) do
|
95
99
|
# Store the script_pubkey for reissue the token.
|
96
100
|
Glueby::Contract::AR::ReissuableToken.create!(color_id: color_id.to_hex, script_pubkey: script_pubkey.to_hex)
|
97
101
|
|
98
|
-
funding_tx = issuer.internal_wallet.broadcast(funding_tx)
|
99
102
|
tx = create_issue_tx_for_reissuable_token(funding_tx: funding_tx, issuer: issuer, amount: amount, split: split)
|
100
103
|
tx = issuer.internal_wallet.broadcast(tx)
|
101
104
|
[[funding_tx, tx], color_id]
|
@@ -30,14 +30,14 @@ module Glueby
|
|
30
30
|
|
31
31
|
utxos.each { |utxo| txb.add_utxo(utxo) }
|
32
32
|
|
33
|
-
shortage = [utxo_provider.utxo_pool_size - current_utxo_pool_size, 0].max
|
33
|
+
shortage = [utxo_provider.utxo_pool_size - utxo_provider.current_utxo_pool_size, 0].max
|
34
34
|
return if shortage == 0
|
35
35
|
|
36
36
|
added_outputs = 0
|
37
37
|
shortage.times do
|
38
38
|
fee = utxo_provider.fee_estimator.fee(dummy_tx(txb.build))
|
39
39
|
break if (sum - fee) < utxo_provider.default_value
|
40
|
-
txb.pay(address, utxo_provider.default_value)
|
40
|
+
txb.pay(utxo_provider.address, utxo_provider.default_value)
|
41
41
|
sum -= utxo_provider.default_value
|
42
42
|
added_outputs += 1
|
43
43
|
end
|
@@ -45,11 +45,11 @@ module Glueby
|
|
45
45
|
return if added_outputs == 0
|
46
46
|
|
47
47
|
fee = utxo_provider.fee_estimator.fee(dummy_tx(txb.build))
|
48
|
-
tx = txb.change_address(address)
|
48
|
+
tx = txb.change_address(utxo_provider.address)
|
49
49
|
.fee(fee)
|
50
50
|
.build
|
51
|
-
tx = wallet.sign_tx(tx)
|
52
|
-
wallet.broadcast(tx)
|
51
|
+
tx = utxo_provider.wallet.sign_tx(tx)
|
52
|
+
utxo_provider.wallet.broadcast(tx)
|
53
53
|
ensure
|
54
54
|
status
|
55
55
|
end
|
@@ -58,13 +58,13 @@ module Glueby
|
|
58
58
|
def status
|
59
59
|
status = :ready
|
60
60
|
|
61
|
-
if current_utxo_pool_size < utxo_provider.utxo_pool_size
|
62
|
-
if tpc_amount < value_to_fill_utxo_pool
|
61
|
+
if utxo_provider.current_utxo_pool_size < utxo_provider.utxo_pool_size
|
62
|
+
if utxo_provider.tpc_amount < utxo_provider.value_to_fill_utxo_pool
|
63
63
|
status = :insufficient_amount
|
64
64
|
message = <<~MESSAGE
|
65
65
|
1. Please replenishment TPC which is for paying tpc to UtxoProvider.
|
66
|
-
UtxoProvider needs #{value_to_fill_utxo_pool} tapyrus in UTXO pool.
|
67
|
-
UtxoProvider wallet's address is '#{address}'
|
66
|
+
UtxoProvider needs #{utxo_provider.value_to_fill_utxo_pool} tapyrus in UTXO pool.
|
67
|
+
UtxoProvider wallet's address is '#{utxo_provider.address}'
|
68
68
|
2. Then create UTXOs for paying in UTXO pool with 'rake glueby:utxo_provider:manage_utxo_pool'
|
69
69
|
MESSAGE
|
70
70
|
else
|
@@ -72,12 +72,12 @@ module Glueby
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
status = :not_ready if current_utxo_pool_size == 0
|
75
|
+
status = :not_ready if utxo_provider.current_utxo_pool_size == 0
|
76
76
|
|
77
77
|
puts <<~EOS
|
78
78
|
Status: #{STATUS[status]}
|
79
|
-
TPC amount: #{delimit(tpc_amount)}
|
80
|
-
UTXO pool size: #{delimit(current_utxo_pool_size)}
|
79
|
+
TPC amount: #{delimit(utxo_provider.tpc_amount)}
|
80
|
+
UTXO pool size: #{delimit(utxo_provider.current_utxo_pool_size)}
|
81
81
|
#{"\n" if message}#{message}
|
82
82
|
Configuration:
|
83
83
|
default_value = #{delimit(utxo_provider.default_value)}
|
@@ -87,17 +87,13 @@ module Glueby
|
|
87
87
|
|
88
88
|
# Show the address of Utxo Provider
|
89
89
|
def print_address
|
90
|
-
puts address
|
90
|
+
puts utxo_provider.address
|
91
91
|
end
|
92
92
|
|
93
93
|
private
|
94
94
|
|
95
|
-
def tpc_amount
|
96
|
-
wallet.balance(false)
|
97
|
-
end
|
98
|
-
|
99
95
|
def collect_outputs
|
100
|
-
wallet.list_unspent.inject([0, []]) do |sum, output|
|
96
|
+
utxo_provider.wallet.list_unspent.inject([0, []]) do |sum, output|
|
101
97
|
next sum if output[:color_id] || output[:amount] == utxo_provider.default_value
|
102
98
|
|
103
99
|
new_sum = sum[0] + output[:amount]
|
@@ -105,34 +101,16 @@ module Glueby
|
|
105
101
|
txid: output[:txid],
|
106
102
|
script_pubkey: output[:script_pubkey],
|
107
103
|
value: output[:amount],
|
108
|
-
index: output[:vout]
|
104
|
+
index: output[:vout],
|
109
105
|
finalized: output[:finalized]
|
110
106
|
}
|
111
107
|
[new_sum, new_outputs]
|
112
108
|
end
|
113
109
|
end
|
114
110
|
|
115
|
-
def current_utxo_pool_size
|
116
|
-
wallet
|
117
|
-
.list_unspent(false)
|
118
|
-
.count { |o| !o[:color_id] && o[:amount] == utxo_provider.default_value }
|
119
|
-
end
|
120
|
-
|
121
|
-
def value_to_fill_utxo_pool
|
122
|
-
utxo_provider.default_value * utxo_provider.utxo_pool_size
|
123
|
-
end
|
124
|
-
|
125
|
-
def wallet
|
126
|
-
utxo_provider.wallet
|
127
|
-
end
|
128
|
-
|
129
111
|
def delimit(num)
|
130
112
|
num.to_s.reverse.scan(/.{1,3}/).join('_').reverse
|
131
113
|
end
|
132
|
-
|
133
|
-
def address
|
134
|
-
@address ||= wallet.get_addresses.first || wallet.receive_address
|
135
|
-
end
|
136
114
|
end
|
137
115
|
end
|
138
116
|
end
|
data/lib/glueby/utxo_provider.rb
CHANGED
@@ -27,7 +27,7 @@ module Glueby
|
|
27
27
|
@fee_estimator = (UtxoProvider.config && UtxoProvider.config[:fee_estimator]) || Glueby::Contract::FixedFeeEstimator.new
|
28
28
|
end
|
29
29
|
|
30
|
-
attr_reader :wallet, :fee_estimator
|
30
|
+
attr_reader :wallet, :fee_estimator, :address
|
31
31
|
|
32
32
|
# Provide a UTXO
|
33
33
|
# @param [Tapyrus::Script] script_pubkey The script to be provided
|
@@ -78,6 +78,24 @@ module Glueby
|
|
78
78
|
)
|
79
79
|
end
|
80
80
|
|
81
|
+
def tpc_amount
|
82
|
+
wallet.balance(false)
|
83
|
+
end
|
84
|
+
|
85
|
+
def current_utxo_pool_size
|
86
|
+
wallet
|
87
|
+
.list_unspent(false)
|
88
|
+
.count { |o| !o[:color_id] && o[:amount] == default_value }
|
89
|
+
end
|
90
|
+
|
91
|
+
def address
|
92
|
+
@address ||= wallet.get_addresses.first || wallet.receive_address
|
93
|
+
end
|
94
|
+
|
95
|
+
def value_to_fill_utxo_pool
|
96
|
+
default_value * utxo_pool_size
|
97
|
+
end
|
98
|
+
|
81
99
|
private
|
82
100
|
|
83
101
|
# Create wallet for provider
|
data/lib/glueby/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-04 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.13
|
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.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|