bitcoin2graphdb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/Rakefile +10 -0
- data/bitcoin2graphdb.gemspec +1 -1
- data/lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb +4 -0
- data/lib/bitcoin2graphdb/migration.rb +16 -8
- data/lib/bitcoin2graphdb/version.rb +1 -1
- data/lib/graphdb.rb +1 -0
- data/lib/graphdb/model/extensions.rb +6 -6
- data/lib/graphdb/model/extensions/open_assets.rb +7 -2
- data/lib/graphdb/model/extensions/open_assets/asset_id.rb +22 -0
- data/lib/graphdb/model/extensions/open_assets/transaction.rb +31 -0
- data/lib/graphdb/model/extensions/open_assets/tx_out.rb +35 -0
- data/lib/graphdb/model/tx_in.rb +1 -1
- metadata +7 -6
- data/lib/graphdb/model/extensions/base.rb +0 -15
- data/lib/graphdb/model/extensions/open_assets/oa_transaction.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186af84d22b883f287e9f11d946b592f83ca6bc2
|
4
|
+
data.tar.gz: ccc22259ee9fed122c00bba36075258409bb7a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9d19e3661d8d1eb375ecf74697ac8f680a2ef99f63b1f872c2b73e2eaacd9d05392bf526ef6246060b89b6d6415be0df33d1a8dd4cc080001f7969456e6f0e
|
7
|
+
data.tar.gz: e7d56c1e9246dd7d8a6406ba3c86fd94c56e64e5eaac5573ac0078638f60da784ca67c3a2ffbb1f5ae24de1c2718a6c49cbfa3879f6a0e236cd38b4cb1b50a11
|
data/README.md
CHANGED
@@ -60,6 +60,30 @@ $ bitcoin2graphdb start -c <configuration file path>
|
|
60
60
|
$ bitcoin2graphdb stop
|
61
61
|
```
|
62
62
|
|
63
|
+
## Extensions
|
64
|
+
|
65
|
+
Bitcoin2Graphdb currently supports following extensions.
|
66
|
+
|
67
|
+
|Extension Key Name|Description|
|
68
|
+
|:-----------|:------------|
|
69
|
+
|open_assets| Add Open Assets Protocol support. If this extension is enabled, the asset quantity and Graphdb::Model::AssetId association will be added to the Graphdb::Model::TxOut.|
|
70
|
+
* Open Assets Protocol
|
71
|
+
|
72
|
+
To enable extension, add an extension key name to enable the Configuration file like following.
|
73
|
+
|
74
|
+
```yaml
|
75
|
+
bitcoin2graphdb:
|
76
|
+
...
|
77
|
+
extensions:
|
78
|
+
- 'open_assets'
|
79
|
+
```
|
80
|
+
|
81
|
+
# Testing
|
82
|
+
|
83
|
+
When you run rspec, you need to run neo4j test server(http://localhost:7475) in advance.
|
84
|
+
Others are the same as normal rspec.
|
85
|
+
|
86
|
+
|
63
87
|
## Contributing
|
64
88
|
|
65
89
|
Bug reports and pull requests are welcome on GitHub at https://github.com/haw-itn/bitcoin2graphdb.
|
data/Rakefile
CHANGED
@@ -2,7 +2,17 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
load 'neo4j/tasks/neo4j_server.rake'
|
4
4
|
load 'neo4j/tasks/migration.rake'
|
5
|
+
require 'base'
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
7
8
|
|
8
9
|
task :default => :spec
|
10
|
+
|
11
|
+
namespace :b2g do
|
12
|
+
desc 'Import specified block to neo4j database.'
|
13
|
+
task :import_block, [:block_height,:config_path] do |task, args|
|
14
|
+
config = YAML.load(File.read(args.config_path)).deep_symbolize_keys
|
15
|
+
puts "import #{args.block_height} block."
|
16
|
+
Bitcoin2Graphdb::Migration.new(config[:bitcoin2graphdb]).run_with_height(args.block_height.to_i)
|
17
|
+
end
|
18
|
+
end
|
data/bitcoin2graphdb.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "openassets-ruby", "~> 0.3.
|
22
|
+
spec.add_runtime_dependency "openassets-ruby", "~> 0.3.8"
|
23
23
|
spec.add_runtime_dependency "daemon-spawn"
|
24
24
|
spec.add_runtime_dependency 'neo4j', '~> 5.0.0'
|
25
25
|
spec.add_runtime_dependency "activesupport", "~> 4.0.2"
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'base'
|
1
2
|
module Bitcoin2Graphdb
|
2
3
|
class Migration
|
3
4
|
|
4
5
|
def initialize(config)
|
6
|
+
Graphdb.configure do |c|
|
7
|
+
c.neo4j_server = config[:neo4j][:server]
|
8
|
+
c.extensions = config[:extensions] unless config[:extensions].nil?
|
9
|
+
end
|
5
10
|
Bitcoin2Graphdb::Bitcoin.provider = Bitcoin2Graphdb::Bitcoin::BlockchainProvider.new(config[:bitcoin])
|
6
|
-
Neo4j::Session.open(:server_db, config[:neo4j][:
|
11
|
+
Neo4j::Session.open(:server_db, config[:neo4j][:server], {basic_auth: config[:neo4j][:basic_auth]})
|
7
12
|
end
|
8
13
|
|
9
14
|
def run
|
@@ -14,15 +19,18 @@ module Bitcoin2Graphdb
|
|
14
19
|
|
15
20
|
def run_with_height(block_height)
|
16
21
|
puts "start migration for block height = #{block_height}. #{Time.now}"
|
17
|
-
|
18
|
-
|
22
|
+
Neo4j::Transaction.run do |tx|
|
23
|
+
begin
|
19
24
|
Graphdb::Model::Block.create_from_block_height(block_height)
|
20
25
|
@block_height = block_height
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
rescue OpenAssets::Provider::ApiError => e
|
27
|
+
if e.message == '{"code"=>-8, "message"=>"Block height out of range"}'
|
28
|
+
puts "Block height out of range. sleep 10 min."
|
29
|
+
sleep 600
|
30
|
+
else
|
31
|
+
tx.failure
|
32
|
+
raise e
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
28
36
|
puts "end migration for block height #{block_height}. #{Time.now}"
|
data/lib/graphdb.rb
CHANGED
@@ -4,19 +4,19 @@ module Graphdb
|
|
4
4
|
autoload :Base, 'graphdb/model/extensions/base'
|
5
5
|
autoload :OpenAssets, 'graphdb/model/extensions/open_assets'
|
6
6
|
|
7
|
-
EXTENSIONS = {open_assets: 'graphdb/model/extensions/open_assets'}
|
8
|
-
|
9
7
|
attr_accessor :extensions
|
10
8
|
|
11
9
|
def load_extensions
|
12
10
|
extensions.each do |e|
|
13
|
-
|
14
|
-
load_module::EXTENSIONS_TARGETS.each do |target|
|
15
|
-
target.origin_class.include target
|
16
|
-
end
|
11
|
+
require "graphdb/model/extensions/#{e}"
|
17
12
|
end
|
18
13
|
end
|
19
14
|
|
15
|
+
def unload_extensions
|
16
|
+
Graphdb::Model.send(:remove_const, :Transaction)
|
17
|
+
load 'graphdb/model/transaction.rb'
|
18
|
+
end
|
19
|
+
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module Graphdb
|
2
2
|
module Model
|
3
|
+
|
4
|
+
autoload :AssetId, 'graphdb/model/extensions/open_assets/asset_id'
|
5
|
+
|
3
6
|
module Extensions
|
4
7
|
module OpenAssets
|
5
|
-
autoload :
|
8
|
+
Graphdb::Model::Extensions::OpenAssets.autoload :TxOut, 'graphdb/model/extensions/open_assets/tx_out'
|
9
|
+
Graphdb::Model::Extensions::OpenAssets.autoload :Transaction, 'graphdb/model/extensions/open_assets/transaction'
|
6
10
|
|
7
|
-
|
11
|
+
Graphdb::Model::Transaction.prepend(Graphdb::Model::Extensions::OpenAssets::Transaction)
|
12
|
+
Graphdb::Model::TxOut.prepend(Graphdb::Model::Extensions::OpenAssets::TxOut)
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
|
4
|
+
class AssetId < ActiveNodeBase
|
5
|
+
property :asset_id, index: :exact, constraint: :unique
|
6
|
+
|
7
|
+
validates :asset_id, :presence => true
|
8
|
+
|
9
|
+
scope :with_asset_id, ->(asset_id){where(asset_id: asset_id)}
|
10
|
+
|
11
|
+
def self.find_or_create(asset_id)
|
12
|
+
a = with_asset_id(asset_id).first
|
13
|
+
unless a
|
14
|
+
a = new
|
15
|
+
a.asset_id = asset_id
|
16
|
+
a.save!
|
17
|
+
end
|
18
|
+
a
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
module Extensions
|
4
|
+
module OpenAssets
|
5
|
+
|
6
|
+
module Transaction
|
7
|
+
|
8
|
+
def self.prepended(base)
|
9
|
+
class << base
|
10
|
+
self.prepend(ClassMethods)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
def create_from_txid(txid)
|
17
|
+
tx = super(txid)
|
18
|
+
outputs = Bitcoin2Graphdb::Bitcoin.provider.oa_outputs(txid)
|
19
|
+
outputs.each{|o|tx.outputs[o['vout']].apply_oa_attributes(o)}
|
20
|
+
tx.save!
|
21
|
+
tx
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
module Extensions
|
4
|
+
module OpenAssets
|
5
|
+
module TxOut
|
6
|
+
|
7
|
+
def self.prepended(base)
|
8
|
+
class << base
|
9
|
+
self.prepend(ClassMethods)
|
10
|
+
|
11
|
+
end
|
12
|
+
base.class_eval do
|
13
|
+
property :asset_quantity, type: Integer
|
14
|
+
property :oa_output_type
|
15
|
+
has_one :out, :asset_id, type: :asset_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def apply_oa_attributes(oa_out)
|
24
|
+
self.asset_quantity = oa_out['asset_quantity']
|
25
|
+
self.oa_output_type = oa_out['output_type']
|
26
|
+
self.asset_id = AssetId.find_or_create(oa_out['asset_id']) unless oa_out['asset_id'].nil?
|
27
|
+
self.oa_output_type = 'uncolored' if self.asset_id.nil? && self.oa_output_type != 'marker'
|
28
|
+
save!
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/graphdb/model/tx_in.rb
CHANGED
@@ -10,7 +10,7 @@ module Graphdb
|
|
10
10
|
property :sequence
|
11
11
|
|
12
12
|
has_one :out, :transaction, type: :transaction, model_class: Transaction
|
13
|
-
has_one :in, :out_point, origin: :out_point, model_class: TxOut
|
13
|
+
has_one :in, :out_point, origin: :out_point, model_class: Graphdb::Model::TxOut
|
14
14
|
|
15
15
|
validates :sequence, :presence => true
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitcoin2graphdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openassets-ruby
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.8
|
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.3.
|
26
|
+
version: 0.3.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: daemon-spawn
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,9 +157,10 @@ files:
|
|
157
157
|
- lib/graphdb/model/address.rb
|
158
158
|
- lib/graphdb/model/block.rb
|
159
159
|
- lib/graphdb/model/extensions.rb
|
160
|
-
- lib/graphdb/model/extensions/base.rb
|
161
160
|
- lib/graphdb/model/extensions/open_assets.rb
|
162
|
-
- lib/graphdb/model/extensions/open_assets/
|
161
|
+
- lib/graphdb/model/extensions/open_assets/asset_id.rb
|
162
|
+
- lib/graphdb/model/extensions/open_assets/transaction.rb
|
163
|
+
- lib/graphdb/model/extensions/open_assets/tx_out.rb
|
163
164
|
- lib/graphdb/model/transaction.rb
|
164
165
|
- lib/graphdb/model/tx_in.rb
|
165
166
|
- lib/graphdb/model/tx_out.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Graphdb
|
2
|
-
module Model
|
3
|
-
module Extensions
|
4
|
-
module OpenAssets
|
5
|
-
|
6
|
-
module OaTransaction
|
7
|
-
|
8
|
-
extend Graphdb::Model::Extensions::Base
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
base.class_eval do
|
12
|
-
# asset output type (:issuance, :transfer, :uncolored)
|
13
|
-
property :output_type
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
set_origin Graphdb::Model::Transaction
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|