tezos_client 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +147 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tezos_client/client_interface/block_contextual.rb +16 -0
- data/lib/tezos_client/client_interface/client_wrapper.rb +37 -0
- data/lib/tezos_client/client_interface/contract.rb +17 -0
- data/lib/tezos_client/client_interface/key.rb +35 -0
- data/lib/tezos_client/client_interface/misc.rb +26 -0
- data/lib/tezos_client/client_interface.rb +25 -0
- data/lib/tezos_client/commands.rb +28 -0
- data/lib/tezos_client/crypto.rb +178 -0
- data/lib/tezos_client/currency_utils.rb +20 -0
- data/lib/tezos_client/encode_utils.rb +139 -0
- data/lib/tezos_client/liquidity_inteface/liquidity_wrapper.rb +34 -0
- data/lib/tezos_client/liquidity_interface.rb +127 -0
- data/lib/tezos_client/logger.rb +78 -0
- data/lib/tezos_client/operation.rb +125 -0
- data/lib/tezos_client/operations/origination_operation.rb +50 -0
- data/lib/tezos_client/operations/transaction_operation.rb +39 -0
- data/lib/tezos_client/rpc_interface/blocks.rb +34 -0
- data/lib/tezos_client/rpc_interface/context.rb +27 -0
- data/lib/tezos_client/rpc_interface/contracts.rb +27 -0
- data/lib/tezos_client/rpc_interface/helper.rb +100 -0
- data/lib/tezos_client/rpc_interface/monitor.rb +19 -0
- data/lib/tezos_client/rpc_interface/request_manager.rb +88 -0
- data/lib/tezos_client/rpc_interface.rb +29 -0
- data/lib/tezos_client/string_utils.rb +16 -0
- data/lib/tezos_client/version.rb +5 -0
- data/lib/tezos_client.rb +149 -0
- data/tezos_client.gemspec +48 -0
- data/travis-scripts/install-liquidity.sh +25 -0
- data/travis-scripts/install-opam.sh +4 -0
- data/travis-scripts/prepare-trusty.sh +16 -0
- metadata +242 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 996f52ab508d2c26e7fc291462f8758b0dd30db32415f657cc050b89cacc272e
|
4
|
+
data.tar.gz: 20138f2fd23c49133d839fa0963c1c0920f4525eee31d8d39a62d1afebeec1ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 287af23b98733a8b8411e8ec85eccdd5b797f74189fd2e88aabc34fb98d997c74f52e163a7eee54611c5de7b67ea124f297b2697fd4e90f3b6c62728ab869428
|
7
|
+
data.tar.gz: 0d73408994a10d1d8906308faf8f5d19995e7d2cd759abe1c520c7aa1577812a55b8490a6a727afe426d7c47837fa77fd47b760b2b53b5f2f5be40bd643185f8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
dist: trusty
|
3
|
+
sudo: required
|
4
|
+
language: ruby
|
5
|
+
cache:
|
6
|
+
bundler: true
|
7
|
+
directories:
|
8
|
+
- $HOME/.opam
|
9
|
+
- liquidity
|
10
|
+
rvm:
|
11
|
+
- 2.5.1
|
12
|
+
env:
|
13
|
+
- OPAMYES=1
|
14
|
+
before_install:
|
15
|
+
- sh travis-scripts/prepare-trusty.sh
|
16
|
+
- sh travis-scripts/install-opam.sh
|
17
|
+
- sh travis-scripts/install-liquidity.sh
|
18
|
+
- gem install bundler -v 1.16.3
|
19
|
+
script:
|
20
|
+
- eval $(opam config env)
|
21
|
+
- bundle exec rake
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tezos_client (0.2.0)
|
5
|
+
activesupport (~> 5.2.0)
|
6
|
+
base58 (~> 0.2.3)
|
7
|
+
httparty (~> 0.16.2)
|
8
|
+
rbnacl (~> 5.0.0)
|
9
|
+
rest-client (~> 2.0.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actionpack (5.2.1)
|
15
|
+
actionview (= 5.2.1)
|
16
|
+
activesupport (= 5.2.1)
|
17
|
+
rack (~> 2.0)
|
18
|
+
rack-test (>= 0.6.3)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
21
|
+
actionview (5.2.1)
|
22
|
+
activesupport (= 5.2.1)
|
23
|
+
builder (~> 3.1)
|
24
|
+
erubi (~> 1.4)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
27
|
+
activesupport (5.2.1)
|
28
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
|
+
i18n (>= 0.7, < 2)
|
30
|
+
minitest (~> 5.1)
|
31
|
+
tzinfo (~> 1.1)
|
32
|
+
addressable (2.5.2)
|
33
|
+
public_suffix (>= 2.0.2, < 4.0)
|
34
|
+
ast (2.4.0)
|
35
|
+
base58 (0.2.3)
|
36
|
+
builder (3.2.3)
|
37
|
+
concurrent-ruby (1.0.5)
|
38
|
+
crack (0.4.3)
|
39
|
+
safe_yaml (~> 1.0.0)
|
40
|
+
crass (1.0.4)
|
41
|
+
diff-lcs (1.3)
|
42
|
+
domain_name (0.5.20180417)
|
43
|
+
unf (>= 0.0.5, < 1.0.0)
|
44
|
+
erubi (1.7.1)
|
45
|
+
ffi (1.9.25)
|
46
|
+
hashdiff (0.3.7)
|
47
|
+
http-cookie (1.0.3)
|
48
|
+
domain_name (~> 0.5)
|
49
|
+
httparty (0.16.2)
|
50
|
+
multi_xml (>= 0.5.2)
|
51
|
+
i18n (1.1.0)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
jaro_winkler (1.5.1)
|
54
|
+
loofah (2.2.2)
|
55
|
+
crass (~> 1.0.2)
|
56
|
+
nokogiri (>= 1.5.9)
|
57
|
+
method_source (0.9.0)
|
58
|
+
mime-types (3.2.2)
|
59
|
+
mime-types-data (~> 3.2015)
|
60
|
+
mime-types-data (3.2018.0812)
|
61
|
+
mini_portile2 (2.3.0)
|
62
|
+
minitest (5.11.3)
|
63
|
+
multi_xml (0.6.0)
|
64
|
+
netrc (0.11.0)
|
65
|
+
nokogiri (1.8.4)
|
66
|
+
mini_portile2 (~> 2.3.0)
|
67
|
+
parallel (1.12.1)
|
68
|
+
parser (2.5.1.2)
|
69
|
+
ast (~> 2.4.0)
|
70
|
+
powerpack (0.1.2)
|
71
|
+
public_suffix (3.0.3)
|
72
|
+
rack (2.0.5)
|
73
|
+
rack-test (1.1.0)
|
74
|
+
rack (>= 1.0, < 3)
|
75
|
+
rails-dom-testing (2.0.3)
|
76
|
+
activesupport (>= 4.2.0)
|
77
|
+
nokogiri (>= 1.6)
|
78
|
+
rails-html-sanitizer (1.0.4)
|
79
|
+
loofah (~> 2.2, >= 2.2.2)
|
80
|
+
railties (5.2.1)
|
81
|
+
actionpack (= 5.2.1)
|
82
|
+
activesupport (= 5.2.1)
|
83
|
+
method_source
|
84
|
+
rake (>= 0.8.7)
|
85
|
+
thor (>= 0.19.0, < 2.0)
|
86
|
+
rainbow (3.0.0)
|
87
|
+
rake (10.5.0)
|
88
|
+
rbnacl (5.0.0)
|
89
|
+
ffi
|
90
|
+
rest-client (2.0.2)
|
91
|
+
http-cookie (>= 1.0.2, < 2.0)
|
92
|
+
mime-types (>= 1.16, < 4.0)
|
93
|
+
netrc (~> 0.8)
|
94
|
+
rspec (3.7.0)
|
95
|
+
rspec-core (~> 3.7.0)
|
96
|
+
rspec-expectations (~> 3.7.0)
|
97
|
+
rspec-mocks (~> 3.7.0)
|
98
|
+
rspec-core (3.7.1)
|
99
|
+
rspec-support (~> 3.7.0)
|
100
|
+
rspec-expectations (3.7.0)
|
101
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
102
|
+
rspec-support (~> 3.7.0)
|
103
|
+
rspec-mocks (3.7.0)
|
104
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
105
|
+
rspec-support (~> 3.7.0)
|
106
|
+
rspec-support (3.7.1)
|
107
|
+
rubocop (0.58.2)
|
108
|
+
jaro_winkler (~> 1.5.1)
|
109
|
+
parallel (~> 1.10)
|
110
|
+
parser (>= 2.5, != 2.5.1.1)
|
111
|
+
powerpack (~> 0.1)
|
112
|
+
rainbow (>= 2.2.2, < 4.0)
|
113
|
+
ruby-progressbar (~> 1.7)
|
114
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
115
|
+
rubocop-rails_config (0.2.3)
|
116
|
+
railties (>= 3.0)
|
117
|
+
rubocop (~> 0.56)
|
118
|
+
ruby-progressbar (1.10.0)
|
119
|
+
safe_yaml (1.0.4)
|
120
|
+
thor (0.20.0)
|
121
|
+
thread_safe (0.3.6)
|
122
|
+
tzinfo (1.2.5)
|
123
|
+
thread_safe (~> 0.1)
|
124
|
+
unf (0.1.4)
|
125
|
+
unf_ext
|
126
|
+
unf_ext (0.0.7.5)
|
127
|
+
unicode-display_width (1.4.0)
|
128
|
+
vcr (4.0.0)
|
129
|
+
webmock (3.4.2)
|
130
|
+
addressable (>= 2.3.6)
|
131
|
+
crack (>= 0.3.2)
|
132
|
+
hashdiff
|
133
|
+
|
134
|
+
PLATFORMS
|
135
|
+
ruby
|
136
|
+
|
137
|
+
DEPENDENCIES
|
138
|
+
bundler (~> 1.16)
|
139
|
+
rake (~> 10.0)
|
140
|
+
rspec (~> 3.0)
|
141
|
+
rubocop-rails_config
|
142
|
+
tezos_client!
|
143
|
+
vcr (~> 4.0.0)
|
144
|
+
webmock
|
145
|
+
|
146
|
+
BUNDLED WITH
|
147
|
+
1.16.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# TezosClient
|
2
|
+
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/54ab3bbbdc10c1faf933/maintainability)](https://codeclimate.com/github/moneytrackio/tezos_client/maintainability)
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/moneytrackio/tezos_client.svg?branch=master)](https://travis-ci.org/moneytrackio/tezos_client)
|
6
|
+
|
7
|
+
Tezos Client interracts with tezos nodes using RPC commands.
|
8
|
+
|
9
|
+
## Requirements:
|
10
|
+
Tezos client requires liquidity to be installed in order to work properly.
|
11
|
+
For installing on linux, you can basically follow the steps coded in travis-script folder.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'tezos_client'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install tezos_client
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Transfer funds
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = TezosClient.new
|
35
|
+
|
36
|
+
client.transfer(
|
37
|
+
amount: 1,
|
38
|
+
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
|
39
|
+
to: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
|
40
|
+
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
|
41
|
+
)
|
42
|
+
```
|
43
|
+
|
44
|
+
### Call a contract
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client = TezosClient.new
|
48
|
+
client.transfer(
|
49
|
+
amount: 5,
|
50
|
+
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
|
51
|
+
to: "KT1MZTrMDPB42P9yvjf7Cy8Lkjxjj4jetbCt",
|
52
|
+
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
|
53
|
+
parameters: '"pro"'
|
54
|
+
)
|
55
|
+
```
|
56
|
+
|
57
|
+
### Originate a contract written in liquidity
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
script = File.expand_path("./spec/fixtures/demo.liq")
|
61
|
+
source = "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq"
|
62
|
+
secret_key = "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
|
63
|
+
amount = 0
|
64
|
+
init_params = '"test"'
|
65
|
+
client = TezosClient.new
|
66
|
+
|
67
|
+
res = client.originate_contract(
|
68
|
+
from: source,
|
69
|
+
amount: amount,
|
70
|
+
script: script,
|
71
|
+
secret_key: secret_key,
|
72
|
+
init_params: init_params
|
73
|
+
)
|
74
|
+
|
75
|
+
puts "Origination operation: #{res[:operation_id]}"
|
76
|
+
puts "Contract address: #{res[:originated_contract]}"
|
77
|
+
```
|
78
|
+
|
79
|
+
### Call a contract written in liquidity
|
80
|
+
```ruby
|
81
|
+
TezosClient.new.call_contract(
|
82
|
+
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
|
83
|
+
amount: 0,
|
84
|
+
script: File.expand_path("./spec/fixtures/demo.liq"),
|
85
|
+
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
|
86
|
+
to: "KT1STzq9p2tfW3K4RdoM9iYd1htJ4QcJ8Njs",
|
87
|
+
parameters: [ "manage", "(Some { destination = tz1YLtLqD1fWHthSVHPD116oYvsd4PTAHUoc; amount = 1tz })" ]
|
88
|
+
)
|
89
|
+
```
|
90
|
+
|
91
|
+
## Development
|
92
|
+
|
93
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
94
|
+
|
95
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tezos_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
104
|
+
|
105
|
+
## Code of Conduct
|
106
|
+
|
107
|
+
Everyone interacting in the TezosClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tezos_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "tezos_client"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class ClientInterface
|
5
|
+
# Commands managing keys and accounts
|
6
|
+
module BlockContextual
|
7
|
+
def transfer(quantity:, from:, to:, dry_run: false, arg: nil)
|
8
|
+
cmd = "transfer #{quantity} from #{from} to #{to}"
|
9
|
+
cmd = "#{cmd} --dry-run" if dry_run
|
10
|
+
cmd = "#{cmd} --arg #{arg}" unless arg.nil?
|
11
|
+
|
12
|
+
res = call_client(cmd)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class ClientInterface
|
5
|
+
# Wrapper used to call the tezos-client binary
|
6
|
+
module ClientWrapper
|
7
|
+
def call_client(command)
|
8
|
+
cmd = "#{client_cmd} #{command}"
|
9
|
+
Open3.popen3(cmd) do |_stdin, stdout, stderr, wait_thr|
|
10
|
+
err = stderr.read
|
11
|
+
status = wait_thr.value.exitstatus
|
12
|
+
|
13
|
+
if status != 0
|
14
|
+
raise "command '#{cmd}' existed with status #{status}: #{err}"
|
15
|
+
end
|
16
|
+
|
17
|
+
log err
|
18
|
+
output = stdout.read
|
19
|
+
|
20
|
+
if block_given?
|
21
|
+
yield(output)
|
22
|
+
else
|
23
|
+
output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def client_cmd
|
29
|
+
res = "tezos-client -l"
|
30
|
+
if config_file
|
31
|
+
res = "#{res} -c #{config_file}"
|
32
|
+
end
|
33
|
+
res
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class ClientInterface
|
5
|
+
# Commands managing keys and accounts
|
6
|
+
module Contract
|
7
|
+
def known_contracts
|
8
|
+
res = call_client("list known contracts")
|
9
|
+
res.lines.reduce({}) do |acc, contract_output|
|
10
|
+
address_format = /([^:]+): (\w+)/
|
11
|
+
res = address_format.match(contract_output)
|
12
|
+
acc.merge(res[1] => res[2])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class ClientInterface
|
5
|
+
# Commands managing keys and accounts
|
6
|
+
module Key
|
7
|
+
def gen_keys(name)
|
8
|
+
call_client("gen keys #{name}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def addresses
|
12
|
+
output = call_client("list known addresses")
|
13
|
+
output.lines.reduce({}) do |acc, address_output|
|
14
|
+
address_format = /([^:]+): (\w+) /
|
15
|
+
res = address_format.match(address_output)
|
16
|
+
acc.merge(res[1] => res[2])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def import_public_key(name, public_key, force: false)
|
21
|
+
cmd = "import public key #{name} #{public_key}"
|
22
|
+
cmd = "#{cmd} --force" if force
|
23
|
+
|
24
|
+
call_client(cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
def import_secret_key(name, secret_key, force: false)
|
28
|
+
cmd = "import secret key #{name} #{secret_key}"
|
29
|
+
cmd = "#{cmd} --force" if force
|
30
|
+
|
31
|
+
call_client(cmd)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "date"
|
5
|
+
|
6
|
+
class TezosClient
|
7
|
+
class ClientInterface
|
8
|
+
module Misc
|
9
|
+
def bootstrapped
|
10
|
+
call_client("bootstrapped") do |output|
|
11
|
+
output_format = /Current head: ([^ ]+) \(timestamp: ([^,]+), validation: (.+)\)/
|
12
|
+
res = output_format.match(output)
|
13
|
+
head = res[1]
|
14
|
+
timestamp = DateTime.parse(res[2])
|
15
|
+
validation = DateTime.parse(res[3])
|
16
|
+
|
17
|
+
{
|
18
|
+
"block" => head,
|
19
|
+
"timestamp" => timestamp,
|
20
|
+
"validated_at" => validation
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "client_interface/client_wrapper"
|
4
|
+
require_relative "client_interface/misc"
|
5
|
+
require_relative "client_interface/key"
|
6
|
+
require_relative "client_interface/contract"
|
7
|
+
require_relative "client_interface/block_contextual"
|
8
|
+
|
9
|
+
class TezosClient
|
10
|
+
class ClientInterface
|
11
|
+
attr_reader :config_file
|
12
|
+
|
13
|
+
include Logger
|
14
|
+
|
15
|
+
include ClientWrapper
|
16
|
+
include Misc
|
17
|
+
include Key
|
18
|
+
include Contract
|
19
|
+
include BlockContextual
|
20
|
+
|
21
|
+
def initialize(config_file: nil)
|
22
|
+
@config_file = config_file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
class TezosClient
|
6
|
+
module Commands
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :rpc_interface,
|
10
|
+
:bootstrapped,
|
11
|
+
:monitor_block,
|
12
|
+
:head_hash,
|
13
|
+
:contract_counter,
|
14
|
+
:block_header,
|
15
|
+
:block_operations,
|
16
|
+
:block_operation_hashes,
|
17
|
+
:blocks,
|
18
|
+
:balance
|
19
|
+
|
20
|
+
def_delegators :client_interface,
|
21
|
+
:gen_keys,
|
22
|
+
:addresses,
|
23
|
+
:import_public_key,
|
24
|
+
:import_secret_key,
|
25
|
+
:known_contracts,
|
26
|
+
:transfer
|
27
|
+
end
|
28
|
+
end
|