bitcoin2graphdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bitcoin2graphdb.gemspec +31 -0
- data/exe/bitcoin2graphdb +38 -0
- data/lib/base.rb +3 -0
- data/lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb +40 -0
- data/lib/bitcoin2graphdb/bitcoin.rb +5 -0
- data/lib/bitcoin2graphdb/migration.rb +39 -0
- data/lib/bitcoin2graphdb/version.rb +3 -0
- data/lib/bitcoin2graphdb.rb +7 -0
- data/lib/graphdb/model/active_node_base.rb +12 -0
- data/lib/graphdb/model/address.rb +21 -0
- data/lib/graphdb/model/block.rb +77 -0
- data/lib/graphdb/model/transaction.rb +52 -0
- data/lib/graphdb/model/tx_in.rb +32 -0
- data/lib/graphdb/model/tx_out.rb +40 -0
- data/lib/graphdb/model.rb +11 -0
- data/lib/graphdb.rb +5 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd77abd096ae6fc686cefebbb651b8997a24711a
|
4
|
+
data.tar.gz: 1da5438a22399a6616e284083e0deaa7dbf93536
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 968447d0b2510df5328154917f1634c14125cb058ef9a5cdc42b84caead13ff7e82b2abe90ba6a4a9a2e595d20afe0bef665fe27f7d1be3ea77d3f0366c3e1b5
|
7
|
+
data.tar.gz: ddd20bea2f8050144a4a7a81be5eb455263d83db6eef088de0c1a0e7bf7706a1458da44defeadaf2ec7535a5ea3cf508f864de671bd81c3b416fce93d2d0b3ae
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bitcoin2graphdb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 azuchi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Bitcoin2Graphdb
|
2
|
+
|
3
|
+
A tool for import Bitcoin blockchain data into neo4j database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bitcoin2graphdb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bitcoin2graphdb
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
This tool requires the following software.
|
24
|
+
|
25
|
+
* Bitcoin Core
|
26
|
+
* Neo4j
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
This tool requires the following configuration file.
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
bitcoin2graphdb:
|
34
|
+
bitcoin:
|
35
|
+
network: 'mainnet or testnet'
|
36
|
+
rpc:
|
37
|
+
user: 'Bitcoin Core rpc user.'
|
38
|
+
password: 'Bitcoin Core rpc password.'
|
39
|
+
schema: 'Bitcoin Core server schema. ex, http'
|
40
|
+
port: 'Bitcoin Core server port. ex, 8332'
|
41
|
+
host: 'Bitcoin Core server host. ex, xxx.xxx.xxx.xxx'
|
42
|
+
neo4j:
|
43
|
+
server: 'neo4j server url. ex, http://localhost:7474'
|
44
|
+
```
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
* Start bitcoin2graphdb daemon
|
49
|
+
```
|
50
|
+
$ bitcoin2graphdb start -c <configuration file path>
|
51
|
+
```
|
52
|
+
|
53
|
+
* Stop bitcoin2graphdb daemon
|
54
|
+
```
|
55
|
+
$ bitcoin2graphdb stop
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/haw-itn/bitcoin2graphdb.
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The MIT License (MIT)
|
65
|
+
|
66
|
+
Copyright (c) 2016 HAW International Inc.
|
67
|
+
|
68
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
69
|
+
of this software and associated documentation files (the "Software"), to deal
|
70
|
+
in the Software without restriction, including without limitation the rights
|
71
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
72
|
+
copies of the Software, and to permit persons to whom the Software is
|
73
|
+
furnished to do so, subject to the following conditions:
|
74
|
+
|
75
|
+
The above copyright notice and this permission notice shall be included in all
|
76
|
+
copies or substantial portions of the Software.
|
77
|
+
|
78
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
79
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
80
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
81
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
82
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
83
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
84
|
+
SOFTWARE.
|
85
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bitcoin2graphdb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bitcoin2graphdb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bitcoin2graphdb"
|
8
|
+
spec.version = Bitcoin2Graphdb::VERSION
|
9
|
+
spec.authors = ["azuchi"]
|
10
|
+
spec.email = ["azuchi@haw.co.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{A tool for import Bitcoin blockchain data into neo4j database.}
|
13
|
+
spec.description = %q{A tool for import Bitcoin blockchain data into neo4j database.}
|
14
|
+
spec.homepage = "https://github.com/haw-itn/bitcoin2graphdb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "openassets-ruby", "~> 0.3.7"
|
23
|
+
spec.add_runtime_dependency "daemon-spawn"
|
24
|
+
spec.add_runtime_dependency 'neo4j', '~> 5.0.0'
|
25
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.2"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "database_cleaner"
|
31
|
+
end
|
data/exe/bitcoin2graphdb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require 'base'
|
5
|
+
require 'optparse'
|
6
|
+
require 'json'
|
7
|
+
require 'yaml'
|
8
|
+
require 'active_support/all'
|
9
|
+
require 'daemon_spawn'
|
10
|
+
|
11
|
+
class Bitcoin2GraphdbDaemon < DaemonSpawn::Base
|
12
|
+
def start(args)
|
13
|
+
puts "Bitcoin2GraphdbDaemon start : #{Time.now}"
|
14
|
+
migration = Bitcoin2Graphdb::Migration.new(config(args)[:bitcoin2graphdb])
|
15
|
+
migration.run
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop
|
19
|
+
puts "Bitcoin2GraphdbDaemon stop : #{Time.now}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def config(args)
|
24
|
+
config_index = args.index("-c")
|
25
|
+
if config_index && args.length > config_index + 1 && File.exists?(args[config_index + 1])
|
26
|
+
YAML.load(File.read(args[config_index + 1])).deep_symbolize_keys
|
27
|
+
else
|
28
|
+
raise ArgumentError.new 'configuration file not specified or does not exist.'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Bitcoin2GraphdbDaemon.spawn!({
|
34
|
+
working_dir: Dir.pwd,
|
35
|
+
log_file: File.expand_path(Dir.pwd + '/bitcoin2graphdb.log'),
|
36
|
+
pid_file: File.expand_path(Dir.pwd + '/bitcoin2graphdb.pid'),
|
37
|
+
sync_log: true,
|
38
|
+
singleton: true})
|
data/lib/base.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Bitcoin2Graphdb
|
2
|
+
module Bitcoin
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :provider
|
6
|
+
|
7
|
+
def open(config)
|
8
|
+
self.provider = BlockchainProvider.new(config)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class BlockchainProvider
|
13
|
+
|
14
|
+
attr_reader :api
|
15
|
+
|
16
|
+
def initialize(config)
|
17
|
+
@api = OpenAssets::Api.new(config)
|
18
|
+
if @api.is_testnet?
|
19
|
+
::Bitcoin.network = :testnet3
|
20
|
+
else
|
21
|
+
::Bitcoin.network = :bitcoin
|
22
|
+
end
|
23
|
+
@api
|
24
|
+
end
|
25
|
+
|
26
|
+
def block(block_hash)
|
27
|
+
api.provider.getblock(block_hash)
|
28
|
+
end
|
29
|
+
|
30
|
+
def block_hash(block_height)
|
31
|
+
api.provider.getblockhash(block_height)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tx(txid)
|
35
|
+
api.provider.getrawtransaction(txid, 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Bitcoin2Graphdb
|
2
|
+
class Migration
|
3
|
+
|
4
|
+
def initialize(config)
|
5
|
+
Bitcoin2Graphdb::Bitcoin.provider = Bitcoin2Graphdb::Bitcoin::BlockchainProvider.new(config[:bitcoin])
|
6
|
+
Neo4j::Session.open(:server_db, config[:neo4j][:server_url])
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
loop {
|
11
|
+
run_with_height(current_block_height + 1)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_with_height(block_height)
|
16
|
+
puts "start migration for block height = #{block_height}. #{Time.now}"
|
17
|
+
begin
|
18
|
+
Neo4j::Transaction.run do |tx|
|
19
|
+
Graphdb::Model::Block.create_from_block_height(block_height)
|
20
|
+
@block_height = block_height
|
21
|
+
end
|
22
|
+
rescue OpenAssets::Provider::ApiError => e
|
23
|
+
if e.message == '{"code"=>-8, "message"=>"Block height out of range"}'
|
24
|
+
puts "Block height out of range. sleep 10 min."
|
25
|
+
sleep 600
|
26
|
+
end
|
27
|
+
end
|
28
|
+
puts "end migration for block height #{block_height}. #{Time.now}"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def current_block_height
|
33
|
+
return @block_height if @block_height
|
34
|
+
block = Graphdb::Model::Block.latest
|
35
|
+
@block_height = block.nil? ? -1 : block.height
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
class Address < ActiveNodeBase
|
4
|
+
property :address, index: :exact, constraint: :unique
|
5
|
+
|
6
|
+
validates :address, presence: true
|
7
|
+
|
8
|
+
scope :with_address, -> (address){where(address: address).first}
|
9
|
+
|
10
|
+
def self.find_or_create(address)
|
11
|
+
a = with_address(address)
|
12
|
+
unless a
|
13
|
+
a = new
|
14
|
+
a.address = address
|
15
|
+
a.save!
|
16
|
+
end
|
17
|
+
a
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
class Block < ActiveNodeBase
|
4
|
+
|
5
|
+
property :block_hash, index: :exact, constraint: :unique
|
6
|
+
property :size, type: Integer
|
7
|
+
property :height, type: Integer
|
8
|
+
property :version
|
9
|
+
property :merkle_root
|
10
|
+
property :time, type: Time
|
11
|
+
property :nonce, type: Integer
|
12
|
+
property :bits
|
13
|
+
property :difficulty
|
14
|
+
property :chain_work
|
15
|
+
property :previous_block_hash
|
16
|
+
property :next_block_hash
|
17
|
+
property :confirmations, type: Integer
|
18
|
+
property :created_at
|
19
|
+
property :updated_at
|
20
|
+
|
21
|
+
has_many :in, :transactions, origin: :block, model_class: Transaction
|
22
|
+
has_one :out, :previous_block, type: :previous_block, model_class: Block
|
23
|
+
|
24
|
+
validates :block_hash, :presence => true
|
25
|
+
validates :height, :presence => true
|
26
|
+
validates :merkle_root, :presence => true
|
27
|
+
validates :version, :presence => true
|
28
|
+
validates :size, :presence => true
|
29
|
+
validates :time, :presence => true
|
30
|
+
validates :nonce, :presence => true
|
31
|
+
|
32
|
+
after_create :chain_previous_block
|
33
|
+
|
34
|
+
scope :latest, -> {order(height: 'DESC').first}
|
35
|
+
scope :with_block_hash, -> (block_hash){where(block_hash: block_hash)}
|
36
|
+
|
37
|
+
def self.create_from_block_height(block_height)
|
38
|
+
block = new
|
39
|
+
block.block_hash = Bitcoin2Graphdb::Bitcoin.provider.block_hash(block_height)
|
40
|
+
hash = Bitcoin2Graphdb::Bitcoin.provider.block(block.block_hash)
|
41
|
+
block.size = hash['size']
|
42
|
+
block.height = hash['height']
|
43
|
+
block.version = hash['version']
|
44
|
+
block.merkle_root = hash['merkleroot']
|
45
|
+
block.time = Time.at(hash['time'])
|
46
|
+
block.nonce = hash['nonce']
|
47
|
+
block.bits = hash['bits']
|
48
|
+
block.difficulty = hash['difficulty']
|
49
|
+
block.chain_work = hash['chainwork']
|
50
|
+
block.previous_block_hash = hash['previousblockhash']
|
51
|
+
block.next_block_hash = hash['nextblockhash']
|
52
|
+
block.confirmations = hash['confirmations']
|
53
|
+
block.save!
|
54
|
+
unless block.genesis_block?
|
55
|
+
hash['tx'].each do |txid|
|
56
|
+
block.transactions << Graphdb::Model::Transaction.create_from_txid(txid)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
block.save!
|
60
|
+
block
|
61
|
+
end
|
62
|
+
|
63
|
+
def genesis_block?
|
64
|
+
Bitcoin.network[:genesis_hash] == block_hash
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def chain_previous_block
|
69
|
+
unless self.previous_block_hash.nil?
|
70
|
+
self.previous_block = Block.with_block_hash(self.previous_block_hash).first
|
71
|
+
save!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
class Transaction < ActiveNodeBase
|
4
|
+
|
5
|
+
property :hex
|
6
|
+
property :txid, index: :exact, constraint: :unique
|
7
|
+
property :version, type: Integer
|
8
|
+
property :lock_time
|
9
|
+
property :block_hash
|
10
|
+
property :block_time, type: Time
|
11
|
+
property :time, type: Time
|
12
|
+
property :confirmations, type: Integer
|
13
|
+
|
14
|
+
has_one :out, :block, type: :block
|
15
|
+
has_many :in, :inputs, origin: :transaction, model_class: TxIn
|
16
|
+
has_many :in, :outputs, origin: :transaction, model_class: TxOut
|
17
|
+
|
18
|
+
validates :hex, :presence => true
|
19
|
+
validates :txid, :presence => true
|
20
|
+
validates :version, :presence => true
|
21
|
+
validates :block_hash, :presence => true
|
22
|
+
|
23
|
+
def self.create_from_txid(txid)
|
24
|
+
tx = new
|
25
|
+
hash = load_tx(txid)
|
26
|
+
tx.hex = hash['hex']
|
27
|
+
tx.txid = hash['txid']
|
28
|
+
tx.version = hash['version']
|
29
|
+
tx.block_time = hash['blocktime']
|
30
|
+
tx.lock_time = hash['locktime']
|
31
|
+
tx.block_hash = hash['blockhash']
|
32
|
+
tx.time = hash['time']
|
33
|
+
tx.confirmations = hash['confirmations']
|
34
|
+
tx.save!
|
35
|
+
hash['vin'].each do |i|
|
36
|
+
tx.inputs << Graphdb::Model::TxIn.create_from_hash(i)
|
37
|
+
end
|
38
|
+
hash['vout'].each do |o|
|
39
|
+
tx.outputs << Graphdb::Model::TxOut.create_from_hash(o)
|
40
|
+
end
|
41
|
+
tx.save!
|
42
|
+
tx
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def self.load_tx(txid)
|
47
|
+
Bitcoin2Graphdb::Bitcoin.provider.tx(txid)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
class TxIn < ActiveNodeBase
|
4
|
+
|
5
|
+
property :txid
|
6
|
+
property :vout, type: Integer
|
7
|
+
property :script_sig_asm
|
8
|
+
property :script_sig_hex
|
9
|
+
property :coinbase
|
10
|
+
property :sequence
|
11
|
+
|
12
|
+
has_one :out, :transaction, type: :transaction, model_class: Transaction
|
13
|
+
|
14
|
+
validates :sequence, :presence => true
|
15
|
+
|
16
|
+
def self.create_from_hash(hash)
|
17
|
+
tx_in = new
|
18
|
+
tx_in.txid = hash['txid']
|
19
|
+
tx_in.vout = hash['vout']
|
20
|
+
if hash['scriptSig']
|
21
|
+
tx_in.script_sig_asm = hash['scriptSig']['asm']
|
22
|
+
tx_in.script_sig_hex = hash['scriptSig']['hex']
|
23
|
+
end
|
24
|
+
tx_in.coinbase = hash['coinbase']
|
25
|
+
tx_in.sequence = hash['sequence']
|
26
|
+
tx_in.save!
|
27
|
+
tx_in
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
class TxOut < ActiveNodeBase
|
4
|
+
|
5
|
+
property :value
|
6
|
+
property :n, type: Integer
|
7
|
+
property :script_pubkey_asm
|
8
|
+
property :script_pubkey_hex
|
9
|
+
property :output_type
|
10
|
+
property :req_sigs, type: Integer
|
11
|
+
|
12
|
+
has_one :out, :transaction, type: :transaction, model_class: Transaction
|
13
|
+
has_many :out, :addresses, type: :address, model_class: Address
|
14
|
+
|
15
|
+
validates :value, :presence => true
|
16
|
+
validates :n, :presence => true
|
17
|
+
|
18
|
+
def self.create_from_hash(hash)
|
19
|
+
tx_out = new
|
20
|
+
tx_out.value = hash['value']
|
21
|
+
tx_out.n = hash['n']
|
22
|
+
tx_out.save!
|
23
|
+
if hash['scriptPubKey']
|
24
|
+
tx_out.script_pubkey_asm = hash['scriptPubKey']['asm']
|
25
|
+
tx_out.script_pubkey_hex = hash['scriptPubKey']['hex']
|
26
|
+
tx_out.output_type = hash['scriptPubKey']['type']
|
27
|
+
tx_out.req_sigs = hash['scriptPubKey']['reqSigs']
|
28
|
+
if hash['scriptPubKey']['addresses']
|
29
|
+
hash['scriptPubKey']['addresses'].each do |a|
|
30
|
+
tx_out.addresses << Address.find_or_create(a)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
tx_out.save!
|
35
|
+
tx_out
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Graphdb
|
2
|
+
module Model
|
3
|
+
autoload :Database, 'graphdb/model/database'
|
4
|
+
autoload :ActiveNodeBase, 'graphdb/model/active_node_base'
|
5
|
+
autoload :Block, 'graphdb/model/block'
|
6
|
+
autoload :Transaction, 'graphdb/model/transaction'
|
7
|
+
autoload :TxIn, 'graphdb/model/tx_in'
|
8
|
+
autoload :TxOut, 'graphdb/model/tx_out'
|
9
|
+
autoload :Address, 'graphdb/model/address'
|
10
|
+
end
|
11
|
+
end
|
data/lib/graphdb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitcoin2graphdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- azuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: openassets-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: daemon-spawn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: neo4j
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: database_cleaner
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A tool for import Bitcoin blockchain data into neo4j database.
|
126
|
+
email:
|
127
|
+
- azuchi@haw.co.jp
|
128
|
+
executables:
|
129
|
+
- bitcoin2graphdb
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".ruby-gemset"
|
136
|
+
- ".ruby-version"
|
137
|
+
- ".travis.yml"
|
138
|
+
- CODE_OF_CONDUCT.md
|
139
|
+
- Gemfile
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- bitcoin2graphdb.gemspec
|
146
|
+
- exe/bitcoin2graphdb
|
147
|
+
- lib/base.rb
|
148
|
+
- lib/bitcoin2graphdb.rb
|
149
|
+
- lib/bitcoin2graphdb/bitcoin.rb
|
150
|
+
- lib/bitcoin2graphdb/bitcoin/blockchain_provider.rb
|
151
|
+
- lib/bitcoin2graphdb/migration.rb
|
152
|
+
- lib/bitcoin2graphdb/version.rb
|
153
|
+
- lib/graphdb.rb
|
154
|
+
- lib/graphdb/model.rb
|
155
|
+
- lib/graphdb/model/active_node_base.rb
|
156
|
+
- lib/graphdb/model/address.rb
|
157
|
+
- lib/graphdb/model/block.rb
|
158
|
+
- lib/graphdb/model/transaction.rb
|
159
|
+
- lib/graphdb/model/tx_in.rb
|
160
|
+
- lib/graphdb/model/tx_out.rb
|
161
|
+
homepage: https://github.com/haw-itn/bitcoin2graphdb
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.4.6
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: A tool for import Bitcoin blockchain data into neo4j database.
|
185
|
+
test_files: []
|