glueby 0.4.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +477 -387
- data/glueby.gemspec +33 -33
- data/lib/generators/glueby/contract/templates/initializer.rb.erb +8 -8
- data/lib/generators/glueby/contract/templates/key_table.rb.erb +16 -16
- data/lib/generators/glueby/contract/templates/timestamp_table.rb.erb +4 -1
- data/lib/generators/glueby/contract/templates/utxo_table.rb.erb +16 -16
- data/lib/glueby/block_syncer.rb +97 -97
- data/lib/glueby/configuration.rb +32 -2
- data/lib/glueby/contract/active_record/timestamp.rb +3 -1
- data/lib/glueby/contract/errors.rb +1 -0
- data/lib/glueby/contract/fee_estimator.rb +5 -1
- data/lib/glueby/contract/timestamp/syncer.rb +13 -13
- data/lib/glueby/contract/timestamp.rb +153 -102
- data/lib/glueby/contract/token.rb +270 -244
- data/lib/glueby/contract/tx_builder.rb +97 -30
- data/lib/glueby/fee_provider/tasks.rb +140 -140
- data/lib/glueby/fee_provider.rb +11 -0
- data/lib/glueby/internal/wallet/abstract_wallet_adapter.rb +153 -151
- data/lib/glueby/internal/wallet/active_record/utxo.rb +51 -51
- data/lib/glueby/internal/wallet/active_record_wallet_adapter/syncer.rb +13 -13
- data/lib/glueby/internal/wallet/active_record_wallet_adapter.rb +159 -151
- data/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb +194 -186
- data/lib/glueby/internal/wallet.rb +164 -162
- data/lib/glueby/railtie.rb +10 -9
- data/lib/glueby/utxo_provider/tasks.rb +135 -0
- data/lib/glueby/utxo_provider.rb +85 -0
- data/lib/glueby/version.rb +3 -3
- data/lib/glueby.rb +40 -39
- data/lib/tasks/glueby/block_syncer.rake +28 -28
- data/lib/tasks/glueby/contract/timestamp.rake +46 -39
- data/lib/tasks/glueby/fee_provider.rake +18 -18
- data/lib/tasks/glueby/utxo_provider.rake +18 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -1,387 +1,477 @@
|
|
1
|
-
# Glueby [![Ruby](https://github.com/chaintope/glueby/actions/workflows/ruby.yml/badge.svg)](https://github.com/chaintope/glueby/actions/workflows/ruby.yml) [![Gem Version](https://badge.fury.io/rb/glueby.svg)](https://badge.fury.io/rb/glueby) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|
2
|
-
|
3
|
-
Glueby is a smart contract library on the [Tapyrus blockchain](https://github.com/chaintope/tapyrus-core). This is
|
4
|
-
designed as you can use without any deep blockchain understanding.
|
5
|
-
|
6
|
-
## Features
|
7
|
-
|
8
|
-
Glueby has below features.
|
9
|
-
|
10
|
-
1. Wallet
|
11
|
-
You can manage wallets for application users. This wallet feature is a foundation of Contracts below to specify tx
|
12
|
-
sender and so on.
|
13
|
-
You can choose two sorts of wallet implementation :activerecord and :core. :activerecord is implemented using
|
14
|
-
ActiveRecord on RDB. :core uses the wallet that bundled with Tapyrus Core.
|
15
|
-
|
16
|
-
2. Contracts
|
17
|
-
You can use some smart contracts easily
|
18
|
-
- [Timestamp](#Timestamp): Record any data as a timestamp to a tapyrus blockchain.
|
19
|
-
- [Payment](./lib/glueby/contract/payment.rb): Transfer TPC.
|
20
|
-
- [Token](./lib/glueby/contract/token.rb): Issue, transfer and burn colored coin.
|
21
|
-
|
22
|
-
3. Sync blocks with your application
|
23
|
-
You can use BlockSyncer when you need to synchronize the state of an application with the state of a blockchain.
|
24
|
-
See more details at [BlockSyncer](./lib/glueby/block_syncer.rb).
|
25
|
-
|
26
|
-
4. Take over tx sender's fees
|
27
|
-
FeeProvider module can bear payments of sender's fees. You should provide funds for fees to FeeProvider before use.
|
28
|
-
See how to set up at [Use fee provider mode](#use-fee-provider-mode)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
$
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
$
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
$ rails g glueby:contract:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
$ rails
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
```
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
"
|
161
|
-
"
|
162
|
-
"
|
163
|
-
"
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
"
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
"
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
"
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
```
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
```
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
```
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
```
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
```
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
The
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
1
|
+
# Glueby [![Ruby](https://github.com/chaintope/glueby/actions/workflows/ruby.yml/badge.svg)](https://github.com/chaintope/glueby/actions/workflows/ruby.yml) [![Gem Version](https://badge.fury.io/rb/glueby.svg)](https://badge.fury.io/rb/glueby) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
|
2
|
+
|
3
|
+
Glueby is a smart contract library on the [Tapyrus blockchain](https://github.com/chaintope/tapyrus-core). This is
|
4
|
+
designed as you can use without any deep blockchain understanding.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
Glueby has below features.
|
9
|
+
|
10
|
+
1. Wallet
|
11
|
+
You can manage wallets for application users. This wallet feature is a foundation of Contracts below to specify tx
|
12
|
+
sender and so on.
|
13
|
+
You can choose two sorts of wallet implementation :activerecord and :core. :activerecord is implemented using
|
14
|
+
ActiveRecord on RDB. :core uses the wallet that bundled with Tapyrus Core.
|
15
|
+
|
16
|
+
2. Contracts
|
17
|
+
You can use some smart contracts easily
|
18
|
+
- [Timestamp](#Timestamp): Record any data as a timestamp to a tapyrus blockchain.
|
19
|
+
- [Payment](./lib/glueby/contract/payment.rb): Transfer TPC.
|
20
|
+
- [Token](./lib/glueby/contract/token.rb): Issue, transfer and burn colored coin.
|
21
|
+
|
22
|
+
3. Sync blocks with your application
|
23
|
+
You can use BlockSyncer when you need to synchronize the state of an application with the state of a blockchain.
|
24
|
+
See more details at [BlockSyncer](./lib/glueby/block_syncer.rb).
|
25
|
+
|
26
|
+
4. Take over tx sender's fees
|
27
|
+
FeeProvider module can bear payments of sender's fees. You should provide funds for fees to FeeProvider before use.
|
28
|
+
See how to set up at [Use fee provider mode](#use-fee-provider-mode)
|
29
|
+
|
30
|
+
5. Utxo Provider
|
31
|
+
The UtxoProvider allows users to create a variety of transactions without having to manage the TPCs they hold in their wallets.
|
32
|
+
See more details at [Use utxo provider](#use-utxo-provider)
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'glueby'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle install
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install glueby
|
49
|
+
|
50
|
+
### Setup for Ruby on Rails application development
|
51
|
+
|
52
|
+
1. Add this line to your application's Gemfile
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'glueby'
|
56
|
+
```
|
57
|
+
|
58
|
+
and then execute
|
59
|
+
|
60
|
+
$ bundle install
|
61
|
+
|
62
|
+
2. Run installation rake task
|
63
|
+
|
64
|
+
$ rails glueby:contract:install
|
65
|
+
|
66
|
+
3. Run Tapyrus Core as dev mode
|
67
|
+
|
68
|
+
We recommend to run as a Docker container.
|
69
|
+
Docker image is here.
|
70
|
+
|
71
|
+
* [tapyus/tapyrusd](https://hub.docker.com/repository/docker/tapyrus/tapyrusd)
|
72
|
+
|
73
|
+
Starts tapryusd container
|
74
|
+
|
75
|
+
$ docker run -d --name 'tapyrus_node_dev' -p 12381:12381 -e GENESIS_BLOCK_WITH_SIG='0100000000000000000000000000000000000000000000000000000000000000000000002b5331139c6bc8646bb4e5737c51378133f70b9712b75548cb3c05f9188670e7440d295e7300c5640730c4634402a3e66fb5d921f76b48d8972a484cc0361e66ef74f45e012103af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d40e05f064662d6b9acf65ae416379d82e11a9b78cdeb3a316d1057cd2780e3727f70a61f901d10acbe349cd11e04aa6b4351e782c44670aefbe138e99a5ce75ace01010000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a010000001976a91445d405b9ed450fec89044f9b7a99a4ef6fe2cd3f88ac00000000' tapyrus/tapyrusd:edge
|
76
|
+
|
77
|
+
4. Modify the glueby configuration
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# Use tapyrus dev network
|
81
|
+
Tapyrus.chain_params = :dev
|
82
|
+
Glueby.configure do |config|
|
83
|
+
config.wallet_adapter = :activerecord
|
84
|
+
# Modify rpc connection info in config/initializers/glueby.rb that is created in step 3.
|
85
|
+
config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'rpcuser', password: 'rpcpassword' }
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
5. Generate db migration files for wallet feature
|
90
|
+
|
91
|
+
These are essential if you use `config.wallet_adapter = :activerecord` configuration.
|
92
|
+
|
93
|
+
$ rails g glueby:contract:block_syncer
|
94
|
+
$ rails g glueby:contract:wallet_adapter
|
95
|
+
|
96
|
+
If you want to use reissuable token or timestamp, you need to do below generators.
|
97
|
+
|
98
|
+
$ rails g glueby:contract:reissuable_token
|
99
|
+
$ rails g glueby:contract:timestamp
|
100
|
+
|
101
|
+
Then, run the migrations.
|
102
|
+
|
103
|
+
$ rails db:migrate
|
104
|
+
|
105
|
+
### Provide initial TPC (Tapyrus Coin) to wallets
|
106
|
+
|
107
|
+
To use contracts, wallets need to have TPC and it can be provided from coinbase tx.
|
108
|
+
|
109
|
+
1. Create a wallet and get receive address
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
wallet = Glueby::Wallet.create
|
113
|
+
wallet.balances # => {}
|
114
|
+
address = wallet.internal_wallet.receive_address
|
115
|
+
puts address
|
116
|
+
```
|
117
|
+
|
118
|
+
2. Generate a block
|
119
|
+
|
120
|
+
Set an address you got in previous step to `[Your address]`
|
121
|
+
|
122
|
+
$ docker exec tapyrus_node_dev tapyrus-cli -conf=/etc/tapyrus/tapyrus.conf generatetoaddress 1 "[Your address]" "cUJN5RVzYWFoeY8rUztd47jzXCu1p57Ay8V7pqCzsBD3PEXN7Dd4"
|
123
|
+
|
124
|
+
3. Sync blocks if you use `:activerecord` wallet adapter
|
125
|
+
|
126
|
+
You don't need to do this if you are using `:core` wallet_adapter.
|
127
|
+
|
128
|
+
$ rails glueby:contract:block_syncer:start
|
129
|
+
|
130
|
+
Here the wallet created in step 1 have 50 TPC and you can see like this:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
wallet.balances # => {""=>5000000000}
|
134
|
+
```
|
135
|
+
|
136
|
+
TPC amount is shown as tapyrus unit. 1 TPC = 100000000 tapyrus.
|
137
|
+
|
138
|
+
## Timestamp
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
|
142
|
+
Glurby.configure do |config|
|
143
|
+
config.wallet_adapter = :activerecord
|
144
|
+
config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
|
145
|
+
end
|
146
|
+
|
147
|
+
wallet = Glueby::Wallet.create
|
148
|
+
timestamp = Glueby::Contract::Timestamp.new(wallet: wallet, content: "\x01\x02\x03")
|
149
|
+
timestamp.save!
|
150
|
+
# "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097"
|
151
|
+
|
152
|
+
```
|
153
|
+
|
154
|
+
We can see the timestamp transaction using getrawblockchain command
|
155
|
+
|
156
|
+
```bash
|
157
|
+
> tapyrus-cli -rpcport=12381 -rpcuser=user -rpcpassword=pass getrawtransaction a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097 1
|
158
|
+
|
159
|
+
{
|
160
|
+
"txid": "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097",
|
161
|
+
"hash": "a559a84d94cff58619bb735862eb93ff7a3b8fe122a8f2f4c10b7814fb15459a",
|
162
|
+
"features": 1,
|
163
|
+
"size": 234,
|
164
|
+
"vsize": 234,
|
165
|
+
"weight": 936,
|
166
|
+
"locktime": 0,
|
167
|
+
"vin": [
|
168
|
+
{
|
169
|
+
"txid": "12658e0289da70d43ae3777a174ac8c40f89cbe6564ed6606f197764b3556200",
|
170
|
+
"vout": 0,
|
171
|
+
"scriptSig": {
|
172
|
+
"asm": "3044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d[ALL] 03b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d",
|
173
|
+
"hex": "473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d"
|
174
|
+
},
|
175
|
+
"sequence": 4294967295
|
176
|
+
}
|
177
|
+
],
|
178
|
+
"vout": [
|
179
|
+
{
|
180
|
+
"value": 0.00000000,
|
181
|
+
"n": 0,
|
182
|
+
"scriptPubKey": {
|
183
|
+
"asm": "OP_RETURN 039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
|
184
|
+
"hex": "6a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
|
185
|
+
"type": "nulldata"
|
186
|
+
}
|
187
|
+
},
|
188
|
+
{
|
189
|
+
"value": 49.99990000,
|
190
|
+
"n": 1,
|
191
|
+
"scriptPubKey": {
|
192
|
+
"asm": "OP_DUP OP_HASH160 3c0422f624f2503193c7413eff32839b9e151b54 OP_EQUALVERIFY OP_CHECKSIG",
|
193
|
+
"hex": "76a9143c0422f624f2503193c7413eff32839b9e151b5488ac",
|
194
|
+
"reqSigs": 1,
|
195
|
+
"type": "pubkeyhash",
|
196
|
+
"addresses": [
|
197
|
+
"16ULVva73ZhQiZu9o3njXc3TZ3aSog7FQQ"
|
198
|
+
]
|
199
|
+
}
|
200
|
+
}
|
201
|
+
],
|
202
|
+
"hex": "0100000001006255b36477196f60d64e56e6cb890fc4c84a177a77e33ad470da89028e6512000000006a473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78dffffffff020000000000000000226a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81f0ca052a010000001976a9143c0422f624f2503193c7413eff32839b9e151b5488ac00000000",
|
203
|
+
"blockhash": "d33efc626114f89445d12c27f453c209382a3cb49de132bf978449093f2d2dbb",
|
204
|
+
"confirmations": 3,
|
205
|
+
"time": 1590822803,
|
206
|
+
"blocktime": 1590822803
|
207
|
+
}
|
208
|
+
```
|
209
|
+
|
210
|
+
### Rails support
|
211
|
+
|
212
|
+
Glueby supports ruby on rails integration.
|
213
|
+
|
214
|
+
To use in rails, Add dependency to Gemfile.
|
215
|
+
|
216
|
+
Then invoke install task.
|
217
|
+
|
218
|
+
```
|
219
|
+
bin/rails glueby:contract:install
|
220
|
+
```
|
221
|
+
|
222
|
+
Install task creates a file `glueby.rb` in `config/initializers` directory like this.
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
# Edit configuration for connection to tapyrus core
|
226
|
+
Glueby.configure do |config|
|
227
|
+
config.wallet_adapter = :activerecord
|
228
|
+
config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
|
229
|
+
end
|
230
|
+
|
231
|
+
# Uncomment next line when using timestamp feature
|
232
|
+
# Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
|
233
|
+
```
|
234
|
+
|
235
|
+
If you use timestamp feature, use `glueby:contract:timestamp` generator.
|
236
|
+
|
237
|
+
```
|
238
|
+
bin/rails g glueby:contract:timestamp
|
239
|
+
create db/migrate/20200613065511_create_timestamp.rb
|
240
|
+
bin/rails db:migrate
|
241
|
+
== 20200613065511 CreateTimestamp: migrating ==================================
|
242
|
+
-- create_table(:timestamps)
|
243
|
+
-> 0.0023s
|
244
|
+
== 20200613065511 CreateTimestamp: migrated (0.0024s) =========================
|
245
|
+
```
|
246
|
+
|
247
|
+
Now, Glueby::Contract::AR::Timestamp model is available
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
irb(main):001:0> wallet = Glueby::Wallet.create
|
251
|
+
=> #<Glueby::Wallet:0x00007fe8333f7d98 @internal_wallet=#<Glueby::Internal::Wallet:0x00007fe8333f7dc0 @id="70a58204a7f4cb10d973b762f17fdb4b">>
|
252
|
+
irb(main):003:0> t = Glueby::Contract::AR::Timestamp.new(wallet_id: wallet.id, content:"\x01010101", prefix: "app")
|
253
|
+
(0.5ms) SELECT sqlite_version(*)
|
254
|
+
=> #<Glueby::Contract::AR::Timestamp id: nil, txid: nil, status: "init", content_hash: "9ccc644b03a88358a754962903a659a2d338767ee61674dde5...", prefix: "app", wallet_id: "70a58204a7f4cb10d973b762f17fdb4b">
|
255
|
+
irb(main):004:0> t.save
|
256
|
+
(0.1ms) begin transaction
|
257
|
+
Glueby::Contract::AR::Timestamp Create (0.4ms) INSERT INTO "timestamps" ("status", "content_hash", "prefix", "wallet_id") VALUES (?, ?, ?, ?) [["status", 0], ["content_hash", "9ccc644b03a88358a754962903a659a2d338767ee61674dde5434702a6256e6d"], ["prefix", "app"], ["wallet_id", "70a58204a7f4cb10d973b762f17fdb4b"]]
|
258
|
+
(2.1ms) commit transaction
|
259
|
+
=> true
|
260
|
+
```
|
261
|
+
|
262
|
+
After create timestamp model, run `glueby:contract:timestamp:create` task to broadcast the transaction to the Tapyrus Core Network and update status(init -> unconfirmed).
|
263
|
+
|
264
|
+
```
|
265
|
+
bin/rails glueby:contract:timestamp:create
|
266
|
+
broadcasted (id=1, txid=8d602ca8ebdd50fa70b5ee6bc6351965b614d0a4843adacf9f43fedd7112fbf4)
|
267
|
+
```
|
268
|
+
|
269
|
+
Run `glueby:block_syncer:start` task to confirm the transaction and update status(unconfirmed -> confirmded).
|
270
|
+
|
271
|
+
```
|
272
|
+
bin/rails glueby:block_syncer:start
|
273
|
+
```
|
274
|
+
|
275
|
+
## Use fee provider mode
|
276
|
+
|
277
|
+
Glueby contracts have two different way of fee provisions.
|
278
|
+
|
279
|
+
1. `:sender_pays_itself`
|
280
|
+
2. `:fee_provider_bears`
|
281
|
+
|
282
|
+
The first one: `:sender_pays_itself`, is the default behavior.
|
283
|
+
In the second Fee Provider mode, the Fee Provider module pays a fee instead of the transaction's sender.
|
284
|
+
|
285
|
+
### Fee Provider Specification
|
286
|
+
|
287
|
+
* Fee Provider pays fixed amount fee, and it is configurable.
|
288
|
+
* Fee Provider needs to have enough funds into their wallet.
|
289
|
+
* Fee Provider is managed to keep some number of UTXOs that have fixed fee value by rake tasks.
|
290
|
+
|
291
|
+
### Setting up Fee Provider
|
292
|
+
|
293
|
+
1. Set like below
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
Glueby.configure do |config|
|
297
|
+
# Use FeeProvider to supply inputs for fees on each transaction that is created on Glueby.
|
298
|
+
config.fee_provider_bears!
|
299
|
+
config.fee_provider_config = {
|
300
|
+
# The fee that Fee Provider pays on each transaction.
|
301
|
+
fixed_fee: 1000,
|
302
|
+
# Fee Provider tries to keep the number of utxo in utxo pool as this size using `glueby:fee_provider:manage_utxo_pool` rake task
|
303
|
+
# This size should not be greater than 2000.
|
304
|
+
utxo_pool_size: 20
|
305
|
+
}
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
2. Deposit TPC into Fee Provider's wallet
|
310
|
+
|
311
|
+
Get an address from the wallet.
|
312
|
+
|
313
|
+
```
|
314
|
+
$ bundle exec rake glueby:fee_provider:address
|
315
|
+
mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD
|
316
|
+
```
|
317
|
+
|
318
|
+
Send TPC to the address.
|
319
|
+
|
320
|
+
If you use `Glueby::Contract::Payment` to the sending, you can do like this:
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
Glueby::Contract::Payment.transfer(sender: sender, receiver_address: 'mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD', amount: 1_000_000)
|
324
|
+
```
|
325
|
+
|
326
|
+
3. Manage UTXO pool
|
327
|
+
|
328
|
+
The Fee Provider's wallet has to keep some UTXOs with `fixed_fee` amount for paying fees using `manage_utxo_pool` rake task below.
|
329
|
+
This rake task tries to split UTOXs up to `utxo_pool_size`. If the pool has more than `utxo_pool_size` UTXOs, it does nothing.
|
330
|
+
|
331
|
+
```
|
332
|
+
$ bundle exec rake glueby:fee_provider:manage_utxo_pool
|
333
|
+
Status: Ready
|
334
|
+
TPC amount: 999_000
|
335
|
+
UTXO pool size: 20
|
336
|
+
|
337
|
+
Configuration:
|
338
|
+
fixed_fee = 1_000
|
339
|
+
utxo_pool_size = 20
|
340
|
+
```
|
341
|
+
|
342
|
+
This shows that the UTXO pool has 20 UTXOs with `fixed_fee` amount for paying fees and has other UTXOs that never use for paying fees.
|
343
|
+
The sum of all the UTXOs that includes both kinds of UTXO is 999_000 tapyrus.
|
344
|
+
|
345
|
+
If the wallet doesn't have enough amount, the rake task shows an error like:
|
346
|
+
|
347
|
+
```
|
348
|
+
$ bundle exec rake glueby:fee_provider:manage_utxo_pool
|
349
|
+
Status: Insufficient Amount
|
350
|
+
TPC amount: 15_000
|
351
|
+
UTXO pool size: 15
|
352
|
+
|
353
|
+
1. Please replenishment TPC which is for paying fee to FeeProvider.
|
354
|
+
FeeProvider needs 21000 tapyrus at least for paying 20 transaction fees.
|
355
|
+
FeeProvider wallet's address is '1DBgMCNBdjQ1Ntz1vpwx2HMYJmc9kw88iT'
|
356
|
+
2. Then create UTXOs for paying in UTXO pool with 'rake glueby:fee_provider:manage_utxo_pool'
|
357
|
+
|
358
|
+
Configuration:
|
359
|
+
fixed_fee = 1_000
|
360
|
+
utxo_pool_size = 20
|
361
|
+
```
|
362
|
+
|
363
|
+
If you want to get the status information, you can use the `status` task.
|
364
|
+
|
365
|
+
```
|
366
|
+
$ bundle exec rake glueby:fee_provider:status
|
367
|
+
Status: Ready
|
368
|
+
TPC amount: 999_000
|
369
|
+
UTXO pool size: 20
|
370
|
+
|
371
|
+
Configuration:
|
372
|
+
fixed_fee = 1_000
|
373
|
+
utxo_pool_size = 20
|
374
|
+
```
|
375
|
+
|
376
|
+
## Use Utxo Provider
|
377
|
+
|
378
|
+
UtxoProvider will pay TPC on behalf of the user.
|
379
|
+
|
380
|
+
TPCs are required to create transactions in many cases where Glueby is used, such as issuing tokens or recording timestamps.
|
381
|
+
However, on the other hand, each user may not want to fund or manage TPCs.
|
382
|
+
|
383
|
+
The UtxoProvider allows users to create a variety of transactions without having to manage the TPCs they hold in their wallets.
|
384
|
+
|
385
|
+
### Set up Utxo Provider
|
386
|
+
|
387
|
+
1. Configure using Glueby.configure
|
388
|
+
|
389
|
+
```ruby
|
390
|
+
Glueby.configure do |config|
|
391
|
+
# using Utxo Provider
|
392
|
+
config.enable_utxo_provider!
|
393
|
+
|
394
|
+
# If not using Utxo Provider and each wallet manages TPCs by itself (Default behavior)
|
395
|
+
# config.disable_utxo_provider!
|
396
|
+
|
397
|
+
config.utxo_provider_config = {
|
398
|
+
# The amount that each utxo in utxo pool posses.
|
399
|
+
default_value: 1_000,
|
400
|
+
# The number of utxos in utxo pool. This size should not be greater than 2000.
|
401
|
+
utxo_pool_size: 20
|
402
|
+
}
|
403
|
+
end
|
404
|
+
```
|
405
|
+
|
406
|
+
2. Deposit TPC into Utxo Provider's wallet
|
407
|
+
|
408
|
+
Get an address from the wallet, and send enough TPCs to the address.
|
409
|
+
|
410
|
+
```
|
411
|
+
$ bundle exec rake glueby:utxo_provider:address
|
412
|
+
mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD
|
413
|
+
```
|
414
|
+
|
415
|
+
3. Manage UTXO pool
|
416
|
+
|
417
|
+
Run the rake task `glueby:utxo_provider:manage_utxo_pool`
|
418
|
+
This rake task tries to split UTOXs up to `utxo_pool_size`. If the pool has more than `utxo_pool_size` UTXOs, it does nothing
|
419
|
+
|
420
|
+
```
|
421
|
+
$ bundle exec rake glueby:utxo_provider:manage_utxo_pool
|
422
|
+
|
423
|
+
Status: Ready
|
424
|
+
TPC amount: 4_999_990_000
|
425
|
+
UTXO pool size: 20
|
426
|
+
|
427
|
+
Configuration:
|
428
|
+
default_value = 1_000
|
429
|
+
utxo_pool_size = 20
|
430
|
+
```
|
431
|
+
|
432
|
+
If you want to get the status information, you can use the `status` task.
|
433
|
+
|
434
|
+
```
|
435
|
+
$ bundle exec rake glueby:utxo_provider:status
|
436
|
+
Status: Ready q
|
437
|
+
TPC amount: 4_999_990_000
|
438
|
+
UTXO pool size: 20
|
439
|
+
|
440
|
+
Configuration:
|
441
|
+
default_value = 1_000
|
442
|
+
utxo_pool_size = 20
|
443
|
+
|
444
|
+
```
|
445
|
+
|
446
|
+
## Other configurations
|
447
|
+
|
448
|
+
### Default fixed fee for the FixedFeeEstimator
|
449
|
+
|
450
|
+
The architecture of Glueby accepts any fee estimation strategies for paying transactions fee. However, we officially support only one strategy: the fixed fee strategy.
|
451
|
+
It just returns a fixed fee value without any estimation.
|
452
|
+
Here provides a configuration to modify the default fixed fee value it returns like this:
|
453
|
+
|
454
|
+
```ruby
|
455
|
+
Glueby.configure do |config|
|
456
|
+
config.default_fixed_fee = 10_000
|
457
|
+
end
|
458
|
+
```
|
459
|
+
|
460
|
+
|
461
|
+
## Development
|
462
|
+
|
463
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
464
|
+
|
465
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
466
|
+
|
467
|
+
## Contributing
|
468
|
+
|
469
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/glueby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tapyrus-contractrb/blob/master/CODE_OF_CONDUCT.md).
|
470
|
+
|
471
|
+
## License
|
472
|
+
|
473
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
474
|
+
|
475
|
+
## Code of Conduct
|
476
|
+
|
477
|
+
Everyone interacting in the Glueby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/glueby/blob/master/CODE_OF_CONDUCT.md).
|