bigchaindb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bigchaindb.rb +16 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d8abc42966871eb1e5cc52e7fa076f71f4db173
|
4
|
+
data.tar.gz: c22dcf61a6a391cad1ac6f9baa0dbd83462c1402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9ce5d7442eb4c78c0d198acacf5c38362a7bb721e0f47c7b0050d93a512242ca5a241c3275f8cd9185adba81146dab767e498eb244f1aaca1f44a49ddf3aea
|
7
|
+
data.tar.gz: 0fbf4e30a803c3de846100972117cd924fdd4008f24ee111e04bd95190175768aaee6d14ccaaf8c420b6d102c376f3c29fbf4d4b9d20789f5b4791bbf96f6272
|
data/lib/bigchaindb.rb
CHANGED
@@ -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 =
|
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.
|
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
|
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
|
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)
|