RecordsKeeperRubyLib 0.1.0 → 0.1.1

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.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/CODE_OF_CONDUCT.md +0 -8
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +4 -62
  6. data/LICENSE.txt +2 -2
  7. data/README.md +92 -1
  8. data/{RecordsKeeperRuby.gemspec → RecordsKeeperRubyLib.gemspec} +4 -5
  9. data/bin/console +1 -1
  10. data/config.yaml +8 -0
  11. data/docs/{addressdoc.rb → address_doc.rb} +105 -116
  12. data/docs/{assetsdoc.rb → asset_doc.rb} +54 -65
  13. data/docs/block_doc.rb +63 -0
  14. data/docs/blockchain_doc.rb +77 -0
  15. data/docs/{permissionsdoc.rb → permissions_doc.rb} +54 -65
  16. data/docs/{streamdoc.rb → stream_doc.rb} +79 -84
  17. data/docs/{transactiondoc.rb → transaction_doc.rb} +110 -121
  18. data/docs/{walletdoc.rb → wallet_doc.rb} +122 -133
  19. data/lib/RecordsKeeperRubyLib.rb +9 -0
  20. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/address.rb +198 -186
  21. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/assets.rb +99 -87
  22. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/block.rb +94 -89
  23. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/blockchain.rb +148 -135
  24. data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
  25. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/permissions.rb +77 -77
  26. data/lib/RecordsKeeperRubyLib/stream.rb +220 -0
  27. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/transaction.rb +213 -182
  28. data/lib/RecordsKeeperRubyLib/version.rb +3 -0
  29. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/wallet.rb +263 -252
  30. data/lib/config.yaml +8 -0
  31. metadata +27 -41
  32. data/docs/blockchaindoc.rb +0 -77
  33. data/docs/blockdoc.rb +0 -76
  34. data/lib/RecordsKeeperRuby.rb +0 -9
  35. data/lib/RecordsKeeperRuby/sample_config.yaml +0 -60
  36. data/lib/RecordsKeeperRuby/stream.rb +0 -169
  37. data/lib/RecordsKeeperRuby/version.rb +0 -3
  38. data/lib/sample_config.yaml +0 -60
  39. data/sample_config.yaml +0 -60
