zold 0.0.6 → 0.0.7
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/zold/commands/check.rb +6 -10
 - data/lib/zold/id.rb +6 -0
 - data/lib/zold/version.rb +1 -1
 - data/lib/zold/wallet.rb +17 -8
 - data/test/node/test_front.rb +1 -1
 - data/test/test_id.rb +4 -0
 - 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: 7a7e5d899910c588ba9fff4987a7341ecb245dad
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d1c940ba9d95d8d57e588fb1a6675f9117e86a4b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ca614449c84d77fe0b5bce135e33168955bf4f71ee62172a6d01e88cb72890ee04e0128ec86f8f98590d943c5eb325f0db1daa26f2d795002f04b31aae7e7600
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 12cbff8839076e9314eee7805f3c75d09f3f22ed64516a1ad964d2018ef637cc0ebd249495eca8b86c48530d031704d3d8f299c03b201e91496371e9c2e7ef7d
         
     | 
    
        data/lib/zold/commands/check.rb
    CHANGED
    
    | 
         @@ -36,23 +36,19 @@ module Zold 
     | 
|
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                def run
         
     | 
| 
       39 
     | 
    
         
            -
                  clean = true
         
     | 
| 
       40 
39 
     | 
    
         
             
                  @wallet.income do |t|
         
     | 
| 
       41 
40 
     | 
    
         
             
                    bnf = Pull.new(
         
     | 
| 
       42 
41 
     | 
    
         
             
                      wallet: @wallets.find(Id.new(t[:beneficiary])),
         
     | 
| 
       43 
42 
     | 
    
         
             
                      log: @log
         
     | 
| 
       44 
43 
     | 
    
         
             
                    ).run
         
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
       46 
     | 
    
         
            -
                    next if clean
         
     | 
| 
       47 
     | 
    
         
            -
                    @log.error("Txn ##{t[:id]} for #{t[:amount]} is absent at #{bnf.id}")
         
     | 
| 
       48 
     | 
    
         
            -
                    break
         
     | 
| 
      
 44 
     | 
    
         
            +
                    bnf.check(t[:id], t[:amount], @wallet.id)
         
     | 
| 
       49 
45 
     | 
    
         
             
                  end
         
     | 
| 
       50 
     | 
    
         
            -
                   
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                    @log.error("The #{@wallet} is compromised")
         
     | 
| 
      
 46 
     | 
    
         
            +
                  balance = @wallet.balance
         
     | 
| 
      
 47 
     | 
    
         
            +
                  if balance.negative? && !@wallet.root?
         
     | 
| 
      
 48 
     | 
    
         
            +
                    raise "Negative balance of #{@wallet} is not allowed: #{balance}"
         
     | 
| 
       54 
49 
     | 
    
         
             
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                  clean
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @log.info("The #{@wallet} is clean")
         
     | 
| 
      
 51 
     | 
    
         
            +
                  true
         
     | 
| 
       56 
52 
     | 
    
         
             
                end
         
     | 
| 
       57 
53 
     | 
    
         
             
              end
         
     | 
| 
       58 
54 
     | 
    
         
             
            end
         
     | 
    
        data/lib/zold/id.rb
    CHANGED
    
    
    
        data/lib/zold/version.rb
    CHANGED
    
    
    
        data/lib/zold/wallet.rb
    CHANGED
    
    | 
         @@ -72,8 +72,12 @@ module Zold 
     | 
|
| 
       72 
72 
     | 
    
         
             
                  ver
         
     | 
| 
       73 
73 
     | 
    
         
             
                end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
      
 75 
     | 
    
         
            +
                def root?
         
     | 
| 
      
 76 
     | 
    
         
            +
                  id == Id::ROOT
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       75 
79 
     | 
    
         
             
                def id
         
     | 
| 
       76 
     | 
    
         
            -
                  load.xpath('/wallet/id/text()').to_s
         
     | 
| 
      
 80 
     | 
    
         
            +
                  Id.new(load.xpath('/wallet/id/text()').to_s)
         
     | 
| 
       77 
81 
     | 
    
         
             
                end
         
     | 
| 
       78 
82 
     | 
    
         | 
| 
       79 
83 
     | 
    
         
             
                def balance
         
     | 
| 
         @@ -114,13 +118,18 @@ module Zold 
     | 
|
| 
       114 
118 
     | 
    
         
             
                def check(id, amount, beneficiary)
         
     | 
| 
       115 
119 
     | 
    
         
             
                  xml = load
         
     | 
| 
       116 
120 
     | 
    
         
             
                  txn = xml.xpath("/wallet/ledger/txn[@id='#{id}']")[0]
         
     | 
| 
       117 
     | 
    
         
            -
                  Amount.new( 
     | 
| 
       118 
     | 
    
         
            -
                    amount 
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 121 
     | 
    
         
            +
                  xamount = Amount.new(
         
     | 
| 
      
 122 
     | 
    
         
            +
                    coins: txn.xpath('amount/text()')[0].to_s.to_i
         
     | 
| 
      
 123 
     | 
    
         
            +
                  ).mul(-1)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  raise "#{xamount} != #{amount}" if xamount != amount
         
     | 
| 
      
 125 
     | 
    
         
            +
                  xbeneficiary = Id.new(txn.xpath('beneficiary/text()')[0].to_s)
         
     | 
| 
      
 126 
     | 
    
         
            +
                  raise "#{xbeneficiary} != #{beneficiary}" if xbeneficiary != beneficiary
         
     | 
| 
      
 127 
     | 
    
         
            +
                  data = "#{id} #{amount.to_i} #{beneficiary}"
         
     | 
| 
      
 128 
     | 
    
         
            +
                  valid = Key.new(text: xml.xpath('/wallet/pkey/text()')[0].to_s).verify(
         
     | 
| 
      
 129 
     | 
    
         
            +
                    txn.xpath('sign/text()')[0].to_s, data
         
     | 
| 
      
 130 
     | 
    
         
            +
                  )
         
     | 
| 
      
 131 
     | 
    
         
            +
                  raise "Signature is not confirming this data: '#{data}'" unless valid
         
     | 
| 
      
 132 
     | 
    
         
            +
                  true
         
     | 
| 
       124 
133 
     | 
    
         
             
                end
         
     | 
| 
       125 
134 
     | 
    
         | 
| 
       126 
135 
     | 
    
         
             
                def income
         
     | 
    
        data/test/node/test_front.rb
    CHANGED
    
    | 
         @@ -51,7 +51,7 @@ class FrontTest < Minitest::Test 
     | 
|
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
              def test_pushes_a_wallet
         
     | 
| 
       53 
53 
     | 
    
         
             
                Dir.mktmpdir 'test' do |dir|
         
     | 
| 
       54 
     | 
    
         
            -
                  id = Zold::Id 
     | 
| 
      
 54 
     | 
    
         
            +
                  id = Zold::Id::ROOT
         
     | 
| 
       55 
55 
     | 
    
         
             
                  file = File.join(dir, "#{id}.xml")
         
     | 
| 
       56 
56 
     | 
    
         
             
                  wallet = Zold::Wallet.new(file)
         
     | 
| 
       57 
57 
     | 
    
         
             
                  wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
         
     | 
    
        data/test/test_id.rb
    CHANGED