bytom 1.0.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.
@@ -0,0 +1,66 @@
1
+ module Bytom
2
+ class Address
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Returns the sub list of all available addresses by account.
12
+ #
13
+ # @param [String] account_alias
14
+ # @param [String] account_id
15
+ # @param [Fixnum] from
16
+ # @param [Fixnum] count
17
+ #
18
+ # @return [Hash]
19
+ #
20
+ def list_addresses(account_alias:, account_id:, from: 0, count:)
21
+ params = {
22
+ account_alias: account_alias,
23
+ account_id: account_id,
24
+ from: from,
25
+ count: count
26
+ }
27
+ client.make_request('/list-addresses', 'post', params: params)
28
+ end
29
+
30
+ ##
31
+ # Verify the address is valid, and judge the address is own.
32
+ #
33
+ # @param [String] address
34
+ #
35
+ # @return [Hash]
36
+ #
37
+ def validate_address(address:)
38
+ params = {
39
+ address: address
40
+ }
41
+ client.make_request('/validate-address', 'post', params: params)
42
+ end
43
+
44
+ ##
45
+ # Query the current mining address.
46
+ #
47
+ def get_mining_address
48
+ client.make_request('/get-mining-address', 'post', params: {})
49
+ end
50
+
51
+ ##
52
+ # Set the current mining address, no matter whethere the address is a local one. It returns an error message if the address format is incorrect.
53
+ #
54
+ # @param [String] mining_address
55
+ #
56
+ # @return [Hash]
57
+ #
58
+ def set_mining_address(mining_address:)
59
+ params = {
60
+ mining_address: mining_address
61
+ }
62
+ client.make_request('/set-mining-address', 'post', params: params)
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,63 @@
1
+ module Bytom
2
+ class Asset
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Create asset definition, it prepares for the issuance of asset.
12
+ #
13
+ # @param [String] alias_name
14
+ # @param [Hash] definition
15
+ # @param [Array] root_xpubs
16
+ # @param [Fixnum] quorum
17
+ # @param [String] issuance_program
18
+ #
19
+ # @return [Hash]
20
+ #
21
+ def create_asset(alias_name:, definition: {}, root_xpubs: [], quorum: 1, issuance_program: nil)
22
+ params = {
23
+ alias: alias_name,
24
+ definition: definition,
25
+ }
26
+ params.merge!(issuance_program: issuance_program) if issuance_program
27
+ params.merge!(root_xpubs: root_xpubs, quorum: quorum) if not root_xpubs.empty?
28
+ client.make_request('/create-asset', 'post', params: params)
29
+ end
30
+
31
+ ##
32
+ # Query detail asset by asset ID.
33
+ #
34
+ # @param [String] id
35
+ #
36
+ def get_asset(id:)
37
+ params = {
38
+ id: id
39
+ }
40
+ client.make_request('/get-asset', 'post', params: params)
41
+ end
42
+ ##
43
+ # Returns the list of all available assets.
44
+ #
45
+ def list_assets
46
+ client.make_request('/list-assets', 'post', params: {})
47
+ end
48
+
49
+ ##
50
+ # Update asset alias by assetID.
51
+ #
52
+ # @param [String] id
53
+ # @param [String] alias_name
54
+ #
55
+ def update_asset_alias(id:, alias_name:)
56
+ params = {
57
+ id: id,
58
+ alias: alias_name
59
+ }
60
+ client.make_request('/update-asset-alias', 'post', params: params)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ module Bytom
2
+ class Balances
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+ ##
10
+ # Returns the list of all available account balances.
11
+ #
12
+ # @param [String] account_id
13
+ # @param [String] account_alias
14
+ #
15
+ def list_balances(account_id: nil, account_alias: nil)
16
+ params = {}
17
+ params.merge!(account_id: account_id) if account_id
18
+ params.merge!(account_alias: account_alias) if account_alias
19
+ client.make_request('/list-balances', 'post', params: params)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ module Bytom
2
+ class Block
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def get_block_count
11
+ client.make_request('/get-block-count', 'post', params: {})
12
+ end
13
+ ##
14
+ # Returns the current block hash for blockchain.
15
+ #
16
+ def get_block_hash
17
+ client.make_request('/get-block-hash', 'post', params: {})
18
+ end
19
+
20
+ ##
21
+ # Returns the detail block by block height or block hash.
22
+ #
23
+ # @param [String] block_height optional
24
+ # @param [String] block_hash optional
25
+ #
26
+ def get_block(block_height: nil, block_hash: nil)
27
+ params = {
28
+ block_height: block_height,
29
+ block_hash: block_hash
30
+ }
31
+ client.make_request('/get-block', 'post', params: params)
32
+ end
33
+
34
+ ##
35
+ # Returns the detail block header by block height or block hash.
36
+ #
37
+ # @param [String] block_height optional
38
+ # @param [String] block_hash optional
39
+ #
40
+ def get_block_header(block_height: nil, block_hash: nil)
41
+ params = {
42
+ block_height: block_height,
43
+ block_hash: block_hash
44
+ }
45
+ client.make_request('/get-block-header', 'post', params: params)
46
+ end
47
+
48
+ ##
49
+ # Returns the block difficulty by block height or block hash.
50
+ #
51
+ # @param [String] block_height optional
52
+ # @param [String] block_hash optional
53
+ #
54
+ def get_difficulty(block_height: nil, block_hash: nil)
55
+ params = {
56
+ block_height: block_height,
57
+ block_hash: block_hash
58
+ }
59
+ client.make_request('/get-difficulty', 'post', params: params)
60
+ end
61
+
62
+ ##
63
+ # Returns the block hash rate by block height or block hash, it returns the current block hash rate when request is empty.
64
+ #
65
+ # @param [String] block_height optional
66
+ # @param [String] block_hash optional
67
+ #
68
+ def get_hash_rate(block_height: nil, block_hash: nil)
69
+ params = {
70
+ block_height: block_height,
71
+ block_hash: block_hash
72
+ }
73
+ client.make_request('/get-hash-rate', 'post', params: params)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,31 @@
1
+ module Bytom
2
+ class Coinbase
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Get coinbase arbitrary.
12
+ #
13
+ def get_coinbase_arbitrary(params: {})
14
+ client.make_request('/get-coinbase-arbitrary', 'post', params: params)
15
+ end
16
+
17
+ ##
18
+ # Set coinbase arbitrary.
19
+ #
20
+ # @param [String] arbitrary
21
+ #
22
+ # @return [Hash] the abitrary data being appended to coinbase, in hexdecimal format. (The full coinbase data for a block will be `0x00`&block_height&abitrary.)
23
+ #
24
+ def set_coinbase_arbitrary(arbitrary:)
25
+ params = {
26
+ arbitrary: arbitrary
27
+ }
28
+ client.make_request('/set-coinbase-arbitrary', 'post', params: params)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ module Bytom
2
+ class CoreConfig
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Returns the information of current network node.
12
+ #
13
+ def net_info
14
+ client.make_request('/net-info', 'post', params: {})
15
+ end
16
+
17
+ def gas_rate
18
+ client.make_request('/gas-rate', 'post', params: {})
19
+ end
20
+
21
+ ##
22
+ # Returns the mining status.
23
+ #
24
+ def is_mining
25
+ client.make_request('/is-mining', 'post', params: {})
26
+ end
27
+
28
+ ##
29
+ # Start up node mining.
30
+ #
31
+ def set_mining(is_mining: true)
32
+ client.make_request('/set-mining', 'post', params: {is_mining: is_mining})
33
+ end
34
+
35
+
36
+
37
+ end
38
+ end
@@ -0,0 +1,124 @@
1
+ module Bytom
2
+ class Keys
3
+
4
+ attr_reader :client
5
+ private :client
6
+
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ ##
13
+ # It is to create private key essentially, returns the information of key. The private key is encrypted in the file and not visible to the user.
14
+ #
15
+ # @param [string] alias_name the filed alias is a keyword in ruby. so use alias_name to map.
16
+ # @param [string] password
17
+ # @param [string] language
18
+ # @param [string] mnemonic Optional
19
+ #
20
+ # @return [Hash]
21
+ #
22
+ def create_key(alias_name:, password:, language: 'en', mnemonic: nil)
23
+ params = {
24
+ alias: alias_name,
25
+ password: password,
26
+ language: language,
27
+ mnemonic: nil
28
+ }
29
+ client.make_request('/create-key', 'post', params: params)
30
+ end
31
+
32
+ ##
33
+ # Returns the list of all available keys.
34
+ #
35
+ # @return [Hash]
36
+ #
37
+ def list_keys
38
+ client.make_request('/list-keys', 'get')
39
+ end
40
+
41
+ ##
42
+ # Update alias for the existed key.
43
+ #
44
+ # @param [string] xpub
45
+ # @param [string] new_alias
46
+ #
47
+ # @return [nil]
48
+ #
49
+ def update_key_alias(xpub:, new_alias:)
50
+ params = {
51
+ xpub: xpub,
52
+ new_alias: new_alias
53
+ }
54
+ client.make_request('/update-key-alias', 'post', params: params)
55
+ end
56
+
57
+ ##
58
+ # Delete existed key, please make sure that there is no balance in the related accounts.
59
+ #
60
+ # @param [string] xpub
61
+ # @param [string] password
62
+ #
63
+ # @return [nil]
64
+ #
65
+ def delete_key(xpub:, password:)
66
+ params = {
67
+ xpub: xpub,
68
+ password: password
69
+ }
70
+ client.make_request('/delete-key', 'post', params: params)
71
+ end
72
+
73
+ ##
74
+ # Check key password.
75
+ #
76
+ # @param [string] xpub
77
+ # @param [string] password
78
+ #
79
+ # @return [Hash] check_result, result of check key password, true is check successfully, otherwise is false.
80
+ #
81
+ def check_key_password(xpub:, password:)
82
+ params = {
83
+ xpub: xpub,
84
+ password: password
85
+ }
86
+ client.make_request('/check-key-password', 'post', params: params)
87
+ end
88
+
89
+ ##
90
+ # Reset key password.
91
+ #
92
+ # @param [string] xpub
93
+ # @param [string] old_password
94
+ # @param [string] new_password
95
+ #
96
+ # @return [Hash] changed, result of reset key password, true is reset successfully, otherwise is false.
97
+ #
98
+ def reset_key_password(xpub:, old_password:, new_password:)
99
+ params = {
100
+ xpub: xpub,
101
+ old_password: old_password,
102
+ new_password: new_password
103
+ }
104
+ client.make_request('/reset-key-password', 'post', params: params)
105
+ end
106
+
107
+ ##
108
+ # Returns the list of all available pubkeys by account.
109
+ #
110
+ # @param [String] account_alias optional
111
+ # @param [String] account_id optional
112
+ # @param [String] public_keyoptional
113
+ #
114
+ # @return [Hash]
115
+ #
116
+ def list_pubkeys(account_alias: nil, account_id: nil, public_key: nil)
117
+ params = {}
118
+ params = {account_alias: account_alias} if account_alias
119
+ params = {account_id: account_id} if account_id
120
+ #params = {public_key: public_key} if public_key
121
+ client.make_request('/list-pubkeys', 'post', params: params)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,48 @@
1
+ module Bytom
2
+ class Message
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Verify a signed message with derived pubkey of the address.
12
+ #
13
+ # @param [String] address
14
+ # @param [String] derived_xpub
15
+ # @param [String] message
16
+ # @param [String] signature
17
+ #
18
+ def verify_message(address:, derived_xpub:, message:, signature:)
19
+ params = {
20
+ address: address,
21
+ derived_xpub: derived_xpub,
22
+ message: message,
23
+ signature: signature
24
+ }
25
+ client.make_request('/verify-message', 'post', params: params)
26
+ end
27
+
28
+ ##
29
+ # Sign a message with the key password(decode encrypted private key) of an address.
30
+ #
31
+ # @param [String] address
32
+ # @param [String] message
33
+ # @param [String] password
34
+ #
35
+ # @return [Hash] signature, derived_xpub
36
+ #
37
+ def sign_message(address:, message:, password:)
38
+ params = {
39
+ address: address,
40
+ message: message,
41
+ password: password
42
+ }
43
+ p params
44
+ client.make_request('/sign-message', 'post', params: params)
45
+ end
46
+
47
+ end
48
+ end