@@ -0,0 +1,9 @@
1
+ require "RecordsKeeperRubyLib/version"
2
+ require_relative ('RecordsKeeperRubyLib/address')
3
+ require_relative ('RecordsKeeperRubyLib/assets')
4
+ require_relative ('RecordsKeeperRubyLib/block')
5
+ require_relative ('RecordsKeeperRubyLib/blockchain')
6
+ require_relative ('RecordsKeeperRubyLib/permissions')
7
+ require_relative ('RecordsKeeperRubyLib/stream')
8
+ require_relative ('RecordsKeeperRubyLib/transaction')
9
+ require_relative ('RecordsKeeperRubyLib/wallet')
@@ -1,186 +1,198 @@
1
- # Library to work with RecordsKeeper address class.
2
- # You can generate new address, check all addresses, check address validity, check address permissions, check address balance
3
- # by using Address class. You just have to pass parameters to invoke the pre-defined functions.
4
-
5
- # import rubygems, httparty, json, binary_parser, objspace and yaml
6
- require 'rubygems'
7
- require 'httparty'
8
- require 'json'
9
- require 'binary_parser'
10
- require 'yaml'
11
-
12
- # Address class to access address related functions
13
- module RecordsKeeperRuby
14
- class Address
15
- # Import values from configuration file.
16
- cfg = YAML::load(File.open('config.yaml','r'))
17
- @network = cfg['testnet'] # 'network' variable to store the network that you want to access
18
- if @network==cfg['testnet']
19
- @url = cfg['testnet']['url']
20
- @user = cfg['testnet']['rkuser']
21
- @password = cfg['testnet']['passwd']
22
- @chain = cfg['testnet']['chain']
23
- else
24
- @url = cfg['mainnet']['url']
25
- @user = cfg['mainnet']['rkuser']
26
- @password = cfg['mainnet']['passwd']
27
- @chain = cfg['mainnet']['chain']
28
- end
29
-
30
- def self.variable
31
- net = @network
32
- return net
33
- end
34
-
35
-
36
- # Function to generate new address on the node's wallet
37
- def self.getAddress
38
-
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":"getnewaddress","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
44
- }
45
- response = HTTParty.get(@url, options)
46
- out = response.parsed_response
47
- address = out[0]['result']
48
- return address
49
- end
50
-
51
- # Function to generate a new multisignature address
52
- def self.getMultisigAddress nrequired, key #getMultisigAddress() function definition
53
-
54
- key_list = key.split(",")
55
- auth = {:username => @user, :password => @password}
56
- options = {
57
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
58
- :basic_auth => auth,
59
- :body => [ {"method":"createmultisig","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
60
- }
61
- response = HTTParty.get(@url, options)
62
- out = response.parsed_response
63
- address = out[0]['result']
64
- if address.nil?
65
- res = out[0]['error']['message']
66
- else
67
- res = out[0]['result']['address']
68
- end
69
- return res; #returns new multisig address
70
- end
71
-
72
- # Function to generate a new multisignature address on the node's wallet
73
- def self.getMultisigWalletAddress nrequired, key
74
- key_list = key.split(",")
75
- auth = {:username => @user, :password => @password}
76
- options = {
77
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
78
- :basic_auth => auth,
79
- :body => [ {"method":"addmultisigaddress","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
80
- }
81
- response = HTTParty.get(@url, options)
82
- out = response.parsed_response
83
- address = out[0]['result']
84
- if address.nil?
85
- res = out[0]['error']['message']
86
- else
87
- res = out[0]['result']
88
- end
89
- return res; # Returns new multisig address
90
- end
91
-
92
- # Function to list all addresses and no of addresses on the node's wallet
93
- def self.retrieveAddresses
94
- auth = {:username => @user, :password => @password}
95
- options = {
96
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
97
- :basic_auth => auth,
98
- :body => [ {"method":"getaddresses","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
99
- }
100
- response = HTTParty.get(@url, options)
101
- out = response.parsed_response
102
- address = out[0]['result']
103
- address_count = address.length
104
- address =[]
105
- for i in 0..address_count
106
- address.push(out[0]['result'][i])
107
- end
108
- return address, address_count; # Returns all addresses and address count
109
- end
110
-
111
- # Function to check if given address is valid or not
112
- def self.checkifValid address
113
- auth = {:username => @user, :password => @password}
114
- options = {
115
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
116
- :basic_auth => auth,
117
- :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
118
- }
119
- response = HTTParty.get(@url, options)
120
- out = response.parsed_response
121
- validity = out[0]['result']['isvalid']
122
- if validity
123
- addressCheck = "Address is valid" # Prints that address is valid
124
- else
125
- addressCheck= "Address is invalid" # Prints that address is invalid
126
- end
127
- return addressCheck; # Return the address check status
128
- end
129
-
130
- # Function to check if given address has mining permission or not
131
- def self.checkifMineAllowed address
132
- auth = {:username => @user, :password => @password}
133
- options = {
134
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
135
- :basic_auth => auth,
136
- :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
137
- }
138
- response = HTTParty.get(@url, options)
139
- out = response.parsed_response
140
- permission = out[0]['result']['ismine']
141
- if permission
142
- permissionCheck = "Address has mining permission" # Prints that address has mining permission
143
- else
144
- permissionCheck = "Address has not given mining permission" # Prints that address hasn't been given mining permission
145
- end
146
- return permissionCheck; # Returns the permission status
147
- end
148
-
149
- # Function to check node address balance on RecordsKeeper Blockchain
150
- def self.checkBalance address
151
- auth = {:username => @user, :password => @password}
152
- options = {
153
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
154
- :basic_auth => auth,
155
- :body => [ {"method":"getaddressbalances","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
156
- }
157
- response = HTTParty.get(@url, options)
158
- out = response.parsed_response
159
- balance = out[0]['result'][0]['qty']
160
- return balance; # Returns balance of a particular node address
161
- end
162
-
163
- # Function to import address on RecordsKeeper Blockchain
164
- def self.importAddress public_address
165
- auth = {:username => @user, :password => @password}
166
- options = {
167
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
168
- :basic_auth => auth,
169
- :body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
170
- }
171
- response = HTTParty.get(@url, options)
172
- out = response.parsed_response
173
- result = out[0]['result']
174
- error = out[0]['error']
175
- if result.nil? && error.nil?
176
- resp = "Address successfully imported" # Prints that address has been succesfully imported
177
- elsif result.nil? && error!= nil
178
- resp = out[0]['error']['message']
179
- else
180
- resp = 0
181
- end
182
- return resp;
183
- end
184
-
185
- end
186
- end
1
+ # Library to work with RecordsKeeper address class.
2
+ # You can generate new address, check all addresses, check address validity, check address permissions, check address balance
3
+ # by using Address class. You just have to pass parameters to invoke the pre-defined functions.
4
+
5
+ # import rubygems, httparty, json, binary_parser, objspace and yaml
6
+ require 'rubygems'
7
+ require 'httparty'
8
+ require 'json'
9
+ require 'binary_parser'
10
+ require 'yaml'
11
+
12
+ # Address class to access Address related functions
13
+ module RecordsKeeperRubyLib
14
+ class Address
15
+ if File.exist?('config.yaml')
16
+ # Import values from configuration file.
17
+ cfg = YAML::load(File.open('config.yaml','r'))
18
+
19
+ @url = cfg['url']
20
+ @user = cfg['rkuser']
21
+ @password = cfg['passwd']
22
+ @chain = cfg['chain']
23
+
24
+ else
25
+ #Import using ENV variables
26
+
27
+ @url = ENV['url']
28
+ @user = ENV['rkuser']
29
+ @password = ENV['passwd']
30
+ @chain = ENV['chain']
31
+ end
32
+
33
+
34
+ # Function to generate new address on the node's wallet
35
+ def self.getAddress
36
+
37
+ auth = {:username => @user, :password => @password}
38
+ options = {
39
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
40
+ :basic_auth => auth,
41
+ :body => [ {"method":"getnewaddress","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
42
+ }
43
+ response = HTTParty.get(@url, options)
44
+ out = response.parsed_response
45
+ address = out[0]['result']
46
+ return address
47
+ end
48
+
49
+ # Function to generate a new multisignature address
50
+ def self.getMultisigAddress nrequired, key #getMultisigAddress() function definition
51
+
52
+ key_list = key.split(",")
53
+ auth = {:username => @user, :password => @password}
54
+ options = {
55
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
56
+ :basic_auth => auth,
57
+ :body => [ {"method":"createmultisig","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
58
+ }
59
+ response = HTTParty.get(@url, options)
60
+ out = response.parsed_response
61
+ address = out[0]['result']
62
+ if address.nil?
63
+ res = out[0]['error']['message']
64
+ else
65
+ res = out[0]['result']['address']
66
+ end
67
+ return res; #returns new multisig address
68
+ end
69
+
70
+ # Function to generate a new multisignature address on the node's wallet
71
+ def self.getMultisigWalletAddress nrequired, key
72
+ key_list = key.split(",")
73
+ auth = {:username => @user, :password => @password}
74
+ options = {
75
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
76
+ :basic_auth => auth,
77
+ :body => [ {"method":"addmultisigaddress","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
78
+ }
79
+ response = HTTParty.get(@url, options)
80
+ out = response.parsed_response
81
+ address = out[0]['result']
82
+ if address.nil?
83
+ res = out[0]['error']['message']
84
+ else
85
+ res = out[0]['result']
86
+ end
87
+ return res; # Returns new multisig address
88
+ end
89
+
90
+ # Function to list all addresses and no of addresses on the node's wallet
91
+ def self.retrieveAddresses
92
+ auth = {:username => @user, :password => @password}
93
+ options = {
94
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
95
+ :basic_auth => auth,
96
+ :body => [ {"method":"getaddresses","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
97
+ }
98
+ response = HTTParty.get(@url, options)
99
+ out = response.parsed_response
100
+ address = out[0]['result']
101
+ address_count = address.length
102
+ address =[]
103
+ for i in 0..address_count
104
+ address.push(out[0]['result'][i])
105
+ end
106
+ retrieved = { :address => address,:address_count => address_count}
107
+ retrievedinfo = JSON.generate retrieved
108
+ return retrievedinfo
109
+ end
110
+
111
+ # Function to check if given address is valid or not
112
+ def self.checkifValid address
113
+ auth = {:username => @user, :password => @password}
114
+ options = {
115
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
116
+ :basic_auth => auth,
117
+ :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
118
+ }
119
+ response = HTTParty.get(@url, options)
120
+ out = response.parsed_response
121
+ validity = out[0]['result']['isvalid']
122
+ if validity
123
+ addressCheck = "Address is valid" # Prints that address is valid
124
+ else
125
+ addressCheck= "Address is invalid" # Prints that address is invalid
126
+ end
127
+ return addressCheck; # Return the address check status
128
+ end
129
+
130
+ # Function to check if given address has mining permission or not
131
+ def self.checkifMineAllowed address
132
+ auth = {:username => @user, :password => @password}
133
+ options = {
134
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
135
+ :basic_auth => auth,
136
+ :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
137
+ }
138
+ response = HTTParty.get(@url, options)
139
+ out = response.parsed_response
140
+
141
+ check = out[0]['result']['isvalid']
142
+
143
+ if check
144
+ permission = out[0]['result']['ismine']
145
+ if permission
146
+ permissionCheck = "Address has mining permission" # Prints that address has mining permission
147
+ else
148
+ permissionCheck = "Address has not given mining permission" # Prints that address hasn't been given mining permission
149
+ end
150
+ else
151
+ permissionCheck = "Invalid address";
152
+ end
153
+ return permissionCheck; # Returns the permission status
154
+ end
155
+
156
+ # Function to check node address balance on RecordsKeeper Blockchain
157
+ def self.checkBalance address
158
+ auth = {:username => @user, :password => @password}
159
+ options = {
160
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
161
+ :basic_auth => auth,
162
+ :body => [ {"method":"getaddressbalances","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
163
+ }
164
+ response = HTTParty.get(@url, options)
165
+ out = response.parsed_response
166
+ check = out[0]['result']
167
+ if check
168
+ balance = out[0]['result'][0]['qty']
169
+ else
170
+ balance = out[0]['error']['message']
171
+ end
172
+ return balance; # Returns balance of a particular node address
173
+ end
174
+
175
+ # Function to import address on RecordsKeeper Blockchain
176
+ def self.importAddress public_address
177
+ auth = {:username => @user, :password => @password}
178
+ options = {
179
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
180
+ :basic_auth => auth,
181
+ :body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
182
+ }
183
+ response = HTTParty.get(@url, options)
184
+ out = response.parsed_response
185
+ result = out[0]['result']
186
+ error = out[0]['error']
187
+ if result.nil? && error.nil?
188
+ resp = "Address successfully imported" # Prints that address has been succesfully imported
189
+ elsif result.nil? && error!= nil
190
+ resp = out[0]['error']['message']
191
+ else
192
+ resp = 0
193
+ end
194
+ return resp;
195
+ end
196
+
197
+ end
198
+ end
@@ -1,87 +1,99 @@
1
- # Library to work with assets.
2
-
3
- # You can issue assets or retrieve assets information by using asset 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 RecordsKeeperRuby
14
- class Assets
15
- # # Entry point for accessing Block class resources.
16
- # # Import values from config file.
17
- cfg = YAML::load(File.open('config.yaml','r'))
18
- @network = cfg['testnet'] # Network variable to store the networrk that you want to access
19
- if @network==cfg['testnet']
20
- @url = cfg['testnet']['url']
21
- @user = cfg['testnet']['rkuser']
22
- @password = cfg['testnet']['passwd']
23
- @chain = cfg['testnet']['chain']
24
- else
25
- @url = cfg['mainnet']['url']
26
- @user = cfg['mainnet']['rkuser']
27
- @password = cfg['mainnet']['passwd']
28
- @chain = cfg['mainnet']['chain']
29
- end
30
-
31
- def self.variable
32
- net = @network
33
- return net
34
- end
35
-
36
-
37
- # Function to create or issue an asset
38
- def self.createAsset address, asset_name, asset_qty
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":"issue","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
44
- }
45
- response = HTTParty.get(@url, options)
46
- out = response.parsed_response
47
- txid = out[0]['result']
48
- return txid; # Variable to store issue transaction id
49
- end
50
-
51
- # Function to retrieve assets information
52
- def self.retrieveAssets
53
- asset_name = []
54
- issue_id = []
55
- issue_qty = []
56
- auth = {:username => @user, :password => @password}
57
- options = {
58
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
59
- :basic_auth => auth,
60
- :body => [ {"method":"listassets","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
61
- }
62
- response = HTTParty.get(@url, options)
63
- out = response.parsed_response
64
- asset_count = out[0]['result'].length # Returns assets count
65
- for i in 0...asset_count
66
- asset_name.push(out[0]['result'][i]['name']) # Returns asset name
67
- issue_id.push(out[0]['result'][i]['issuetxid']) # Returns issue id
68
- issue_qty.push(out[0]['result'][i]['issueraw']) # Returns issue quantity
69
- end
70
- return asset_name, issue_id, issue_qty, asset_count;
71
- end
72
-
73
- # Function to send quantity of assets to an address
74
- def self.sendasset address, asset_name, asset_qty
75
- auth = {:username => @user, :password => @password}
76
- options = {
77
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
78
- :basic_auth => auth,
79
- :body => [ {"method":"sendasset","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
80
- }
81
- response = HTTParty.get(@url, options)
82
- out = response.parsed_response
83
- txid = out[0]['result']
84
- return txid; # Variable to store send asset transaction id
85
- end
86
- end
87
- end
1
+ # Library to work with assets.
2
+
3
+ # You can issue assets, send assets or retrieve assets information by using asset 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
+ class Assets
15
+ # # Entry point for accessing Asset class functions
16
+ if File.exist?('config.yaml')
17
+ # Import values from configuration file.
18
+ cfg = YAML::load(File.open('config.yaml','r'))
19
+
20
+ @url = cfg['url']
21
+ @user = cfg['rkuser']
22
+ @password = cfg['passwd']
23
+ @chain = cfg['chain']
24
+
25
+ else
26
+ #Import using ENV variables
27
+
28
+ @url = ENV['url']
29
+ @user = ENV['rkuser']
30
+ @password = ENV['passwd']
31
+ @chain = ENV['chain']
32
+ end
33
+
34
+
35
+ # Function to create or issue an asset
36
+ def self.createAsset address, asset_name, asset_qty
37
+
38
+ auth = {:username => @user, :password => @password}
39
+ options = {
40
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
41
+ :basic_auth => auth,
42
+ :body => [ {"method":"issue","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
43
+ }
44
+ response = HTTParty.get(@url, options)
45
+ out = response.parsed_response
46
+ check = out[0]['result']
47
+ if check == nil
48
+ txid = out[0]['error']['message']
49
+ else
50
+ txid = out[0]['result']
51
+ end
52
+ return txid; # Variable to store issue transaction id
53
+ end
54
+
55
+ # Function to retrieve assets information
56
+ def self.retrieveAssets
57
+ asset_name = []
58
+ issue_id = []
59
+ issue_qty = []
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":"listassets","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
65
+ }
66
+ response = HTTParty.get(@url, options)
67
+ out = response.parsed_response
68
+ asset_count = out[0]['result'].length # Returns assets count
69
+ for i in 0...asset_count
70
+ asset_name.push(out[0]['result'][i]['name']) # Returns asset name
71
+ issue_id.push(out[0]['result'][i]['issuetxid']) # Returns issue id
72
+ issue_qty.push(out[0]['result'][i]['issueraw']) # Returns issue quantity
73
+ end
74
+ retrieve = {:asset_name => asset_name,:issue_id => issue_id,:issue_qty => issue_qty,:asset_count => asset_count}
75
+ retrievedinfo = JSON.generate retrieve
76
+ return retrievedinfo
77
+ end
78
+
79
+ # Function to send assets to an address
80
+ def self.sendasset address, asset_name, asset_qty
81
+ auth = {:username => @user, :password => @password}
82
+ options = {
83
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
84
+ :basic_auth => auth,
85
+ :body => [ {"method":"sendasset","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
86
+ }
87
+ response = HTTParty.get(@url, options)
88
+ out = response.parsed_response
89
+ if out[0]['result'].nil?
90
+ txid = out[0]['error']['message']
91
+ else
92
+ txid = out[0]['result']
93
+ end
94
+ return txid; # Variable to store send asset transaction id
95
+ end
96
+
97
+ end
98
+
99
+ end