bitcoin2graphdb 0.1.5 → 0.1.6

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: e7248f3cef0dff2462fb9a7126612d8045941733
4
- data.tar.gz: c572be8943e1a8cc3b894cb49d1687a14c246aaa
3
+ metadata.gz: 3abd39596fb30ef8f52ff0387fbcc0adcd18efc1
4
+ data.tar.gz: 73c24c9bf6fbfd0821fa1916709cafba35487118
5
5
  SHA512:
6
- metadata.gz: 6ced644afd085b7eedaaeada3c6043c8b880b6cf63de6a68187923d5d015de6a5aedb31b782af5bc6b9e70c722651f0e62db494508719622fa87b3c3f08c668a
7
- data.tar.gz: a39f314a88a2c61ded9f8eed92d4ef4392df35341b8f418af9ce6b308c852f98f129bde2c4092e8d33691b98769893b51834ccb95b19533c7b6259a27bedc1ea
6
+ metadata.gz: f5bb775614cc38d5984bd180bb752fc4de6f7eb3605bccff9d95674792e2b3d02999be1ff3a80357a00f2476ce05951e921e8ef5865b9a37db36b17cb91c761a
7
+ data.tar.gz: 771e9ee594c438532fd41ff59b3e43ad6534c8ec16316d96c919a1ae0a14e8ce749393bc96212edf4ef1715a4cffb76eb73743292b2a4f06626586df1fd481a1
data/Rakefile CHANGED
@@ -11,8 +11,40 @@ task :default => :spec
11
11
  namespace :b2g do
12
12
  desc 'Import specified block to neo4j database.'
13
13
  task :import_block, [:block_height,:config_path] do |task, args|
14
- config = YAML.load(File.read(args.config_path)).deep_symbolize_keys
15
14
  puts "import #{args.block_height} block."
16
- Bitcoin2Graphdb::Migration.new(config[:bitcoin2graphdb]).run_with_height(args.block_height.to_i)
15
+ Bitcoin2Graphdb::Migration.new(load_config(args.config_path)).run_with_height(args.block_height.to_i)
16
+ end
17
+
18
+ desc 'Remove specified block from neo4j database.'
19
+ task :remove_block, [:block_height,:config_path] do |task, args|
20
+ load_neo4j_session(args.config_path)
21
+ block = Graphdb::Model::Block.with_height(args.block_height.to_i).first
22
+ if block.nil?
23
+ puts "block height #{args.block_height} does not exist."
24
+ else
25
+ block.destroy
26
+ puts "block height #{args.block_height} is deleted."
27
+ end
28
+ end
29
+
30
+ desc 'Remove specified transaction from neo4j database.'
31
+ task :remove_tx, [:txid,:config_path] do |task, args|
32
+ load_neo4j_session(args.config_path)
33
+ tx = Graphdb::Model::Transaction.with_txid(args.txid).first
34
+ if tx.nil?
35
+ puts "txid #{args.txid} does not exist."
36
+ else
37
+ tx.destroy
38
+ puts "tixd #{args.txid} is deleted."
39
+ end
40
+ end
41
+
42
+ def load_neo4j_session(config_path)
43
+ config = load_config(config_path)
44
+ Neo4j::Session.open(:server_db, config[:neo4j][:server], {basic_auth: config[:neo4j][:basic_auth]})
45
+ end
46
+
47
+ def load_config(config_path)
48
+ YAML.load(File.read(config_path)).deep_symbolize_keys[:bitcoin2graphdb]
17
49
  end
18
50
  end
@@ -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.9"
22
+ spec.add_runtime_dependency "openassets-ruby", ">= 0.4.1"
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"
@@ -19,7 +19,7 @@ module Bitcoin2Graphdb
19
19
 
20
20
  def run_with_height(block_height)
21
21
  puts "start migration for block height = #{block_height}. #{Time.now}"
22
- # Neo4j::Transaction.run do |tx|
22
+ Neo4j::Transaction.run do |tx|
23
23
  begin
24
24
  Graphdb::Model::Block.create_from_block_height(block_height)
25
25
  @block_height = block_height
@@ -28,18 +28,18 @@ module Bitcoin2Graphdb
28
28
  puts "Block height out of range. sleep 10 min."
29
29
  sleep 600
30
30
  else
31
- # tx.failure
31
+ tx.failure
32
32
  raise e
33
33
  end
34
34
  end
35
- # end
35
+ end
36
36
  puts "end migration for block height #{block_height}. #{Time.now}"
37
37
  end
38
38
 
39
39
  private
40
40
  def current_block_height
41
41
  return @block_height if @block_height
42
- block = Graphdb::Model::Block.latest
42
+ block = Graphdb::Model::Block.latest.first
43
43
  @block_height = block.nil? ? -1 : block.height
44
44
  end
45
45
 
@@ -1,3 +1,3 @@
1
1
  module Bitcoin2Graphdb
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -3,12 +3,14 @@ module Graphdb
3
3
  class Address < ActiveNodeBase
4
4
  property :address, index: :exact, constraint: :unique
5
5
 
6
+ has_many :in, :outputs, origin: :addresses, model_class: TxOut
7
+
6
8
  validates :address, presence: true
7
9
 
8
- scope :with_address, -> (address){where(address: address).first}
10
+ scope :with_address, -> (address){where(address: address)}
9
11
 
10
12
  def self.find_or_create(address)
11
- a = with_address(address)
13
+ a = with_address(address).first
12
14
  unless a
13
15
  a = new
14
16
  a.address = address
@@ -18,7 +18,7 @@ module Graphdb
18
18
  property :created_at
19
19
  property :updated_at
20
20
 
21
- has_many :in, :transactions, origin: :block, model_class: Transaction
21
+ has_many :in, :transactions, origin: :block, model_class: Transaction, dependent: :destroy
22
22
  has_one :out, :previous_block, type: :previous_block, model_class: Block
23
23
 
24
24
  validates :block_hash, :presence => true
@@ -31,8 +31,9 @@ module Graphdb
31
31
 
32
32
  after_create :chain_previous_block
33
33
 
34
- scope :latest, -> {order(height: 'DESC').first}
34
+ scope :latest, -> {order(height: 'DESC')}
35
35
  scope :with_block_hash, -> (block_hash){where(block_hash: block_hash)}
36
+ scope :with_height, -> (height){where(height: height)}
36
37
 
37
38
  def self.create_from_block_height(block_height)
38
39
  block = new
@@ -12,8 +12,8 @@ module Graphdb
12
12
  property :confirmations, type: Integer
13
13
 
14
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
15
+ has_many :in, :inputs, origin: :transaction, model_class: TxIn, dependent: :destroy
16
+ has_many :in, :outputs, origin: :transaction, model_class: TxOut, dependent: :destroy
17
17
 
18
18
  validates :hex, :presence => true
19
19
  validates :txid, :presence => true
@@ -23,6 +23,7 @@ module Graphdb
23
23
  scope :with_txid, ->(txid){where(txid: txid)}
24
24
 
25
25
  def self.create_from_txid(txid)
26
+ puts "create tx #{txid}"
26
27
  tx = new
27
28
  hash = load_tx(txid)
28
29
  tx.hex = hash['hex']
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-06 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.9
19
+ version: 0.4.1
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.9
26
+ version: 0.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: daemon-spawn
29
29
  requirement: !ruby/object:Gem::Requirement