beowulf-ruby-testnet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +204 -0
- data/Rakefile +52 -0
- data/beowulf.gemspec +43 -0
- data/lib/beowulf.rb +35 -0
- data/lib/beowulf/account_history_api.rb +15 -0
- data/lib/beowulf/api.rb +845 -0
- data/lib/beowulf/base_error.rb +21 -0
- data/lib/beowulf/block_api.rb +14 -0
- data/lib/beowulf/broadcast_operations.json +74 -0
- data/lib/beowulf/chain_config.rb +15 -0
- data/lib/beowulf/condenser_api.rb +48 -0
- data/lib/beowulf/database_api.rb +5 -0
- data/lib/beowulf/error_parser.rb +228 -0
- data/lib/beowulf/logger.rb +20 -0
- data/lib/beowulf/methods.json +129 -0
- data/lib/beowulf/network_broadcast_api.rb +7 -0
- data/lib/beowulf/operation.rb +99 -0
- data/lib/beowulf/operation_ids.rb +33 -0
- data/lib/beowulf/operation_types.rb +31 -0
- data/lib/beowulf/transaction.rb +320 -0
- data/lib/beowulf/type/amount.rb +23 -0
- data/lib/beowulf/type/array.rb +17 -0
- data/lib/beowulf/type/authority.rb +48 -0
- data/lib/beowulf/type/authority_update.rb +50 -0
- data/lib/beowulf/type/future.rb +16 -0
- data/lib/beowulf/type/hash.rb +17 -0
- data/lib/beowulf/type/permission.rb +17 -0
- data/lib/beowulf/type/point_in_time.rb +17 -0
- data/lib/beowulf/type/public_key.rb +18 -0
- data/lib/beowulf/type/serializer.rb +12 -0
- data/lib/beowulf/type/u_int16.rb +17 -0
- data/lib/beowulf/type/u_int32.rb +17 -0
- data/lib/beowulf/utils.rb +221 -0
- data/lib/beowulf/version.rb +4 -0
- data/lib/beowulf/wallet.rb +212 -0
- metadata +463 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa825486188eacb7d78874e1df62ddc66ea95fc0b34c9afef73957d991e34896
|
4
|
+
data.tar.gz: 521d4eabe5ec1d841b94ada6acd8d74779981357e710182a1892449a8e0d3c11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a87dfef370a330650476c3fd5b03d9fe2b89162fff816c5605598f65572f98c845fd0d054e22e91f07adc82d8748f19389e5f10cde87b95ab3e5f8a2e551190
|
7
|
+
data.tar.gz: 10bee63887ef219c547978d7cf2b22062ad02b804b25b43fb8d24b320607d17030264a4f0bf4687303ff1ee583640faef8d7e122f33a5c114dc6e5c1bf3b22fb
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
hashie.log
|
55
|
+
output.mp4
|
56
|
+
|
57
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
58
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 beowulf-foundation
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# beowulf-ruby
|
2
|
+
|
3
|
+
beowulf-ruby is the official Beowulf library for Ruby.
|
4
|
+
|
5
|
+
### Quick Start
|
6
|
+
|
7
|
+
Add the gem to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# MainNet
|
11
|
+
gem 'beowulf-ruby'
|
12
|
+
|
13
|
+
# TestNet
|
14
|
+
gem 'beowulf-ruby-testnet'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
If you don't have `bundler`, see the next section.
|
24
|
+
|
25
|
+
### Prerequisites
|
26
|
+
|
27
|
+
`minimum ruby version: 2.2`
|
28
|
+
|
29
|
+
#### Linux
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
|
33
|
+
$ gem install bundler
|
34
|
+
```
|
35
|
+
|
36
|
+
#### macOS
|
37
|
+
|
38
|
+
```
|
39
|
+
$ gem install bundler
|
40
|
+
```
|
41
|
+
|
42
|
+
### Usage
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'beowulf'
|
46
|
+
|
47
|
+
api = Beowulf::Api.new
|
48
|
+
api.get_dynamic_global_properties do |properties|
|
49
|
+
properties.head_block_number
|
50
|
+
end
|
51
|
+
=> 2307597
|
52
|
+
```
|
53
|
+
|
54
|
+
... or ...
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'beowulf'
|
58
|
+
|
59
|
+
api = Beowulf::Api.new
|
60
|
+
response = api.get_dynamic_global_properties
|
61
|
+
response.result.head_block_number
|
62
|
+
=> 2307597
|
63
|
+
```
|
64
|
+
|
65
|
+
### Example
|
66
|
+
```ruby
|
67
|
+
require 'beowulf'
|
68
|
+
|
69
|
+
# 0. Init
|
70
|
+
## MainNet: https://bw.beowulfchain.com/rpc
|
71
|
+
## TestNet: https://testnet-bw.beowulfchain.com/rpc
|
72
|
+
api = Beowulf::Api.new(url: 'http://localhost:8376/rpc') # Replace this url with your node url
|
73
|
+
|
74
|
+
# 1. get_version
|
75
|
+
version = api.get_version
|
76
|
+
puts version.to_json
|
77
|
+
|
78
|
+
# 2. get_block
|
79
|
+
bk = api.get_blocks(1)
|
80
|
+
puts bk.to_json
|
81
|
+
|
82
|
+
# 3. get_config
|
83
|
+
cfg = api.get_config
|
84
|
+
puts cfg.to_json
|
85
|
+
puts cfg.result.BEOWULF_INIT_SUPPLY
|
86
|
+
|
87
|
+
# 4. get_accounts
|
88
|
+
acc = api.get_accounts(["beowulf2", "beowulf3"])
|
89
|
+
puts acc.to_json
|
90
|
+
|
91
|
+
# 5. get_transaction
|
92
|
+
gtx = api.get_transaction("e725f75544dbeea7a017250bd0186ca247b24724")
|
93
|
+
puts gtx.to_json
|
94
|
+
|
95
|
+
# 6. Transfer native coin
|
96
|
+
## 6.1. Transfer BWF from alice to bob
|
97
|
+
tx = Beowulf::Transaction.new(url: 'https://testnet-bw.beowulfchain.com/rpc', wif: 'alice Private-Key Here')
|
98
|
+
transfer = {
|
99
|
+
type: :transfer,
|
100
|
+
from: 'alice',
|
101
|
+
to: 'bob',
|
102
|
+
amount: '100.00000 BWF',
|
103
|
+
fee: '0.01000 W',
|
104
|
+
memo: 'alice to bob'
|
105
|
+
}
|
106
|
+
tx.operations << transfer
|
107
|
+
tx_resp = tx.process(true)
|
108
|
+
puts tx_resp.to_json
|
109
|
+
puts "tx_resp.result.id:", tx_resp.result.id
|
110
|
+
|
111
|
+
## 6.2. Transfer W from alice to bob
|
112
|
+
tx = Beowulf::Transaction.new(url: 'https://testnet-bw.beowulfchain.com/rpc', wif: 'alice Private-Key Here')
|
113
|
+
transfer = {
|
114
|
+
type: :transfer,
|
115
|
+
from: 'alice',
|
116
|
+
to: 'bob',
|
117
|
+
amount: '1.00000 W',
|
118
|
+
fee: '0.01000 W',
|
119
|
+
memo: 'alice to bob'
|
120
|
+
}
|
121
|
+
tx.operations << transfer
|
122
|
+
tx_resp = tx.process(true)
|
123
|
+
puts tx_resp.to_json
|
124
|
+
puts "tx_resp.result.id:", tx_resp.result.id
|
125
|
+
|
126
|
+
# 7. Transfer token
|
127
|
+
## Transfer token KNOW from alice to bob
|
128
|
+
tx = Beowulf::Transaction.new(url: 'https://testnet-bw.beowulfchain.com/rpc', wif: 'alice Private-Key Here')
|
129
|
+
transfer = {
|
130
|
+
type: :transfer,
|
131
|
+
from: 'alice',
|
132
|
+
to: 'bob',
|
133
|
+
amount: '100.00000 KNOW',
|
134
|
+
fee: '0.01000 W',
|
135
|
+
memo: 'alice to bob'
|
136
|
+
}
|
137
|
+
tx.operations << transfer
|
138
|
+
tx_resp = tx.process(true)
|
139
|
+
puts tx_resp.to_json
|
140
|
+
puts "tx_resp.result.id:", tx_resp.result.id
|
141
|
+
|
142
|
+
|
143
|
+
# 8. Create account
|
144
|
+
## 8.1. GenKeys
|
145
|
+
wl = Beowulf::Wallet.new(name: "new-account-name")
|
146
|
+
wl.gen_keys
|
147
|
+
puts "wl.private_key:", wl.private_key
|
148
|
+
puts "wl.public_key:", wl.public_key
|
149
|
+
|
150
|
+
## 8.2. AccountCreate
|
151
|
+
tx = Beowulf::Transaction.new(url: 'https://testnet-bw.beowulfchain.com/rpc', wif: 'creator Private-Key Here')
|
152
|
+
owner = {
|
153
|
+
weight_threshold: 1,
|
154
|
+
account_auths: [],
|
155
|
+
key_auths: [[wl.public_key, 1]]
|
156
|
+
}
|
157
|
+
account_create = {
|
158
|
+
type: :account_create,
|
159
|
+
fee: '0.10000 W',
|
160
|
+
creator: 'creator',
|
161
|
+
new_account_name: wl.name,
|
162
|
+
owner: owner,
|
163
|
+
json_metadata: ''
|
164
|
+
}
|
165
|
+
tx.operations << account_create
|
166
|
+
tx_resp = tx.process(true)
|
167
|
+
puts "tx_resp:", tx_resp.to_json
|
168
|
+
puts "tx_resp.result.id:", tx_resp.result.id
|
169
|
+
|
170
|
+
## 8.3. Write file wallet.
|
171
|
+
wallet_path = "/path/to/folder/save/wallet"
|
172
|
+
password = "your_password"
|
173
|
+
wl.save_wallet_file(wallet_path, "", password)
|
174
|
+
|
175
|
+
## 8.4. Load file wallet.
|
176
|
+
sleep(2)
|
177
|
+
wallet_path_file = File.join(wallet_path, "new-account-name-wallet.json")
|
178
|
+
wl2 = Beowulf::Wallet.new
|
179
|
+
wl2.read_wallet_file(wallet_path_file, password)
|
180
|
+
puts "wl2.private_key:", wl2.private_key
|
181
|
+
puts "wl2.public_key:", wl2.public_key
|
182
|
+
```
|
183
|
+
|
184
|
+
|
185
|
+
## Failover
|
186
|
+
|
187
|
+
Beowulf supports failover for situations where a node has, for example, become unresponsive. When creating a new instance of `::Api` and `::Transaction`, you may provide a list of alternative nodes, or leave them out to use the default list. For example:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
options = {
|
191
|
+
url: 'https://api.yournodedomain.com',
|
192
|
+
failover_urls: [
|
193
|
+
'https://api.otherdomain1.com',
|
194
|
+
'https://api.otherdomain2.com'
|
195
|
+
]
|
196
|
+
}
|
197
|
+
|
198
|
+
api = Beowulf::Api.new(options)
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
## License
|
203
|
+
|
204
|
+
MIT, see the `LICENSE` file.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'yard'
|
4
|
+
require 'beowulf'
|
5
|
+
require 'awesome_print'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'test'
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
|
+
t.ruby_opts << if ENV['HELL_ENABLED']
|
12
|
+
'-W2'
|
13
|
+
else
|
14
|
+
'-W1'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
YARD::Rake::YardocTask.new do |t|
|
19
|
+
t.files = ['lib/**/*.rb']
|
20
|
+
end
|
21
|
+
|
22
|
+
task default: :test
|
23
|
+
|
24
|
+
namespace :clean do
|
25
|
+
desc 'Deletes test/fixtures/vcr_cassettes/*.yml so they can be rebuilt fresh.'
|
26
|
+
task :vcr do |t|
|
27
|
+
exec 'rm -v test/fixtures/vcr_cassettes/*.yml'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Ruby console with beowulf already required.'
|
32
|
+
task :console do
|
33
|
+
exec "irb -r beowulf -I ./lib"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Build a new version of the beowulf gem.'
|
37
|
+
task :build do
|
38
|
+
exec 'gem build beowulf.gemspec'
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Publish the current version of the beowulf gem.'
|
42
|
+
task :push do
|
43
|
+
exec "gem push beowulf-ruby-#{Beowulf::VERSION}.gem"
|
44
|
+
end
|
45
|
+
|
46
|
+
# We're not going to yank on a regular basis, but this is how it's done if you
|
47
|
+
# really want a task for that for some reason.
|
48
|
+
|
49
|
+
# desc 'Yank the current version of the beowulf gem.'
|
50
|
+
# task :yank do
|
51
|
+
# exec "gem yank beowulf -v #{Beowulf::VERSION}"
|
52
|
+
# end
|
data/beowulf.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'beowulf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'beowulf-ruby-testnet'
|
8
|
+
spec.version = Beowulf::VERSION
|
9
|
+
spec.authors = ['NghiaTC']
|
10
|
+
spec.email = ['contact@beowulfchain.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Beowulf RPC Ruby Client}
|
13
|
+
spec.description = %q{Beowulf-ruby is the official Beowulf library for Ruby.}
|
14
|
+
spec.homepage = 'https://github.com/beowulf-foundation/beowulf-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
|
21
|
+
spec.add_development_dependency 'rake', '~> 12.1', '>= 12.1.0'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
|
23
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6.3'
|
24
|
+
spec.add_development_dependency 'minitest-proveit', '~> 1.0', '>= 1.0.0'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 3.6', '>= 3.6.0'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.17.0'
|
27
|
+
spec.add_development_dependency 'vcr', '~> 5.0', '>= 5.0.0'
|
28
|
+
spec.add_development_dependency 'yard', '~> 0.9.20'
|
29
|
+
spec.add_development_dependency 'pry', '~> 0.11', '>= 0.11.3'
|
30
|
+
spec.add_development_dependency 'rb-readline', '~> 0.5', '>= 0.5.5'
|
31
|
+
spec.add_development_dependency 'irb', '~> 1.0', '>= 1.0.0'
|
32
|
+
|
33
|
+
# net-http-persistent has an open-ended dependency because beowulf directly
|
34
|
+
# supports net-http-persistent-3.0.0 as well as net-http-persistent-2.5.2.
|
35
|
+
spec.add_dependency('net-http-persistent', '~> 2.5', '>= 2.5.2')
|
36
|
+
spec.add_dependency('json', '~> 2.0', '>= 2.0.2')
|
37
|
+
spec.add_dependency('logging', '~> 2.2', '>= 2.2.0')
|
38
|
+
spec.add_dependency('hashie', '~> 3.5', '>= 3.5.5')
|
39
|
+
spec.add_dependency('bitcoin-ruby', '~> 0.0', '>= 0.0.11')
|
40
|
+
spec.add_dependency('ffi', '~> 1.9', '>= 1.9.18')
|
41
|
+
spec.add_dependency('awesome_print', '~> 1.7', '>= 1.7.0')
|
42
|
+
spec.add_dependency 'base58', '~> 0.2', '>= 0.2.3'
|
43
|
+
end
|
data/lib/beowulf.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'beowulf/version'
|
2
|
+
require 'json'
|
3
|
+
require 'awesome_print' if ENV['USE_AWESOME_PRINT'] == 'true'
|
4
|
+
|
5
|
+
module Beowulf
|
6
|
+
require 'beowulf/utils'
|
7
|
+
require 'beowulf/type/serializer'
|
8
|
+
require 'beowulf/type/amount'
|
9
|
+
require 'beowulf/type/u_int16'
|
10
|
+
require 'beowulf/type/u_int32'
|
11
|
+
require 'beowulf/type/point_in_time'
|
12
|
+
require 'beowulf/type/permission'
|
13
|
+
require 'beowulf/type/public_key'
|
14
|
+
require 'beowulf/type/array'
|
15
|
+
require 'beowulf/type/hash'
|
16
|
+
require 'beowulf/type/future'
|
17
|
+
require 'beowulf/type/authority'
|
18
|
+
require 'beowulf/type/authority_update'
|
19
|
+
require 'beowulf/logger'
|
20
|
+
require 'beowulf/chain_config'
|
21
|
+
require 'beowulf/api'
|
22
|
+
require 'beowulf/database_api'
|
23
|
+
require 'beowulf/network_broadcast_api'
|
24
|
+
require 'beowulf/account_history_api'
|
25
|
+
require 'beowulf/condenser_api'
|
26
|
+
require 'beowulf/block_api'
|
27
|
+
require 'beowulf/operation_ids'
|
28
|
+
require 'beowulf/operation_types'
|
29
|
+
require 'beowulf/operation'
|
30
|
+
require 'beowulf/transaction'
|
31
|
+
require 'beowulf/base_error'
|
32
|
+
require 'beowulf/error_parser'
|
33
|
+
require 'beowulf/wallet'
|
34
|
+
extend self
|
35
|
+
end
|