RecordsKeeperRubyLib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # = Permissions Class Usage
2
+ # This is a library to work with RecordsKeeper permissions.
3
+ # You can grant and revoke permissions like connect, send, receive, create, issue, mine, activate, admin by using Assets class. You just have to pass parameters to invoke the pre-defined functions.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # -----------------
13
+ # == Create Connection
14
+ # Entry point for accessing Address class resources.
15
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
16
+ # * Chain-name: chain name
17
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
18
+ # * Set a *network* value to change the network-type
19
+ # network = cfg['testnet'] # Network variable to store the network that you want to access
20
+ # **NOTE:* Default network is *Test-net*, you can change it to mainnet or testnet
21
+ # Check the network type for url and chain name:
22
+ # if @network==cfg['testnet']
23
+ # @url = cfg['testnet']['url']
24
+ # @chain = cfg['testnet']['chain']
25
+ # else
26
+ # @url = cfg['mainnet']['url']
27
+ # @chain = cfg['mainnet']['chain']
28
+ # end
29
+ # -------------------
30
+ # == Node Authentication
31
+ # Import values from config file.
32
+ # * User name: The rpc user is used to call the APIs.
33
+ # * Password: The rpc password is used to authenticate the APIs.
34
+ # * Check the network type for username and password:
35
+ # if @network==cfg['testnet']
36
+ # @user = cfg['testnet']['rkuser']
37
+ # @password = cfg['testnet']['passwd']
38
+ # else
39
+ # @user = cfg['mainnet']['rkuser']
40
+ # @password = cfg['mainnet']['passwd']
41
+ # end
42
+ # Now we have node authentication credentials.
43
+ # ------------
44
+ # = class Permissions
45
+ # Permissions class is used to call permissions related functions like grant and revoke permissions for an address functions which are used on the RecordsKeeeper Blockchain.
46
+ # === 1. grantPermission address, permissions
47
+ # This function is used to grant permissions like connect, send, receive, create, issue, mine, activate, admin to an address on RecordsKeeper Blockchain.
48
+ #
49
+ # You have to pass these two arguments to the grantPermission function call:
50
+ # * Permissions: list of comma-seperated permissions passed as a string
51
+ # * Address: to which you have to grant permission
52
+ # result = grantPermission address, permissions
53
+ #
54
+ # puts txid # prints response of the grant permision transaction
55
+ # === 2. revokePermission address, permissions
56
+ # This function is used to revoke permissions like connect, send, receive, create, issue, mine, activate, admin to an address on RecordsKeeper Blockchain.
57
+ #
58
+ # You have to pass these two arguments to the grantPermission function call:
59
+ # * Permissions: list of comma-seperated permissions passed as a string
60
+ # * Address: to which you have to grant permission
61
+ # result = revokePermission address, permissions
62
+ #
63
+ # puts result # prints response of the revoke permision transaction
64
+ class Permissions
65
+ end
data/docs/streamdoc.rb ADDED
@@ -0,0 +1,84 @@
1
+ # = Stream Class Usage
2
+ # This is a library to work with streams in RecordsKeeper Blockchain.
3
+ # You can publish address, retrieve data, retrieve with address, retrieve with key, verify data and retrieve items.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # require 'hex_string'
13
+ # -----------------
14
+ # == Create Connection
15
+ # Entry point for accessing Blockchain class resources.
16
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
17
+ # * Chain-name: Name of the chain
18
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
19
+ # * Set a *network* value to change the network-type
20
+ # network = cfg['testnet'] # Network variable to store the network that you want to access
21
+ # **NOTE:* Default network is *Test-net* ( i.e., you can set it to either testnet or mainnet).
22
+ # Check the network type for url and chain name:
23
+ # if @network==cfg['testnet']
24
+ # @url = cfg['testnet']['url']
25
+ # @chain = cfg['testnet']['chain']
26
+ # else
27
+ # @url = cfg['mainnet']['url']
28
+ # @chain = cfg['mainnet']['chain']
29
+ # end
30
+ # -------------------
31
+ # == Node Authentication
32
+ # Import values from config file.
33
+ # * User name: The rpc user is used to call the APIs.
34
+ # * Password: The rpc password is used to authenticate the APIs.
35
+ # * Check the network type for username and password:
36
+ # if @network==cfg['testnet']
37
+ # @user = cfg['testnet']['rkuser']
38
+ # @password = cfg['testnet']['passwd']
39
+ # else
40
+ # @user = cfg['mainnet']['rkuser']
41
+ # @password = cfg['mainnet']['passwd']
42
+ # end
43
+ # Now we have node authentication credentials.
44
+ # ------------
45
+ # = class Stream
46
+ # Stream class is used to call stream related functions to publish address, retrieve data, retrieve with address, retrieve with key, verify data and retrieve items.
47
+ # === 1. publish address, stream, key, data
48
+ # This function retrieves information about the chain.
49
+ # publish address, stream, key, data
50
+ # transacid = publish address, stream, key, data # Function call
51
+ #
52
+ # puts transacid # Prints txid.
53
+ # === 2. retrieve stream, txid
54
+ # This function retrieves information related to your node.
55
+ # retrieve stream, txid
56
+ # data = retrieve stream, txid # Function call
57
+ #
58
+ # puts data # Prints raw_data.
59
+ # === 3. retrieveWithAddress stream, address
60
+ # This function lists all the permissions.
61
+ # retrieveWithAddress stream, address
62
+ # retadd = retrieveWithAddress stream, address # Function call
63
+ #
64
+ # puts retadd # Prints key, data and txid.
65
+ # === 4. retrieveWithKey stream, key
66
+ # This function retrieves information related to your node.
67
+ # retrieveWithKey stream, key
68
+ # retkey = retrieveWithKey stream, key # Function call
69
+ #
70
+ # puts retkey # Prints publisher, data and txid.
71
+ # === 5. verifyData stream, data, count
72
+ # This function retrieves information related to your node.
73
+ # verifyData stream, data, count
74
+ # verifystat = verifyData stream, data, count # Function call
75
+ #
76
+ # puts verifystat # Prints result.
77
+ # === 6. retrieveItems stream, count
78
+ # This function retrieves information related to your node.
79
+ # retrieveItems stream, count
80
+ # retitem = retrieveItems stream, count # Function call
81
+ #
82
+ # puts retitem # Prints address, key_value, raw_data and txid.
83
+ class Stream
84
+ end
@@ -0,0 +1,121 @@
1
+ # = Transaction Class Usage
2
+ # This is a library to work with RecordsKeeper transactions.
3
+ # You can send transaction, create raw transaction, sign raw transaction, send raw transaction, send signed transaction, retrieve transaction information and calculate transaction’s fees by using transaction class. You just have to pass parameters to invoke the pre-defined functions.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # require 'hex_string'
13
+ # -----------------
14
+ # == Create Connection
15
+ # Entry point for accessing Blockchain class resources.
16
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
17
+ # * Chain-name: Name of the chain
18
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
19
+ # * Set a *network* value to change the network-type
20
+ # network = cfg['testnet'] # Network variable to store the network that you want to access
21
+ # **NOTE:* Default network is *Test-net* ( i.e., you can set it to either testnet or mainnet).
22
+ # Check the network type for url and chain name:
23
+ # if @network==cfg['testnet']
24
+ # @url = cfg['testnet']['url']
25
+ # @chain = cfg['testnet']['chain']
26
+ # else
27
+ # @url = cfg['mainnet']['url']
28
+ # @chain = cfg['mainnet']['chain']
29
+ # end
30
+ # -------------------
31
+ # == Node Authentication
32
+ # Import values from config file.
33
+ # * User name: The rpc user is used to call the APIs.
34
+ # * Password: The rpc password is used to authenticate the APIs.
35
+ # * Check the network type for username and password:
36
+ # if @network==cfg['testnet']
37
+ # @user = cfg['testnet']['rkuser']
38
+ # @password = cfg['testnet']['passwd']
39
+ # else
40
+ # @user = cfg['mainnet']['rkuser']
41
+ # @password = cfg['mainnet']['passwd']
42
+ # end
43
+ # Now we have node authentication credentials.
44
+ # ------------
45
+ # = class Transaction
46
+ # Transaction class is used to call transaction related functions like create raw transaction, sign transaction, send transaction , retrieve transaction and verify transaction functions which are used to create raw transactions, send transactions, sign transactions, retrieve transactions and verify transactions on the RecordsKeeeper Blockchain.
47
+ # === 1. sendTransaction sender_address, reciever_address, amount
48
+ # This function is used to send transaction by passing reciever’s address, sender’s address and amount.
49
+ #
50
+ # You have to pass these three arguments to the sendTransaction function call:
51
+ # * Transaction’s sender address
52
+ # * Transaction’s reciever address
53
+ # * Amount to be sent in transaction
54
+ #
55
+ # txid = sendTransaction sender_address, reciever_address, amount # Function call
56
+ #
57
+ # puts txid # prints transaction id of the sent transaction
58
+ # === 2. sendSignedTransaction
59
+ # This function is used to send transaction by passing reciever’s address, sender’s address, private key of sender and amount. In this function private key is required to sign transaction.
60
+ #
61
+ # You have to pass these four arguments to the sendSignedTransaction function call:
62
+ # * Transaction’s sender address
63
+ # * Transaction’s reciever address
64
+ # * Amount to be sent in transaction
65
+ # * Private key of the sender’s address
66
+ #
67
+ # transaction_id = sendSignedTransaction # Function call
68
+ #
69
+ # puts transaction_id # prints transaction id of the signed transaction
70
+ # === 3. createRawTransaction sender_address, reciever_address, amount
71
+ # This function is used to create raw transaction by passing reciever’s address, sender’s address and amount.
72
+ #
73
+ # You have to pass these three arguments to the sendTransaction function call:
74
+ # * Transaction’s sender address
75
+ # * Transaction’s reciever address
76
+ # * Amount to be sent in transaction
77
+ #
78
+ # tx_hex = createRawTransaction sender_address, reciever_address, amount # Function call
79
+ #
80
+ # puts tx_hex # prints transaction hex of the raw transaction
81
+ # === 4. signRawTransaction tx_hex, private_key
82
+ # This function retrieves is used to sign raw transaction by passing transaction hex of the raw transaction and the private key to sign the raw transaction.
83
+ #
84
+ # You have to pass these three arguments to the signRawTransaction function call:
85
+ # * Transaction hex of the raw transaction
86
+ # * Private key to sign raw transaction
87
+ #
88
+ # signed_hex = signRawTransaction txHex, private_key # Function call
89
+ #
90
+ # puts signed_hex # prints signed transaction hex of the raw transaction
91
+ # === 5. sendRawTransaction signed_txHex
92
+ # This function is used to send raw transaction by passing signed transaction hex of the raw transaction.
93
+ #
94
+ # You have to pass the signed transaction hex of the raw transaction.
95
+ #
96
+ # tx_id = sendRawTransaction signed_txHex # Function call
97
+ #
98
+ # puts tx_id # prints transaction id of the raw transaction
99
+ # === 6. retrieveTransaction tx_id
100
+ # This function is used to retrieve transaction’s information by passing transaction id to the function.
101
+ #
102
+ # You have to pass the transaction id of the transaction you want to retrieve.
103
+ #
104
+ # sent_data, sent_amount, reciever_address = retrieveTransaction tx_id # Function call
105
+ #
106
+ # puts sent_data #prints sent data
107
+ # puts sent_amount #prints sent amount
108
+ # puts reciever_address #prints reciever's address
109
+ # === 7. getFee address, tx_id
110
+ # This function is used to calculate transaction’s fee by passing transaction id and sender’s address to the function.
111
+ #
112
+ # You have to pass these two arguments to the getFee function call:
113
+ # * Transaction id of the transaction you want to calculate fee for
114
+ # * Sender’s address
115
+ #
116
+ # Fees = getFee address, tx_id # Function call
117
+ #
118
+ # puts Fees #prints fees consumed in the verified transaction
119
+
120
+ class Transaction
121
+ end
data/docs/walletdoc.rb ADDED
@@ -0,0 +1,133 @@
1
+ # = Wallet Class Usage
2
+ # Library to work with RecordsKeeper wallet functionalities.
3
+ # You can create wallet, dump wallet into a file, backup wallet into a file, import wallet from a file, lock wallet, unlock wallet, change wallet’s password, retrieve private key, retrieve wallet’s information, sign and verify message by using wallet class. You just have to pass parameters to invoke the pre-defined functions.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # require 'hex_string'
13
+ # -----------------
14
+ # == Create Connection
15
+ # Entry point for accessing Blockchain class resources.
16
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
17
+ # * Chain-name: Name of the chain
18
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
19
+ # * Set a *network* value to change the network-type
20
+ # network = cfg['testnet'] # Network variable to store the network that you want to access
21
+ # **NOTE:* Default network is *Test-net* ( i.e., you can set it to either testnet or mainnet).
22
+ # Check the network type for url and chain name:
23
+ # if @network==cfg['testnet']
24
+ # @url = cfg['testnet']['url']
25
+ # @chain = cfg['testnet']['chain']
26
+ # else
27
+ # @url = cfg['mainnet']['url']
28
+ # @chain = cfg['mainnet']['chain']
29
+ # end
30
+ # -------------------
31
+ # == Node Authentication
32
+ # Import values from config file.
33
+ # * User name: The rpc user is used to call the APIs.
34
+ # * Password: The rpc password is used to authenticate the APIs.
35
+ # * Check the network type for username and password:
36
+ # if @network==cfg['testnet']
37
+ # @user = cfg['testnet']['rkuser']
38
+ # @password = cfg['testnet']['passwd']
39
+ # else
40
+ # @user = cfg['mainnet']['rkuser']
41
+ # @password = cfg['mainnet']['passwd']
42
+ # end
43
+ # Now we have node authentication credentials.
44
+ # ------------
45
+ # = class Wallet
46
+ # Wallet class is used to call wallet related functions like create wallet, retrieve private key of wallet address, retrieve wallet’s information, dump wallet, lock wallet, unlock wallet, change wallet’s password, create wallet’s backup, import wallet’s backup, sign message and verify message functions on RecordsKeeeper Blockchain.
47
+ # === 1. createWallet
48
+ # This function is used to create wallet on RecordsKeeper blockchain
49
+ # publicaddress, privatekey, publickey = createWallet
50
+ #
51
+ # puts publicaddress # prints public address of the wallet
52
+ # puts privatekey # prints private key of the wallet
53
+ # puts publickey # prints public key of the wallet
54
+ # === 2. getPrivateKey
55
+ # This function is used to retrieve private key of the given address.
56
+ # privkey = getPrivateKey
57
+ #
58
+ # puts privkey # prints private key of the given address
59
+ # === 3. retrieveWalletinfo
60
+ # This function is used to retrieve node wallet’s information.
61
+ # balance, tx_count, unspent_tx = retrieveWalletinfo
62
+ #
63
+ # puts balance # prints wallet's balance
64
+ # puts tx_count # prints wallet transaction count
65
+ # puts unspent_tx # prints unspent wallet transactions
66
+ # === 4. backupWallet filename
67
+ # This function is used to create backup of the wallet.dat file.
68
+ #
69
+ # You have to pass filename; wallet’s backup file name
70
+ # result = backupWallet filename
71
+ #
72
+ # puts result # prints result
73
+ # It will return the response of the backup wallet function. The backup of the wallet is created in your chain’s directory and you can simply access your file by using same filename that you have passed with the backupwallet function. Creates a backup of the wallet.dat file in which the node’s private keys and watch-only addresses are stored. The backup is created in file filename. Use with caution – any node with access to this file can perform any action restricted to this node’s addresses.
74
+ # === 5. importWallet filename
75
+ # This function is used to import wallet’s backup file.
76
+ #
77
+ # You have to pass the filename; wallet’s backup file name.
78
+ # result = importWallet filename
79
+ #
80
+ # puts result # prints result
81
+ # It will return the response of the import wallet function. It will import the entire set of private keys which were dumped (using dumpwallet) into file filename.
82
+ # === 6. dumpWallet filename
83
+ # This function is used to retrieve transaction’s information by passing transaction id to the function.
84
+ #
85
+ # You have to pass the filename; file name to dump wallet in.
86
+ # result = dumpWallet filename
87
+ #
88
+ # puts result # prints result
89
+ # === 7. lockWallet password
90
+ # This function is used to verify transaction’s information by passing transaction id and sender’s address to the function.
91
+ #
92
+ # You have to pass password; password to lock the wallet.
93
+ # result = lockWallet password
94
+ #
95
+ # puts result # prints result
96
+ # === 8. unlockWallet password, unlock_time
97
+ # This function is used to verify transaction’s information by passing transaction id and sender’s address to the function.
98
+ #
99
+ # You have to pass these two arguments to the unlockWallet function call:
100
+ # * Password: password to unlock the wallet
101
+ # * unlocktime: seconds for which wallet remains unlock
102
+ # result = unlockWallet password, unlock_time
103
+ #
104
+ # puts result # prints result
105
+ # === 9. changeWalletPassword old_password, new_password
106
+ # This function is used to change wallet’s password and set new password.
107
+ #
108
+ # You have to pass these two arguments to the changeWalletPassword function call:
109
+ # * Old Password: old password of the wallet
110
+ # * New Password: new password of the wallet
111
+ # result = changeWalletPassword password, new_password
112
+ #
113
+ # puts result # prints result
114
+ # === 10. signMessage private_key, message
115
+ # This function is used to change wallet’s password and set new password.
116
+ #
117
+ # You have to pass these two arguments to the signMessage function call:
118
+ # * Message: message to send
119
+ # * Private Key: private key of the sender’s wallet address
120
+ # signedMessage = signMessage private_key, message
121
+ #
122
+ # puts signedMessage # prints signed message
123
+ # === 11. verifyMessage address, signedMessage, message
124
+ # This function is used to change wallet’s password and set new password.
125
+ #
126
+ # You have to pass these three arguments to the verifyMessage function call:
127
+ # * Message: message to send
128
+ # * Private Key: private key of the sender’s wallet address
129
+ # validity = verifyMessage address, signedMessage, message
130
+ #
131
+ # puts validity # prints validity of the message
132
+ class Wallet
133
+ end
@@ -0,0 +1,186 @@
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
@@ -0,0 +1,87 @@
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