bigchaindb 0.0.5 → 0.0.6
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 +9 -10
- 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: 3e580cfe72ce29831bf5f59c7668acd7fcd43099
|
4
|
+
data.tar.gz: 4ab58de601a18bda19161e3ed6dc11da1c52b679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a2d52b6ed5929683f2588b8b1a92f5a5d7702e639dbe8962373e4893d38765a3aa9e226657b9dcbd0111808654391c261b9c00bb41d264428c2f25b7834b21
|
7
|
+
data.tar.gz: 6fa188ae7253540457c2e31713aab14b10f1c07252e464b85ffd7327bcceaace2ca2aa761e7aa6a7ec88a8aee1e75e2f378e64ae17693ad87c70671b3ef8fe36
|
data/lib/bigchaindb.rb
CHANGED
@@ -67,6 +67,9 @@ module Bdb
|
|
67
67
|
if inputs.nil? || inputs.none?
|
68
68
|
# ask IPDB for unspent outputs
|
69
69
|
unspent = Bdb.unspent_outputs(ipdb, sender_pubkey)
|
70
|
+
if unspent.none?
|
71
|
+
return nil, "#{sender_pubkey} does not have any unspent outputs for asset #{asset_id}"
|
72
|
+
end
|
70
73
|
unspent.each do |u|
|
71
74
|
txn = JSON.parse(Bdb.get_transaction_by_id(ipdb, u["transaction_id"]).body)
|
72
75
|
next unless txn["asset"]["id"] == asset_id
|
@@ -84,15 +87,13 @@ module Bdb
|
|
84
87
|
outgoing_amount = 0
|
85
88
|
receiver_pubkeys_amounts.each do |pa|
|
86
89
|
if pa[:amount] <= 0
|
87
|
-
|
88
|
-
return nil
|
90
|
+
return nil, "Invalid amount (<=0) found for #{pa[:pubkey]}"
|
89
91
|
end
|
90
92
|
outgoing_amount += pa[:amount]
|
91
93
|
end
|
92
94
|
|
93
95
|
if outgoing_amount > input_amount
|
94
|
-
|
95
|
-
return nil
|
96
|
+
return nil, "input_amount #{input_amount} < outgoing_amount #{outgoing_amount}"
|
96
97
|
end
|
97
98
|
outputs = receiver_pubkeys_amounts.collect { |pa| Bdb.generate_output(pa[:pubkey],pa[:amount]) }
|
98
99
|
if outgoing_amount < input_amount
|
@@ -109,21 +110,19 @@ module Bdb
|
|
109
110
|
sleep(5)
|
110
111
|
status_resp = get_transaction_status(ipdb, txn["id"])
|
111
112
|
if (status_resp.code == 200) && JSON.parse(status_resp.body)["status"] == "valid"
|
112
|
-
return
|
113
|
+
return txn, "success"
|
113
114
|
else
|
114
115
|
puts "Trying again: #{status_resp.code} #{status_resp.body}"
|
115
116
|
sleep(5)
|
116
117
|
status_resp = get_transaction_status(ipdb, txn["id"])
|
117
118
|
if (status_resp.code == 200) && JSON.parse(status_resp.body)["status"] == "valid"
|
118
|
-
return
|
119
|
+
return txn, "success"
|
119
120
|
else
|
120
|
-
|
121
|
-
return nil
|
121
|
+
return nil, "Tried twice but failed. #{status_resp.code} #{status_resp.body}"
|
122
122
|
end
|
123
123
|
end
|
124
124
|
else
|
125
|
-
|
126
|
-
return nil
|
125
|
+
return nil, "Error in transfer_asset: #{resp.code} #{resp.body}"
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|