near 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 147f21ee313f56cb2e1327e8817df79796dd56fe90eff771e9057e6d7248c4f5
4
- data.tar.gz: bf81f3240cb7e18c519d85696bf472b1bf2c8e56c3049aa942fe2aaae37e38f6
3
+ metadata.gz: aa0995c2a2fec35657f6ce459546a2f3a83b69d306965a301da46a99fb64afc3
4
+ data.tar.gz: 56826739970ee57d1485fd533404523408fc8072f1db2b7cd64f18864e6c99ce
5
5
  SHA512:
6
- metadata.gz: 4cfef8be7777c9dd2f2f839284581a44a0f2479f256f09e759628c21509a6d3bc9b95ad07c7e0e13a2e8c22aa5238bd826a224cdac9c6e649388bd060971569d
7
- data.tar.gz: 4c5e69608fe79e7a1e0f7a9046477ea9c590d61d1ee6bf12b530054775fc26464d68ddd29c6c9655f05459faf2752a4c7119e5a29afb17a2500ba115618d0b3d
6
+ metadata.gz: dfa74fb61db51e15c37af7c9b95c2b0d5ae15595f59bdce9b1198ed866eec9a2c7bc739b2149e0217593ee340af72af78e674fd7891b2b825f487f66bf979985
7
+ data.tar.gz: dfce931afa3709136c6f1f5bf42d9d1bdbf180af3e1d172d179c702b6614678cfae746829f3a3fb698c59d26c2bec17e5aa37169deb05f89e55312dbac86dab9
data/CHANGES.md CHANGED
@@ -5,30 +5,35 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## 0.3.0 - 2025-02-02
8
+ ## 0.3.2 - 2025-05-12
9
+ ### Changed
10
+ - Enhance `call_function` and `deploy_contract`
11
+ ### Added
12
+ - Define `NEAR::Transaction::MAX_SIZE`
13
+ ### Fixed
14
+ - Fix detection of printable strings
15
+
16
+ ## 0.3.1 - 2025-02-05
9
17
 
18
+ ## 0.3.0 - 2025-02-02
10
19
  ### Added
11
20
  - Implement block data accessors
12
21
  - Implement transaction data accessors
13
22
  - Implement action parsing
14
-
15
23
  ### Changed
16
24
  - Adopt Faraday as the HTTP client
17
25
  - Improve HTTP error handling and retries
18
26
 
19
27
  ## 0.2.0 - 2025-01-29
20
-
21
28
  ### Added
22
29
  - `Network#fetch(block)`
23
30
  - `NEAR.testnet`, `NEAR.mainnet`
24
-
25
31
  ### Changed
26
32
  - Use the NEAR_CLI environmnet variable, if set
27
33
  - Use a temporary file for `call_function`
28
34
  - Enhance `call_function()`
29
35
  - Enhance `create_account_with_funding()`
30
36
  - Enhance `delete_account()`
31
-
32
37
  ### Fixed
33
38
  - Fix the formatting of balances
34
39
 
