bigchaindb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/bigchaindb.rb +29 -10
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2618f49e57cb2ca1f60a063f1158f67aa8fdcb1a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7baed025c2623ac93d98ef0f69c0a1468fa1566d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2cee9717b4f5c95b51d94412e69f14625ff1b820a0dba70cb3e42d780dddfc16dc3173cc79cacbf9a6d623a62a262203e1ed137de36f3b744f3226aa8306d6b3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6fdd7c0f337fa04bb93ac3cace765729ac2617394c25763f79444fdb60cf519a8f6d93c68f4c782e3ac8d596a6166478f679c242c03971eaa0284f68e6a8e378
         
     | 
    
        data/lib/bigchaindb.rb
    CHANGED
    
    | 
         @@ -47,9 +47,9 @@ module Bdb 
     | 
|
| 
       47 
47 
     | 
    
         
             
              def self.spend(txn, output_ids = [])
         
     | 
| 
       48 
48 
     | 
    
         
             
                # Convert outputs in txn to signable/spendable inputs.
         
     | 
| 
       49 
49 
     | 
    
         
             
                if output_ids.any?
         
     | 
| 
       50 
     | 
    
         
            -
                  args = [txn.to_json]
         
     | 
| 
       51 
     | 
    
         
            -
                else
         
     | 
| 
       52 
50 
     | 
    
         
             
                  args = [txn.to_json, output_ids.to_json]
         
     | 
| 
      
 51 
     | 
    
         
            +
                else
         
     | 
| 
      
 52 
     | 
    
         
            +
                  args = [txn.to_json]
         
     | 
| 
       53 
53 
     | 
    
         
             
                end
         
     | 
| 
       54 
54 
     | 
    
         
             
                JSON.parse(`bdb spend #{args.shelljoin}`)
         
     | 
| 
       55 
55 
     | 
    
         
             
              end
         
     | 
| 
         @@ -61,9 +61,28 @@ module Bdb 
     | 
|
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
              def self.transfer_asset(ipdb, receiver_pubkey, sender_pubkey, sender_privkey, inputs, amount, asset_id, metadata = {"ts"=> Time.now.to_s})
         
     | 
| 
       63 
63 
     | 
    
         
             
                asset = { "id" => asset_id}
         
     | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
      
 64 
     | 
    
         
            +
                new_inputs = []
         
     | 
| 
      
 65 
     | 
    
         
            +
                input_amount = 0
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                if inputs.blank?
         
     | 
| 
      
 68 
     | 
    
         
            +
                  # ask IPDB for unspent outputs
         
     | 
| 
      
 69 
     | 
    
         
            +
                  unspent = Bdb.unspent_outputs(ipdb, sender_pubkey)
         
     | 
| 
      
 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
         
     | 
| 
      
 73 
     | 
    
         
            +
                    input_amount += txn["outputs"][u["output_index"]]["amount"].to_i
         
     | 
| 
      
 74 
     | 
    
         
            +
                    new_inputs.push(Bdb.spend(txn, u["output_index"]))
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
                else
         
     | 
| 
      
 77 
     | 
    
         
            +
                  # assume that every output for sender_pubkey in given inputs is unspent and can be used as input
         
     | 
| 
      
 78 
     | 
    
         
            +
                  inputs.each do |inp|
         
     | 
| 
      
 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)))
         
     | 
| 
      
 81 
     | 
    
         
            +
                  end
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
       65 
84 
     | 
    
         
             
                if amount > input_amount
         
     | 
| 
       66 
     | 
    
         
            -
                  puts "input_amount < amount"
         
     | 
| 
      
 85 
     | 
    
         
            +
                  puts "input_amount #{input_amount} < amount #{amount}"
         
     | 
| 
       67 
86 
     | 
    
         
             
                  return nil
         
     | 
| 
       68 
87 
     | 
    
         
             
                end
         
     | 
| 
       69 
88 
     | 
    
         
             
                outputs = [Bdb.generate_output(receiver_pubkey,amount)]
         
     | 
| 
         @@ -71,14 +90,14 @@ module Bdb 
     | 
|
| 
       71 
90 
     | 
    
         
             
                  # left-over amount should be transferred back to sender
         
     | 
| 
       72 
91 
     | 
    
         
             
                  outputs.push(Bdb.generate_output(sender_pubkey,input_amount - amount))
         
     | 
| 
       73 
92 
     | 
    
         
             
                end
         
     | 
| 
       74 
     | 
    
         
            -
                 
     | 
| 
       75 
     | 
    
         
            -
                transfer = Bdb.transfer_txn( 
     | 
| 
      
 93 
     | 
    
         
            +
                
         
     | 
| 
      
 94 
     | 
    
         
            +
                transfer = Bdb.transfer_txn(new_inputs, outputs, asset, metadata)
         
     | 
| 
       76 
95 
     | 
    
         
             
                signed_transfer = Bdb.sign(transfer, sender_privkey)
         
     | 
| 
       77 
96 
     | 
    
         
             
                resp = post_transaction(ipdb, signed_transfer)
         
     | 
| 
       78 
97 
     | 
    
         
             
                if resp.code == 202
         
     | 
| 
       79 
     | 
    
         
            -
                  puts "Transaction posted. Now checking status..."
         
     | 
| 
       80 
     | 
    
         
            -
                  sleep(5)
         
     | 
| 
       81 
98 
     | 
    
         
             
                  txn = JSON.parse(resp.body)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  puts "Transaction #{txn["id"]} posted. Now checking status..."
         
     | 
| 
      
 100 
     | 
    
         
            +
                  sleep(5)
         
     | 
| 
       82 
101 
     | 
    
         
             
                  status_resp = get_transaction_status(ipdb, txn["id"])
         
     | 
| 
       83 
102 
     | 
    
         
             
                  if (status_resp.code == 200) && JSON.parse(status_resp.body)["status"] == "valid"
         
     | 
| 
       84 
103 
     | 
    
         
             
                    return {"transfer" => transfer, "txn" => txn}
         
     | 
| 
         @@ -105,9 +124,9 @@ module Bdb 
     | 
|
| 
       105 
124 
     | 
    
         
             
                signed_create = Bdb.sign(create, private_key)
         
     | 
| 
       106 
125 
     | 
    
         
             
                resp = post_transaction(ipdb, signed_create)
         
     | 
| 
       107 
126 
     | 
    
         
             
                if resp.code == 202
         
     | 
| 
       108 
     | 
    
         
            -
                  puts "Transaction posted. Now checking status..."
         
     | 
| 
       109 
     | 
    
         
            -
                  sleep(5)
         
     | 
| 
       110 
127 
     | 
    
         
             
                  txn = JSON.parse(resp.body)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  puts "Transaction #{txn["id"]} posted. Now checking status..."
         
     | 
| 
      
 129 
     | 
    
         
            +
                  sleep(5)
         
     | 
| 
       111 
130 
     | 
    
         
             
                  status_resp = get_transaction_status(ipdb, txn["id"])
         
     | 
| 
       112 
131 
     | 
    
         
             
                  if (status_resp.code == 200) && JSON.parse(status_resp.body)["status"] == "valid"
         
     | 
| 
       113 
132 
     | 
    
         
             
                    return {"create" => create, "txn" => txn}
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bigchaindb
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Nilesh Trivedi
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-09-05 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: httparty
         
     |