glueby 0.4.0 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 572e6f36cf1b1df86b93fcd264ce1a537769588a43cbe8bac5ad3d6d9df21f44
4
- data.tar.gz: 4516f08781b324f76846057cfe4722552bc413e7f9518d68b038c7bc16f03f79
3
+ metadata.gz: 7e1446a10f90a642304f51d8c9fed70565a507b1b5f86675fa0db715e638828b
4
+ data.tar.gz: ddcbc8d730235087cfcab5fc4678ef3325ae8921cc98a06d0cc269369d77e997
5
5
  SHA512:
6
- metadata.gz: b04613b40d622b24e14fb45440ea974905daeea6726c4a44c9e458eabe9ea552e1b8a5ad581a7ea19ab8824216f001b95c49101fdefaf2bc424a39c2fdf23d07
7
- data.tar.gz: 1e6a50bf51dd39249c5b2746e27831ca2b63da7bb02090ba2f04b978bfa172dc0372885774986cbbf94f07ccca11d82194b1d104c467d232e0916adab50c2308
6
+ metadata.gz: 3c43bd873752bb6b99ce1bcf23cc7fafef6c20c5b7e6366a490579efbb59e06a093d440012102514d341bd522f703aff776ea9fd7b2c2082957c96a9f6eae051
7
+ data.tar.gz: a0ba6f6d981136434b977ce753f4bab8e698aa40ff4d86950a4f19b8b8a35b91a66b3204286ac54ae809ac40f728b74efc47b5dda7c51d016ae7a9610bccd77d
data/README.md CHANGED
@@ -1,281 +1,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
-
4
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/glueby`. To experiment with that code, run `bin/console` for an interactive prompt.
5
-
6
- TODO: Delete this and the text above, and describe your gem
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'glueby'
14
- ```
15
-
16
- And then execute:
17
-
18
- $ bundle install
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install glueby
23
-
24
- ## Usage
25
-
26
- Glueby has below features.
27
-
28
- - [Timestamp](#Timestamp)
29
-
30
- ### Timestamp
31
-
32
- ```ruby
33
-
34
- Glurby.configure do |config|
35
- config.wallet_adapter = :activerecord
36
- config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
37
- end
38
-
39
- wallet = Glueby::Wallet.create
40
- timestamp = Glueby::Contract::Timestamp.new(wallet: wallet, content: "\x01\x02\x03")
41
- timestamp.save!
42
- # "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097"
43
-
44
- ```
45
-
46
- We can see the timestamp transaction using getrawblockchain command
47
-
48
- ```bash
49
- > tapyrus-cli -rpcport=12381 -rpcuser=user -rpcpassword=pass getrawtransaction a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097 1
50
-
51
- {
52
- "txid": "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097",
53
- "hash": "a559a84d94cff58619bb735862eb93ff7a3b8fe122a8f2f4c10b7814fb15459a",
54
- "features": 1,
55
- "size": 234,
56
- "vsize": 234,
57
- "weight": 936,
58
- "locktime": 0,
59
- "vin": [
60
- {
61
- "txid": "12658e0289da70d43ae3777a174ac8c40f89cbe6564ed6606f197764b3556200",
62
- "vout": 0,
63
- "scriptSig": {
64
- "asm": "3044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d[ALL] 03b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d",
65
- "hex": "473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d"
66
- },
67
- "sequence": 4294967295
68
- }
69
- ],
70
- "vout": [
71
- {
72
- "value": 0.00000000,
73
- "n": 0,
74
- "scriptPubKey": {
75
- "asm": "OP_RETURN 039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
76
- "hex": "6a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
77
- "type": "nulldata"
78
- }
79
- },
80
- {
81
- "value": 49.99990000,
82
- "n": 1,
83
- "scriptPubKey": {
84
- "asm": "OP_DUP OP_HASH160 3c0422f624f2503193c7413eff32839b9e151b54 OP_EQUALVERIFY OP_CHECKSIG",
85
- "hex": "76a9143c0422f624f2503193c7413eff32839b9e151b5488ac",
86
- "reqSigs": 1,
87
- "type": "pubkeyhash",
88
- "addresses": [
89
- "16ULVva73ZhQiZu9o3njXc3TZ3aSog7FQQ"
90
- ]
91
- }
92
- }
93
- ],
94
- "hex": "0100000001006255b36477196f60d64e56e6cb890fc4c84a177a77e33ad470da89028e6512000000006a473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78dffffffff020000000000000000226a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81f0ca052a010000001976a9143c0422f624f2503193c7413eff32839b9e151b5488ac00000000",
95
- "blockhash": "d33efc626114f89445d12c27f453c209382a3cb49de132bf978449093f2d2dbb",
96
- "confirmations": 3,
97
- "time": 1590822803,
98
- "blocktime": 1590822803
99
- }
100
- ```
101
-
102
- #### Rails support
103
-
104
- Glueby supports ruby on rails integration.
105
-
106
- To use in rails, Add dependency to Gemfile.
107
-
108
- Then invoke install task.
109
-
110
- ```
111
- bin/rails glueby:contract:install
112
- ```
113
-
114
- Install task creates a file `glueby.rb` in `config/initializers` directory like this.
115
-
116
- ```ruby
117
- # Edit configuration for connection to tapyrus core
118
- Glueby.configure do |config|
119
- config.wallet_adapter = :activerecord
120
- config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
121
- end
122
- ```
123
-
124
- If you use timestamp feature, use `glueby:contract:timestamp` generator.
125
-
126
- ```
127
- bin/rails g glueby:contract:timestamp
128
- create db/migrate/20200613065511_create_timestamp.rb
129
- bin/rails db:migrate
130
- == 20200613065511 CreateTimestamp: migrating ==================================
131
- -- create_table(:timestamps)
132
- -> 0.0023s
133
- == 20200613065511 CreateTimestamp: migrated (0.0024s) =========================
134
- ```
135
-
136
- Now, Glueby::Contract::AR::Timestamp model is available
137
-
138
- ```ruby
139
- irb(main):001:0> wallet = Glueby::Wallet.create
140
- => #<Glueby::Wallet:0x00007fe8333f7d98 @internal_wallet=#<Glueby::Internal::Wallet:0x00007fe8333f7dc0 @id="70a58204a7f4cb10d973b762f17fdb4b">>
141
- irb(main):003:0> t = Glueby::Contract::AR::Timestamp.new(wallet_id: wallet.id, content:"\x01010101", prefix: "app")
142
- (0.5ms) SELECT sqlite_version(*)
143
- => #<Glueby::Contract::AR::Timestamp id: nil, txid: nil, status: "init", content_hash: "9ccc644b03a88358a754962903a659a2d338767ee61674dde5...", prefix: "app", wallet_id: "70a58204a7f4cb10d973b762f17fdb4b">
144
- irb(main):004:0> t.save
145
- (0.1ms) begin transaction
146
- 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"]]
147
- (2.1ms) commit transaction
148
- => true
149
- ```
150
-
151
- After create timestamp model, run `glueby:contract:timestamp:create` task to broadcast the transaction to the Tapyrus Core Network and update status(init -> unconfirmed).
152
-
153
- ```
154
- bin/rails glueby:contract:timestamp:create
155
- broadcasted (id=1, txid=8d602ca8ebdd50fa70b5ee6bc6351965b614d0a4843adacf9f43fedd7112fbf4)
156
- ```
157
-
158
- Run `glueby:contract:timestamp:confirm` task to confirm the transaction and update status(unconfirmed -> confirmded).
159
-
160
- ```
161
- bin/rails glueby:contract:timestamp:confirm
162
- confirmed (id=1, txid=8d602ca8ebdd50fa70b5ee6bc6351965b614d0a4843adacf9f43fedd7112fbf4)
163
- ```
164
-
165
- ## Use fee provider mode
166
-
167
- Glueby contracts have two different way of fee provisions.
168
-
169
- 1. `:sender_pays_itself`
170
- 2. `:fee_provider_bears`
171
-
172
- The first one: `:sender_pays_itself`, is the default behavior.
173
- In the second Fee Provider mode, the Fee Provider module pays a fee instead of the transaction's sender.
174
-
175
- ### Fee Provider Specification
176
-
177
- * Fee Provider pays fixed amount fee, and it is configurable.
178
- * Fee Provider needs to have enough funds into their wallet.
179
- * Fee Provider is managed to keep some number of UTXOs that have fixed fee value by rake tasks.
180
-
181
- ### Setting up Fee Provider
182
-
183
- 1. Set like below
184
-
185
- ```ruby
186
- Glurby.configure do |config|
187
- # Use FeeProvider to supply inputs for fees on each transaction that is created on Glueby.
188
- config.fee_provider_bears!
189
- config.fee_provider_config = {
190
- # The fee that Fee Provider pays on each transaction.
191
- fixed_fee: 1000,
192
- # Fee Provider tries to keep the number of utxo in utxo pool as this size using `glueby:fee_provider:manage_utxo_pool` rake task
193
- utxo_pool_size: 20
194
- }
195
- end
196
- ```
197
-
198
- 2. Deposit TPC into Fee Provider's wallet
199
-
200
- Get an address from the wallet.
201
-
202
- ```
203
- $ bundle exec rake glueby:fee_provider:address
204
- mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD
205
- ```
206
-
207
- Send TPC to the address.
208
-
209
- If you use `Glueby::Contract::Payment` to the sending, you can do like this:
210
-
211
- ```ruby
212
- Glueby::Contract::Payment.transfer(sender: sender, receiver_address: 'mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD', amount: 1_000_000)
213
- ```
214
-
215
- 3. Manage UTXO pool
216
-
217
- The Fee Provider's wallet has to keep some UTXOs with `fixed_fee` amount for paying fees using `manage_utxo_pool` rake task below.
218
- 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.
219
-
220
- ```
221
- $ bundle exec rake glueby:fee_provider:manage_utxo_pool
222
- Status: Ready
223
- TPC amount: 999_000
224
- UTXO pool size: 20
225
-
226
- Configuration:
227
- fixed_fee = 1_000
228
- utxo_pool_size = 20
229
- ```
230
-
231
- 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.
232
- The sum of all the UTXOs that includes both kinds of UTXO is 999_000 tapyrus.
233
-
234
- If the wallet doesn't have enough amount, the rake task shows an error like:
235
-
236
- ```
237
- $ bundle exec rake glueby:fee_provider:manage_utxo_pool
238
- Status: Insufficient Amount
239
- TPC amount: 15_000
240
- UTXO pool size: 15
241
-
242
- 1. Please replenishment TPC which is for paying fee to FeeProvider.
243
- FeeProvider needs 21000 tapyrus at least for paying 20 transaction fees.
244
- FeeProvider wallet's address is '1DBgMCNBdjQ1Ntz1vpwx2HMYJmc9kw88iT'
245
- 2. Then create UTXOs for paying in UTXO pool with 'rake glueby:fee_provider:manage_utxo_pool'
246
-
247
- Configuration:
248
- fixed_fee = 1_000
249
- utxo_pool_size = 20
250
- ```
251
-
252
- If you want to get the status information, you can use the `status` task.
253
-
254
- ```
255
- $ bundle exec rake glueby:fee_provider:status
256
- Status: Ready
257
- TPC amount: 999_000
258
- UTXO pool size: 20
259
-
260
- Configuration:
261
- fixed_fee = 1_000
262
- utxo_pool_size = 20
263
- ```
264
-
265
- ## Development
266
-
267
- 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.
268
-
269
- 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).
270
-
271
- ## Contributing
272
-
273
- 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).
274
-
275
- ## License
276
-
277
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
278
-
279
- ## Code of Conduct
280
-
281
- 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).
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
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'glueby'
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle install
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install glueby
45
+
46
+ ### Setup for Ruby on Rails application development
47
+
48
+ 1. Add this line to your application's Gemfile
49
+
50
+ ```ruby
51
+ gem 'glueby'
52
+ ```
53
+
54
+ and then execute
55
+
56
+ $ bundle install
57
+
58
+ 2. Run installation rake task
59
+
60
+ $ rails glueby:contract:install
61
+
62
+ 3. Run Tapyrus Core as dev mode
63
+
64
+ We recommend to run as a Docker container.
65
+ Docker image is here.
66
+
67
+ * [tapyus/tapyrusd](https://hub.docker.com/repository/docker/tapyrus/tapyrusd)
68
+
69
+ Starts tapryusd container
70
+
71
+ $ docker run -d --name 'tapyrus_node_dev' -p 12381:12381 -e GENESIS_BLOCK_WITH_SIG='0100000000000000000000000000000000000000000000000000000000000000000000002b5331139c6bc8646bb4e5737c51378133f70b9712b75548cb3c05f9188670e7440d295e7300c5640730c4634402a3e66fb5d921f76b48d8972a484cc0361e66ef74f45e012103af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d40e05f064662d6b9acf65ae416379d82e11a9b78cdeb3a316d1057cd2780e3727f70a61f901d10acbe349cd11e04aa6b4351e782c44670aefbe138e99a5ce75ace01010000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a010000001976a91445d405b9ed450fec89044f9b7a99a4ef6fe2cd3f88ac00000000' tapyrus/tapyrusd:edge
72
+
73
+ 4. Modify the glueby configuration
74
+
75
+ ```ruby
76
+ # Use tapyrus dev network
77
+ Tapyrus.chain_params = :dev
78
+ Glueby.configure do |config|
79
+ config.wallet_adapter = :activerecord
80
+ # Modify rpc connection info in config/initializers/glueby.rb that is created in step 3.
81
+ config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'rpcuser', password: 'rpcpassword' }
82
+ end
83
+ ```
84
+
85
+ 5. Generate db migration files for wallet feature
86
+
87
+ These are essential if you use `config.wallet_adapter = :activerecord` configuration.
88
+
89
+ $ rails g glueby:contract:block_syncer
90
+ $ rails g glueby:contract:wallet_adapter
91
+
92
+ If you want to use reissuable token or timestamp, you need to do below generators.
93
+
94
+ $ rails g glueby:contract:reissuable_token
95
+ $ rails g glueby:contract:timestamp
96
+
97
+ Then, run the migrations.
98
+
99
+ $ rails db:migrate
100
+
101
+ ### Provide initial TPC (Tapyrus Coin) to wallets
102
+
103
+ To use contracts, wallets need to have TPC and it can be provided from coinbase tx.
104
+
105
+ 1. Create a wallet and get receive address
106
+
107
+ ```ruby
108
+ wallet = Glueby::Wallet.create
109
+ wallet.balances # => {}
110
+ address = wallet.internal_wallet.receive_address
111
+ puts address
112
+ ```
113
+
114
+ 2. Generate a block
115
+
116
+ Set an address you got in previous step to `[Your address]`
117
+
118
+ $ docker exec tapyrus_node_dev tapyrus-cli -conf=/etc/tapyrus/tapyrus.conf generatetoaddress 1 "[Your address]" "cUJN5RVzYWFoeY8rUztd47jzXCu1p57Ay8V7pqCzsBD3PEXN7Dd4"
119
+
120
+ 3. Sync blocks if you use `:activerecord` wallet adapter
121
+
122
+ You don't need to do this if you are using `:core` wallet_adapter.
123
+
124
+ $ rails glueby:contract:block_syncer:start
125
+
126
+ Here the wallet created in step 1 have 50 TPC and you can see like this:
127
+
128
+ ```ruby
129
+ wallet.balances # => {""=>5000000000}
130
+ ```
131
+
132
+ TPC amount is shown as tapyrus unit. 1 TPC = 100000000 tapyrus.
133
+
134
+ ## Timestamp
135
+
136
+ ```ruby
137
+
138
+ Glurby.configure do |config|
139
+ config.wallet_adapter = :activerecord
140
+ config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
141
+ end
142
+
143
+ wallet = Glueby::Wallet.create
144
+ timestamp = Glueby::Contract::Timestamp.new(wallet: wallet, content: "\x01\x02\x03")
145
+ timestamp.save!
146
+ # "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097"
147
+
148
+ ```
149
+
150
+ We can see the timestamp transaction using getrawblockchain command
151
+
152
+ ```bash
153
+ > tapyrus-cli -rpcport=12381 -rpcuser=user -rpcpassword=pass getrawtransaction a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097 1
154
+
155
+ {
156
+ "txid": "a01eace94ce6cdc30f389609de8a7584a4e208ee82fec33a2f5875b7cee47097",
157
+ "hash": "a559a84d94cff58619bb735862eb93ff7a3b8fe122a8f2f4c10b7814fb15459a",
158
+ "features": 1,
159
+ "size": 234,
160
+ "vsize": 234,
161
+ "weight": 936,
162
+ "locktime": 0,
163
+ "vin": [
164
+ {
165
+ "txid": "12658e0289da70d43ae3777a174ac8c40f89cbe6564ed6606f197764b3556200",
166
+ "vout": 0,
167
+ "scriptSig": {
168
+ "asm": "3044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d[ALL] 03b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d",
169
+ "hex": "473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78d"
170
+ },
171
+ "sequence": 4294967295
172
+ }
173
+ ],
174
+ "vout": [
175
+ {
176
+ "value": 0.00000000,
177
+ "n": 0,
178
+ "scriptPubKey": {
179
+ "asm": "OP_RETURN 039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
180
+ "hex": "6a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
181
+ "type": "nulldata"
182
+ }
183
+ },
184
+ {
185
+ "value": 49.99990000,
186
+ "n": 1,
187
+ "scriptPubKey": {
188
+ "asm": "OP_DUP OP_HASH160 3c0422f624f2503193c7413eff32839b9e151b54 OP_EQUALVERIFY OP_CHECKSIG",
189
+ "hex": "76a9143c0422f624f2503193c7413eff32839b9e151b5488ac",
190
+ "reqSigs": 1,
191
+ "type": "pubkeyhash",
192
+ "addresses": [
193
+ "16ULVva73ZhQiZu9o3njXc3TZ3aSog7FQQ"
194
+ ]
195
+ }
196
+ }
197
+ ],
198
+ "hex": "0100000001006255b36477196f60d64e56e6cb890fc4c84a177a77e33ad470da89028e6512000000006a473044022067285c57a57fc0d7f64576abbec65639b0f4a8c31b5605eefe881edccb97c62402201ddec93c0c9bf3bb5707757e97e7fa6566c0183b41537e4f9ec46dcfe401864d012103b8ad9e3271a20d5eb2b622e455fcffa5c9c90e38b192772b2e1b58f6b442e78dffffffff020000000000000000226a20039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81f0ca052a010000001976a9143c0422f624f2503193c7413eff32839b9e151b5488ac00000000",
199
+ "blockhash": "d33efc626114f89445d12c27f453c209382a3cb49de132bf978449093f2d2dbb",
200
+ "confirmations": 3,
201
+ "time": 1590822803,
202
+ "blocktime": 1590822803
203
+ }
204
+ ```
205
+
206
+ ### Rails support
207
+
208
+ Glueby supports ruby on rails integration.
209
+
210
+ To use in rails, Add dependency to Gemfile.
211
+
212
+ Then invoke install task.
213
+
214
+ ```
215
+ bin/rails glueby:contract:install
216
+ ```
217
+
218
+ Install task creates a file `glueby.rb` in `config/initializers` directory like this.
219
+
220
+ ```ruby
221
+ # Edit configuration for connection to tapyrus core
222
+ Glueby.configure do |config|
223
+ config.wallet_adapter = :activerecord
224
+ config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
225
+ end
226
+
227
+ # Uncomment next line when using timestamp feature
228
+ # Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
229
+ ```
230
+
231
+ If you use timestamp feature, use `glueby:contract:timestamp` generator.
232
+
233
+ ```
234
+ bin/rails g glueby:contract:timestamp
235
+ create db/migrate/20200613065511_create_timestamp.rb
236
+ bin/rails db:migrate
237
+ == 20200613065511 CreateTimestamp: migrating ==================================
238
+ -- create_table(:timestamps)
239
+ -> 0.0023s
240
+ == 20200613065511 CreateTimestamp: migrated (0.0024s) =========================
241
+ ```
242
+
243
+ Now, Glueby::Contract::AR::Timestamp model is available
244
+
245
+ ```ruby
246
+ irb(main):001:0> wallet = Glueby::Wallet.create
247
+ => #<Glueby::Wallet:0x00007fe8333f7d98 @internal_wallet=#<Glueby::Internal::Wallet:0x00007fe8333f7dc0 @id="70a58204a7f4cb10d973b762f17fdb4b">>
248
+ irb(main):003:0> t = Glueby::Contract::AR::Timestamp.new(wallet_id: wallet.id, content:"\x01010101", prefix: "app")
249
+ (0.5ms) SELECT sqlite_version(*)
250
+ => #<Glueby::Contract::AR::Timestamp id: nil, txid: nil, status: "init", content_hash: "9ccc644b03a88358a754962903a659a2d338767ee61674dde5...", prefix: "app", wallet_id: "70a58204a7f4cb10d973b762f17fdb4b">
251
+ irb(main):004:0> t.save
252
+ (0.1ms) begin transaction
253
+ 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"]]
254
+ (2.1ms) commit transaction
255
+ => true
256
+ ```
257
+
258
+ After create timestamp model, run `glueby:contract:timestamp:create` task to broadcast the transaction to the Tapyrus Core Network and update status(init -> unconfirmed).
259
+
260
+ ```
261
+ bin/rails glueby:contract:timestamp:create
262
+ broadcasted (id=1, txid=8d602ca8ebdd50fa70b5ee6bc6351965b614d0a4843adacf9f43fedd7112fbf4)
263
+ ```
264
+
265
+ Run `glueby:block_syncer:start` task to confirm the transaction and update status(unconfirmed -> confirmded).
266
+
267
+ ```
268
+ bin/rails glueby:block_syncer:start
269
+ ```
270
+
271
+ ## Use fee provider mode
272
+
273
+ Glueby contracts have two different way of fee provisions.
274
+
275
+ 1. `:sender_pays_itself`
276
+ 2. `:fee_provider_bears`
277
+
278
+ The first one: `:sender_pays_itself`, is the default behavior.
279
+ In the second Fee Provider mode, the Fee Provider module pays a fee instead of the transaction's sender.
280
+
281
+ ### Fee Provider Specification
282
+
283
+ * Fee Provider pays fixed amount fee, and it is configurable.
284
+ * Fee Provider needs to have enough funds into their wallet.
285
+ * Fee Provider is managed to keep some number of UTXOs that have fixed fee value by rake tasks.
286
+
287
+ ### Setting up Fee Provider
288
+
289
+ 1. Set like below
290
+
291
+ ```ruby
292
+ Glueby.configure do |config|
293
+ # Use FeeProvider to supply inputs for fees on each transaction that is created on Glueby.
294
+ config.fee_provider_bears!
295
+ config.fee_provider_config = {
296
+ # The fee that Fee Provider pays on each transaction.
297
+ fixed_fee: 1000,
298
+ # Fee Provider tries to keep the number of utxo in utxo pool as this size using `glueby:fee_provider:manage_utxo_pool` rake task
299
+ utxo_pool_size: 20
300
+ }
301
+ end
302
+ ```
303
+
304
+ 2. Deposit TPC into Fee Provider's wallet
305
+
306
+ Get an address from the wallet.
307
+
308
+ ```
309
+ $ bundle exec rake glueby:fee_provider:address
310
+ mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD
311
+ ```
312
+
313
+ Send TPC to the address.
314
+
315
+ If you use `Glueby::Contract::Payment` to the sending, you can do like this:
316
+
317
+ ```ruby
318
+ Glueby::Contract::Payment.transfer(sender: sender, receiver_address: 'mqYTLdLCUCCZkTkcpbVx1GqpvV1gK4euRD', amount: 1_000_000)
319
+ ```
320
+
321
+ 3. Manage UTXO pool
322
+
323
+ The Fee Provider's wallet has to keep some UTXOs with `fixed_fee` amount for paying fees using `manage_utxo_pool` rake task below.
324
+ 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.
325
+
326
+ ```
327
+ $ bundle exec rake glueby:fee_provider:manage_utxo_pool
328
+ Status: Ready
329
+ TPC amount: 999_000
330
+ UTXO pool size: 20
331
+
332
+ Configuration:
333
+ fixed_fee = 1_000
334
+ utxo_pool_size = 20
335
+ ```
336
+
337
+ 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.
338
+ The sum of all the UTXOs that includes both kinds of UTXO is 999_000 tapyrus.
339
+
340
+ If the wallet doesn't have enough amount, the rake task shows an error like:
341
+
342
+ ```
343
+ $ bundle exec rake glueby:fee_provider:manage_utxo_pool
344
+ Status: Insufficient Amount
345
+ TPC amount: 15_000
346
+ UTXO pool size: 15
347
+
348
+ 1. Please replenishment TPC which is for paying fee to FeeProvider.
349
+ FeeProvider needs 21000 tapyrus at least for paying 20 transaction fees.
350
+ FeeProvider wallet's address is '1DBgMCNBdjQ1Ntz1vpwx2HMYJmc9kw88iT'
351
+ 2. Then create UTXOs for paying in UTXO pool with 'rake glueby:fee_provider:manage_utxo_pool'
352
+
353
+ Configuration:
354
+ fixed_fee = 1_000
355
+ utxo_pool_size = 20
356
+ ```
357
+
358
+ If you want to get the status information, you can use the `status` task.
359
+
360
+ ```
361
+ $ bundle exec rake glueby:fee_provider:status
362
+ Status: Ready
363
+ TPC amount: 999_000
364
+ UTXO pool size: 20
365
+
366
+ Configuration:
367
+ fixed_fee = 1_000
368
+ utxo_pool_size = 20
369
+ ```
370
+
371
+ ## Development
372
+
373
+ 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.
374
+
375
+ 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).
376
+
377
+ ## Contributing
378
+
379
+ 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).
380
+
381
+ ## License
382
+
383
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
384
+
385
+ ## Code of Conduct
386
+
387
+ 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).