data/README.md CHANGED
@@ -1,17 +1,18 @@
1
1
  # NEAR.rb: NEAR for Ruby
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-Public%20Domain-blue.svg)](https://unlicense.org)
4
- [![Compatibility](https://img.shields.io/badge/ruby-3.0%2B-blue)](https://rubygems.org/gems/near)
4
+ [![Compatibility](https://img.shields.io/badge/ruby-3.0%2B-blue)](https://rubyreferences.github.io/rubychanges/3.0.html)
5
5
  [![Package](https://img.shields.io/gem/v/near)](https://rubygems.org/gems/near)
6
6
  [![Documentation](https://img.shields.io/badge/rubydoc-latest-blue)](https://rubydoc.info/gems/near)
7
7
 
8
8
  **NEAR.rb** is a [Ruby] client library for the [NEAR Protocol].
9
- It provides a [neardata.xyz] API client as well as wraps the
10
- [NEAR command-line interface] (CLI) in a usable Ruby interface.
9
+ It provides a [neardata.xyz] API client for block data as well as wraps the
10
+ [NEAR Command-Line Interface] (CLI) in a high-productivity Ruby interface.
11
11
 
12
12
  ## ✨ Features
13
13
 
14
14
  - Fetches block data from the [neardata.xyz] API.
15
+ - Supports parsing of block, chunk, transaction, and action data.
15
16
  - Wraps the complete CLI features in an idiomatic Ruby interface.
16
17
  - Provides comprehensive account management operations.
17
18
  - Supports token operations for NEAR and other assets.
@@ -25,7 +26,7 @@ It provides a [neardata.xyz] API client as well as wraps the
25
26
 
26
27
  ## 🛠️ Prerequisites
27
28
 
28
- - [NEAR CLI] 0.19+
29
+ - [NEAR CLI] 0.18+
29
30
  - [Ruby] 3.0+
30
31
 
31
32
  ## ⬇️ Installation
@@ -84,8 +85,6 @@ end
84
85
 
85
86
  ### Tracking chain transactions
86
87
 
87
- See [`examples/monitor_all_transactions.rb`](examples/monitor_all_transactions.rb).
88
-
89
88
  ```ruby
90
89
  NEAR.testnet.fetch_blocks do |block|
91
90
  puts block.inspect
@@ -96,9 +95,12 @@ NEAR.testnet.fetch_blocks do |block|
96
95
  end
97
96
  ```
98
97
 
99
- ### Tracking chain actions
98
+ For a more elaborated example, see
99
+ [`examples/monitor_all_transactions.rb`](examples/monitor_all_transactions.rb):
100
100
 
101
- See [`examples/monitor_all_actions.rb`](examples/monitor_all_actions.rb).
101
+ [![monitor_all_transactions.rb](examples/monitor_all_transactions.gif)](examples/monitor_all_transactions.gif)
102
+
103
+ ### Tracking chain actions
102
104
 
103
105
  ```ruby
104
106
  NEAR.testnet.fetch_blocks do |block|
@@ -110,9 +112,12 @@ NEAR.testnet.fetch_blocks do |block|
110
112
  end
111
113
  ```
112
114
 
113
- ### Tracking contract interactions
115
+ For a more elaborated example, see
116
+ [`examples/monitor_all_actions.rb`](examples/monitor_all_actions.rb):
114
117
 
115
- See [`examples/index_evm_transactions.rb`](examples/index_evm_transactions.rb).
118
+ [![monitor_all_actions.rb](examples/monitor_all_actions.gif)](examples/monitor_all_actions.gif)
119
+
120
+ ### Tracking contract interactions
116
121
 
117
122
  ```ruby
118
123
  NEAR.testnet.fetch_blocks do |block|
@@ -124,6 +129,11 @@ NEAR.testnet.fetch_blocks do |block|
124
129
  end
125
130
  ```
126
131
 
132
+ For a more elaborated example, see
133
+ [`examples/index_evm_transactions.rb`](examples/index_evm_transactions.rb):
134
+
135
+ [![index_evm_transactions.rb](examples/index_evm_transactions.gif)](examples/index_evm_transactions.gif)
136
+
127
137
  ### Instantiating the CLI wrapper
128
138
 
129
139
  ```ruby
@@ -177,7 +187,7 @@ result = testnet.import_account_with_private_key(
177
187
  # Create an account funded from a faucet (testnet only):
178
188
  result = testnet.create_account_with_faucet(
179
189
  'mynewaccount.testnet',
180
- 'ed25519:HVPgAsZkZ7cwLZDqK313XJsDyqAvgBxrATcD7VacA8KE'
190
+ public_key: 'ed25519:HVPgAsZkZ7cwLZDqK313XJsDyqAvgBxrATcD7VacA8KE'
181
191
  )
182
192
 
183
193
  # Create an account funded by another account:
@@ -197,8 +207,8 @@ result = testnet.create_implicit_account('/path/to/credentials/folder')
197
207
  ```ruby
198
208
  # Delete an existing account:
199
209
  result = testnet.delete_account(
200
- 'todelete.testnet', # account to delete
201
- 'beneficiary.testnet' # account receiving remaining balance
210
+ 'my-obsolete-account.testnet', # account to delete
211
+ beneficiary: 'v2.faucet.nonofficial.testnet' # account receiving remaining balance
202
212
  )
203
213
  ```
204
214
 
@@ -303,12 +313,13 @@ https://rubydoc.info/gems/near
303
313
  git clone https://github.com/dryruby/near.rb.git
304
314
  ```
305
315
 
306
- - - -
316
+ ---
307
317
 
308
- [![Share on Twitter](https://img.shields.io/badge/share%20on-twitter-03A9F4?logo=twitter)](https://x.com/share?url=https://github.com/dryruby/near.rb&text=NEAR.rb)
318
+ [![Share on X](https://img.shields.io/badge/share%20on-x-03A9F4?logo=x)](https://x.com/intent/post?url=https://github.com/dryruby/near.rb&text=NEAR.rb)
309
319
  [![Share on Reddit](https://img.shields.io/badge/share%20on-reddit-red?logo=reddit)](https://reddit.com/submit?url=https://github.com/dryruby/near.rb&title=NEAR.rb)
310
- [![Share on Hacker News](https://img.shields.io/badge/share%20on-hacker%20news-orange?logo=ycombinator)](https://news.ycombinator.com/submitlink?u=https://github.com/dryruby/near.rb&t=NEAR.rb)
311
- [![Share on Facebook](https://img.shields.io/badge/share%20on-facebook-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/dryruby/near.rb)
320
+ [![Share on Hacker News](https://img.shields.io/badge/share%20on-hn-orange?logo=ycombinator)](https://news.ycombinator.com/submitlink?u=https://github.com/dryruby/near.rb&t=NEAR.rb)
321
+ [![Share on Facebook](https://img.shields.io/badge/share%20on-fb-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/dryruby/near.rb)
322
+ [![Share on LinkedIn](https://img.shields.io/badge/share%20on-linkedin-3949AB?logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/dryruby/near.rb)
312
323
 
313
324
  [NEAR CLI]: https://github.com/near/near-cli-rs
314
325
  [NEAR Protocol]: https://near.org
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
data/lib/near/account.rb CHANGED
@@ -5,10 +5,20 @@
5
5
  #
6
6
  # @see https://nomicon.io/DataStructures/Account
7
7
  class NEAR::Account
8
+ ##
9
+ # @param [String, #to_s] id
10
+ # @return [NEAR::Account]
8
11
  def self.parse(id)
9
12
  self.new(id.to_s)
10
13
  end
11
14
 
15
+ ##
16
+ # @return [NEAR::Account]
17
+ def self.temp
18
+ timestamp = (Time.now.to_f * 1_000).to_i
19
+ self.new("temp-#{timestamp}.testnet")
20
+ end
21
+
12
22
  ##
13
23
  # @param [String, #to_s] id
14
24
  def initialize(id)
@@ -70,15 +70,20 @@ module NEAR::CLI::Account
70
70
  ##
71
71
  # Creates a new account sponsored by the faucet service.
72
72
  #
73
- # @param [String] new_account_id
74
- # @param [String] public_key
73
+ # @param [NEAR::Account, #to_s] new_account
74
+ # @param [String, nil] public_key
75
75
  # @return [String]
76
- def create_account_with_faucet(new_account_id, public_key)
76
+ def create_account_with_faucet(new_account, public_key: nil)
77
77
  stdout, stderr = execute(
78
78
  'account',
79
79
  'create-account',
80
- 'sponsor-by-faucet-service', new_account_id,
81
- 'use-manually-provided-public-key', public_key,
80
+ 'sponsor-by-faucet-service', new_account.to_s,
81
+ *case public_key
82
+ when nil then ['autogenerate-new-keypair', 'save-to-keychain']
83
+ when String then ['use-manually-provided-public-key', public_key]
84
+ when Array then public_key
85
+ else raise ArgumentError
86
+ end,
82
87
  'network-config', @network,
83
88
  'create'
84
89
  )
@@ -88,16 +93,22 @@ module NEAR::CLI::Account
88
93
  ##
89
94
  # Creates a new account funded by another account.
90
95
  #
91
- # @param [NEAR::Account] new_account
92
- # @param [NEAR::Account] signer Account that signs & funds the transaction
93
- # @param [NEAR::Balance] deposit Amount of NEAR to attach
96
+ # @param [NEAR::Account, #to_s] new_account
97
+ # @param [NEAR::Account, #to_s] signer Account that signs & funds the transaction
98
+ # @param [String, nil] public_key
99
+ # @param [NEAR::Balance, #to_s] deposit Amount of NEAR to attach
94
100
  # @return [String]
95
- def create_account_with_funding(new_account, signer:, deposit: nil)
101
+ def create_account_with_funding(new_account, signer:, public_key: nil, deposit: nil)
96
102
  stdout, stderr = execute(
97
103
  'account',
98
104
  'create-account',
99
105
  'fund-myself', new_account.to_s, (deposit ? deposit.to_s : '0') + ' NEAR',
100
- 'autogenerate-new-keypair', 'save-to-keychain',
106
+ *case public_key
107
+ when nil then ['autogenerate-new-keypair', 'save-to-keychain']
108
+ when String then ['use-manually-provided-public-key', public_key]
109
+ when Array then public_key
110
+ else raise ArgumentError
111
+ end,
101
112
  'sign-as', signer.to_s,
102
113
  'network-config', @network,
103
114
  'sign-with-keychain',
@@ -36,12 +36,12 @@ module NEAR::CLI::Contract
36
36
  # @param [NEAR::Balance] deposit Amount of NEAR to attach
37
37
  # @param [NEAR::Gas, #to_s] gas Amount of gas to attach
38
38
  # @return [String] Transaction result
39
- def call_function(contract, method_name, args = {}, signer:, deposit: nil, gas: '100.0 Tgas')
39
+ def call_function(contract, method_name, args = {}, signer: nil, deposit: nil, gas: '100.0 Tgas')
40
40
  args = case args
41
41
  when Hash, Array then ['json-args', args.to_json]
42
- when String then case
43
- when args.ascii_only? then ['text-args', args]
44
- else ['base64-args', Base64.strict_encode64(args)]
42
+ when String then case args
43
+ when /[^[:print:]]/ then ['base64-args', Base64.strict_encode64(args)]
44
+ else ['text-args', args]
45
45
  end
46
46
  when Pathname then ['file-args', args.to_s]
47
47
  else raise ArgumentError, "Invalid argument type: #{args.inspect}"
@@ -53,7 +53,7 @@ module NEAR::CLI::Contract
53
53
  *args,
54
54
  'prepaid-gas', gas.to_s,
55
55
  'attached-deposit', (deposit ? deposit.to_s : '0') + ' NEAR',
56
- 'sign-as', signer.to_s,
56
+ 'sign-as', (signer || contract).to_s,
57
57
  'network-config', @network,
58
58
  'sign-with-keychain',
59
59
  'send'
@@ -65,34 +65,34 @@ module NEAR::CLI::Contract
65
65
  ##
66
66
  # Deploys a new contract.
67
67
  #
68
- # @param [String] contract_id Account to deploy the contract to
68
+ # @param [NEAR::Account, #to_s] contract Account to deploy the contract to
69
69
  # @param [String] wasm_path Path to the .wasm file
70
- # @param [String] signer_id Account that signs the transaction
71
70
  # @param [String, nil] init_method Method to call after deployment
72
71
  # @param [Hash] init_args Arguments for the init method
73
72
  # @param [String] init_deposit Deposit for the init method
74
73
  # @param [String] init_gas Gas for the init method
75
74
  # @return [String] Transaction result
76
- def deploy_contract(contract_id, wasm_path, signer_id:, init_method: nil, init_args: {},
75
+ def deploy_contract(contract, wasm_path, init_method: nil, init_args: {},
77
76
  init_deposit: '0 NEAR', init_gas: '30 TGas')
78
77
  args = [
79
78
  'contract',
80
79
  'deploy',
81
- contract_id,
80
+ contract.to_s,
82
81
  'use-file', wasm_path
83
82
  ]
84
83
 
85
- if init_method
86
- args += [
84
+ args += if init_method
85
+ [
87
86
  'with-init-call', init_method,
88
87
  'json-args', init_args.to_json,
89
88
  'prepaid-gas', init_gas,
90
89
  'attached-deposit', init_deposit
91
90
  ]
91
+ else
92
+ ['without-init-call']
92
93
  end
93
94
 
94
95
  args += [
95
- 'sign-as', signer_id,
96
96
  'network-config', @network,
97
97
  'sign-with-keychain',
98
98
  'send'
@@ -3,6 +3,12 @@
3
3
  ##
4
4
  # Represents a NEAR transaction.
5
5
  class NEAR::Transaction
6
+ ##
7
+ # The maximum byte size of a NEAR transaction.
8
+ #
9
+ # @see https://github.com/near/nearcore/blob/3a584c2/core/parameters/res/runtime_configs/parameters.snap#L187
10
+ MAX_SIZE = 1_572_864
11
+
6
12
  ##
7
13
  # @param [Hash] json
8
14
  # @return [NEAR::Transaction]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: near
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-02 00:00:00.000000000 Z
10
+ date: 2025-05-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -85,14 +85,14 @@ dependencies:
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.12'
88
+ version: '3.13'
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '3.12'
95
+ version: '3.13'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: yard
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.6.2
162
+ rubygems_version: 3.6.3
163
163
  specification_version: 4
164
164
  summary: 'NEAR.rb: NEAR for Ruby'
165
165
  test_files: []