RecordsKeeperRubyLib 0.3.0 → 0.4.0
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 +5 -5
 - data/.gitignore +1 -1
 - data/Gemfile.lock +3 -1
 - data/README.md +92 -1
 - data/config.yaml +8 -0
 - data/docs/address_doc.rb +105 -0
 - data/docs/asset_doc.rb +54 -0
 - data/docs/block_doc.rb +63 -0
 - data/docs/blockchain_doc.rb +77 -0
 - data/docs/permissions_doc.rb +54 -0
 - data/docs/stream_doc.rb +79 -0
 - data/docs/transaction_doc.rb +110 -0
 - data/docs/wallet_doc.rb +122 -0
 - data/lib/RecordsKeeperRubyLib/address.rb +198 -186
 - data/lib/RecordsKeeperRubyLib/assets.rb +99 -92
 - data/lib/RecordsKeeperRubyLib/block.rb +94 -88
 - data/lib/RecordsKeeperRubyLib/blockchain.rb +148 -138
 - data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
 - data/lib/RecordsKeeperRubyLib/permissions.rb +77 -71
 - data/lib/RecordsKeeperRubyLib/stream.rb +220 -164
 - data/lib/RecordsKeeperRubyLib/transaction.rb +213 -183
 - data/lib/RecordsKeeperRubyLib/version.rb +1 -1
 - data/lib/RecordsKeeperRubyLib/wallet.rb +263 -247
 - data/lib/config.yaml +8 -0
 - metadata +14 -6
 - data/lib/RecordsKeeperRubyLib/sample_config.yaml +0 -29
 - data/lib/sample_config.yaml +0 -29
 - data/sample_config.yaml +0 -29
 
| 
         @@ -1,71 +1,77 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #   Library to work with RecordsKeeper Blockchain permissions.
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            #   You can grant and revoke permissions to any node on Recordskeeper Blockchain by using permissions class.
         
     | 
| 
       4 
     | 
    
         
            -
            #   You just have to pass parameters to invoke the pre-defined functions.
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            require 'rubygems'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'httparty'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'json'
         
     | 
| 
       9 
     | 
    
         
            -
            require 'binary_parser'
         
     | 
| 
       10 
     | 
    
         
            -
            require 'yaml'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'hex_string'
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            module RecordsKeeperRubyLib
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            	class Permissions
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            		# Entry point for accessing  
     | 
| 
       18 
     | 
    
         
            -
            		 
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            		 
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            			 
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
            	     
     | 
| 
       40 
     | 
    
         
            -
            	     
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
            	       
     | 
| 
       44 
     | 
    
         
            -
            	     
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            	     
     | 
| 
       47 
     | 
    
         
            -
            	     
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
            	     
     | 
| 
       53 
     | 
    
         
            -
            	     
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
            	     
     | 
| 
       59 
     | 
    
         
            -
            	     
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
            	       
     | 
| 
       63 
     | 
    
         
            -
            	     
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
            	     
     | 
| 
       66 
     | 
    
         
            -
            	     
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            #   Library to work with RecordsKeeper Blockchain permissions.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #   You can grant and revoke permissions to any node on Recordskeeper Blockchain by using permissions class.
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   You just have to pass parameters to invoke the pre-defined functions.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'binary_parser'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'hex_string'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            module RecordsKeeperRubyLib
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            	class Permissions
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            		# # Entry point for accessing Permissions class functions
         
     | 
| 
      
 18 
     | 
    
         
            +
            		if File.exist?('config.yaml')
         
     | 
| 
      
 19 
     | 
    
         
            +
            			# Import values from configuration file.
         
     | 
| 
      
 20 
     | 
    
         
            +
            			cfg = YAML::load(File.open('config.yaml','r'))
         
     | 
| 
      
 21 
     | 
    
         
            +
            			
         
     | 
| 
      
 22 
     | 
    
         
            +
            			@url = cfg['url']
         
     | 
| 
      
 23 
     | 
    
         
            +
            			@user = cfg['rkuser']
         
     | 
| 
      
 24 
     | 
    
         
            +
            			@password = cfg['passwd']
         
     | 
| 
      
 25 
     | 
    
         
            +
            			@chain = cfg['chain']
         
     | 
| 
      
 26 
     | 
    
         
            +
            		
         
     | 
| 
      
 27 
     | 
    
         
            +
            		else
         
     | 
| 
      
 28 
     | 
    
         
            +
            			#Import using ENV variables
         
     | 
| 
      
 29 
     | 
    
         
            +
            			
         
     | 
| 
      
 30 
     | 
    
         
            +
            			@url = ENV['url']
         
     | 
