bitcoin2graphdb 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: bd77abd096ae6fc686cefebbb651b8997a24711a
4
- data.tar.gz: 1da5438a22399a6616e284083e0deaa7dbf93536
3
+ metadata.gz: 55b1eb9d3024b24308bb0c1ae4268eccc5a97591
4
+ data.tar.gz: d481780673fc69dba52669c77b323b96dc70064d
5
5
  SHA512:
6
- metadata.gz: 968447d0b2510df5328154917f1634c14125cb058ef9a5cdc42b84caead13ff7e82b2abe90ba6a4a9a2e595d20afe0bef665fe27f7d1be3ea77d3f0366c3e1b5
7
- data.tar.gz: ddd20bea2f8050144a4a7a81be5eb455263d83db6eef088de0c1a0e7bf7706a1458da44defeadaf2ec7535a5ea3cf508f864de671bd81c3b416fce93d2d0b3ae
6
+ metadata.gz: f6dbe2b91830b2dccbf0a294e549d5bfc940534eeed7f101c22ddd39b624bcf36979fc58b2eff0c68645831841c0bf872fddc7ee2ae5bcab5a0ebeacc90c5268
7
+ data.tar.gz: 47f705deaacb59bfa8ed9228024efa164a42bb49a1d4f089f00909362d694f07316b037457550d555a3bf018035609418e416578d5f78964cca8fd0b270b038d
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A tool for import Bitcoin blockchain data into neo4j database.
4
4
 
