bigchaindb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bigchaindb.rb +16 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2618f49e57cb2ca1f60a063f1158f67aa8fdcb1a
4
- data.tar.gz: 7baed025c2623ac93d98ef0f69c0a1468fa1566d
3
+ metadata.gz: 4d8abc42966871eb1e5cc52e7fa076f71f4db173
4
+ data.tar.gz: c22dcf61a6a391cad1ac6f9baa0dbd83462c1402
5
5
  SHA512:
6
- metadata.gz: 2cee9717b4f5c95b51d94412e69f14625ff1b820a0dba70cb3e42d780dddfc16dc3173cc79cacbf9a6d623a62a262203e1ed137de36f3b744f3226aa8306d6b3
7
- data.tar.gz: 6fdd7c0f337fa04bb93ac3cace765729ac2617394c25763f79444fdb60cf519a8f6d93c68f4c782e3ac8d596a6166478f679c242c03971eaa0284f68e6a8e378
6
+ metadata.gz: fc9ce5d7442eb4c78c0d198acacf5c38362a7bb721e0f47c7b0050d93a512242ca5a241c3275f8cd9185adba81146dab767e498eb244f1aaca1f44a49ddf3aea
7
+ data.tar.gz: 0fbf4e30a803c3de846100972117cd924fdd4008f24ee111e04bd95190175768aaee6d14ccaaf8c420b6d102c376f3c29fbf4d4b9d20789f5b4791bbf96f6272
@@ -55,7 +55,7 @@ module Bdb
55
55
  end
56
56
 
57
57
  def self.unspent_outputs(ipdb, pubkey)
58
- resp = self.get_outputs_by_pubkey(ipdb, pubkey, spent = :both)
58
+ resp = self.get_outputs_by_pubkey(ipdb, pubkey, spent = false)
59
59
  JSON.parse(resp.body)
60
60
  end
61
61
 
@@ -64,12 +64,12 @@ module Bdb
64
64
  new_inputs = []
65
65
  input_amount = 0
66
66
 
67
- if inputs.blank?
67
+ if inputs.nil? || inputs.none?
68
68
  # ask IPDB for unspent outputs
69
69
  unspent = Bdb.unspent_outputs(ipdb, sender_pubkey)
70
70
  unspent.each do |u|
71
- txn = JSON.parse(Bdb.get_transaction_by_id(ipdb, u["transaction_id"]))
72
- next unless t["asset"]["id"] == asset_id
71
+ txn = JSON.parse(Bdb.get_transaction_by_id(ipdb, u["transaction_id"]).body)
72
+ next unless txn["asset"]["id"] == asset_id
73
73
  input_amount += txn["outputs"][u["output_index"]]["amount"].to_i
74
74
  new_inputs.push(Bdb.spend(txn, u["output_index"]))
75
75
  end
@@ -77,7 +77,7 @@ module Bdb
77
77
  # assume that every output for sender_pubkey in given inputs is unspent and can be used as input
78
78
  inputs.each do |inp|
79
79
  input_amount += inp["outputs"].select { |o| o["condition"]["details"]["public_key"] == sender_pubkey }.inject(0) { |sum,out| sum + out["amount"].to_i }
80
- new_inputs.push(Bdb.spend(inp, inputs["outputs"].each_with_index.select { |o,i| o["condition"]["details"]["public_key"] == sender_pubkey }.map(&:last)))
80
+ new_inputs += Bdb.spend(inp, inp["outputs"].each_with_index.select { |o,i| o["condition"]["details"]["public_key"] == sender_pubkey }.map(&:last))
81
81
  end
82
82
  end
83
83
 
@@ -118,6 +118,17 @@ module Bdb
118
118
  end
119
119
  end
120
120
 
121
+ def self.balance_asset(ipdb, public_key, asset_id)
122
+ unspent = Bdb.unspent_outputs(ipdb, public_key)
123
+ balance = 0
124
+ unspent.each do |u|
125
+ txn = JSON.parse(Bdb.get_transaction_by_id(ipdb, u["transaction_id"]).body)
126
+ next unless ((txn["operation"] == "CREATE") && (txn["id"] == asset_id)) || (txn["asset"]["id"] == asset_id)
127
+ balance += txn["outputs"][u["output_index"]]["amount"].to_i
128
+ end
129
+ return balance
130
+ end
131
+
121
132
  def self.create_asset(ipdb, public_key, private_key, asset_data, amount = 1, metadata = {"x"=> "y"})
122
133
  output = Bdb.generate_output(public_key, amount)
123
134
  create = Bdb.create_txn(public_key, output, asset_data, metadata)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigchaindb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nilesh Trivedi