near 0.1.0
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 +7 -0
- data/AUTHORS +1 -0
- data/CHANGES.md +10 -0
- data/README.md +232 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/lib/near/account.rb +31 -0
- data/lib/near/balance.rb +57 -0
- data/lib/near/block.rb +59 -0
- data/lib/near/cli/account.rb +264 -0
- data/lib/near/cli/config.rb +7 -0
- data/lib/near/cli/contract.rb +158 -0
- data/lib/near/cli/staking.rb +7 -0
- data/lib/near/cli/tokens.rb +70 -0
- data/lib/near/cli/transaction.rb +252 -0
- data/lib/near/cli.rb +87 -0
- data/lib/near/transaction.rb +21 -0
- data/lib/near/version.rb +1 -0
- data/lib/near.rb +10 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ab3d2b8796c8b9d6db6d842a843882a02b1497070454e67dda41a2105dbe7aa
|
4
|
+
data.tar.gz: 66de38abb9b8bd7162116f110ae2a3f81412f7e580bb2e479db5133d2504f725
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cead3d3f26398a34925d6ba326c981f19be8e4324348f7dd8879a1c291ad11bd80080c11023477e3f4ee5bbfcf5bddfc421e85bea05f8e42acfd672e28bea0f
|
7
|
+
data.tar.gz: f11b1a7a3c795865375feb3c873e9158009b6508a06150d91b3dff126b074920b2c91e658c6bc121e91098f64c198e47aaff0a7ee1348adb1e39364212eb2db5
|
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Arto Bendiken <arto@bendiken.net>
|
data/CHANGES.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## 0.1.0 - 2025-01-19
|
9
|
+
|
10
|
+
## 0.0.0 - 2025-01-11
|
data/README.md
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
# NEAR.rb: NEAR for Ruby
|
2
|
+
|
3
|
+
[](https://unlicense.org)
|
4
|
+
[](https://rubygems.org/gems/near)
|
5
|
+
[](https://rubygems.org/gems/near)
|
6
|
+
[](https://rubydoc.info/gems/near)
|
7
|
+
|
8
|
+
**NEAR.rb** is a [Ruby] client library for the [NEAR Protocol].
|
9
|
+
It wraps the [NEAR command-line interface] (CLI) into a Ruby interface.
|
10
|
+
|
11
|
+
## ✨ Features
|
12
|
+
|
13
|
+
- Wraps the complete CLI features in an idiomatic Ruby interface.
|
14
|
+
- Provides comprehensive account management operations.
|
15
|
+
- Supports token operations for NEAR and other assets.
|
16
|
+
- Supports smart contract deployment and interaction.
|
17
|
+
- Handles transaction construction, signing, and monitoring.
|
18
|
+
- Integrates with hardware wallets and secure key storage.
|
19
|
+
- Implements type-safe balance operations and input validation.
|
20
|
+
- Supports both the [mainnet] and [testnet] environments.
|
21
|
+
- Offers cross-platform support with zero library dependencies.
|
22
|
+
- 100% free and unencumbered public domain software.
|
23
|
+
|
24
|
+
## 🛠️ Prerequisites
|
25
|
+
|
26
|
+
- [NEAR CLI] 0.17+
|
27
|
+
- [Ruby] 3.0+
|
28
|
+
|
29
|
+
## ⬇️ Installation
|
30
|
+
|
31
|
+
### Installation via RubyGems
|
32
|
+
|
33
|
+
```bash
|
34
|
+
gem install near
|
35
|
+
```
|
36
|
+
|
37
|
+
## 👉 Examples
|
38
|
+
|
39
|
+
### Importing the library
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'near'
|
43
|
+
|
44
|
+
# Use the NEAR testnet (the default):
|
45
|
+
testnet = NEAR::CLI.new(network: 'testnet')
|
46
|
+
|
47
|
+
# Use the NEAR mainnet (to test in prod):
|
48
|
+
# mainnet = NEAR::CLI.new(network: 'mainnet')
|
49
|
+
```
|
50
|
+
|
51
|
+
### Viewing account details
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# View an account summary:
|
55
|
+
summary = testnet.view_account_summary('arto.testnet')
|
56
|
+
puts summary
|
57
|
+
|
58
|
+
# View an account at a specific block height:
|
59
|
+
summary = testnet.view_account_summary('arto.testnet',
|
60
|
+
block: 185_304_186
|
61
|
+
)
|
62
|
+
|
63
|
+
# View an account at a specific block hash:
|
64
|
+
summary = testnet.view_account_summary('arto.testnet',
|
65
|
+
block: '13UmYhdcdst88aC19QhjYjNMF1zRmaAyY6iqwc5q45bx'
|
66
|
+
)
|
67
|
+
|
68
|
+
# List access keys in an account:
|
69
|
+
keys = testnet.list_keys('arto.testnet')
|
70
|
+
puts keys
|
71
|
+
```
|
72
|
+
|
73
|
+
### Importing accounts
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
# Import an account using a seed phrase:
|
77
|
+
result = testnet.import_account_with_seed_phrase(
|
78
|
+
'rapid cover napkin accuse junk drill sick tooth poem patch evil fan',
|
79
|
+
hd_path: "m/44'/397'/0'"
|
80
|
+
)
|
81
|
+
|
82
|
+
# Import an account using a private key:
|
83
|
+
result = testnet.import_account_with_private_key(
|
84
|
+
'ed25519:5YhAaEe3G4VtiBavJMvpzPPmknfsTauzVjwK1ZjPVw2MFM6zFyUv4tSiSfCbCn78mEnMifE6iX5qbhFsWEwErcC2'
|
85
|
+
)
|
86
|
+
```
|
87
|
+
|
88
|
+
### Creating accounts
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# Create an account funded from a faucet (testnet only):
|
92
|
+
result = testnet.create_account_with_faucet(
|
93
|
+
'mynewaccount.testnet',
|
94
|
+
'ed25519:HVPgAsZkZ7cwLZDqK313XJsDyqAvgBxrATcD7VacA8KE'
|
95
|
+
)
|
96
|
+
|
97
|
+
# Create an account funded by another account:
|
98
|
+
result = testnet.create_account_with_funding(
|
99
|
+
'sub.example.testnet', # new account
|
100
|
+
'example.testnet', # funding account
|
101
|
+
'ed25519:6jm8hWUgwoEeGmpdEyk9zrCqtXM8kHhvg8M236ZaGusS', # public key
|
102
|
+
'1 NEAR' # initial deposit
|
103
|
+
)
|
104
|
+
|
105
|
+
# Create a new implicit account:
|
106
|
+
result = testnet.create_implicit_account('/path/to/credentials/folder')
|
107
|
+
```
|
108
|
+
|
109
|
+
### Deleting accounts
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
# Delete an existing account:
|
113
|
+
result = testnet.delete_account(
|
114
|
+
'todelete.testnet', # account to delete
|
115
|
+
'beneficiary.testnet' # account receiving remaining balance
|
116
|
+
)
|
117
|
+
```
|
118
|
+
|
119
|
+
### Managing access keys
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
# Add a full-access key to an account:
|
123
|
+
result = testnet.add_full_access_key(
|
124
|
+
'myaccount.testnet',
|
125
|
+
'ed25519:75a5ZgVZ9DFTxs4THtFxPtLj7AY3YzpxtapTQBdcMXx3'
|
126
|
+
)
|
127
|
+
|
128
|
+
# Add a function-call key to an account:
|
129
|
+
result = testnet.add_function_call_key(
|
130
|
+
'myaccount.testnet',
|
131
|
+
'ed25519:27R66L6yevyHbsk4fESZDC8QUQBwCdx6vvkk1uQmG7NY',
|
132
|
+
'app.example.testnet', # contract that can be called
|
133
|
+
['set_status', 'get_status'], # allowed methods
|
134
|
+
'1 NEAR' # allowance
|
135
|
+
)
|
136
|
+
|
137
|
+
# Delete an access key from an account:
|
138
|
+
result = testnet.delete_key(
|
139
|
+
'myaccount.testnet',
|
140
|
+
'ed25519:75a5ZgVZ9DFTxs4THtFxPtLj7AY3YzpxtapTQBdcMXx3'
|
141
|
+
)
|
142
|
+
```
|
143
|
+
|
144
|
+
### Managing tokens
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
# Send NEAR tokens from one account to another:
|
148
|
+
result = testnet.send_near(
|
149
|
+
'mysender.testnet',
|
150
|
+
'myreceiver.testnet',
|
151
|
+
NEAR::Balance.new('0.1')
|
152
|
+
)
|
153
|
+
```
|
154
|
+
|
155
|
+
### Calling read-only contract methods
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
# Call a view method:
|
159
|
+
result = testnet.view_call(
|
160
|
+
'myapp.testnet', # contract account
|
161
|
+
'get_status', # method name
|
162
|
+
{ account_id: 'user.testnet' } # arguments
|
163
|
+
)
|
164
|
+
|
165
|
+
# Call a view method at a specific block height:
|
166
|
+
result = testnet.view_call(
|
167
|
+
'myapp.testnet',
|
168
|
+
'get_status',
|
169
|
+
{ account_id: 'user.testnet' },
|
170
|
+
block: 12345678
|
171
|
+
)
|
172
|
+
```
|
173
|
+
|
174
|
+
### Calling mutative contract methods
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
# Call a mutative method as a transaction:
|
178
|
+
result = testnet.call_function(
|
179
|
+
'myapp.testnet', # contract account
|
180
|
+
'set_status', # method name
|
181
|
+
{ status: 'Hello NEAR!' }, # arguments
|
182
|
+
signer_id: 'user.testnet', # account that signs tx
|
183
|
+
deposit: '1 NEAR', # attached deposit
|
184
|
+
gas: '30 TGas' # attached gas
|
185
|
+
)
|
186
|
+
```
|
187
|
+
|
188
|
+
### Deploying a smart contract
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
# Deploy a new contract:
|
192
|
+
result = testnet.deploy_contract(
|
193
|
+
'myapp.testnet', # contract account
|
194
|
+
'/tmp/contract.wasm', # WASM file path
|
195
|
+
signer_id: 'deployer.testnet',
|
196
|
+
# Optional initialization:
|
197
|
+
init_method: 'new',
|
198
|
+
init_args: { owner_id: 'deployer.testnet' },
|
199
|
+
init_deposit: '0 NEAR',
|
200
|
+
init_gas: '30 TGas'
|
201
|
+
)
|
202
|
+
|
203
|
+
# Download a contract WebAssembly blob:
|
204
|
+
result = testnet.download_wasm(
|
205
|
+
'myapp.testnet',
|
206
|
+
'/tmp/contract.wasm'
|
207
|
+
)
|
208
|
+
```
|
209
|
+
|
210
|
+
## 📚 Reference
|
211
|
+
|
212
|
+
https://rubydoc.info/gems/near
|
213
|
+
|
214
|
+
## 👨💻 Development
|
215
|
+
|
216
|
+
```bash
|
217
|
+
git clone https://github.com/dryruby/near.rb.git
|
218
|
+
```
|
219
|
+
|
220
|
+
- - -
|
221
|
+
|
222
|
+
[](https://x.com/share?url=https://github.com/dryruby/near.rb&text=NEAR.rb)
|
223
|
+
[](https://reddit.com/submit?url=https://github.com/dryruby/near.rb&title=NEAR.rb)
|
224
|
+
[](https://news.ycombinator.com/submitlink?u=https://github.com/dryruby/near.rb&t=NEAR.rb)
|
225
|
+
[](https://www.facebook.com/sharer/sharer.php?u=https://github.com/dryruby/near.rb)
|
226
|
+
|
227
|
+
[NEAR CLI]: https://github.com/near/near-cli-rs
|
228
|
+
[NEAR Protocol]: https://near.org
|
229
|
+
[NEAR command-line interface]: https://docs.near.org/tools/near-cli
|
230
|
+
[Ruby]: https://ruby-lang.org
|
231
|
+
[mainnet]: https://docs.near.org/concepts/basics/networks#mainnet
|
232
|
+
[testnet]: https://docs.near.org/concepts/basics/networks#testnet
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/near/account.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# Represents a NEAR account.
|
5
|
+
#
|
6
|
+
# @see https://nomicon.io/DataStructures/Account
|
7
|
+
class NEAR::Account
|
8
|
+
##
|
9
|
+
# @param [String, #to_s] id
|
10
|
+
def initialize(id)
|
11
|
+
@id = id.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# The account name.
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
attr_reader :id
|
19
|
+
|
20
|
+
##
|
21
|
+
# The balance as a Ⓝ-prefixed string.
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
def inspect
|
25
|
+
"Ⓝ#{@id}"
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# @return [String]
|
30
|
+
def to_s; @id; end
|
31
|
+
end # NEAR::Block
|
data/lib/near/balance.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Represents a NEAR balance.
|
7
|
+
class NEAR::Balance
|
8
|
+
def self.from_near(s)
|
9
|
+
self.new(s)
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param [Numeric] quantity
|
14
|
+
# @raise [ArgumentError] if quantity is not a valid number
|
15
|
+
def initialize(quantity)
|
16
|
+
@quantity = case quantity
|
17
|
+
when BigDecimal then quantity
|
18
|
+
when Rational then quantity
|
19
|
+
when Integer then quantity
|
20
|
+
when Float then quantity
|
21
|
+
when String then BigDecimal(quantity)
|
22
|
+
else raise ArgumentError, "invalid quantity: #{quantity.inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# The balance as a Ⓝ-prefixed string.
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
def inspect
|
31
|
+
"Ⓝ#{@quantity.to_f}"
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# The balance as a string.
|
36
|
+
#
|
37
|
+
# @return [String]
|
38
|
+
def to_s; @quantity.to_s; end
|
39
|
+
|
40
|
+
##
|
41
|
+
# The balance as a rational number.
|
42
|
+
#
|
43
|
+
# @return [Rational]
|
44
|
+
def to_r; @quantity.to_r; end
|
45
|
+
|
46
|
+
##
|
47
|
+
# The balance as an integer.
|
48
|
+
#
|
49
|
+
# @return [Integer]
|
50
|
+
def to_i; @quantity.to_i; end
|
51
|
+
|
52
|
+
##
|
53
|
+
# The balance as a floating-point number.
|
54
|
+
#
|
55
|
+
# @return [Float]
|
56
|
+
def to_f; @quantity.to_f; end
|
57
|
+
end # NEAR::Balance
|
data/lib/near/block.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# Represents a NEAR block.
|
5
|
+
class NEAR::Block
|
6
|
+
##
|
7
|
+
# @return [NEAR::Block]
|
8
|
+
def self.now
|
9
|
+
self.new
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param [Integer, #to_i] height
|
14
|
+
# @return [NEAR::Block]
|
15
|
+
def self.at_height(height)
|
16
|
+
self.new(height: height)
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# @param [String, #to_s] hash
|
21
|
+
# @return [NEAR::Block]
|
22
|
+
def self.at_hash(hash)
|
23
|
+
self.new(hash: hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param [Integer, #to_i] height
|
28
|
+
# @param [String, #to_s] hash
|
29
|
+
def initialize(height: nil, hash: nil)
|
30
|
+
@height = height.to_i if height
|
31
|
+
@hash = hash.to_s if hash
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# The height of the block.
|
36
|
+
#
|
37
|
+
# @return [Integer]
|
38
|
+
attr_reader :height
|
39
|
+
|
40
|
+
##
|
41
|
+
# The hash of the block.
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
attr_reader :hash
|
45
|
+
|
46
|
+
##
|
47
|
+
# @return [Array<String>]
|
48
|
+
def to_cli_args
|
49
|
+
return ['at-block-height', @height] if @height
|
50
|
+
return ['at-block-hash', @hash] if @hash
|
51
|
+
['now']
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# @return [String]
|
56
|
+
def to_s
|
57
|
+
(@height || @hash || :now).to_s
|
58
|
+
end
|
59
|
+
end # NEAR::Block
|
@@ -0,0 +1,264 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# @see https://github.com/near/near-cli-rs/blob/main/docs/GUIDE.en.md#account---Manage-accounts
|
5
|
+
module NEAR::CLI::Account
|
6
|
+
##
|
7
|
+
# Views properties for an account.
|
8
|
+
#
|
9
|
+
# @param [String] account_id
|
10
|
+
# @param [Block, Integer, String, Symbol] block
|
11
|
+
# @return [String]
|
12
|
+
def view_account_summary(account_id, block: :now)
|
13
|
+
stdout, _ = execute(
|
14
|
+
'account',
|
15
|
+
'view-account-summary', account_id,
|
16
|
+
'network-config', @network,
|
17
|
+
*block_args(block)
|
18
|
+
)
|
19
|
+
stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Lists access keys for an account.
|
24
|
+
#
|
25
|
+
# @param [String] account_id
|
26
|
+
# @param [Block, Integer, String, Symbol] block
|
27
|
+
# @return [String]
|
28
|
+
def list_keys(account_id, block: :now)
|
29
|
+
stdout, _ = execute(
|
30
|
+
'account',
|
31
|
+
'list-keys', account_id,
|
32
|
+
'network-config', @network,
|
33
|
+
*block_args(block)
|
34
|
+
)
|
35
|
+
stdout
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Imports an existing account using a seed phrase.
|
40
|
+
#
|
41
|
+
# @param [String] seed_phrase
|
42
|
+
# @param [String] hd_path
|
43
|
+
# @return [String]
|
44
|
+
def import_account_with_seed_phrase(seed_phrase, hd_path: "m/44'/397'/0'")
|
45
|
+
_, stderr = execute(
|
46
|
+
'account',
|
47
|
+
'import-account',
|
48
|
+
'using-seed-phrase', seed_phrase,
|
49
|
+
'--seed-phrase-hd-path', hd_path,
|
50
|
+
'network-config', @network
|
51
|
+
)
|
52
|
+
stderr
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Imports an existing account using a private key.
|
57
|
+
#
|
58
|
+
# @param [String] private_key
|
59
|
+
# @return [String]
|
60
|
+
def import_account_with_private_key(private_key)
|
61
|
+
_, stderr = execute(
|
62
|
+
'account',
|
63
|
+
'import-account',
|
64
|
+
'using-private-key', private_key,
|
65
|
+
'network-config', @network
|
66
|
+
)
|
67
|
+
stderr
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Creates a new account sponsored by the faucet service.
|
72
|
+
#
|
73
|
+
# @param [String] new_account_id
|
74
|
+
# @param [String] public_key
|
75
|
+
# @return [String]
|
76
|
+
def create_account_with_faucet(new_account_id, public_key)
|
77
|
+
stdout, stderr = execute(
|
78
|
+
'account',
|
79
|
+
'create-account',
|
80
|
+
'sponsor-by-faucet-service', new_account_id,
|
81
|
+
'use-manually-provided-public-key', public_key,
|
82
|
+
'network-config', @network,
|
83
|
+
'create'
|
84
|
+
)
|
85
|
+
stderr
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Creates a new account funded by another account.
|
90
|
+
#
|
91
|
+
# @param [String] new_account_id
|
92
|
+
# @param [String] funding_account_id
|
93
|
+
# @param [String] public_key
|
94
|
+
# @param [String] deposit
|
95
|
+
# @return [String]
|
96
|
+
def create_account_with_funding(new_account_id, funding_account_id, public_key, deposit)
|
97
|
+
stdout, stderr = execute(
|
98
|
+
'account',
|
99
|
+
'create-account',
|
100
|
+
'fund-myself', new_account_id, deposit,
|
101
|
+
'use-manually-provided-public-key', public_key,
|
102
|
+
'sign-as', funding_account_id,
|
103
|
+
'network-config', @network,
|
104
|
+
'sign-with-keychain',
|
105
|
+
'send'
|
106
|
+
)
|
107
|
+
stderr
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Creates an implicit account.
|
112
|
+
#
|
113
|
+
# @param [String] save_path
|
114
|
+
# @return [String]
|
115
|
+
def create_implicit_account(save_path)
|
116
|
+
stdout, stderr = execute(
|
117
|
+
'account',
|
118
|
+
'create-account',
|
119
|
+
'fund-later',
|
120
|
+
'use-auto-generation',
|
121
|
+
'save-to-folder', save_path
|
122
|
+
)
|
123
|
+
stderr
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Deletes an account and transfers remaining balance to beneficiary.
|
128
|
+
#
|
129
|
+
# @param [String] account_id
|
130
|
+
# @param [String] beneficiary_id
|
131
|
+
# @return [String]
|
132
|
+
def delete_account(account_id, beneficiary_id)
|
133
|
+
stdout, stderr = execute(
|
134
|
+
'account',
|
135
|
+
'delete-account', account_id,
|
136
|
+
'beneficiary', beneficiary_id,
|
137
|
+
'network-config', @network,
|
138
|
+
'sign-with-keychain',
|
139
|
+
'send'
|
140
|
+
)
|
141
|
+
stderr
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Adds a full access key to an account.
|
146
|
+
#
|
147
|
+
# @param [String] account_id
|
148
|
+
# @param [String] public_key
|
149
|
+
# @return [String]
|
150
|
+
def add_full_access_key(account_id, public_key)
|
151
|
+
stdout, stderr = execute(
|
152
|
+
'account',
|
153
|
+
'add-key', account_id,
|
154
|
+
'grant-full-access',
|
155
|
+
'use-manually-provided-public-key', public_key,
|
156
|
+
'network-config', @network,
|
157
|
+
'sign-with-keychain',
|
158
|
+
'send'
|
159
|
+
)
|
160
|
+
stderr
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Adds a function call access key to an account.
|
165
|
+
#
|
166
|
+
# @param [String] account_id
|
167
|
+
# @param [String] public_key
|
168
|
+
# @param [String] receiver_id
|
169
|
+
# @param [Array<String>] method_names
|
170
|
+
# @param [String] allowance
|
171
|
+
# @return [String]
|
172
|
+
def add_function_call_key(account_id, public_key, receiver_id, method_names, allowance)
|
173
|
+
stdout, stderr = execute(
|
174
|
+
'account',
|
175
|
+
'add-key', account_id,
|
176
|
+
'grant-function-call-access',
|
177
|
+
'--allowance', allowance,
|
178
|
+
'--receiver-account-id', receiver_id,
|
179
|
+
'--method-names', method_names.join(', '),
|
180
|
+
'use-manually-provided-public-key', public_key,
|
181
|
+
'network-config', @network,
|
182
|
+
'sign-with-keychain',
|
183
|
+
'send'
|
184
|
+
)
|
185
|
+
stderr
|
186
|
+
end
|
187
|
+
|
188
|
+
##
|
189
|
+
# Deletes an access key from an account.
|
190
|
+
#
|
191
|
+
# @param [String] account_id
|
192
|
+
# @param [String] public_key
|
193
|
+
# @return [String]
|
194
|
+
def delete_key(account_id, public_key)
|
195
|
+
stdout, stderr = execute(
|
196
|
+
'account',
|
197
|
+
'delete-key', account_id,
|
198
|
+
public_key,
|
199
|
+
'network-config', @network,
|
200
|
+
'sign-with-keychain',
|
201
|
+
'send'
|
202
|
+
)
|
203
|
+
stderr
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# Views storage balance for an account.
|
208
|
+
#
|
209
|
+
# @param [String] contract_id
|
210
|
+
# @param [String] account_id
|
211
|
+
# @param [Block, Integer, String, Symbol] block
|
212
|
+
# @return [String]
|
213
|
+
def view_storage_balance(contract_id, account_id, block: :now)
|
214
|
+
stdout, _ = execute(
|
215
|
+
'account',
|
216
|
+
'manage-storage-deposit', contract_id,
|
217
|
+
'view-balance', account_id,
|
218
|
+
'network-config', @network,
|
219
|
+
*block_args(block)
|
220
|
+
)
|
221
|
+
stdout
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# Makes a storage deposit for an account.
|
226
|
+
#
|
227
|
+
# @param [String] contract_id
|
228
|
+
# @param [String] account_id
|
229
|
+
# @param [String] deposit
|
230
|
+
# @param [String] sign_as
|
231
|
+
# @return [String]
|
232
|
+
def make_storage_deposit(contract_id, account_id, deposit, sign_as)
|
233
|
+
stdout, stderr = execute(
|
234
|
+
'account',
|
235
|
+
'manage-storage-deposit', contract_id,
|
236
|
+
'deposit', account_id, deposit,
|
237
|
+
'sign-as', sign_as,
|
238
|
+
'network-config', @network,
|
239
|
+
'sign-with-keychain',
|
240
|
+
'send'
|
241
|
+
)
|
242
|
+
stderr
|
243
|
+
end
|
244
|
+
|
245
|
+
##
|
246
|
+
# Withdraws storage deposit for an account.
|
247
|
+
#
|
248
|
+
# @param [String] contract_id
|
249
|
+
# @param [String] amount
|
250
|
+
# @param [String] account_id
|
251
|
+
# @return [String]
|
252
|
+
def withdraw_storage_deposit(contract_id, amount, account_id)
|
253
|
+
stdout, stderr = execute(
|
254
|
+
'account',
|
255
|
+
'manage-storage-deposit', contract_id,
|
256
|
+
'withdraw', amount,
|
257
|
+
'sign-as', account_id,
|
258
|
+
'network-config', @network,
|
259
|
+
'sign-with-keychain',
|
260
|
+
'send'
|
261
|
+
)
|
262
|
+
stderr
|
263
|
+
end
|
264
|
+
end # NEAR::CLI::Account
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# @see https://github.com/near/near-cli-rs/blob/main/docs/GUIDE.en.md#config---Manage-connections-in-a-configuration-file
|
5
|
+
module NEAR::CLI::Config
|
6
|
+
# TODO: implement the `NEAR::CLI::Config` module.
|
7
|
+
end # NEAR::CLI::Config
|