5
+ ![neo4jgraph](https://raw.githubusercontent.com/wiki/haw-itn/bitcoin2graphdb/images/graph.png)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -1,3 +1,3 @@
1
1
  module Bitcoin2Graphdb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/graphdb.rb CHANGED
@@ -2,4 +2,15 @@ require 'neo4j'
2
2
 
3
3
  module Graphdb
4
4
  autoload :Model, 'graphdb/model'
5
+ autoload :Configuration, 'graphdb/configuration'
6
+
7
+ def self.configuration
8
+ @configuration ||= Graphdb::Configuration.new
9
+ end
10
+
11
+ def self.configure
12
+ yield configuration if block_given?
13
+ configuration.load_extensions
14
+ end
15
+
5
16
  end
@@ -0,0 +1,14 @@
1
+ module Graphdb
2
+ class Configuration
3
+
4
+ include Graphdb::Model::Extensions
5
+
6
+ attr_accessor :neo4j_server
7
+
8
+ def initialize
9
+ @extensions = []
10
+ @neo4j_server = 'http://localhost:7474'
11
+ end
12
+
13
+ end
14
+ end
data/lib/graphdb/model.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Graphdb
2
2
  module Model
3
- autoload :Database, 'graphdb/model/database'
4
3
  autoload :ActiveNodeBase, 'graphdb/model/active_node_base'
5
4
  autoload :Block, 'graphdb/model/block'
6
5
  autoload :Transaction, 'graphdb/model/transaction'
7
6
  autoload :TxIn, 'graphdb/model/tx_in'
8
7
  autoload :TxOut, 'graphdb/model/tx_out'
9
8
  autoload :Address, 'graphdb/model/address'
9
+ autoload :Extensions, 'graphdb/model/extensions'
10
10
  end
11
11
  end
@@ -7,6 +7,9 @@ module Graphdb
7
7
  property :created_at
8
8
  property :updated_at
9
9
 
10
+ def self.remove_module(m)
11
+ m.instance_methods.each{|m| undef_method(m)}
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -0,0 +1,22 @@
1
+ module Graphdb
2
+ module Model
3
+ module Extensions
4
+ autoload :Base, 'graphdb/model/extensions/base'
5
+ autoload :OpenAssets, 'graphdb/model/extensions/open_assets'
6
+
7
+ EXTENSIONS = {open_assets: 'graphdb/model/extensions/open_assets'}
8
+
9
+ attr_accessor :extensions
10
+
11
+ def load_extensions
12
+ extensions.each do |e|
13
+ load_module = "Graphdb::Model::Extensions::#{e.camelize}".constantize
14
+ load_module::EXTENSIONS_TARGETS.each do |target|
15
+ target.origin_class.include target
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Graphdb
2
+ module Model
3
+ module Extensions
4
+ module Base
5
+
6
+ attr_accessor :origin_class
7
+
8
+ def set_origin(clazz)
9
+ @origin_class ||= clazz
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Graphdb
2
+ module Model
3
+ module Extensions
4
+ module OpenAssets
5
+ autoload :OaTransaction, 'graphdb/model/extensions/open_assets/oa_transaction'
6
+
7
+ EXTENSIONS_TARGETS = [OaTransaction]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
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
@@ -20,6 +20,8 @@ module Graphdb
20
20
  validates :version, :presence => true
21
21
  validates :block_hash, :presence => true
22
22
 
23
+ scope :with_txid, ->(txid){where(txid: txid)}
24
+
23
25
  def self.create_from_txid(txid)
24
26
  tx = new
25
27
  hash = load_tx(txid)
@@ -10,9 +10,12 @@ 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
14
 
14
15
  validates :sequence, :presence => true
15
16
 
17
+ after_create :add_out_point_rel
18
+
16
19
  def self.create_from_hash(hash)
17
20
  tx_in = new
18
21
  tx_in.txid = hash['txid']
@@ -27,6 +30,15 @@ module Graphdb
27
30
  tx_in
28
31
  end
29
32
 
33
+ private
34
+ def add_out_point_rel
35
+ tx_out = Graphdb::Model::TxOut.find_by_outpoint(self.txid, self.vout)
36
+ if tx_out
37
+ self.out_point = tx_out
38
+ save!
39
+ end
40
+ end
41
+
30
42
  end
31
43
  end
32
44
  end
@@ -11,10 +11,13 @@ module Graphdb
11
11
 
12
12
  has_one :out, :transaction, type: :transaction, model_class: Transaction
13
13
  has_many :out, :addresses, type: :address, model_class: Address
14
+ has_one :out, :out_point, type: :spent_input, model_class: TxIn
14
15
 
15
16
  validates :value, :presence => true
16
17
  validates :n, :presence => true
17
18
 
19
+ scope :with_out_index, -> (n){where(n: n)}
20
+
18
21
  def self.create_from_hash(hash)
19
22
  tx_out = new
20
23
  tx_out.value = hash['value']
@@ -35,6 +38,15 @@ module Graphdb
35
38
  tx_out
36
39
  end
37
40
 
41
+ def self.find_by_outpoint(txid, n)
42
+ tx = Graphdb::Model::Transaction.with_txid(txid).first
43
+ if tx
44
+ tx.outputs.each{|o|
45
+ return o if o.n == n
46
+ }
47
+ end
48
+ end
49
+
38
50
  end
39
51
  end
40
52
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openassets-ruby
@@ -151,10 +151,15 @@ files:
151
151
  - lib/bitcoin2graphdb/migration.rb
152
152
  - lib/bitcoin2graphdb/version.rb
153
153
  - lib/graphdb.rb
154
+ - lib/graphdb/configuration.rb
154
155
  - lib/graphdb/model.rb
155
156
  - lib/graphdb/model/active_node_base.rb
156
157
  - lib/graphdb/model/address.rb
157
158
  - lib/graphdb/model/block.rb
159
+ - lib/graphdb/model/extensions.rb
160
+ - lib/graphdb/model/extensions/base.rb
161
+ - lib/graphdb/model/extensions/open_assets.rb
162
+ - lib/graphdb/model/extensions/open_assets/oa_transaction.rb
158
163
  - lib/graphdb/model/transaction.rb
159
164
  - lib/graphdb/model/tx_in.rb
160
165
  - lib/graphdb/model/tx_out.rb