glueby 1.2.0 → 1.2.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/lib/generators/glueby/contract/templates/initializer.rb.erb +8 -8
- data/lib/generators/glueby/contract/templates/key_table.rb.erb +16 -16
- data/lib/glueby/block_syncer.rb +97 -97
- data/lib/glueby/contract/timestamp/tx_builder/simple.rb +1 -4
- data/lib/glueby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d24ac7453ad1f867e539ac7d602fd2eb05be9b8cbf2b961d7543455ade732b38
|
4
|
+
data.tar.gz: 97bf9172250dd6ff7f1858df2d193c0f702166de46464684259427187ef3c87c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8f001ac884309b2bc1130ba10960bb433d7ef4eb1730e49de060bd343e604d78437e0293b1945e7258be5d03732d7b527755745bfaed19cd2c6ce659387bb3
|
7
|
+
data.tar.gz: 22ba0d8435451c88943ef4720887e38744477d9a321d61df0a6d15a8ea5f78b568398f8bfa4c8076b6288f9940b00aaf321668294284ec8b57c5effb92d6575b
|
@@ -1,8 +1,8 @@
|
|
1
|
-
# Edit configuration for connection to tapyrus core
|
2
|
-
Glueby.configure do |config|
|
3
|
-
config.wallet_adapter = :activerecord
|
4
|
-
config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
|
5
|
-
end
|
6
|
-
|
7
|
-
# Uncomment next line when using timestamp feature
|
8
|
-
# Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
|
1
|
+
# Edit configuration for connection to tapyrus core
|
2
|
+
Glueby.configure do |config|
|
3
|
+
config.wallet_adapter = :activerecord
|
4
|
+
config.rpc_config = { schema: 'http', host: '127.0.0.1', port: 12381, user: 'user', password: 'pass' }
|
5
|
+
end
|
6
|
+
|
7
|
+
# Uncomment next line when using timestamp feature
|
8
|
+
# Glueby::BlockSyncer.register_syncer(Glueby::Contract::Timestamp::Syncer)
|
@@ -1,16 +1,16 @@
|
|
1
|
-
class CreateKey < ActiveRecord::Migration<%= migration_version %>
|
2
|
-
def change
|
3
|
-
create_table :glueby_keys<%= table_options %> do |t|
|
4
|
-
t.string :private_key
|
5
|
-
t.string :public_key
|
6
|
-
t.string :script_pubkey
|
7
|
-
t.string :label, index: true
|
8
|
-
t.integer :purpose
|
9
|
-
t.belongs_to :wallet
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
|
13
|
-
add_index :glueby_keys, [:script_pubkey], unique: true
|
14
|
-
add_index :glueby_keys, [:private_key], unique: true
|
15
|
-
end
|
16
|
-
end
|
1
|
+
class CreateKey < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :glueby_keys<%= table_options %> do |t|
|
4
|
+
t.string :private_key
|
5
|
+
t.string :public_key
|
6
|
+
t.string :script_pubkey
|
7
|
+
t.string :label, index: true
|
8
|
+
t.integer :purpose
|
9
|
+
t.belongs_to :wallet
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :glueby_keys, [:script_pubkey], unique: true
|
14
|
+
add_index :glueby_keys, [:private_key], unique: true
|
15
|
+
end
|
16
|
+
end
|
data/lib/glueby/block_syncer.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
module Glueby
|
2
|
-
# You can use BlockSyncer when you need to synchronize the state of
|
3
|
-
# an application with the state of a blockchain. When BlockSyncer
|
4
|
-
# detects the generation of a new block, it executes the registered
|
5
|
-
# syncer code on a block-by-block or transaction-by-transaction basis.
|
6
|
-
# By using this, an application can detect that the issued transaction
|
7
|
-
# has been captured in blocks, receive a new remittance, and so on.
|
8
|
-
#
|
9
|
-
# # Syncer logic registration
|
10
|
-
#
|
11
|
-
# For registration, create a class that implements the method that performs
|
12
|
-
# synchronization processing and registers it in BlockSyncer. Implement
|
13
|
-
# methods with the following name in that class.
|
14
|
-
#
|
15
|
-
# Method name | Arguments | Call conditions
|
16
|
-
# ------------------ | --------------------- | ------------------------------
|
17
|
-
# block_sync (block) | block: Tapyrus::Block | When a new block is created
|
18
|
-
# block_tx (tx) | tx: Tapyrus::Tx | When a new block is created, it is executed for each tx contained in that block.
|
19
|
-
#
|
20
|
-
# @example Register a synchronous logic
|
21
|
-
# class Syncer
|
22
|
-
# def block_sync (block)
|
23
|
-
# # sync a block
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# def tx_sync (tx)
|
27
|
-
# # sync a tx
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# BlockSyncer.register_syncer(Syncer)
|
31
|
-
#
|
32
|
-
# @example Unregister the synchronous logic
|
33
|
-
# BlockSyncer.unregister_syncer(Syncer)
|
34
|
-
#
|
35
|
-
# # Run BlockSyncer
|
36
|
-
#
|
37
|
-
# Run the `glueby: block_syncer: start` rake task periodically with a program
|
38
|
-
# for periodic execution such as cron. If it detects the generation of a new
|
39
|
-
# block when it is executed, the synchronization process will be executed.
|
40
|
-
# Determine the execution interval according to the requirements of the application.
|
41
|
-
class BlockSyncer
|
42
|
-
# @!attribute [r] height
|
43
|
-
# @return [Integer] The block height to be synced
|
44
|
-
attr_reader :height
|
45
|
-
|
46
|
-
class << self
|
47
|
-
# @!attribute r syncers
|
48
|
-
# @return [Array<Class>] The syncer classes that is registered
|
49
|
-
attr_reader :syncers
|
50
|
-
|
51
|
-
# Register syncer class
|
52
|
-
# @param [Class] syncer The syncer to be registered.
|
53
|
-
def register_syncer(syncer)
|
54
|
-
@syncers ||= []
|
55
|
-
@syncers << syncer
|
56
|
-
end
|
57
|
-
|
58
|
-
# Unregister syncer class
|
59
|
-
# @param [Class] syncer The syncer to be unregistered.
|
60
|
-
def unregister_syncer(syncer)
|
61
|
-
@syncers ||= []
|
62
|
-
@syncers.delete(syncer)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# @param [Integer] height The block height to be synced in the instance
|
67
|
-
def initialize(height)
|
68
|
-
@height = height
|
69
|
-
end
|
70
|
-
|
71
|
-
# Run a block synchronization
|
72
|
-
def run
|
73
|
-
return if self.class.syncers.nil?
|
74
|
-
|
75
|
-
self.class.syncers.each do |syncer|
|
76
|
-
instance = syncer.new
|
77
|
-
instance.block_sync(block) if instance.respond_to?(:block_sync)
|
78
|
-
|
79
|
-
if instance.respond_to?(:tx_sync)
|
80
|
-
block.transactions.each { |tx| instance.tx_sync(tx) }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def block
|
88
|
-
@block ||= begin
|
89
|
-
block = Glueby::Internal::RPC.client.getblock(block_hash, 0)
|
90
|
-
Tapyrus::Block.parse_from_payload(block.htb)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def block_hash
|
95
|
-
@block_hash ||= Glueby::Internal::RPC.client.getblockhash(height)
|
96
|
-
end
|
97
|
-
end
|
1
|
+
module Glueby
|
2
|
+
# You can use BlockSyncer when you need to synchronize the state of
|
3
|
+
# an application with the state of a blockchain. When BlockSyncer
|
4
|
+
# detects the generation of a new block, it executes the registered
|
5
|
+
# syncer code on a block-by-block or transaction-by-transaction basis.
|
6
|
+
# By using this, an application can detect that the issued transaction
|
7
|
+
# has been captured in blocks, receive a new remittance, and so on.
|
8
|
+
#
|
9
|
+
# # Syncer logic registration
|
10
|
+
#
|
11
|
+
# For registration, create a class that implements the method that performs
|
12
|
+
# synchronization processing and registers it in BlockSyncer. Implement
|
13
|
+
# methods with the following name in that class.
|
14
|
+
#
|
15
|
+
# Method name | Arguments | Call conditions
|
16
|
+
# ------------------ | --------------------- | ------------------------------
|
17
|
+
# block_sync (block) | block: Tapyrus::Block | When a new block is created
|
18
|
+
# block_tx (tx) | tx: Tapyrus::Tx | When a new block is created, it is executed for each tx contained in that block.
|
19
|
+
#
|
20
|
+
# @example Register a synchronous logic
|
21
|
+
# class Syncer
|
22
|
+
# def block_sync (block)
|
23
|
+
# # sync a block
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# def tx_sync (tx)
|
27
|
+
# # sync a tx
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
# BlockSyncer.register_syncer(Syncer)
|
31
|
+
#
|
32
|
+
# @example Unregister the synchronous logic
|
33
|
+
# BlockSyncer.unregister_syncer(Syncer)
|
34
|
+
#
|
35
|
+
# # Run BlockSyncer
|
36
|
+
#
|
37
|
+
# Run the `glueby: block_syncer: start` rake task periodically with a program
|
38
|
+
# for periodic execution such as cron. If it detects the generation of a new
|
39
|
+
# block when it is executed, the synchronization process will be executed.
|
40
|
+
# Determine the execution interval according to the requirements of the application.
|
41
|
+
class BlockSyncer
|
42
|
+
# @!attribute [r] height
|
43
|
+
# @return [Integer] The block height to be synced
|
44
|
+
attr_reader :height
|
45
|
+
|
46
|
+
class << self
|
47
|
+
# @!attribute r syncers
|
48
|
+
# @return [Array<Class>] The syncer classes that is registered
|
49
|
+
attr_reader :syncers
|
50
|
+
|
51
|
+
# Register syncer class
|
52
|
+
# @param [Class] syncer The syncer to be registered.
|
53
|
+
def register_syncer(syncer)
|
54
|
+
@syncers ||= []
|
55
|
+
@syncers << syncer
|
56
|
+
end
|
57
|
+
|
58
|
+
# Unregister syncer class
|
59
|
+
# @param [Class] syncer The syncer to be unregistered.
|
60
|
+
def unregister_syncer(syncer)
|
61
|
+
@syncers ||= []
|
62
|
+
@syncers.delete(syncer)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param [Integer] height The block height to be synced in the instance
|
67
|
+
def initialize(height)
|
68
|
+
@height = height
|
69
|
+
end
|
70
|
+
|
71
|
+
# Run a block synchronization
|
72
|
+
def run
|
73
|
+
return if self.class.syncers.nil?
|
74
|
+
|
75
|
+
self.class.syncers.each do |syncer|
|
76
|
+
instance = syncer.new
|
77
|
+
instance.block_sync(block) if instance.respond_to?(:block_sync)
|
78
|
+
|
79
|
+
if instance.respond_to?(:tx_sync)
|
80
|
+
block.transactions.each { |tx| instance.tx_sync(tx) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def block
|
88
|
+
@block ||= begin
|
89
|
+
block = Glueby::Internal::RPC.client.getblock(block_hash, 0)
|
90
|
+
Tapyrus::Block.parse_from_payload(block.htb)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def block_hash
|
95
|
+
@block_hash ||= Glueby::Internal::RPC.client.getblockhash(height)
|
96
|
+
end
|
97
|
+
end
|
98
98
|
end
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|