| 
      
 31 
     | 
    
         
            +
                		@user = ENV['rkuser']
         
     | 
| 
      
 32 
     | 
    
         
            +
                		@password = ENV['passwd']
         
     | 
| 
      
 33 
     | 
    
         
            +
                		@chain = ENV['chain']	
         
     | 
| 
      
 34 
     | 
    
         
            +
            		end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            	  # Function to grant permissions on RecordsKeeper Blockchain
         
     | 
| 
      
 38 
     | 
    
         
            +
            	  def self.grantPermission address, permissions
         
     | 
| 
      
 39 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 40 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 41 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 42 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 43 
     | 
    
         
            +
            	      :body => [ {"method":"grant","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 44 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 45 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 46 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 47 
     | 
    
         
            +
            	    result = out[0]['result']
         
     | 
| 
      
 48 
     | 
    
         
            +
            	    if result.nil?
         
     | 
| 
      
 49 
     | 
    
         
            +
            	      res = out[0]['error']['message']
         
     | 
| 
      
 50 
     | 
    
         
            +
            	    else
         
     | 
| 
      
 51 
     | 
    
         
            +
            	      res = out[0]['result']
         
     | 
| 
      
 52 
     | 
    
         
            +
            	    end
         
     | 
| 
      
 53 
     | 
    
         
            +
            	    return res;									#returns permissions tx id
         
     | 
| 
      
 54 
     | 
    
         
            +
            	  end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            	  # Function to revoke permissions on RecordsKeeper Blockchain
         
     | 
| 
      
 57 
     | 
    
         
            +
            	  def self.revokePermission address, permissions
         
     | 
| 
      
 58 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 59 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 60 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 61 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 62 
     | 
    
         
            +
            	      :body => [ {"method":"revoke","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 63 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 64 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 65 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 66 
     | 
    
         
            +
            	    result = out[0]['result']
         
     | 
| 
      
 67 
     | 
    
         
            +
            	    if result.nil?
         
     | 
| 
      
 68 
     | 
    
         
            +
            	      res = out[0]['error']['message']
         
     | 
| 
      
 69 
     | 
    
         
            +
            	    else
         
     | 
| 
      
 70 
     | 
    
         
            +
            	      res = out[0]['result']
         
     | 
| 
      
 71 
     | 
    
         
            +
            	    end
         
     | 
| 
      
 72 
     | 
    
         
            +
            	    return res;									#returns revoke permissions tx id
         
     | 
| 
      
 73 
     | 
    
         
            +
            	  end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            	end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,164 +1,220 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # 	Library to work with RecordsKeeper streams.
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            #   You can publish, retrieve and verify stream data by using stream class.
         
     | 
| 
       4 
     | 
    
         
            -
            # 	   You just have to pass parameters to invoke the pre-defined functions.
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            require 'rubygems'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'httparty'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'json'
         
     | 
| 
       9 
     | 
    
         
            -
            require 'binary_parser'
         
     | 
| 
       10 
     | 
    
         
            -
            require 'yaml'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'hex_string'
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            module RecordsKeeperRubyLib
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            	class Stream
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            		# Entry point for accessing  
     | 
| 
       18 
     | 
    
         
            -
            		 
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            		 
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            			 
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            			 
     | 
| 
       43 
     | 
    
         
            -
            			 
     | 
| 
       44 
     | 
    
         
            -
            			 
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
            	     
     | 
| 
       89 
     | 
    
         
            -
            	     
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
            	     
     | 
| 
       95 
     | 
    
         
            -
            	     
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
            	     
     | 
| 
       99 
     | 
    
         
            -
            			 
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
            			 
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
            		 
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
            	     
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
            	     
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # 	Library to work with RecordsKeeper streams.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #   You can publish, retrieve and verify stream data by using stream class.
         
     | 
| 
      
 4 
     | 
    
         
            +
            # 	   You just have to pass parameters to invoke the pre-defined functions.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'binary_parser'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'yaml'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'hex_string'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            module RecordsKeeperRubyLib
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            	class Stream
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            		# # Entry point for accessing Stream class functions
         
     | 
| 
      
 18 
     | 
    
         
            +
            		if File.exist?('config.yaml')
         
     | 
| 
      
 19 
     | 
    
         
            +
            			# Import values from configuration file.
         
     | 
| 
      
 20 
     | 
    
         
            +
            			cfg = YAML::load(File.open('config.yaml','r'))
         
     | 
| 
      
 21 
     | 
    
         
            +
            			
         
     | 
| 
      
 22 
     | 
    
         
            +
            			@url = cfg['url']
         
     | 
| 
      
 23 
     | 
    
         
            +
            			@user = cfg['rkuser']
         
     | 
| 
      
 24 
     | 
    
         
            +
            			@password = cfg['passwd']
         
     | 
| 
      
 25 
     | 
    
         
            +
            			@chain = cfg['chain']
         
     | 
| 
      
 26 
     | 
    
         
            +
            		
         
     | 
| 
      
 27 
     | 
    
         
            +
            		else
         
     | 
| 
      
 28 
     | 
    
         
            +
            			#Import using ENV variables
         
     | 
| 
      
 29 
     | 
    
         
            +
            			
         
     | 
| 
      
 30 
     | 
    
         
            +
            			@url = ENV['url']
         
     | 
| 
      
 31 
     | 
    
         
            +
                		@user = ENV['rkuser']
         
     | 
| 
      
 32 
     | 
    
         
            +
                		@password = ENV['passwd']
         
     | 
| 
      
 33 
     | 
    
         
            +
                		@chain = ENV['chain']	
         
     | 
| 
      
 34 
     | 
    
         
            +
            		end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            	  # Function to publish data into the stream
         
     | 
| 
      
 37 
     | 
    
         
            +
            	  def self.publish address, stream, key, data
         
     | 
| 
      
 38 
     | 
    
         
            +
            	    datahex1 = data.to_hex_string
         
     | 
| 
      
 39 
     | 
    
         
            +
            	    datahex = datahex1.delete(' ')
         
     | 
| 
      
 40 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 41 
     | 
    
         
            +
            		options = {
         
     | 
| 
      
 42 
     | 
    
         
            +
            			:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 43 
     | 
    
         
            +
            			:basic_auth => auth,
         
     | 
| 
      
 44 
     | 
    
         
            +
            			:body => [ {"method":"publishfrom","params":[address, stream, key, datahex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 45 
     | 
    
         
            +
            		}
         
     | 
| 
      
 46 
     | 
    
         
            +
            		response = HTTParty.get(@url, options)
         
     | 
| 
      
 47 
     | 
    
         
            +
            		out = response.parsed_response
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            		txid = out[0]['result']
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            		if txid.nil?
         
     | 
| 
      
 52 
     | 
    
         
            +
            			txid = out[0]['error']['message']
         
     | 
| 
      
 53 
     | 
    
         
            +
            		end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            		return txid;
         
     | 
| 
      
 56 
     | 
    
         
            +
            	   end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            	  # Function to retrieve data against transaction id from the stream
         
     | 
| 
      
 59 
     | 
    
         
            +
            	  def self.retrieve stream, txid
         
     | 
| 
      
 60 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 61 
     | 
    
         
            +
            		options = {
         
     | 
| 
      
 62 
     | 
    
         
            +
            			:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 63 
     | 
    
         
            +
            			:basic_auth => auth,
         
     | 
| 
      
 64 
     | 
    
         
            +
            			:body => [ {"method":"getstreamitem","params":[stream, txid],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 65 
     | 
    
         
            +
            		}
         
     | 
| 
      
 66 
     | 
    
         
            +
            		response = HTTParty.get(@url, options)
         
     | 
| 
      
 67 
     | 
    
         
            +
            		out = response.parsed_response
         
     | 
| 
      
 68 
     | 
    
         
            +
            		check = out[0]['result']
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            		if check.nil?
         
     | 
| 
      
 71 
     | 
    
         
            +
            			raw_data = out[0]['error']['message']
         
     | 
| 
      
 72 
     | 
    
         
            +
            		else 
         
     | 
| 
      
 73 
     | 
    
         
            +
            			data = out[0]['result']['data']
         
     | 
| 
      
 74 
     | 
    
         
            +
                    	raw_data = data.to_byte_string
         
     | 
| 
      
 75 
     | 
    
         
            +
                   	end
         
     | 
| 
      
 76 
     | 
    
         
            +
            		return raw_data;
         
     | 
| 
      
 77 
     | 
    
         
            +
            	  end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            	  # Function to retrieve data against a particular publisher address
         
     | 
| 
      
 80 
     | 
    
         
            +
            	  def self.retrieveWithAddress stream, address, count
         
     | 
| 
      
 81 
     | 
    
         
            +
            	    check = []
         
     | 
| 
      
 82 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 83 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 84 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 85 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 86 
     | 
    
         
            +
            	      :body => [ {"method":"liststreampublisheritems","params":[stream, address, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 87 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 88 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 89 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            	    check = out[0]['result']
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            	    
         
     | 
| 
      
 95 
     | 
    
         
            +
            	    if check.empty?
         
     | 
| 
      
 96 
     | 
    
         
            +
            	    	retrievedinfo = "No published data found for this address"
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            	    else
         
     | 
| 
      
 99 
     | 
    
         
            +
            			key = []
         
     | 
| 
      
 100 
     | 
    
         
            +
            		    raw_data = []
         
     | 
| 
      
 101 
     | 
    
         
            +
            		    txid = []
         
     | 
| 
      
 102 
     | 
    
         
            +
            			for i in 0...check.length
         
     | 
| 
      
 103 
     | 
    
         
            +
            				key.push(out[0]['result'][i]['key'])           	  #returns key value of the published data
         
     | 
| 
      
 104 
     | 
    
         
            +
            		        data = out[0]['result'][i]['data']                #returns hex data
         
     | 
| 
      
 105 
     | 
    
         
            +
            		        raw_data.push(data.to_byte_string)    						#returns raw data
         
     | 
| 
      
 106 
     | 
    
         
            +
            		        txid.push(out[0]['result'][i]['txid'])            #returns tx id
         
     | 
| 
      
 107 
     | 
    
         
            +
            			end
         
     | 
| 
      
 108 
     | 
    
         
            +
            			retrieve = {:key => key,:raw_data => raw_data,:txid => txid}
         
     | 
| 
      
 109 
     | 
    
         
            +
            			retrievedinfo = JSON.generate retrieve
         
     | 
| 
      
 110 
     | 
    
         
            +
            		end
         
     | 
| 
      
 111 
     | 
    
         
            +
            		return retrievedinfo
         
     | 
| 
      
 112 
     | 
    
         
            +
            	   end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
            	  # Function to retrieve data against a particular key value
         
     | 
| 
      
 115 
     | 
    
         
            +
            	  def self.retrieveWithKey stream, key, count
         
     | 
| 
      
 116 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 117 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 118 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 119 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 120 
     | 
    
         
            +
            	      :body => [ {"method":"liststreamkeyitems","params":[stream, key, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 121 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 122 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 123 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 124 
     | 
    
         
            +
            	    
         
     | 
| 
      
 125 
     | 
    
         
            +
            	    check = out[0]['result']
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
            	    if check.nil?
         
     | 
| 
      
 128 
     | 
    
         
            +
            			retrievedinfo = out[0]['error']['message']
         
     | 
| 
      
 129 
     | 
    
         
            +
            		
         
     | 
| 
      
 130 
     | 
    
         
            +
            		else
         
     | 
| 
      
 131 
     | 
    
         
            +
               
         
     | 
| 
      
 132 
     | 
    
         
            +
            			publisher = []
         
     | 
| 
      
 133 
     | 
    
         
            +
            		    raw_data = []
         
     | 
| 
      
 134 
     | 
    
         
            +
            		    txid = []
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
            			for i in 0...check.length
         
     | 
| 
      
 137 
     | 
    
         
            +
            			  publisher.push(out[0]['result'][i]['publishers'][0])    	#returns publisher's address of published data
         
     | 
| 
      
 138 
     | 
    
         
            +
            		      data = out[0]['result'][i]['data']                        #returns published hex data
         
     | 
| 
      
 139 
     | 
    
         
            +
            		      raw_data.push(data.to_byte_string)           				#returns data published
         
     | 
| 
      
 140 
     | 
    
         
            +
            		      txid.push(out[0]['result'][i]['txid'])                    #returns transaction id of published data
         
     | 
| 
      
 141 
     | 
    
         
            +
            			end
         
     | 
| 
      
 142 
     | 
    
         
            +
            			retrieve = {:publisher => publisher,:raw_data => raw_data,:txid => txid}
         
     | 
| 
      
 143 
     | 
    
         
            +
            			retrievedinfo = JSON.generate retrieve
         
     | 
| 
      
 144 
     | 
    
         
            +
            			return retrievedinfo
         
     | 
| 
      
 145 
     | 
    
         
            +
            		end
         
     | 
| 
      
 146 
     | 
    
         
            +
            	  end	
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            	  # Function to verify data on RecordsKeeper Blockchain
         
     | 
| 
      
 149 
     | 
    
         
            +
            	  def self.verifyData stream, data, count
         
     | 
| 
      
 150 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 151 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 152 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 153 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 154 
     | 
    
         
            +
            	      :body => [ {"method":"liststreamitems","params":[stream,false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 155 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 156 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 157 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            	    check = out[0]['result']
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
            	    if check.nil?
         
     | 
| 
      
 162 
     | 
    
         
            +
            			result = out[0]['error']['message']
         
     | 
| 
      
 163 
     | 
    
         
            +
            		else 
         
     | 
| 
      
 164 
     | 
    
         
            +
            			raw_data = []
         
     | 
| 
      
 165 
     | 
    
         
            +
            			for i in 0...check.length
         
     | 
| 
      
 166 
     | 
    
         
            +
            				result_data = out[0]['result'][i]['data']						       # returns hex data
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
            		    	if result_data.unicode_normalized?
         
     | 
| 
      
 169 
     | 
    
         
            +
            					raw_data.push(result_data.to_byte_string)	                 # returns raw data
         
     | 
| 
      
 170 
     | 
    
         
            +
            					
         
     | 
| 
      
 171 
     | 
    
         
            +
            				else
         
     | 
| 
      
 172 
     | 
    
         
            +
            		      		raw_data.push("No data found")
         
     | 
| 
      
 173 
     | 
    
         
            +
            		    	end
         
     | 
| 
      
 174 
     | 
    
         
            +
            		    end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
            		    if raw_data.include?data
         
     | 
| 
      
 177 
     | 
    
         
            +
            				result = "Data is successfully verified."
         
     | 
| 
      
 178 
     | 
    
         
            +
            			else
         
     | 
| 
      
 179 
     | 
    
         
            +
            				result = "Data not found."
         
     | 
| 
      
 180 
     | 
    
         
            +
            		    end
         
     | 
| 
      
 181 
     | 
    
         
            +
            		end
         
     | 
| 
      
 182 
     | 
    
         
            +
            		return result;
         
     | 
| 
      
 183 
     | 
    
         
            +
            	  end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
            	  # Function to list stream items on RecordsKeeper Blockchain
         
     | 
| 
      
 186 
     | 
    
         
            +
            	  def self.retrieveItems stream, count
         
     | 
| 
      
 187 
     | 
    
         
            +
            	    auth = {:username => @user, :password => @password}
         
     | 
| 
      
 188 
     | 
    
         
            +
            	    options = {
         
     | 
| 
      
 189 
     | 
    
         
            +
            	      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
         
     | 
| 
      
 190 
     | 
    
         
            +
            	      :basic_auth => auth,
         
     | 
| 
      
 191 
     | 
    
         
            +
            	      :body => [ {"method":"liststreamitems","params":[stream, false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         
     | 
| 
      
 192 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 193 
     | 
    
         
            +
            	    response = HTTParty.get(@url, options)
         
     | 
| 
      
 194 
     | 
    
         
            +
            	    out = response.parsed_response
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
            	    check = out[0]['result']
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
            		if check.nil?
         
     | 
| 
      
 199 
     | 
    
         
            +
            			retrieveditems = out[0]['error']['message']
         
     | 
| 
      
 200 
     | 
    
         
            +
            		else 
         
     | 
| 
      
 201 
     | 
    
         
            +
            			address =[]
         
     | 
| 
      
 202 
     | 
    
         
            +
            			key_value = []
         
     | 
| 
      
 203 
     | 
    
         
            +
            			raw_data = []
         
     | 
| 
      
 204 
     | 
    
         
            +
            			txid = []
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
            			for i in 0...check.length
         
     | 
| 
      
 207 
     | 
    
         
            +
            				address.push(out[0]['result'][i]['publishers'])		        # returns publisher address
         
     | 
| 
      
 208 
     | 
    
         
            +
            				key_value.push(out[0]['result'][i]['key'])			          # returns key value of data
         
     | 
| 
      
 209 
     | 
    
         
            +
            				data = out[0]['result'][i]['data']					              # returns hex data
         
     | 
| 
      
 210 
     | 
    
         
            +
            		        raw_data.push(data.to_byte_string)                     	  # returns raw data
         
     | 
| 
      
 211 
     | 
    
         
            +
            				txid.push(out[0]['result'][i]['txid'])				            # returns tx id
         
     | 
| 
      
 212 
     | 
    
         
            +
            			end
         
     | 
| 
      
 213 
     | 
    
         
            +
            			retrieve = {:address => address,:key_value => key_value,:raw_data => raw_data,:txid => txid}
         
     | 
| 
      
 214 
     | 
    
         
            +
            			retrieveditems = JSON.generate retrieve
         
     | 
| 
      
 215 
     | 
    
         
            +
            		end
         
     | 
| 
      
 216 
     | 
    
         
            +
            		return retrieveditems
         
     | 
| 
      
 217 
     | 
    
         
            +
            	   end
         
     | 
| 
      
 218 
     | 
    
         
            +
            	end
         
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
      
 220 
     | 
    
         
            +
            end
         
     |