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,56 @@
1
+ module Bytom
2
+ class Other
3
+
4
+ attr_reader :client
5
+ private :client
6
+
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ ##
13
+ # Decode program.
14
+ #
15
+ # @param [String] program
16
+ #
17
+ def decode_program(program:)
18
+ client.make_request('/decode-program', 'post', params: {program: program})
19
+ end
20
+
21
+ ##
22
+ # Compile equity contract.
23
+ #
24
+ def compile(contract:, args: [])
25
+ params = {
26
+ contract: contract,
27
+ args: args
28
+ }
29
+ client.make_request('/compile', 'post', params: params)
30
+ end
31
+
32
+ ##
33
+ # Returns the sub list of all available unspent outputs for all accounts in your wallet.
34
+ #
35
+ # @param [String] id
36
+ # @param [Boolean] unconfirmed
37
+ # @param [Boolean] smart_contract
38
+ # @param [Fixnum] from
39
+ # @param [Fixnum] count
40
+ # @param [String] account_id
41
+ # @param [String] account_alias
42
+ #
43
+ def list_unspent_outputs(id: nil, unconfirmed: nil, smart_contract: nil, from: nil, count: nil, account_id: nil, account_alias: nil)
44
+ params = {
45
+ id: id,
46
+ unconfirmed: unconfirmed,
47
+ smart_contract: smart_contract,
48
+ from: from,
49
+ count: count,
50
+ account_id: account_id,
51
+ account_alias: account_alias
52
+ }
53
+ client.make_request('/list-unspent-outputs', 'post', params: params)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,42 @@
1
+ module Bytom
2
+ class Peer
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Returns the list of connected peers.
12
+ #
13
+ def list_peers
14
+ client.make_request('/list-peers', 'post', params: {})
15
+ end
16
+
17
+ ##
18
+ # Disconnect to specified peer.
19
+ #
20
+ # @param [String] peer_id
21
+ #
22
+ def disconnect_peer(peer_id:)
23
+ client.make_request('/disconnect-peer', 'post', params: {peer_id: peer_id})
24
+ end
25
+
26
+ ##
27
+ # Connect to specified peer.
28
+ #
29
+ # @param [String] ip peer IP address.
30
+ # @param [Fixnum] port peer port.
31
+ #
32
+ def connect_peer(ip:, port:)
33
+ params = {
34
+ ip: ip,
35
+ port: port
36
+ }
37
+ client.make_request('/connect-peer', 'post', params: params)
38
+ end
39
+
40
+ end
41
+ end
42
+
@@ -0,0 +1,210 @@
1
+ module Bytom
2
+ class Transactions
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Query the account related transaction by transaction ID.
12
+ #
13
+ # @param [String] tx_id transaction id, hash of transaction.
14
+ #
15
+ def get_transaction(tx_id:)
16
+ client.make_request('/get-transaction', 'post', params: {tx_id: tx_id})
17
+ end
18
+
19
+ ##
20
+ # Returns the sub list of all the account related transactions.
21
+ #
22
+ # @param [String] id
23
+ # @param [String] account_id
24
+ # @param [Boolean] detail
25
+ # @param [OBoolean unconfirmed
26
+ # @param [Fixnum] from
27
+ # @param [Fixnum] count
28
+ #
29
+ def list_transactions(id: nil, account_id: nil, detail: nil, unconfirmed: nil, from: nil, count: nil)
30
+ params = {
31
+ id: id,
32
+ account_id: account_id,
33
+ detail: detail,
34
+ unconfirmed: unconfirmed,
35
+ from: from,
36
+ count: count
37
+ }
38
+ client.make_request('/list-transactions', 'post', params: params)
39
+ end
40
+
41
+ ##
42
+ # Build transaction.
43
+ #
44
+ # @param [String] base_transaction
45
+ # @param [Fixnum] ttl
46
+ # @param [Fixnum] time_range the block height at which this transaction will be allowed to be included in a block. If the block height of the main chain exceeds this value, the transaction will expire and no longer be valid.
47
+ # @param [Hash] actions
48
+ #
49
+ def build_transaction(base_transaction: nil, ttl: 0, time_range:, actions: [])
50
+ params = {
51
+ base_transaction: base_transaction,
52
+ ttl: ttl,
53
+ time_range: time_range,
54
+ actions: actions
55
+ }
56
+ client.make_request('/build-transaction', 'post', params: params)
57
+ end
58
+
59
+ def build_chain_transactions(base_transaction: nil, ttl:, time_range:, actions: [])
60
+ params = {
61
+ base_transaction: base_transaction,
62
+ ttl: ttl,
63
+ time_range: time_range,
64
+ actions: actions
65
+ }
66
+ client.make_request('/build-chain-transactions', 'post', params: params)
67
+ end
68
+
69
+ ##
70
+ # Sign transaction.
71
+ #
72
+ # @param [String] password
73
+ # @param [Hash] transaction
74
+ #
75
+ def sign_transaction(password:, transaction: {})
76
+ params = {
77
+ password: password,
78
+ transaction: transaction
79
+ }
80
+ client.make_request('/sign-transaction', 'post', params: params)
81
+ end
82
+
83
+ def sign_transactions(password: nil, transactions: [])
84
+ params = {
85
+ password: password,
86
+ transactions: transactions
87
+ }
88
+ client.make_request('/sign-transactions', 'post', params: params)
89
+ end
90
+
91
+ ##
92
+ # Submit transaction.
93
+ #
94
+ # @param [String] raw_transaction raw_transaction of signed transaction.
95
+ #
96
+ def submit_transaction(raw_transaction: {})
97
+ params = {
98
+ raw_transaction: raw_transaction,
99
+ }
100
+ client.make_request('/submit-transaction', 'post', params: params)
101
+ end
102
+
103
+ ##
104
+ # Submit transactions used for batch submit transactions.
105
+ #
106
+ # @param [Array] raw_transactions Submit transactions used for batch submit transactions.
107
+ #
108
+ def submit_transactions(raw_transactions: [])
109
+ params = {
110
+ raw_transactions: raw_transactions,
111
+ }
112
+ client.make_request('/submit-transactions', 'post', params: params)
113
+ end
114
+
115
+ ##
116
+ # Estimate consumed neu(1BTM = 10^8NEU) for the transaction.
117
+ #
118
+ def estimate_transaction_gas(transaction_template: {})
119
+ params = {
120
+ transaction_template: transaction_template,
121
+ }
122
+ client.make_request('/estimate-transaction-gas', 'post', params: params)
123
+ end
124
+ ##
125
+ # Create transaction feed.
126
+ #
127
+ # @param [String] alias_name
128
+ # @param [String] filter
129
+ #
130
+ def create_transaction_feed(alias_name:, filter:)
131
+ params = {
132
+ alias: alias_name,
133
+ filter: filter
134
+ }
135
+ client.make_request('/create-transaction-feed', 'post', params: params)
136
+ end
137
+
138
+ ##
139
+ # Query detail transaction feed by name.
140
+ #
141
+ def get_transaction_feed(alias_name:)
142
+ params = {
143
+ alias: alias_name
144
+ }
145
+ client.make_request('/get-transaction-feed', 'post', params: params)
146
+ end
147
+
148
+ ##
149
+ # Returns the list of all available transaction feeds.
150
+ #
151
+ def list_transaction_feeds
152
+ client.make_request('/list-transaction-feeds', 'post', params: {})
153
+ end
154
+
155
+ ##
156
+ # Delete transaction feed by name.
157
+ #
158
+ # @param [String] alias_name name of the transaction feed.
159
+ #
160
+ def delete_transaction_feed(alias_name:)
161
+ params = {
162
+ alias: alias_name,
163
+ }
164
+ client.make_request('/delete-transaction-feed', 'post', params: params)
165
+ end
166
+
167
+ ##
168
+ # Update transaction feed.
169
+ #
170
+ # @param [String] alias_name
171
+ # @param [String] filter
172
+ #
173
+ def update_transaction_feed(alias_name:, filter:)
174
+ params = {
175
+ alias: alias_name,
176
+ filter: filter
177
+ }
178
+ client.make_request('/update-transaction-feed', 'post', params: params)
179
+ end
180
+
181
+ ##
182
+ # Query mempool transaction by transaction ID.
183
+ #
184
+ def get_unconfirmed_transaction(tx_id:)
185
+ params = {
186
+ tx_id: tx_id,
187
+ }
188
+ client.make_request('/get-unconfirmed-transaction', 'post', params: params)
189
+ end
190
+
191
+ ##
192
+ # Returns the total number of mempool transactions and the list of transaction IDs.
193
+ #
194
+ def list_unconfirmed_transactions
195
+ client.make_request('/list-unconfirmed-transactions', 'post', params: {})
196
+ end
197
+
198
+ ##
199
+ # Decode a serialized transaction hex string into a JSON object describing the transaction.
200
+ #
201
+ def decode_raw_transaction(raw_transaction:)
202
+ params = {
203
+ raw_transaction: raw_transaction,
204
+ }
205
+ client.make_request('/decode-raw-transaction', 'post', params: params)
206
+ end
207
+
208
+
209
+ end
210
+ end
@@ -0,0 +1,57 @@
1
+ module Bytom
2
+ class Wallet
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Backup wallet to image file, it contain accounts image, assets image and keys image.
12
+ #
13
+ def backup_wallet
14
+ client.make_request('/backup-wallet', 'post', params: {})
15
+ end
16
+
17
+ ##
18
+ # Restore wallet by image file.
19
+ #
20
+ # @param [Hash] account_image
21
+ # @param [Hash] asset_image
22
+ # @param [Hash] key_images
23
+ #
24
+ def restore_wallet(account_image: {}, asset_image: {}, key_images: {})
25
+ params = {
26
+ account_image: account_image,
27
+ asset_image: asset_image,
28
+ key_images: key_images
29
+ }
30
+ client.make_request('/restore-wallet', 'post', params: params)
31
+ end
32
+
33
+ ##
34
+ # Trigger to rescan block information into related wallet.
35
+ #
36
+ def rescan_wallet
37
+ client.make_request('/rescan-wallet', 'post', params: {})
38
+ end
39
+
40
+ ##
41
+ # Recovery wallet and accounts from root XPubs.
42
+ # All accounts and balances of bip44 multi-account hierarchy for deterministic wallets can be restored via root xpubs.
43
+ #
44
+ # @param [Array] xpubs
45
+ #
46
+ def recovery_wallet(xpubs: [])
47
+ client.make_request('/recovery-wallet', 'post', params: {xpubs: xpubs})
48
+ end
49
+
50
+ ##
51
+ # Return the information of wallet.
52
+ #
53
+ def wallet_info
54
+ client.make_request('/wallet-info', 'post', params: {})
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,43 @@
1
+ module Bytom
2
+ class Work
3
+ attr_reader :client
4
+ private :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ ##
11
+ # Get the proof of work.
12
+ #
13
+ def get_work
14
+ client.make_request('/get-work', 'post', params: {})
15
+ end
16
+
17
+ ##
18
+ # Submit the proof of work.
19
+ #
20
+ # @param [String] block_header
21
+ #
22
+ def submit_work(block_header:)
23
+ client.make_request('/submit-work', 'post', params: {block_header: block_header})
24
+ end
25
+
26
+ ##
27
+ # Get the proof of work by json.
28
+ #
29
+ def get_work_json
30
+ client.make_request('/get-work-json', 'post', params: {})
31
+ end
32
+
33
+ ##
34
+ # Submit the proof of work by json.
35
+ #
36
+ def submit_work_json(block_header:)
37
+ client.make_request('/submit-work-json', 'post', params: {block_header: block_header})
38
+ end
39
+
40
+ end
41
+ end
42
+
43
+
@@ -0,0 +1,89 @@
1
+ require 'bytom/api/keys'
2
+ require 'bytom/api/accounts'
3
+ require 'bytom/api/address'
4
+ require 'bytom/api/coinbase'
5
+ require 'bytom/api/asset'
6
+ require 'bytom/api/balances'
7
+ require 'bytom/api/access_token'
8
+ require 'bytom/api/transactions'
9
+ require 'bytom/api/block'
10
+ require 'bytom/api/core_config'
11
+ require 'bytom/api/peer'
12
+ require 'bytom/api/wallet'
13
+ require 'bytom/api/message'
14
+ require 'bytom/api/work'
15
+ require 'bytom/api/other'
16
+
17
+ require 'bytom/constants'
18
+ require 'bytom/request'
19
+
20
+ module Bytom
21
+ # The entry point to the SDK. API endpoint categories are accessed through this object's readable
22
+ # attributes.
23
+ #
24
+ # @!attribute [r] client
25
+ # @return [Client]
26
+ # @!attribute [r] keys
27
+ # @return [Keys]
28
+ # @!attribute [r] accounts
29
+ # @return [Accounts]
30
+ # @!attribute [r] address
31
+ # @return [Address]
32
+ # @!attribute [r] coinbase
33
+ # @return [Coinbase]
34
+ # @!attribute [r] asset
35
+ # @return [Asset]
36
+ # @!attribute [r] balances
37
+ # @return [Balances]
38
+ # @!attribute [r] access_token
39
+ # @return [AccessToken]
40
+ # @!attribute [r] transactions
41
+ # @return [Transactions]
42
+ # @!attribute [r] block
43
+ # @return [Block]
44
+ # @!attribute [r] core_config
45
+ # @return [CoreConfig]
46
+ # @!attribute [r] peer
47
+ # @return [Peer]
48
+ # @!attribute [r] wallet
49
+ # @return [Wallet]
50
+ # @!attribute [r] message
51
+ # @return [Message]
52
+ # @!attribute [r] work
53
+ # @return [Work]
54
+ # @!attribute [r] other
55
+ # @return [Other]
56
+ #
57
+ class Client
58
+ include Bytom::Constants
59
+ attr_reader :client, :keys, :accounts, :address, :coinbase, :asset, :balances, :access_token,
60
+ :transactions, :block, :core_config, :peer, :wallet, :message, :work, :other
61
+
62
+ def initialize(
63
+ base_url: API_URL,
64
+ token: nil
65
+ )
66
+ @client = Request.new(base_url: base_url, token: token)
67
+ build_categories
68
+ end
69
+
70
+ def build_categories
71
+ @keys = Keys.new(client)
72
+ @accounts = Accounts.new(client)
73
+ @address = Address.new(client)
74
+ @coinbase = Coinbase.new(client)
75
+ @asset = Asset.new(client)
76
+ @balances = Balances.new(client)
77
+ @access_token = AccessToken.new(client)
78
+ @transactions = Transactions.new(client)
79
+ @block = Block.new(client)
80
+ @core_config = CoreConfig.new(client)
81
+ @peer = Peer.new(client)
82
+ @wallet = Wallet.new(client)
83
+ @message = Message.new(client)
84
+ @work = Work.new(client)
85
+ @other = Other.new(client)
86
+ end
87
+
88
+ end
89
+ end