platon 0.2.7

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +18 -0
  3. data/.gitignore +15 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +10 -0
  6. data/Gemfile +12 -0
  7. data/Gemfile.lock +69 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +216 -0
  10. data/Rakefile +12 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/doc/zh-cn.md +1762 -0
  14. data/lib/bech32.rb +82 -0
  15. data/lib/platon.rb +77 -0
  16. data/lib/platon/abi.rb +32 -0
  17. data/lib/platon/address.rb +62 -0
  18. data/lib/platon/client.rb +175 -0
  19. data/lib/platon/contract.rb +351 -0
  20. data/lib/platon/contract_event.rb +24 -0
  21. data/lib/platon/contract_initializer.rb +54 -0
  22. data/lib/platon/decoder.rb +99 -0
  23. data/lib/platon/deployment.rb +49 -0
  24. data/lib/platon/encoder.rb +120 -0
  25. data/lib/platon/explorer_url_helper.rb +0 -0
  26. data/lib/platon/formatter.rb +142 -0
  27. data/lib/platon/function.rb +36 -0
  28. data/lib/platon/function_input.rb +13 -0
  29. data/lib/platon/function_output.rb +14 -0
  30. data/lib/platon/gas.rb +9 -0
  31. data/lib/platon/http_client.rb +55 -0
  32. data/lib/platon/initializer.rb +0 -0
  33. data/lib/platon/ipc_client.rb +45 -0
  34. data/lib/platon/key.rb +105 -0
  35. data/lib/platon/key/decrypter.rb +113 -0
  36. data/lib/platon/key/encrypter.rb +128 -0
  37. data/lib/platon/open_ssl.rb +267 -0
  38. data/lib/platon/ppos.rb +344 -0
  39. data/lib/platon/railtie.rb +0 -0
  40. data/lib/platon/secp256k1.rb +7 -0
  41. data/lib/platon/sedes.rb +40 -0
  42. data/lib/platon/segwit_addr.rb +66 -0
  43. data/lib/platon/singleton.rb +39 -0
  44. data/lib/platon/solidity.rb +40 -0
  45. data/lib/platon/transaction.rb +41 -0
  46. data/lib/platon/tx.rb +201 -0
  47. data/lib/platon/utils.rb +180 -0
  48. data/lib/platon/version.rb +5 -0
  49. data/lib/tasks/platon_contract.rake +27 -0
  50. data/platon-ruby-logo.png +0 -0
  51. data/platon.gemspec +50 -0
  52. metadata +235 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b21ae9984ff18a3127a41dcdf874b2faf09e0a5894ff76f6a1cb8c2f0bdabd4
4
+ data.tar.gz: 9e7fa8d362e19aa6a242c102dcf4ec9f26ca82d4766294e0e1bcb50c23cad4d8
5
+ SHA512:
6
+ metadata.gz: 47433d9c023943de1c279ce43628f127670085f48e5f01d5af85a002d129d680c8401ae29330e1a481cb2192e2540879f38f5757d7b589ed3a922d72c7f247d1
7
+ data.tar.gz: d24a4404809cb945d595d869d701fe6542065b352143174583cf00bf59e8a9cdae4fdc94b8623f21f3a956a1952eb40fb2774ae1321eaf8892463647d2e1c5a0
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.3.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.4
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ # /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ test.rb
14
+ *.gem
15
+ *.bak
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in platon.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ # gem "rubocop", "~> 0.80"
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ platon (0.2.6)
5
+ activesupport (>= 4.0)
6
+ digest-sha3 (~> 1.1)
7
+ ffi (~> 1.0)
8
+ money-tree (= 0.10.0)
9
+ rlp (= 0.7.3)
10
+ scrypt (~> 3.0.6)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (5.2.6)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.8)
22
+ diff-lcs (1.4.4)
23
+ digest-sha3 (1.1.0)
24
+ ffi (1.15.1)
25
+ ffi-compiler (1.0.1)
26
+ ffi (>= 1.0.0)
27
+ rake
28
+ i18n (1.8.10)
29
+ concurrent-ruby (~> 1.0)
30
+ method_source (1.0.0)
31
+ minitest (5.14.4)
32
+ money-tree (0.10.0)
33
+ ffi
34
+ pry (0.14.1)
35
+ coderay (~> 1.1)
36
+ method_source (~> 1.0)
37
+ rake (13.0.3)
38
+ rlp (0.7.3)
39
+ rspec (3.10.0)
40
+ rspec-core (~> 3.10.0)
41
+ rspec-expectations (~> 3.10.0)
42
+ rspec-mocks (~> 3.10.0)
43
+ rspec-core (3.10.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-expectations (3.10.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-mocks (3.10.2)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-support (3.10.2)
52
+ scrypt (3.0.7)
53
+ ffi-compiler (>= 1.0, < 2.0)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.9)
56
+ thread_safe (~> 0.1)
57
+
58
+ PLATFORMS
59
+ x86_64-darwin-18
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 2.0)
63
+ platon!
64
+ pry (~> 0.10)
65
+ rake (~> 13.0)
66
+ rspec (~> 3.0)
67
+
68
+ BUNDLED WITH
69
+ 2.2.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 vianull
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,216 @@
1
+ # Ruby SDK for Platon & Alaya
2
+
3
+
4
+
5
+ <p align="center">
6
+ <img src="./platon-ruby-logo.png" width="80" title="platon ruby SDK" alt="platon ruby SDK">
7
+ </p>
8
+
9
+
10
+ Gem "platon" helps to make interacting with platon&alaya blockchain from ruby .
11
+
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'platon'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install platon
28
+
29
+
30
+ ## Quick Start
31
+
32
+ ```
33
+ ## generate new key
34
+ key = Platon::Key.new
35
+
36
+ ## print bech32 address
37
+ puts key.bech32_address(hrp: "atp")
38
+
39
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
40
+
41
+ ## see current block number
42
+ client.platon_block_number
43
+
44
+ ## transfer 0.01 ATP to others
45
+ client.transfer key,"atpxxxxxxxxxxxxxxx",10**16
46
+
47
+ ```
48
+
49
+
50
+ ## Usage
51
+
52
+ #### Keys
53
+
54
+ Create a new public/private key and get its address
55
+
56
+ ```
57
+ key = Platon::Key.new
58
+ key.private_hex ## private key
59
+ => "08bb093d6184cb06a3f80507953ba6768c03d8114a429b0ec7875bb6b6e1a8a6"
60
+
61
+ key.public_hex ## public key
62
+ => "04641129e66399310ce4a41098d3b3fc4d722edf423dfdc0a76eba5d6e2155bbe611ee2a5c06011ab76040ca53b9ead4c5061d8cc8a89afa3f45af5830661d4b34"
63
+
64
+ key.bech32_address ## bech32 address ,default "atp"
65
+ => "atp1ls87d3mqfhxadjsmn0ns844tj8ljlsq89k95cn"
66
+
67
+ key.bech32_address(hrp: "lat")
68
+ => "lat1ls87d3mqfhxadjsmn0ns844tj8ljlsq8uqnv8u"
69
+
70
+ key.address ## EIP55 checksummed address
71
+ => "0xFc0Fe6c7604dcDd6ca1B9be703D6AB91fF2fC007"
72
+ ```
73
+
74
+ Encrypt keys to json file
75
+
76
+ ```
77
+ encrypted_key_info = Platon::Key.encrypt key,"your_password"
78
+
79
+ ## or save to location
80
+
81
+ Platon::Key.encrypt_and_save key,"your_password",'./some/path.json'
82
+
83
+ ## or default: ~/.platon/keystore
84
+
85
+ Platon::Key.encrypt_and_save key,"your_password"
86
+
87
+ ```
88
+
89
+ Decrypt keys from json file
90
+
91
+ ```
92
+ decrypted_key = Platon::Key.decrypt encrypted_key_info,"your_password"
93
+
94
+ or
95
+
96
+ decrypted_key = Platon::Key.decrypt File.read('./some/path.json'), 'your_password'
97
+ ```
98
+
99
+ #### Transactions
100
+
101
+ Build a transcation :
102
+
103
+ ```
104
+ args = {
105
+ from: key.address,
106
+ to: key2.address,
107
+ value: 1_000_000_000_000,
108
+ data: hex_data,
109
+ nonce: 1,
110
+ gas_limit: 21_000,
111
+ gas_price: 10_000_000_000,
112
+ chain_id: chain_id
113
+ }
114
+ tx = Platon::Tx.new args
115
+ ```
116
+
117
+ Or decode from an encoded raw transaction
118
+
119
+ ```
120
+ tx = Platon::Tx.decode hex
121
+ ```
122
+
123
+ You can sign the transaction:
124
+
125
+ ```
126
+ tx.sign key
127
+ platon_send_raw_transaction(tx.hex)
128
+ ```
129
+
130
+ Get the raw transaction with `tx.hex`, and broadcast it through any PlatON node with `platon_send_raw_transaction` . Or just get the TXID with `tx.hash`
131
+
132
+ #### Client
133
+
134
+ By default methods interactiong with contracts&PPOS will use default JSON RPC Client that will handle connection to platon node.
135
+
136
+ ```
137
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
138
+ ```
139
+
140
+ Default setting:
141
+ ```
142
+ platondev: {hrp: "lat", chain_id: 210309}
143
+ alaya:{hrp:"atp",chain_id:201018}
144
+ alayadev:{hrp:"atp",chain_id: 201030}
145
+ ```
146
+
147
+ You can use `client.update_setting` to change chain configs:
148
+
149
+ ```
150
+ client.update_setting(hrp:"atx",chain_id: 1234)
151
+ ```
152
+
153
+ #### Contracts
154
+
155
+ You can get contract from blockchain. To do so you need a contract name ,contract address and ABI definition:
156
+
157
+ ```
158
+ contract = Platon::Contract.create(client: client ,name: "MyContract", address: "atpxxxx_your_bench32_address", abi: abi)
159
+ ```
160
+
161
+ Alternatively you can obtain abi definition and name from contract source file:
162
+ ```
163
+ contract = Platon::Contract.create(client: client , file: "MyContract.sol", address: "atpxxxx_your_bench32_address")
164
+ ```
165
+
166
+ Interacting with contracts:
167
+
168
+ You can `call` contract read-only method , no transaction will be sent to the network. If method changes contract state ,`transact` method can be used .
169
+
170
+ ```
171
+ contract.call.[function_name](params)
172
+
173
+ contract.transact.[function_name](params)
174
+
175
+ contract.transact_and_wait.[function_name](params)
176
+ ```
177
+
178
+ #### PPOS
179
+
180
+ All PPOS methods have been implemented. See [Docs](./doc/zh-cn.md)
181
+
182
+ #### Utils
183
+
184
+ ```
185
+ Platon::Utils.is_bech32_address?("atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425")
186
+ => true
187
+
188
+ Platon::Utils.decode_bech32_address "atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425"
189
+ => "0x5a771cd6b27365bcff18293b8e43cf7bb0b83c57"
190
+
191
+ Platon::Utils.to_bech32_address("atp","0x5a771cd6b27365bcff18293b8e43cf7bb0b83c57")
192
+ =>"atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425"
193
+
194
+ Platon::Formatter.new.to_von(0.5)
195
+ => 500000000000000000
196
+
197
+ Platon::Formatter.new.to_gvon(10)
198
+ => 10000000000
199
+
200
+ Platon::Formatter.new.from_von(500000000000000000)
201
+ => "0.5"
202
+ ```
203
+
204
+ ## Development
205
+
206
+ 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.
207
+
208
+ To install this gem onto your local machine, run `bundle exec rake install`.
209
+
210
+ ## Contributing
211
+
212
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vianull/client-sdk-ruby.
213
+
214
+ ## License
215
+
216
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ # import "./lib/tasks/platon_test.rake"
7
+ # import "./lib/tasks/platon_node.rake"
8
+ import "./lib/tasks/platon_contract.rake"
9
+ # import "./lib/tasks/platon_transaction.rake"
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
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 "platon"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/doc/zh-cn.md ADDED
@@ -0,0 +1,1762 @@
1
+
2
+
3
+ 本Gem是PlatON与Alaya的Ruby SDK ,通过对PlatON RPC接口的调用,实现了钱包管理、链信息查询及质押、委托奖励、治理、锁仓等模块,也可通过该SDK实现合约的部署、查询、调用等操作。
4
+
5
+ ## 安装
6
+
7
+ 在应用的 Gemfile 中添加如下一行:
8
+
9
+ ```ruby
10
+ gem 'platon'
11
+ ```
12
+
13
+ 然后执行:
14
+
15
+ $ bundle install
16
+
17
+ 或手动安装platon gem:
18
+
19
+ $ gem install platon
20
+
21
+
22
+ ## 快速入门示例
23
+
24
+ ```ruby
25
+ ## generate new key
26
+ key = Platon::Key.new
27
+
28
+ ## print bech32 address
29
+ puts key.bech32_address(hrp: "atp")
30
+
31
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
32
+
33
+ ## see current block number
34
+ client.platon_block_number
35
+
36
+ ## transfer 0.01 ATP to others
37
+ client.transfer key,"atpxxxxxxxxxxxxxxx",10**16
38
+
39
+ ```
40
+
41
+
42
+ ## 使用
43
+
44
+ #### Keys
45
+
46
+ 创建一组Key,获得其公钥、私钥、地址等
47
+
48
+ ```ruby
49
+ key = Platon::Key.new
50
+ key.private_hex ## private key
51
+ => "08bb093d6184cb06a3f80507953ba6768c03d8114a429b0ec7875bb6b6e1a8a6"
52
+
53
+ key.public_hex ## public key
54
+ => "04641129e66399310ce4a41098d3b3fc4d722edf423dfdc0a76eba5d6e2155bbe611ee2a5c06011ab76040ca53b9ead4c5061d8cc8a89afa3f45af5830661d4b34"
55
+
56
+ key.bech32_address ## bech32 address ,default "atp"
57
+ => "atp1ls87d3mqfhxadjsmn0ns844tj8ljlsq89k95cn"
58
+
59
+ key.bech32_address(hrp: "lat")
60
+ => "lat1ls87d3mqfhxadjsmn0ns844tj8ljlsq8uqnv8u"
61
+
62
+ key.address ## EIP55 checksummed address
63
+ => "0xFc0Fe6c7604dcDd6ca1B9be703D6AB91fF2fC007"
64
+ ```
65
+
66
+ 将key加密保存至json文件
67
+
68
+ ```ruby
69
+ encrypted_key_info = Platon::Key.encrypt key,"your_password"
70
+
71
+ ## or save to location
72
+
73
+ Platon::Key.encrypt_and_save key,"your_password",'./some/path.json'
74
+
75
+ ## or default: ~/.platon/keystore
76
+
77
+ Platon::Key.encrypt_and_save key,"your_password"
78
+
79
+ ```
80
+
81
+ 从json文件解密
82
+
83
+ ```ruby
84
+ decrypted_key = Platon::Key.decrypt encrypted_key_info,"your_password"
85
+
86
+ or
87
+
88
+ decrypted_key = Platon::Key.decrypt File.read('./some/path.json'), 'your_password'
89
+ ```
90
+
91
+ #### Client
92
+
93
+ 建立http client 用于Contract 与 PPOS 方法调用。需要传入 PlatON Node地址及指定网络
94
+
95
+ ```ruby
96
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
97
+ ```
98
+
99
+ 传入网络,会使用一下参数:
100
+ ```ruby
101
+ platondev: {hrp: "lat", chain_id: 210309}
102
+ alaya:{hrp:"atp",chain_id:201018}
103
+ alayadev:{hrp:"atp",chain_id: 201030}
104
+ ```
105
+
106
+ 你可以通过 `client.update_setting` 来自定义hrp及chain_id:
107
+
108
+ ```ruby
109
+ client.update_setting(hrp:"atx",chain_id: 1234)
110
+ ```
111
+
112
+ #### Transactions
113
+
114
+ 构建一笔交易 :
115
+
116
+ ```ruby
117
+ args = {
118
+ from: key.address,
119
+ to: key2.address,
120
+ value: 1_000_000_000_000,
121
+ data: hex_data,
122
+ nonce: 1,
123
+ gas_limit: 21_000,
124
+ gas_price: 10_000_000_000,
125
+ chain_id: chain_id
126
+ }
127
+ tx = Platon::Tx.new args
128
+ ```
129
+
130
+ 或者从raw transaction中进行解密
131
+
132
+ ```ruby
133
+ tx = Platon::Tx.decode hex
134
+ ```
135
+
136
+ 使用指定key进行签名及广播
137
+
138
+ ```ruby
139
+ tx.sign key
140
+ client.platon_send_raw_transaction(tx.hex)
141
+ ```
142
+
143
+ 通过 `tx.hex`查看交易的raw transaction, 通过 `platon_send_raw_transaction` 广播至区块链网络. 通过 `tx.hash` 可查看txid
144
+
145
+
146
+ #### Contracts
147
+
148
+ 可通过链上已部署合约来获得Contract实例,需要传入合约名、合约地址及abi文件
149
+
150
+ ```ruby
151
+ contract = Platon::Contract.create(client: client ,name: "MyContract", address: "atpxxxx_your_bench32_address", abi: abi)
152
+ ```
153
+
154
+ 或者可直接通过传入合约源代码获取Contract实例:
155
+
156
+ ```ruby
157
+ contract = Platon::Contract.create(client: client , file: "MyContract.sol", address: "atpxxxx_your_bench32_address")
158
+ ```
159
+
160
+ #### 合约调用
161
+
162
+
163
+
164
+ 对于合约的只读方法,使用 `call` 进行调用 , 该方法不会向链上发送任何transaction. 对于可能改变合约状态的方法,需要通过`transact` 或 `transact_and_wait` 进行调用 .
165
+
166
+ ```ruby
167
+ contract.call.[function_name](params)
168
+
169
+ contract.transact.[function_name](params)
170
+
171
+ contract.transact_and_wait.[function_name](params)
172
+ ```
173
+
174
+ #### PPOS
175
+
176
+ 我们实现了所有的系统合约PPOS的调用,详见下述文档。
177
+
178
+ #### Utils
179
+
180
+ ```ruby
181
+ Platon::Utils.is_bech32_address?("atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425")
182
+ => true
183
+
184
+ Platon::Utils.decode_bech32_address "atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425"
185
+ => "0x5a771cd6b27365bcff18293b8e43cf7bb0b83c57"
186
+
187
+ Platon::Utils.to_bech32_address("atp","0x5a771cd6b27365bcff18293b8e43cf7bb0b83c57")
188
+ =>"atp1tfm3e44jwdjmelcc9yacus700wcts0zhgw6425"
189
+
190
+ Platon::Formatter.new.to_von(0.5)
191
+ => 500000000000000000
192
+
193
+ Platon::Formatter.new.to_gvon(10)
194
+ => 10000000000
195
+
196
+ Platon::Formatter.new.from_von(500000000000000000)
197
+ => "0.5"
198
+ ```
199
+
200
+
201
+ ## 基础RPC接口
202
+ 基础API包括网络、交易、查询、节点信息、经济模型参数配置等相关的接口,具体说明如下。
203
+
204
+ ### web3_client_version
205
+ 返回当前客户端版本
206
+
207
+ * 参数:
208
+
209
+
210
+ * 返回值
211
+ `String`: 当前版本号
212
+ * 示例
213
+
214
+ ```ruby
215
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
216
+ client.web3_client_version
217
+ => "PlatONnetwork/alaya-node/v0.15.0-unstable-9867ee68/linux-amd64/go1.13.4"
218
+ ```
219
+
220
+ ### web3_sha3
221
+ 返回给定数据的keccak-256(并非标准sha3-256)
222
+
223
+ * 参数
224
+
225
+ `String`:待转换的哈希值
226
+ * 返回值
227
+ `String`:sha3计算结果
228
+
229
+ * 示例
230
+
231
+ ```ruby
232
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
233
+ client.web3_sha3("0x68656c6c6f20776f726c64")
234
+ => "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
235
+ ```
236
+
237
+ ### net_listening
238
+ 如果客户端正活跃监听网络链接,则返回true
239
+
240
+ * 参数
241
+
242
+ * 返回值
243
+ `Boolean`: 正在监听返回true,否则返回false
244
+ * 示例
245
+
246
+
247
+ ```ruby
248
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
249
+ client.net_listening
250
+ => true
251
+ ```
252
+
253
+ ### net_peer_count
254
+ 查看当前客户端所连接的节点数
255
+
256
+ * 参数
257
+
258
+ * 返回值
259
+ `Integer`: 返回当前客户端链接的节点数
260
+ * 示例
261
+
262
+ ```ruby
263
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
264
+ client.net_peer_count
265
+ => 24
266
+ ```
267
+
268
+ ### platon_protocol_version
269
+ 查询
270
+
271
+ * 参数
272
+
273
+ * 返回值
274
+ `Integer`: 返回当前Platon协议版本
275
+ * 示例
276
+
277
+ ```ruby
278
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
279
+ client.platon_protocol_version
280
+ => 63
281
+ ```
282
+
283
+ ### platon_syncing
284
+ 查询当前节点的同步状态
285
+
286
+ * 参数
287
+
288
+ * 返回值
289
+ `Object | Boolean`: 返回当前同步的状态,或返回 `false`,当没在同步时:
290
+ `startingBlock`:`QUANTITY` - 起始区块
291
+ `currentBlock` :`QUANTITI` - 当前区块,与 platon_block_number 相同
292
+ `highestBlock` :`QUANTITY` - 估计最高的区块
293
+ * 示例
294
+
295
+ ```ruby
296
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
297
+ client.platon_syncing
298
+ ### syncing
299
+ =>{
300
+ startingBlock: '0x384',
301
+ currentBlock: '0x386',
302
+ highestBlock: '0x454'
303
+ }
304
+ ### or when not syncing
305
+ => false
306
+ ```
307
+
308
+ ### platon_gas_price
309
+ 返回当前gas价格
310
+ * 参数
311
+
312
+ * 返回值
313
+ ```Integer```: 当前gas价格,单位为von
314
+ * 示例
315
+
316
+ ```ruby
317
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
318
+ client.platon_gas_price
319
+ => 1000000000
320
+ ```
321
+
322
+ ### platon_accounts
323
+ 返回客户端拥有的platon账户
324
+
325
+ * 参数
326
+
327
+ * 返回值
328
+ `Array`: 客户端拥有的platon账户
329
+ * 示例
330
+
331
+ ```ruby
332
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
333
+ client.platon_accounts
334
+ =>[]
335
+ ```
336
+
337
+ ### platon_block_number
338
+ 返回区块链上最新区块
339
+
340
+ * 参数
341
+
342
+ * 返回值
343
+ `Integer`: 客户端中监听到的链上最新区块
344
+ * 示例
345
+
346
+ ```ruby
347
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
348
+ client.platon_block_number
349
+ => => 10513205
350
+ ```
351
+
352
+ ### platon_get_balance
353
+
354
+ 查询账户余额
355
+
356
+ * 参数
357
+ * `String` 待查询地址,bech32
358
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
359
+ * 返回值
360
+ * `Integer`: 账户余额(von)
361
+ * 示例
362
+
363
+ ```ruby
364
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
365
+ client.platon_get_balance("atp12kwg77yu4aqf0xmjgdysrkjzqnapt3wasvnpne","latest")
366
+ => 28907596000000000
367
+
368
+ client.platon_get_balance("atp12kwg77yu4aqf0xmjgdysrkjzqnapt3wasvnpne", 10713205)
369
+ => 28907596000000000
370
+ ```
371
+
372
+ ### platon_get_storage_at
373
+ * 参数
374
+ * `String` 待查询地址,bech32
375
+ * `String` hex string ,存储的位置
376
+ * `String` "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)
377
+ * 返回值
378
+ * `String` 该存储位置的值
379
+ * 示例
380
+
381
+ ```ruby
382
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
383
+ client.platon_get_storage_at("atp12kwg77yu4aqf0xmjgdysrkjzqnapt3wasvnpne","0x2","latest")
384
+ => "0x"
385
+ ```
386
+
387
+ ### platon_get_transaction_count
388
+ 返回地址发起的交易数量
389
+
390
+ * 参数
391
+
392
+ * `String` 待查询地址,bech32 address
393
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
394
+ * 返回值
395
+ * `Integer`: 返回该地址发起的交易数量
396
+ * 示例
397
+
398
+ ```ruby
399
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
400
+ client.platon_get_transaction_count("atp12kwg77yu4aqf0xmjgdysrkjzqnapt3wasvnpne","latest")
401
+ => 50
402
+ ```
403
+
404
+ ### platon_get_block_transaction_count_by_hash
405
+ 根据区块哈希值查询交易数量
406
+
407
+ * 参数
408
+
409
+ * `String` 待查询的区块哈希值
410
+ * 返回值
411
+
412
+ * `Integer` 返回该区块中交易数
413
+ * 示例
414
+
415
+ ```ruby
416
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
417
+ client.platon_get_block_transaction_count_by_hash("0xd2dede658ef3ec62336b5cd3b6d62997d5a025edb48860c1ec84bd186f8225b8")
418
+ => 1
419
+ ```
420
+
421
+
422
+ ### platon_get_block_transaction_count_by_number
423
+ 根据区块高度查询交易数量
424
+
425
+ * 参数
426
+
427
+ * `Integer`: 待查询的区块高度
428
+ * 返回值
429
+
430
+ * `Integer`: 返回该区块中的交易数
431
+ * 示例
432
+
433
+ ```ruby
434
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
435
+ client.platon_get_block_transaction_count_by_number(10805358)
436
+ => 1
437
+ ```
438
+
439
+ ### platon_get_code
440
+ 返回指定地址的code
441
+
442
+ * 参数
443
+
444
+ * `String`: 待查询的地址 bech32 address
445
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
446
+ * 返回值
447
+
448
+ `String`: 该地址的code
449
+ * 示例
450
+
451
+ ```ruby
452
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
453
+ client.platon_get_code("atp1cay80hvyqpmt65wsn6nwng048q88jcg2jlf3sv","latest")
454
+ => "0x608060405260...
455
+ ```
456
+
457
+ ### platon_sign
458
+
459
+ 使用某给定账号对data进行签名,注意:该地址需要提前解锁
460
+
461
+ * 参数
462
+
463
+ * `String`: 指定签名的bench32地址
464
+ * `String`: 待签名的信息,需要为0x开头的hex字符串
465
+ * 返回值
466
+
467
+ * `String`: 已签名数据
468
+ * 示例
469
+
470
+ ```ruby
471
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
472
+ client.platon_sign("atp1zdpu5f55gxurfzgkn8tgc7pwwl34jquf5twpyn","0x1234")
473
+ => "0x1d39459e2050493f89ec0aa09112bce7a08a9774d054fc71159e2435961ef1732862145cd0cedd1859bfd8698044c2a0963262b75aeb187650f4ca4f8b5b754c1b"
474
+ ```
475
+
476
+ ### platon_send_transaction
477
+ 发送服务待签名交易
478
+
479
+ * 参数
480
+
481
+ * `Object`: Transaction 交易结构
482
+ * `String`: from ,交易发送地址
483
+ * `String`: to , 交易接收地址
484
+ * `Integer`: gas, 本次交易gas用量上限
485
+ * `Integer`: gasPrice, gas价格
486
+ * `Integer`: value,转账金额
487
+ * `String`: data, 上链数据,合约的已编译代码或调用的方法的签名与编码参数的哈希
488
+ * `Integer`: nonce, 交易nonce值
489
+ * 返回值
490
+
491
+ `String`: 32Bytes 的已签名字符串 或 如果交易不可用返回zero hash
492
+ * 示例
493
+
494
+ ```ruby
495
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
496
+ client.platon_send_transaction({
497
+ "from": "atp1zdpu5f55gxurfzgkn8tgc7pwwl34jquf5twpyn",
498
+ "to": "atp1h5dx7v9qgf40mctz5cm76kl4ap5lmau759ap70",
499
+ "gas": "0x76c0", # 30400,
500
+ "gasPrice": "0x9184e72a000", # 10000000000000
501
+ "value": "0x9184e72a", # 2441406250
502
+ "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
503
+ })
504
+ => "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
505
+ ```
506
+
507
+ ### platon_send_raw_transaction
508
+ 创建一个新的消息调用交易,或对于已签名交易做合约创建
509
+
510
+ * 参数
511
+
512
+ * `Object`: Transaction 交易结构
513
+ * `String`: data 已签名交易
514
+ * 返回值
515
+
516
+ * `String`: 32Bytes 的已签名字符串 或 如果交易不可用返回zero hash
517
+ ```
518
+ params: ["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"]
519
+ ```
520
+ * 示例
521
+
522
+ ```ruby
523
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
524
+ client.platon_send_raw_transaction(["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"])
525
+ ```
526
+
527
+ ### platon_call
528
+ 执行一个消息调用交易,消息调用交易直接在节点旳执行而不需要通过区块链的挖矿来执行
529
+
530
+ * 参数
531
+
532
+ * `Object`: Transaction 交易结构
533
+ * `String`: from ,交易发送地址
534
+ * `String`: to , 交易接收地址
535
+ * `Integer`: gas, 本次交易gas用量上限
536
+ * `Integer`: gasPrice, gas价格
537
+ * `Integer`: value,转账金额
538
+ * `String`: data, 上链数据,合约的已编译代码或调用的方法的签名与编码参数的哈希
539
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
540
+ * 返回值
541
+
542
+ * 执行合约的返回值
543
+ * 示例
544
+
545
+ ```ruby
546
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
547
+ client.platon_call({
548
+ "from": "atp1zdpu5f55gxurfzgkn8tgc7pwwl34jquf5twpyn",
549
+ "to": "atp1h5dx7v9qgf40mctz5cm76kl4ap5lmau759ap70",
550
+ "gas": "0x76c0", # 30400,
551
+ "gasPrice": "0x9184e72a000", # 10000000000000
552
+ "value": "0x9184e72a", # 2441406250
553
+ "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
554
+ },"latest")
555
+ => "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
556
+ ```
557
+
558
+ ### platon_estimate_gas
559
+ 生成并返回完成交易所需的gas估算值。 交易将不会添加到区块链中。 注:由于各种原因(包括EVM机制和节点性能),估算值可能大大超过交易实际使用的gas
560
+
561
+ * 参数
562
+
563
+ * `Object`: Transaction 交易结构
564
+ * `String`: from ,交易发送地址
565
+ * `String`: to , 交易接收地址
566
+ * `Integer`: gas, 本次交易gas用量上限
567
+ * `Integer`: gasPrice, gas价格
568
+ * `Integer`: value,转账金额
569
+ * `String`: data, 上链数据,合约的已编译代码或调用的方法的签名与编码参数的哈希
570
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
571
+ * 返回值
572
+
573
+ * `Integer`: 评估的gas使用值
574
+ * 示例
575
+
576
+ ```ruby
577
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
578
+ client.platon_estimate_gas({
579
+ "from": "atp1zdpu5f55gxurfzgkn8tgc7pwwl34jquf5twpyn",
580
+ "to": "atp1h5dx7v9qgf40mctz5cm76kl4ap5lmau759ap70",
581
+ "gasPrice": "0x9184e72a000", # 10000000000000
582
+ "value": "0x9184e72a", # 2441406250
583
+ "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
584
+ })
585
+ => 21000
586
+ ```
587
+
588
+ ### platon_get_block_by_hash
589
+ 通过交易hash查询block
590
+
591
+ * 参数
592
+
593
+ * `String`: 32Bytes 区块哈希值
594
+ * `Boolean`: true 返回区块全量信息,false 只返回交易的hash值
595
+ * 返回值
596
+ * `Object`: 区块的结构,或如果未找到返回 `nil`
597
+ * 示例
598
+
599
+ ```ruby
600
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
601
+ client.platon_get_block_by_hash("0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7",false)
602
+ => {"extraData"=>"0xd9820f0086706c61746f6e88676f312e31332e34856c696e7578000000000000d0ce481ee2aeca0cc474c03882afa2bb25968d025f63ee9b114df8965bb8efd11557c936950c4b40cc1ce540bc98e117df88f4f0f08081cbfbabd2e614fcd7e800", "gasLimit"=>"0x8fcf88", "gasUsed"=>"0x8a34", "hash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "logsBloom"=>"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000", "miner"=>"atp1vthcqh8cvl5lcz98zeh53r5mtjp89ulma9ghnd", "nonce"=>"0x037185230d3468bb10d034e1679330d7bc6fdc8cc4d61b5f0892148e81b14dfd8ba9ec00f52ebc67bfd58195ef8da0fb85ba82707fc90f379e5802c56f8b5e1dd0fb4f1cbb796b4e78de9d2813217c5476", "number"=>"0xa80ea9", "parentHash"=>"0x032bbd2d3f940b130bf79fe228ba2ec323cf3695f163a1aa0a57dec33fb67afb", "receiptsRoot"=>"0x9bc39b40af8267744a06a5060335eeaf8e2854244c710cdcc81d8768acc0654c", "size"=>"0x355", "stateRoot"=>"0x10475ff8bcfa50364e33883a2a6b0e92b12acf9727c703fe9d84078ad497cab0", "timestamp"=>"0x177ff4bfd89", "transactions"=>["0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c"], "transactionsRoot"=>"0x2c3e9057fe0bf02fc2dc09580eb11a678cd39893e0341722bb07ed53a9f89d88"}
603
+ ```
604
+
605
+ ### platon_get_block_by_number
606
+ 通过区块高度返回区块信息
607
+
608
+ * 参数
609
+
610
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
611
+ * `Boolean`: true 返回区块全量信息,false 只返回交易的hash值
612
+ * 返回值
613
+
614
+ * `Object`: 区块的结构,或如果未找到返回 `nil`
615
+ * 示例
616
+
617
+ ```ruby
618
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
619
+ client.platon_get_block_by_number(11013801,false)
620
+ => {"extraData"=>"0xd9820f0086706c61746f6e88676f312e31332e34856c696e7578000000000000d0ce481ee2aeca0cc474c03882afa2bb25968d025f63ee9b114df8965bb8efd11557c936950c4b40cc1ce540bc98e117df88f4f0f08081cbfbabd2e614fcd7e800", "gasLimit"=>"0x8fcf88", "gasUsed"=>"0x8a34", "hash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "logsBloom"=>"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000", "miner"=>"atp1vthcqh8cvl5lcz98zeh53r5mtjp89ulma9ghnd", "nonce"=>"0x037185230d3468bb10d034e1679330d7bc6fdc8cc4d61b5f0892148e81b14dfd8ba9ec00f52ebc67bfd58195ef8da0fb85ba82707fc90f379e5802c56f8b5e1dd0fb4f1cbb796b4e78de9d2813217c5476", "number"=>"0xa80ea9", "parentHash"=>"0x032bbd2d3f940b130bf79fe228ba2ec323cf3695f163a1aa0a57dec33fb67afb", "receiptsRoot"=>"0x9bc39b40af8267744a06a5060335eeaf8e2854244c710cdcc81d8768acc0654c", "size"=>"0x355", "stateRoot"=>"0x10475ff8bcfa50364e33883a2a6b0e92b12acf9727c703fe9d84078ad497cab0", "timestamp"=>"0x177ff4bfd89", "transactions"=>["0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c"], "transactionsRoot"=>"0x2c3e9057fe0bf02fc2dc09580eb11a678cd39893e0341722bb07ed53a9f89d88"}
621
+ ```
622
+
623
+ ### platon_get_transaction_by_hash
624
+ 通过指定交易hash查询交易内容
625
+
626
+ * 参数
627
+
628
+ `String`: 32Bytes 交易hash值
629
+ * 返回值
630
+
631
+ `Object`: 交易object, 或未找到时返回 `nil`
632
+ * 示例
633
+
634
+ ```ruby
635
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
636
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
637
+ client.platon_get_transaction_by_hash("0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c")
638
+ => {"blockHash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "blockNumber"=>"0xa80ea9", "from"=>"atp196439hyj6mwnr23876cu59wfjaga2wntr36wz0", "gas"=>"0x186a0", "gasPrice"=>"0x1dcd65000", "hash"=>"0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c", "input"=>"0xc483821388", "nonce"=>"0xc48", "to"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxxwje8t", "transactionIndex"=>"0x0", "value"=>"0x0", "v"=>"0x62298", "r"=>"0xe79901088b2d0825b2b333b587562d980fd1d7fe1053de5992ee3449ddf7276d", "s"=>"0x467bee5c4372f718de469f6e64a0927e95641ff585f01243b47f65407db4097e"}
639
+ ```
640
+
641
+ ### platon_get_transaction_by_block_hash_and_index
642
+ 通过指定区块hash与交易index position 查询交易
643
+
644
+ * 参数
645
+
646
+ * `String`: 32Bytes, 区块hash
647
+ * `Integer`: 交易的索引位置
648
+ * 返回值
649
+
650
+ `Object`: 交易object, 或未找到时返回 `nil`
651
+ * 示例
652
+
653
+ ```ruby
654
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
655
+ client.platon_get_transaction_by_block_hash_and_index("0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7",0)
656
+ => {"blockHash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "blockNumber"=>"0xa80ea9", "from"=>"atp196439hyj6mwnr23876cu59wfjaga2wntr36wz0", "gas"=>"0x186a0", "gasPrice"=>"0x1dcd65000", "hash"=>"0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c", "input"=>"0xc483821388", "nonce"=>"0xc48", "to"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxxwje8t", "transactionIndex"=>"0x0", "value"=>"0x0", "v"=>"0x62298", "r"=>"0xe79901088b2d0825b2b333b587562d980fd1d7fe1053de5992ee3449ddf7276d", "s"=>"0x467bee5c4372f718de469f6e64a0927e95641ff585f01243b47f65407db4097e"}
657
+ ```
658
+
659
+
660
+ ### platon_get_transaction_by_block_number_and_index
661
+ 通过区块高度及交易在区块中位置查询交易信息
662
+
663
+ * 参数
664
+
665
+ * `Integer | String` :可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
666
+ * `Integer`: 交易的索引位置
667
+ * 返回值
668
+
669
+ `Object`: Transaction object
670
+ * 示例
671
+
672
+ ```ruby
673
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
674
+ client.platon_get_transaction_by_block_number_and_index(11013801,0)
675
+ => {"blockHash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "blockNumber"=>"0xa80ea9", "from"=>"atp196439hyj6mwnr23876cu59wfjaga2wntr36wz0", "gas"=>"0x186a0", "gasPrice"=>"0x1dcd65000", "hash"=>"0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c", "input"=>"0xc483821388", "nonce"=>"0xc48", "to"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxxwje8t", "transactionIndex"=>"0x0", "value"=>"0x0", "v"=>"0x62298", "r"=>"0xe79901088b2d0825b2b333b587562d980fd1d7fe1053de5992ee3449ddf7276d", "s"=>"0x467bee5c4372f718de469f6e64a0927e95641ff585f01243b47f65407db4097e"}
676
+ ```
677
+
678
+
679
+ ###platon_get_transaction_receipt
680
+ 根据交易hash返回交易回执
681
+
682
+ * 参数
683
+
684
+ * `String`: 32Bytes ,交易哈希值
685
+ * 返回值
686
+
687
+ * `Object`: Transaction Receipt Object, 未找到回执时返回nil
688
+ * 示例
689
+
690
+ ```ruby
691
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
692
+ client.platon_get_transaction_receipt("0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c")
693
+ => {"blockHash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "blockNumber"=>"0xa80ea9", "contractAddress"=>nil, "cumulativeGasUsed"=>"0x8a34", "from"=>"atp196439hyj6mwnr23876cu59wfjaga2wntr36wz0", "gasUsed"=>"0x8a34", "logs"=>[{"address"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxxwje8t", "topics"=>[], "data"=>"0xf8f830b8f5f8f3f84fb84088e70a87f6acc8edf3b381c02f3c3317392e458af688920bbfe04e3694979847e25d59fb7fe2c1d3487f1ae5a7876fbcefabe06f722dfa28a83f3ca4853c42548307a2f5880518bc6e5f2b8cb4f84fb8409460fce5beea98e4d56c62a920bb041f45e48a5a7b96d12d02a16cbb20863be9c76491127533d9cefa5b4cec48ae6595b7ba347ef7dc8277cfb343eebde4646b8307a2f488060ff2b59a3ef16bf84fb840ab74f5500dd35497ce09b2dc92a3da26ea371dd9f6d438559b6e19c8f1622ee630951b510cb370aca8267f9bb9a9108bc532ec48dd077474cb79a48122f2ab038307bd438806d8e64037faad55", "blockNumber"=>"0xa80ea9", "transactionHash"=>"0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c", "transactionIndex"=>"0x0", "blockHash"=>"0xf71f0868b162b5b6d8240d44790a9cf4159add927c880218c9a17cb590bd6ea7", "logIndex"=>"0x0", "removed"=>false}], "logsBloom"=>"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000", "status"=>"0x1", "to"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqxxwje8t", "transactionHash"=>"0x11b3640628b0a8b28fa9e7aa20f70962b9dd6eecc9d8c8521af3f4898cc3b88c", "transactionIndex"=>"0x0"}
694
+
695
+ ```
696
+
697
+
698
+ ### platon_evidences
699
+ 返回双签证据
700
+
701
+ * 参数
702
+
703
+
704
+ * 返回值
705
+
706
+ * `String`: 证据字符串包含三种类型的证据:duplicatePrepare,duplicateVote,duplicateViewchange。 每种类型都包含多个证据,因此它是一个数组结构。 解析时请注意。
707
+ * duplicatePrepare
708
+
709
+ ```ruby
710
+ {
711
+ "prepareA": {
712
+ "epoch": 0, //共识轮epoch值
713
+ "viewNumber": 0, //共识轮view值
714
+ "blockHash": "0x06abdbaf7a0a5cb1deddf69de5b23d6bc3506fdadbdcfc32333a1220da1361ba", //区块hash
715
+ "blockNumber": 16013, //区块number
716
+ "blockIndex": 0, //区块在一轮view中的索引值
717
+ "blockData": "0xe1a507a57c1e9d8cade361fefa725d7a271869aea7fd923165c872e7c0c2b3f2", //区块rlp编码值
718
+ "validateNode": {
719
+ "index": 0, //验证人在一轮epoch中的索引值
720
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4", //验证人地址
721
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365", //验证人nodeID
722
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f" //验证人bls公钥
723
+ },
724
+ "signature": "0x1afdf43596e07d0f5b59ae8f45d30d21a9c5ac793071bfb6382ae151081a901fd3215e0b9645040c9071d0be08eb200900000000000000000000000000000000" //消息签名
725
+ },
726
+ "prepareB": {
727
+ "epoch": 0,
728
+ "viewNumber": 0,
729
+ "blockHash": "0x74e3744545e95f4defc82d731504a39994b8013575491f83f7520cf796347b8f",
730
+ "blockNumber": 16013,
731
+ "blockIndex": 0,
732
+ "blockData": "0xb11be0a3634e29281403d690c1a0bc38e96ea34b3aea0b0da2883800f610c3b7",
733
+ "validateNode": {
734
+ "index": 0,
735
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4",
736
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365",
737
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f"
738
+ },
739
+ "signature": "0x16795379ca8e28953e74b23d1c384dda760579ad70c5e490225403664a8d4490cabb1dc64a2e0967b5f0c1e9dbd6578c00000000000000000000000000000000"
740
+ }
741
+ }
742
+ ```
743
+
744
+ * duplicateVote
745
+
746
+ ```ruby
747
+ {
748
+ "voteA": {
749
+ "epoch": 0, //共识轮epoch值
750
+ "viewNumber": 0, //共识轮view值
751
+ "blockHash": "0x58b5976a471f86c4bd198984827bd594dce6ac861ef15bbbb1555e7b2edc2fc9", //区块hash
752
+ "blockNumber": 16013, //区块number
753
+ "blockIndex": 0, //区块在一轮view中的索引值
754
+ "validateNode": {
755
+ "index": 0, //验证人在一轮epoch中的索引值
756
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4", //验证人地址
757
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365", //验证人nodeID
758
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f" //验证人bls公钥
759
+ },
760
+ "signature": "0x071350aed09f226e218715357ffb7523ba41271dd1d82d4dded451ee6509cd71f6888263b0b14bdfb33f88c04f76790d00000000000000000000000000000000" //消息签名
761
+ },
762
+ "voteB": {
763
+ "epoch": 0,
764
+ "viewNumber": 0,
765
+ "blockHash": "0x422515ca50b9aa01c46dffee53f3bef0ef29884bfd014c3b6170c05d5cf67696",
766
+ "blockNumber": 16013,
767
+ "blockIndex": 0,
768
+ "validateNode": {
769
+ "index": 0,
770
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4",
771
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365",
772
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f"
773
+ },
774
+ "signature": "0x9bf6c01643058c0c828c35dc3277666edd087cb439c5f6a78ba065d619f812fb42c5ee881400a7a42dd8366bc0c5c88100000000000000000000000000000000"
775
+ }
776
+ }
777
+ ```
778
+
779
+ * duplicateViewchange
780
+
781
+ ```ruby
782
+ {
783
+ "viewA": {
784
+ "epoch": 0,
785
+ "viewNumber": 0,
786
+ "blockHash": "0xb84a40bb954e579716e7a6b9021618f6b25cdb0e0dd3d8c2c0419fe835640f36", //区块hash
787
+ "blockNumber": 16013,
788
+ "validateNode": {
789
+ "index": 0,
790
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4",
791
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365",
792
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f"
793
+ },
794
+ "signature": "0x9c8ba2654c6b8334b1b94d3b421c5901242973afcb9d87c4ab6d82c2aee8e212a08f2ae000c9203f05f414ca578cda9000000000000000000000000000000000",
795
+ "blockEpoch": 0,
796
+ "blockView": 0
797
+ },
798
+ "viewB": {
799
+ "epoch": 0,
800
+ "viewNumber": 0,
801
+ "blockHash": "0x2a60ed6f04ccb9e468fbbfdda98b535653c42a16f1d7ccdfbd5d73ae1a2f4bf1",
802
+ "blockNumber": 16013,
803
+ "validateNode": {
804
+ "index": 0,
805
+ "address": "0xc30671be006dcbfd6d36bdf0dfdf95c62c23fad4",
806
+ "nodeId": "19f1c9aa5140bd1304a3260de640a521c33015da86b88cd2ecc83339b558a4d4afa4bd0555d3fa16ae43043aeb4fbd32c92b34de1af437811de51d966dc64365",
807
+ "blsPubKey": "f93a2381b4cbb719a83d80a4feb93663c7aa026c99f64704d6cc464ae1239d3486d0cf6e0b257ac02d5dd3f5b4389907e9d1d5b434d784bfd7b89e0822148c7f5b8e1d90057a5bbf4a0abf88bbb12902b32c94ca390a2e16eea8132bf8c2ed8f"
808
+ },
809
+ "signature": "0xed69663fb943ce0e0dd90df1b65e96514051e82df48b3867516cc7e505234b9ca707fe43651870d9141354a7a993e09000000000000000000000000000000000",
810
+ "blockEpoch": 0,
811
+ "blockView": 0
812
+ }
813
+ }
814
+
815
+ ```
816
+
817
+ * 示例
818
+
819
+ ```ruby
820
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
821
+ client.platon_evidences
822
+ => "{}" ## 暂无的状态
823
+ ```
824
+
825
+
826
+
827
+ ### admin_node_info
828
+ 查看当前节点详情
829
+
830
+ * 参数
831
+
832
+
833
+ * 返回值
834
+
835
+ `Object`: 当前节点详情
836
+ * 示例
837
+
838
+ ```ruby
839
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
840
+ client.admin_node_info
841
+ => {node information } #略
842
+ ```
843
+
844
+ ### admin_peers
845
+
846
+ 查看当前节点所连接的节点信息
847
+ * 参数
848
+
849
+
850
+ * 返回值
851
+
852
+ `Array`: 已连接的节点信息
853
+ * 示例
854
+
855
+ ```ruby
856
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
857
+ client.admin_peers
858
+ => [{Node 1 information} , {Node 2 information}, ..., {node information N}] # 略
859
+ ```
860
+
861
+ ### admin_get_program_version
862
+
863
+ 查询code版本及签名
864
+
865
+ * 参数
866
+
867
+
868
+ * 返回值
869
+
870
+ `Object`: 包含两部分内容,版本与签名
871
+ * 示例
872
+
873
+ ```ruby
874
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
875
+ client. admin_get_program_version
876
+ =>{"Version"=>3840, "Sign"=>"0x169237f89092ad73f1db8dbb58703e59fe07e2ee5ce60aed16ff20c6313d800006b586ac074e03d7616664ee2c934bf5d2496dd4bd1592dae6c31a90641fbaaa00"}
877
+ ```
878
+
879
+ ### admin_get_schnorr_NIZK_Prove
880
+ 返回BLS证明
881
+
882
+ * 参数
883
+
884
+
885
+ * 返回值
886
+
887
+ `String`: BLS证明
888
+ * 示例
889
+
890
+ ```ruby
891
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
892
+ client.admin_get_schnorr_nizk_prove
893
+ => "98d139a10b5e0d4d0968da2ed7d49cb654fcd3b19fd1cd88f6413480e88eb557ad66487ed9e97fe28a868e7da77e91d061df9996b4a1f1d675c415a962764770"
894
+ ```
895
+
896
+ ### admin_datadir
897
+ 返回数据存储路径
898
+
899
+ * 参数
900
+
901
+
902
+ * 返回值
903
+
904
+ `String`: 数据路径
905
+ * 示例
906
+
907
+ ```ruby
908
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
909
+ client.admin_datadir
910
+ => "/home/ubuntu/platon-node/data"
911
+ ```
912
+
913
+
914
+
915
+
916
+ ## 钱包&转账接口
917
+
918
+ ### keys创建 & 地址转换
919
+ 创建一组新的public/private key并得到 bech32 地址
920
+
921
+ ```ruby
922
+ key = Platon::Key.new
923
+ key.private_hex ## 私钥
924
+ => "08bb093d6184cb06a3f80507953ba6768c03d8114a429b0ec7875bb6b6e1a8a6"
925
+
926
+ key.public_hex ## 公钥
927
+ => "04641129e66399310ce4a41098d3b3fc4d722edf423dfdc0a76eba5d6e2155bbe611ee2a5c06011ab76040ca53b9ead4c5061d8cc8a89afa3f45af5830661d4b34"
928
+
929
+ key.address
930
+ => "0xFc0Fe6c7604dcDd6ca1B9be703D6AB91fF2fC007"
931
+
932
+ key.bech32_address ## bech32 格式公钥 ,默认是 "atp"
933
+ => "atp1ls87d3mqfhxadjsmn0ns844tj8ljlsq89k95cn"
934
+
935
+ key.bech32_address(hrp: "lat")
936
+ => "lat1ls87d3mqfhxadjsmn0ns844tj8ljlsq8uqnv8u"
937
+ ```
938
+
939
+ ### 使用已有私钥导入创建key
940
+
941
+ ```ruby
942
+ key = Platon::Key.new priv: private_key
943
+ ```
944
+
945
+
946
+ ### 备份钱包 encrypt
947
+
948
+ 备份钱包,输入密码加密得到json字符串
949
+
950
+ ```ruby
951
+ encrypted_key_info = Platon::Key.encrypt key,"your_password"
952
+
953
+ # or
954
+
955
+ Platon::Key.encrypt_and_save key,"your_password",'./some/path.json'
956
+
957
+ # or 使用默认地址: ~/.platon/keystore
958
+
959
+ Platon::Key.encrypt_and_save key,"your_password"
960
+
961
+ ```
962
+
963
+ ### 恢复钱包 decrypt
964
+ 恢复钱包,输入密码得到key对象
965
+
966
+ ```ruby
967
+ decrypted_key = Platon::Key.decrypt encrypted_key_info,"your_password"
968
+
969
+ # or
970
+
971
+ decrypted_key = Platon::Key.decrypt File.read('./some/path.json'), 'your_password'
972
+ ```
973
+
974
+ ###查询本地钱包 list_wallets
975
+
976
+ ```ruby
977
+ Platon::Key.list_wallets
978
+
979
+ # or
980
+
981
+ Platon::Key.list_wallets("/your/wallet/path/")
982
+ ```
983
+
984
+
985
+ ### 转账操作 transfer:
986
+
987
+ 转账操作,可以指定gas_price与gas_limit
988
+
989
+ ```ruby
990
+ client = Platon::HttpClient.new("http://127.0.0.1:6789",:alayadev)
991
+ client.transfer key,"atpxxxxxxxxxxxxxxx",10**16
992
+
993
+ # or
994
+
995
+ client.transfer key,"atpxxxxxxxxxxxxxxx",10**16,{gas_limit: 500_000 , gas_price: 2_000_000_000} ## 指定gas_price 与 gas_limit
996
+ ```
997
+
998
+ 通过如下方式验证是否为bech32地址:
999
+
1000
+ ```ruby
1001
+ Platon::Utils.is_bech32_address?("atp1c5jsm49tp69cv0sktgg5ntj8pp5ppzqr4735gv")
1002
+ => true
1003
+ ```
1004
+
1005
+ ### 签名交易 tx.sign
1006
+
1007
+ 使用给定的key进行交易签名
1008
+
1009
+ ```ruby
1010
+ key = Platon::Key.new
1011
+ args = {
1012
+ key: "some contents"
1013
+ }
1014
+ tx = Platon::Tx.new(args)
1015
+ tx.sign key
1016
+ ```
1017
+
1018
+ ## Rake任务辅助工具
1019
+ 提供了一些 rake 任务可以作为辅助工具,如:
1020
+
1021
+ ```ruby
1022
+ rake 'platon:contract:compile[path]' # Compile a contract
1023
+ rake 'platon:contract:deploy[path]' # Compile and deploy contract
1024
+ rake 'platon:transaction:byhash[id]' # Get info about transaction
1025
+ rake 'platon:transaction:send[address,amount]' # Send [amount of] ATP to an account
1026
+ ```
1027
+
1028
+ 举例如下:
1029
+ ```ruby
1030
+ rake 'platon:contract:compile[./spec/fixtures/greeter.sol]'
1031
+ ```
1032
+
1033
+
1034
+ ## 验证人&质押模块
1035
+
1036
+
1037
+ ### 发起质押
1038
+
1039
+ 发起质押(1000)
1040
+
1041
+ * 参数
1042
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1043
+ * `Integer`: typ, 表示使用账户自由金额还是账户的锁仓金额做质押,0: 自由金额; 1: 锁仓金额
1044
+ * `String`: benefitAddress,用于接受出块奖励和质押奖励的收益账户
1045
+ * `String`: nodeId,被质押的节点Id(也叫候选人的节点Id)
1046
+ * `String`: externalId,外部Id(有长度限制,给第三方拉取节点描述的Id)
1047
+ * `String`: nodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1048
+ * `String`: website,节点的第三方主页(有长度限制,表示该节点的主页)
1049
+ * `String`: details 节点的描述(有长度限制,表示该节点的描述)
1050
+ * `Integer`: amount , 质押的金额,填写单位 ATP或者 LAT
1051
+ * `Integer`: rewardPer, 委托所得到的奖励分成比例,采用BasePoint 1BP=0.01%
1052
+ * `Integer`: programVersion, 程序的真实版本,治理rpc获取
1053
+ * `String`: programVersionSign,程序的真实版本签名,治理rpc获取
1054
+ * `String`: blsPubKey,bls的公钥
1055
+ * `String`: blsProof, bls的证明,通过拉取证明接口获取
1056
+
1057
+ * 返回值
1058
+ * `String`: 交易hash
1059
+
1060
+ * 示例
1061
+
1062
+ ```ruby
1063
+ client.ppos.create_staking key,0,key.bech32_address,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d","", "hello-dposclub","https://www.baidu.com","integration-node1-details", 100000, 8888,65536,"0x7f4d68fb9f100aff45b9c4730c102973ca7bd63d262c2707bb3e8b18ead2865272c1b4ed23de9bfd13ebb41b3562969cfdafc303e070c4b71723c997a8c53fbd01","69365262afd3c8a6971db4f8a97a0dec049b83a85905f41429c45635de483e03f058f7ae4befb592f391fa49f68a970581a3ab4688baf9eaa6c5d0bf3e80669536ac44c91db0bacc88379ccbb33561e08f03b722ef0f296a94c06873f7b71a06","ce36b2fd6d6d76cf3a7a35e77455b3cae261568454027bbb4c28268d3c5cc16f9f6e56ca9f44c723d3181011bd31d50e39437776c474708b02ffabf088d79a1f"
1064
+ ==> "0x46b763893c43e2296404dfbc1a669b76ca3be7e59f37783e2fa610cb48112df4"
1065
+ ```
1066
+
1067
+
1068
+ ### 修改质押
1069
+
1070
+ 节点修改质押信息(1001)
1071
+
1072
+ * 参数
1073
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1074
+ * `String`: benefitAddress,用于接受出块奖励和质押奖励的收益账户
1075
+ * `String`: nodeId,被质押的节点Id(也叫候选人的节点Id)
1076
+ * `String`: externalId,外部Id(有长度限制,给第三方拉取节点描述的Id)
1077
+ * `String`: nodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1078
+ * `String`: website,节点的第三方主页(有长度限制,表示该节点的主页)
1079
+ * `String`: details 节点的描述(有长度限制,表示该节点的描述)
1080
+ * `Integer`: amount , 质押的金额,填写单位 ATP或者 LAT
1081
+ * `Integer`: rewardPer, 委托所得到的奖励分成比例,采用BasePoint 1BP=0.01%
1082
+ * `Integer`: programVersion, 程序的真实版本,治理rpc获取。可通过client.admin_get_program_version获取
1083
+ * `String`: programVersionSign,程序的真实版本签名,治理rpc获取,可通过client.admin_get_program_version 获取
1084
+ * `String`: blsPubKey,bls的公钥
1085
+ * `String`: blsProof, bls的证明,通过拉取证明接口获取。可通过client.admin_get_program_version 获取
1086
+
1087
+ * 返回值
1088
+ * `String`: 交易hash
1089
+
1090
+ * 示例
1091
+
1092
+ ```ruby
1093
+ client.ppos.update_staking_info(key,key.bech32_address,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d",8866,"","hi-new-name-dpos","https://baidu.com","integration-node2-details")
1094
+ => "0xc5c1fd9a1259cb3a1c138bfc5a48a823e2018248f9e53c16b43f3fd2d91a8d98"
1095
+ ```
1096
+
1097
+ ### 增加质押
1098
+
1099
+ 节点增持质押(1002)
1100
+
1101
+ * 参数
1102
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1103
+ * `String`: nodeId,被质押的节点Id(也叫候选人的节点Id)
1104
+ * `Integer`: typ, 表示使用账户自由金额还是账户的锁仓金额做质押,0: 自由金额; 1: 锁仓金额
1105
+ * `Integer`: amount , 质押的金额,填写单位 ATP或者 LAT
1106
+
1107
+ * 返回值
1108
+ * `String`: 交易hash
1109
+
1110
+ * 示例
1111
+
1112
+ ```ruby
1113
+ client.ppos.add_staking(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d",0,20)
1114
+ => "0x2a2a523b1d1ba1c3430a1a4e40d485596ad455c56fe3cfc77ae42179890fd82e"
1115
+ ```
1116
+
1117
+ ### 撤销质押
1118
+ 撤销质押(一次性发起全部撤销,多次到账),注意有退出时间。 (1003)
1119
+
1120
+ * 参数
1121
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1122
+ * `String`: nodeId,被质押的节点Id(也叫候选人的节点Id)
1123
+
1124
+ * 返回值
1125
+ * `String`: 交易hash
1126
+
1127
+ * 示例
1128
+
1129
+ ```ruby
1130
+ client.ppos.cancel_staking(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d")
1131
+ => 0x6409062ce61ea5a74bf8be7f0f0cb04c1874de4aa3e4897c1ea71482ce9b78ec
1132
+ ```
1133
+
1134
+
1135
+
1136
+ ### 发起委托 delegate
1137
+
1138
+ 发起委托
1139
+
1140
+ * 参数
1141
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1142
+ * `Integer`: 0或者1,表示使用账户自由金额还是账户的锁仓金额做委托,0: 自由金额; 1: 锁仓金额
1143
+ * `String`: 被质押节点的node_id
1144
+ * `Integer`: amount, 委托金额 (按照最小单位算,1LAT = 10**18 von)
1145
+
1146
+ * 返回值
1147
+ * `String`: 交易hash
1148
+
1149
+ * 示例
1150
+
1151
+ ```ruby
1152
+ # 质押10ATP/LAT
1153
+
1154
+ client.ppos.delegate(key,0,"0x62f537293042326df6637a38319c3cb7abd032554137a800c25c29f0e07287407f96df7601b7b00d1c0c9b26a3eedffd3397af470ba564298e047c450202cfd2",10*10**18)
1155
+ ```
1156
+
1157
+ ### 减少/撤销委托 reduce_delegate
1158
+
1159
+ 减持/撤销委托(全部减持就是撤销)
1160
+
1161
+ * 参数
1162
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1163
+ * `Integer`: 质押时的区块高度,代表着某个node的某次质押的唯一标示
1164
+ * `String`: 被质押节点的node_id
1165
+ * `Integer`: amount, 委托金额 (按照最小单位算,1LAT = 10**18 von)
1166
+
1167
+ * 返回值
1168
+ * `String`: 交易hash
1169
+
1170
+ * 示例
1171
+
1172
+ ```ruby
1173
+ ## 取出10ATP/LAT质押
1174
+
1175
+ client.ppos.reduce_delegate(key,453063,"62f537293042326df6637a38319c3cb7abd032554137a800c25c29f0e07287407f96df7601b7b00d1c0c9b26a3eedffd3397af470ba564298e047c450202cfd2",10*10**18)
1176
+ ```
1177
+
1178
+ ### 查询未领取的委托奖励 get_delegate_reward
1179
+
1180
+ 查询账户在各节点未领取的奖励,funcType:5100
1181
+
1182
+ * 参数
1183
+ * `String`: 待查询地址,bech32 地址
1184
+ * `Array`: (可选)node_ids 默认为[],即查询账户委托的所有节点。也可传入数组,每项元素为质押节点的node_id
1185
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1186
+
1187
+ * 返回值
1188
+ * `String`: nodeID, 质押节点的ID
1189
+ * `String(0x十六进制字符串)`: reward, 未领取的奖励数量
1190
+ * `Integer`: stakingNum ,质押时的区块高度,代表着某个node的某次质押的唯一标示
1191
+
1192
+ * 示例
1193
+
1194
+ ```ruby
1195
+ client.ppos.get_delegate_reward(key.bech32_address)
1196
+
1197
+ or
1198
+
1199
+ client.ppos.get_delegate_reward(key.bech32_address,["62f537293042326df6637a38319c3cb7abd032554137a800c25c29f0e07287407f96df7601b7b00d1c0c9b26a3eedffd3397af470ba564298e047c450202cfd2"])
1200
+ ```
1201
+
1202
+
1203
+ ### 提取所有委托奖励 withdraw_delegate_reward
1204
+ 提取账户当前所有的可提取的委托奖励,funcType:5000
1205
+ * 参数
1206
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1207
+
1208
+ * 返回值
1209
+ * `String`: 交易hash
1210
+
1211
+ * 示例
1212
+
1213
+ ```ruby
1214
+ client.ppos.withdraw_delegate_reward key
1215
+ ```
1216
+
1217
+
1218
+
1219
+ ### 查看结算周期验证人 get_epoch_validators
1220
+
1221
+ 查看当前结算周期的验证人,funcType 1100
1222
+
1223
+ * 参数
1224
+ * 无
1225
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1226
+ * 返回值
1227
+
1228
+ * 返回值
1229
+
1230
+ Array,其中每个元素中参数如下:
1231
+
1232
+ * `String`: NodeId ,被质押的节点Id(也叫候选人的节点Id)
1233
+ * `String`: BlsPubKey, BLS公钥
1234
+ * `String`: StakingAddress,发起质押时使用的账户(后续操作质押信息只能用这个账户,撤销质押时,von会被退回该账户或者该账户的锁仓信息中)
1235
+ * `String`: BenefitAddress, 用于接受出块奖励和质押奖励的收益账户
1236
+ * `Integer`: RewardPer, 节点收益返还比例, 10000为 100%
1237
+ * `Integer`: NextRewardPer
1238
+ * `Integer`: RewardPerChangeEpoch
1239
+ * `String`: StakingTxIndex,发起质押时的交易索引
1240
+ * `String`: ProgramVersion, 被质押节点的PlatON进程的真实版本号(获取版本号的接口由治理提供)
1241
+ * `Integer`: StakingBlockNum,发起质押时的区块高度
1242
+ * `String(0x十六进制字符串)`: Shares,当前候选人总共质押加被委托的von数目
1243
+ * `String`: ExternalId, 外部Id(有长度限制,给第三方拉取节点描述的Id)
1244
+ * `String`: NodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1245
+ * `String`: Website,节点的第三方主页(有长度限制,表示该节点的主页)
1246
+ * `String`: Details,节点的描述(有长度限制,表示该节点的描述)
1247
+
1248
+ * 示例
1249
+
1250
+ ```ruby
1251
+ client.ppos.get_epoch_validators
1252
+ or
1253
+ client.ppos.get_epoch_validators("latest")
1254
+ ```
1255
+
1256
+ ### 查看共识周期验证人
1257
+
1258
+ 查看当前共识周期的验证人,即共识中+出块中 ,funcType 1101。
1259
+
1260
+ * 参数
1261
+ * 无
1262
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1263
+ * 返回值
1264
+
1265
+ * 返回值
1266
+
1267
+ Array,其中每个元素中参数如下:
1268
+
1269
+ * `String`: NodeId ,被质押的节点Id(也叫候选人的节点Id)
1270
+ * `String`: BlsPubKey, BLS公钥
1271
+ * `String`: StakingAddress,发起质押时使用的账户(后续操作质押信息只能用这个账户,撤销质押时,von会被退回该账户或者该账户的锁仓信息中)
1272
+ * `String`: BenefitAddress, 用于接受出块奖励和质押奖励的收益账户
1273
+ * `Integer`: RewardPer, 节点收益返还比例, 10000为 100%
1274
+ * `Integer`: NextRewardPer
1275
+ * `Integer`: RewardPerChangeEpoch
1276
+ * `String`: StakingTxIndex,发起质押时的交易索引
1277
+ * `String`: ProgramVersion, 被质押节点的PlatON进程的真实版本号(获取版本号的接口由治理提供)
1278
+ * `Integer`: StakingBlockNum,发起质押时的区块高度
1279
+ * `String(0x十六进制字符串)`: Shares,当前候选人总共质押加被委托的von数目
1280
+ * `String`: ExternalId, 外部Id(有长度限制,给第三方拉取节点描述的Id)
1281
+ * `String`: NodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1282
+ * `String`: Website,节点的第三方主页(有长度限制,表示该节点的主页)
1283
+ * `String`: Details,节点的描述(有长度限制,表示该节点的描述)
1284
+
1285
+ * 示例
1286
+
1287
+ ```ruby
1288
+ client.ppos.get_round_validators
1289
+ or
1290
+ client.ppos.get_round_validators("latest")
1291
+ ```
1292
+
1293
+ ### 查看实时验证人列表 get_current_candidates
1294
+
1295
+ 查看当前共识周期的验证人,即当前所有节点,含候选中 ,funcType 1102。
1296
+
1297
+ * 参数
1298
+ * 无
1299
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1300
+ * 返回值
1301
+
1302
+ * 返回值
1303
+
1304
+ Array,其中每个元素中参数如下:
1305
+
1306
+ * `String`: NodeId ,被质押的节点Id(也叫候选人的节点Id)
1307
+ * `String`: BlsPubKey, BLS公钥
1308
+ * `String`: StakingAddress,发起质押时使用的账户(后续操作质押信息只能用这个账户,撤销质押时,von会被退回该账户或者该账户的锁仓信息中)
1309
+ * `String`: BenefitAddress, 用于接受出块奖励和质押奖励的收益账户
1310
+ * `Integer`: RewardPer, 节点收益返还比例, 10000为 100%
1311
+ * `Integer`: NextRewardPer
1312
+ * `Integer`: RewardPerChangeEpoch
1313
+ * `String`: StakingTxIndex,发起质押时的交易索引
1314
+ * `String`: ProgramVersion, 被质押节点的PlatON进程的真实版本号(获取版本号的接口由治理提供)
1315
+ * `String`: Status, 候选人的状态(状态是根据uint32的32bit来放置的,可同时存在多个状态,值为多个同时存在的状态值相加【0: 节点可用 (32个bit全为0); 1: 节点不可用 (只有最后一bit为1); 2: 节点出块率低但没有达到移除条件的(只有倒数第二bit为1); 4: 节点的von不足最低质押门槛(只有倒数第三bit为1); 8:节点被举报双签(只有倒数第四bit为1)); 16: 节点出块率低且达到移除条件(倒数第五位bit为1); 32: 节点主动发起撤销(只有倒数第六位bit为1)】
1316
+ * `Integer`: StakingEpoch, 当前变更质押金额时的结算周期
1317
+ * `Integer`: StakingBlockNum,发起质押时的区块高度
1318
+ * `String(0x十六进制字符串)`: Shares,当前候选人总共质押加被委托的von数目
1319
+ * `String(0x十六进制字符串)`: Released,发起质押账户的自由金额的锁定期质押的von
1320
+ * `String(0x十六进制字符串)`: ReleasedHes,发起质押账户的自由金额的犹豫期质押的von
1321
+ * `String(0x十六进制字符串)`: RestrictingPlan,发起质押账户的锁仓金额的锁定期质押的von
1322
+ * `String(0x十六进制字符串)`: RestrictingPlanHes,发起质押账户的锁仓金额的犹豫期质押的von
1323
+ * `Integer`: DelegateEpoch,最近一次对该候选人发起的委托时的结算周期
1324
+ * `String(0x十六进制字符串)`: DelegateTotal, 接受委托总数
1325
+ * `String(0x十六进制字符串)`: DelegateTotalHes
1326
+ * `String(0x十六进制字符串)`: DelegateRewardTotal 累计委托奖励
1327
+ * `String`: ExternalId, 外部Id(有长度限制,给第三方拉取节点描述的Id)
1328
+ * `String`: NodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1329
+ * `String`: Website,节点的第三方主页(有长度限制,表示该节点的主页)
1330
+ * `String`: Details,节点的描述(有长度限制,表示该节点的描述)
1331
+
1332
+ * 示例
1333
+
1334
+ ```ruby
1335
+ client.ppos.get_current_candidates
1336
+ or
1337
+ client.ppos.get_current_candidates("latest")
1338
+ ```
1339
+
1340
+ ### 查询账户所代理的节点ID get_delegate_nodeids_by_addr
1341
+
1342
+ 查询某账户锁代理的节点ID信息 , funcType 1103
1343
+
1344
+ * 参数
1345
+ * `String`: bech32 address ,委托人的账户地址
1346
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1347
+
1348
+ * 返回值
1349
+
1350
+ Array,其中每个元素中参数如下:
1351
+ * `String`: Addr , 委托人的账户地址
1352
+ * `Integer`: StakingBlockNum, 发起质押时的区块高度
1353
+
1354
+ * 示例
1355
+
1356
+ ```ruby
1357
+ client.ppos.get_delegate_nodeids_by_addr("your_atp_or_lat_address")
1358
+ ```
1359
+
1360
+ ### 查询单个委托信息 get_address_delegate_info
1361
+ 查询单个委托的相关信息, funType 1104
1362
+
1363
+ * 参数
1364
+ * `Integer`:发起质押时的区块高度
1365
+ * `String`: 委托人账户地址
1366
+ * `String`: 验证人的节点Id
1367
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1368
+ * 返回值
1369
+
1370
+ Array,其中每个元素中参数如下:
1371
+ * `String`: Addr , 委托人的账户地址
1372
+ * `Integer`: StakingBlockNum, 发起质押时的区块高度
1373
+ * `String`: NodeId ,被质押的节点Id(也叫候选人的节点Id)
1374
+ * `Integer`: DelegateEpoch: 最近一次对该候选人发起的委托时的结算周期
1375
+ * `String(0x十六进制字符串)`: Released,发起质押账户的自由金额的锁定期质押的von
1376
+ * `String(0x十六进制字符串)`: ReleasedHes,发起质押账户的自由金额的犹豫期质押的von
1377
+ * `String(0x十六进制字符串)`: RestrictingPlan,发起质押账户的锁仓金额的锁定期质押的von
1378
+ * `String(0x十六进制字符串)`: RestrictingPlanHes,发起质押账户的锁仓金额的犹豫期质押的von
1379
+ * `String(0x十六进制字符串)`: CumulativeIncome
1380
+
1381
+ * 示例
1382
+
1383
+ ```ruby
1384
+ client.ppos.get_address_delegate_info(509677,"atp1842mp45vw30vgvzmylwdxmxxc00ggjp6q2gv8v","fad2c7f917eb3057d85031eae8bbda52541b527dd1d24a25e7e9b40d7329570a85dc45ec61b189a9cc30047ae906a08dc375558828e1c76dc853ce99b42b91e4")
1385
+ ```
1386
+
1387
+
1388
+
1389
+ ### 查询质押信息 get_node_delegate_info
1390
+
1391
+ 查询节点的质押信息 , funcType 1105
1392
+
1393
+ * 参数
1394
+
1395
+ * `String`: 验证人的节点id
1396
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1397
+
1398
+ * 返回值
1399
+
1400
+ Array,其中每个元素中参数如下:
1401
+ * `String`: NodeId ,被质押的节点Id(也叫候选人的节点Id)
1402
+ * `String`: StakingAddress,发起质押时使用的账户(后续操作质押信息只能用这个账户,撤销质押时,von会被退回该账户或者该账户的锁仓信息中)
1403
+ * `String`: BenefitAddress, 用于接受出块奖励和质押奖励的收益账户
1404
+ * `String`: StakingTxIndex,发起质押时的交易索引
1405
+ * `String`: ProgramVersion, 被质押节点的PlatON进程的真实版本号(获取版本号的接口由治理提供)
1406
+ * `String`: Status, 候选人的状态(状态是根据uint32的32bit来放置的,可同时存在多个状态,值为多个同时存在的状态值相加【0: 节点可用 (32个bit全为0); 1: 节点不可用 (只有最后一bit为1); 2: 节点出块率低但没有达到移除条件的(只有倒数第二bit为1); 4: 节点的von不足最低质押门槛(只有倒数第三bit为1); 8:节点被举报双签(只有倒数第四bit为1)); 16: 节点出块率低且达到移除条件(倒数第五位bit为1); 32: 节点主动发起撤销(只有倒数第六位bit为1)】
1407
+ * `Integer`: StakingEpoch, 当前变更质押金额时的结算周期
1408
+ * `Integer`: StakingBlockNum,发起质押时的区块高度
1409
+ * `String(0x十六进制字符串)`: Shares,当前候选人总共质押加被委托的von数目
1410
+ * `String(0x十六进制字符串)`: Released,发起质押账户的自由金额的锁定期质押的von
1411
+ * `String(0x十六进制字符串)`: ReleasedHes,发起质押账户的自由金额的犹豫期质押的von
1412
+ * `String(0x十六进制字符串)`: RestrictingPlan,发起质押账户的锁仓金额的锁定期质押的von
1413
+ * `String(0x十六进制字符串)`: RestrictingPlanHes,发起质押账户的锁仓金额的犹豫期质押的von
1414
+ * `String`: ExternalId, 外部Id(有长度限制,给第三方拉取节点描述的Id)
1415
+ * `String`: NodeName,被质押节点的名称(有长度限制,表示该节点的名称)
1416
+ * `String`: Website,节点的第三方主页(有长度限制,表示该节点的主页)
1417
+ * `String`: Details,节点的描述(有长度限制,表示该节点的描述)
1418
+
1419
+ * 示例
1420
+
1421
+ ```ruby
1422
+ client.ppos.get_node_delegate_info("0x48f9ebd7559b7849f80e00d89d87fb92604c74a541a7d76fcef9f2bcc67043042dfab0cfbaeb5386f921208ed9192c403f438934a0a39f4cad53c55d8272e5fb")
1423
+ => {:jsonrpc=>"2.0", :method=>"platon_call", :params=>[{"data"=>"0xf84883820451b842b84048f9ebd7559b7849f80e00d89d87fb92604c74a541a7d76fcef9f2bcc67043042dfab0cfbaeb5386f921208ed9192c403f438934a0a39f4cad53c55d8272e5fb", "to"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzfyslg3"}, "latest"], :id=>1}
1424
+ => {"Code"=>0, "Ret"=>{"NodeId"=>"48f9ebd7559b7849f80e00d89d87fb92604c74a541a7d76fcef9f2bcc67043042dfab0cfbaeb5386f921208ed9192c403f438934a0a39f4cad53c55d8272e5fb", "BlsPubKey"=>"821043f4df086533691f0445deb51cf524f45ab7a855a3f1a79fa0f65ceb1cabd2674bbe4575c645dfbd878734ad0910568db5aebcd46bfd72d50c9007c1328559fb1e7de876990ab7c7d3bc7cb9e291da6fe28ba185de5fe7f99566de3b8381", "StakingAddress"=>"atp129fa9ypppsfv5kljjdg6g49kc4tuzhz6f9cleu", "BenefitAddress"=>"atp1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr5jy24r", "RewardPer"=>0, "NextRewardPer"=>0, "RewardPerChangeEpoch"=>0, "StakingTxIndex"=>0, "ProgramVersion"=>3841, "Status"=>0, "StakingEpoch"=>0, "StakingBlockNum"=>0, "Shares"=>"0x23934c5a09da1900000", "Released"=>"0x23934c5a09da1900000", "ReleasedHes"=>"0x0", "RestrictingPlan"=>"0x0", "RestrictingPlanHes"=>"0x0", "DelegateEpoch"=>0, "DelegateTotal"=>"0x0", "DelegateTotalHes"=>"0x0", "DelegateRewardTotal"=>"0x0", "ExternalId"=>"", "NodeName"=>"alaya.node.1", "Website"=>"alaya.network", "Details"=>"The Alaya Node"}}
1425
+ ```
1426
+
1427
+ ### 查询当前结算周期的区块奖励 get_block_reward
1428
+ 查询当前结算周期的区块奖励
1429
+
1430
+ * 参数
1431
+ * 无
1432
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1433
+
1434
+ * 返回值
1435
+ * `String(0x十六进制字符串)`
1436
+
1437
+ * 示例
1438
+
1439
+ ```ruby
1440
+ client.ppos.get_block_reward
1441
+ ```
1442
+
1443
+ ### 查询当前结算周期的质押奖励 get_staking_reward
1444
+ 查询当前结算周期的质押奖励
1445
+ * 参数
1446
+ * 无
1447
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1448
+
1449
+ * 返回值
1450
+ * `String(0x十六进制字符串)`
1451
+
1452
+ * 示例
1453
+
1454
+ ```ruby
1455
+ client.ppos.get_staking_reward
1456
+ ```
1457
+
1458
+ ## 治理模块
1459
+
1460
+ ### 提交文本提案 submit_proposal
1461
+ 提交文本提案(2000)
1462
+
1463
+ * 参数
1464
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1465
+ * `String`: verifier, 传入node_id,提交提案的验证人
1466
+ * `String(uint64)`: piDID, PIPID
1467
+
1468
+ * 返回值
1469
+ * `String`: 交易hash
1470
+ * 示例
1471
+
1472
+ ```ruby
1473
+ client.ppos.submit_proposal(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d","1",{gas_price:(1.5 * 10**15).to_i,gas_limit:350000})
1474
+ ```
1475
+
1476
+ ### 提交升级提案 update_proposal
1477
+ 提交升级提案2001
1478
+
1479
+ * 参数
1480
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1481
+ * `String`: verifier, 传入node_id,提交提案的验证人
1482
+ * `String(uint64)`: piDID, PIPID
1483
+ * `Integer`: newVersion, 升级版本
1484
+ * `Integer`: endVotingRounds, 投票共识轮数量。说明:假设提交提案的交易,被打包进块时的共识轮序号时round1,则提案投票截止块高,就是round1 + endVotingRounds这个共识轮的第230个块高(假设一个共识轮出块250,ppos揭榜提前20个块高,250,20都是可配置的 ),其中0 < endVotingRounds <= 4840(约为2周,实际论述根据配置可计算),且为整数)
1485
+ * 返回值
1486
+ * `String`: 交易hash
1487
+ * 示例
1488
+
1489
+ ```ruby
1490
+ client.ppos.update_proposal(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d","15",2,10,{gas_price:(2.2 * 10**15).to_i,gas_limit:480000})
1491
+ ```
1492
+
1493
+ ### 提交取消提案 cancel_proposal
1494
+ 提交取消提案 (2005)
1495
+
1496
+ * 参数
1497
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1498
+ * `String`: verifier, 传入node_id,提交提案的验证人
1499
+ * `String(uint64)`: piDID, PIPID
1500
+ * `Integer`: endVotingRounds,投票共识轮数量。参考提交升级提案的说明,同时,此接口中此参数的值不能大于对应升级提案中的值
1501
+ * `String`: tobeCanceledProposalID,待取消的升级提案ID
1502
+
1503
+ * 返回值
1504
+ * `String`: 交易hash
1505
+ * 示例
1506
+
1507
+ ```ruby
1508
+ client.ppos.cancel_proposal(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d","15",9,"0x01bb9da5d4a5649aa6adf5cfc87f2986c5bd8c7be3c1bf1addf30f4c99caf432")
1509
+ ```
1510
+
1511
+ ### 给提案投票 vote_proposal
1512
+ 给提案投票(2003)
1513
+
1514
+ * 参数
1515
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1516
+ * `String`: verifier, 传入node_id,提交提案的验证人
1517
+ * `String(uint64)`: piDID, PIPID
1518
+ * `Integer`: option,投票选项 , 1:支持;2:反对;3:弃权
1519
+ * `String`: programVersion,节点代码版本,有rpc的get_program_version接口获取
1520
+ * `String`: versionSign,代码版本签名,有rpc的get_program_version接口获取
1521
+ * 返回值
1522
+ * `String`: 交易hash
1523
+ * 示例
1524
+
1525
+ ```ruby
1526
+ client.ppos.vote_proposal(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d","15", 1, 65536,"0x7f4d68fb9f100aff45b9c4730c102973ca7bd63d262c2707bb3e8b18ead2865272c1b4ed23de9bfd13ebb41b3562969cfdafc303e070c4b71723c997a8c53fbd01")
1527
+ ```
1528
+
1529
+ ### 版本声明 declare_version
1530
+ 版本声明(2004)
1531
+
1532
+ * 参数
1533
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1534
+ * `String`: verifier, 传入node_id,提交提案的验证人
1535
+ * `String`: programVersion,节点代码版本,有rpc的get_program_version接口获取
1536
+ * `String`: versionSign,代码版本签名,有rpc的get_program_version接口获取
1537
+ * 返回值
1538
+ * `String`: 交易hash
1539
+ * 示例
1540
+
1541
+ ```ruby
1542
+ client.ppos.declare_version(key,"9d3f5a4d80a4b5b89df5ad7dadd1ef0e54854decfd5c4b808d064d4e73374e9848ac6b02bc651e9ea15f184b2a4317ea50424402670799bb0910cafeb7323f4d",65536,"0x7f4d68fb9f100aff45b9c4730c102973ca7bd63d262c2707bb3e8b18ead2865272c1b4ed23de9bfd13ebb41b3562969cfdafc303e070c4b71723c997a8c53fbd01")
1543
+ ```
1544
+
1545
+ ### 查询提案列表 get_proposals
1546
+ 查询提案列表,funcType 2102
1547
+
1548
+ * 参数
1549
+ * 无
1550
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1551
+
1552
+ * 返回值
1553
+
1554
+ Array,其中每个元素为Proposal数据结构
1555
+
1556
+ * 示例
1557
+
1558
+ ```ruby
1559
+ client.ppos.get_proposals
1560
+ ```
1561
+
1562
+ ### 提案查询 get_proposal_info
1563
+ 针对某提案进行查询,funcType:2100
1564
+
1565
+ * 参数
1566
+ * `String`: proposal id ,待查询的提案ID
1567
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1568
+ * 返回值
1569
+
1570
+ Proposal接口实现对象的json字符串
1571
+
1572
+ * 示例
1573
+
1574
+ ```ruby
1575
+ client.ppos.get_proposal_info("0x261cf6c0f518aeddffb2aa5536685af6f13f8ba763c77b42f12ce025ef7170ed")
1576
+ ```
1577
+
1578
+ ### 查询提案结果 get_proposal_result
1579
+ 针对某提案,查询提案结果, funcType: 2101
1580
+
1581
+ * 参数
1582
+ * `String`: proposal id ,待查询的提案ID
1583
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1584
+
1585
+ * 返回值
1586
+ TallyResult对象的json字符串,TallyResult:保存单个提案结果的对象
1587
+
1588
+ * `String`: proposalID 提案ID
1589
+ * `Integer`: yeas 赞成票票数
1590
+ * `Integer`: nays 反对票票数
1591
+ * `Integer`: abstentions 弃权票票数
1592
+ * `Integer`: accuVerifiers 在整个投票期内有投票资格的验证人总数
1593
+ * `Integer`: status 提案状态 。 1 投票中,2:投票通过,3:投票失败,4:(升级提案)预生效,5:(升级提案)生效,6:被取消
1594
+
1595
+ * 示例
1596
+
1597
+ ```ruby
1598
+ client.ppos.get_proposal_result("0x261cf6c0f518aeddffb2aa5536685af6f13f8ba763c77b42f12ce025ef7170ed")
1599
+ => {"Code"=>0, "Ret"=>{"proposalID"=>"0x261cf6c0f518aeddffb2aa5536685af6f13f8ba763c77b42f12ce025ef7170ed", "yeas"=>102, "nays"=>0, "abstentions"=>0, "accuVerifiers"=>116, "status"=>5, "canceledBy"=>"0x0000000000000000000000000000000000000000000000000000000000000000"}}
1600
+ ```
1601
+
1602
+ ### 查询节点的链生效版本 get_version_in_effect
1603
+
1604
+ 查询节点的链生效版本, funcType:2103
1605
+
1606
+ * 参数
1607
+
1608
+ * 无
1609
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1610
+
1611
+ * 返回值
1612
+ * 版本号的json字符串,如{65536},表示版本是:1.0.0。 解析时,需要把ver转成4个字节。主版本:第二个字节;小版本:第三个字节,patch版本,第四个字节。解析示例见下:
1613
+ * 示例
1614
+
1615
+ ```ruby
1616
+ client.ppos.get_version_in_effect
1617
+ {"Code"=>0, "Ret"=>3840}
1618
+
1619
+ ## 版本号解析
1620
+ 65535.to_s(16) => "10000" 即 1.0.0
1621
+ 3840.to_s(16) => "f00" 即 0.15.0
1622
+
1623
+ ```
1624
+
1625
+ ### 查询提案投票人数 get_votes_number
1626
+ 指定proposal id 与区块hash,查询提案投票人数,funcType:2105
1627
+
1628
+ * 参数
1629
+
1630
+ * 无
1631
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1632
+
1633
+ * 返回值
1634
+ * `Array`: 包含4个元素,含义分别为:累积可投票人数、赞成票数、反对票数、弃权票数
1635
+
1636
+ * 示例
1637
+
1638
+ ```ruby
1639
+ client.ppos.get_votes_number("0x261cf6c0f518aeddffb2aa5536685af6f13f8ba763c77b42f12ce025ef7170ed","0x520a94980d6a243d469040936fcb64928e2a3bde1d79508ffd80e4a0d4fc3e57")
1640
+
1641
+ => {"Code"=>0, "Ret"=>[116, 102, 0, 0]}
1642
+
1643
+ ```
1644
+
1645
+ ### 查询治理参数列表 get_govern_params
1646
+ 查询治理参数列表,funcType: 2106
1647
+
1648
+ * 参数
1649
+ * `String`, module name
1650
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1651
+
1652
+ * 返回值
1653
+ Array,其中每个元素结构为:
1654
+ * `Object`: ParamItem :
1655
+ * `String`: Module
1656
+ * `String`: Name
1657
+ * `String`: Desc ,描述
1658
+ * `Object`: ParamValue :
1659
+ * `String`: StaleValue
1660
+ * `String`: Value ,值
1661
+ * `Integer`: ActiveBlock
1662
+ * 示例
1663
+
1664
+ ```ruby
1665
+ client.ppos.get_govern_params("staking")
1666
+
1667
+ => {"Code"=>0, "Ret"=>[{"ParamItem"=>{"Module"=>"staking", "Name"=>"stakeThreshold", "Desc"=>"minimum amount of stake, range: [10000000000000000000000, 1000000000000000000000000]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"10000000000000000000000", "ActiveBlock"=>0}}, {"ParamItem"=>{"Module"=>"staking", "Name"=>"operatingThreshold", "Desc"=>"minimum amount of stake increasing funds, delegation funds, or delegation withdrawing funds, range: [1000000000000000000, 10000000000000000000000]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"1000000000000000000", "ActiveBlock"=>0}}, {"ParamItem"=>{"Module"=>"staking", "Name"=>"maxValidators", "Desc"=>"maximum amount of validator, range: [25, 201]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"101", "ActiveBlock"=>0}}, {"ParamItem"=>{"Module"=>"staking", "Name"=>"unStakeFreezeDuration", "Desc"=>"quantity of epoch for skake withdrawal, range: (MaxEvidenceAge, 336]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"168", "ActiveBlock"=>0}}, {"ParamItem"=>{"Module"=>"staking", "Name"=>"rewardPerMaxChangeRange", "Desc"=>"Delegated Reward Ratio The maximum adjustable range of each modification, range: [1, 2000]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"500", "ActiveBlock"=>0}}, {"ParamItem"=>{"Module"=>"staking", "Name"=>"rewardPerChangeInterval", "Desc"=>"The interval for each modification of the commission reward ratio, range: [2, 28]"}, "ParamValue"=>{"StaleValue"=>"", "Value"=>"10", "ActiveBlock"=>0}}]}
1668
+ ```
1669
+
1670
+ ### 查询当前块高的治理参数值 get_govern_param_value
1671
+ 查询当前块高的治理参数值 funcType:2106
1672
+ * 参数
1673
+
1674
+ * `String`, module name 模块名称
1675
+ * `String`, name ,方法名
1676
+ * `Integer | String` : (可选,默认"latest")可传递区块号 或 "lastest", "earliest","pending"。详见默认区块参数 [默认区块参数说明](#默认区块参数说明)。
1677
+ * 返回值
1678
+
1679
+ * `String`: 该param的值
1680
+
1681
+ * 示例
1682
+
1683
+ ```ruby
1684
+ client.ppos.get_govern_param_value("staking","stakeThreshold")
1685
+ => {"Code"=>0, "Ret"=>"10000000000000000000000"}
1686
+ ```
1687
+
1688
+
1689
+ ### 举报双签 report_duplicate_sign
1690
+ 举报节点双签(3000)
1691
+
1692
+ * 参数
1693
+ * `Object`: 发起方的 Key 实例,通过 Platon::Key.new 创建或导入
1694
+ * `Integer`: typ, 代表双签类型,1:prepareBlock,2:prepareVote,3:viewChange
1695
+ * `String`: data, 单个证据的json值,格式参照[RPC接口Evidences]
1696
+ * 返回值
1697
+ * `String`: 交易hash
1698
+ * 示例
1699
+
1700
+ ```ruby
1701
+ client.ppos.report_duplicate_sign(key,1,"{}")
1702
+ ```
1703
+
1704
+ ### 查询节点被举报双签 get_node_oversign
1705
+ funcType:3001
1706
+
1707
+ * 参数
1708
+ * `Integer`: type 代表双签类型,1:prepareBlock,2:prepareVote,3:viewChange
1709
+ * `String`: 节点ID ,64bytes
1710
+ * `Integer`: 多签的块高
1711
+ * 返回值
1712
+ * `String`: 举报的交易hash
1713
+ * 示例
1714
+
1715
+ ```ruby
1716
+ client.ppos.get_node_oversign(1,"0xed552a64f708696ac53962b88e927181688c8bc260787c82e1c9c21a62da4ce59c31fc594e48249e89392ce2e6e2a0320d6688b38ad7884ff6fe664faf4b12d9",12300000)
1717
+ ```
1718
+
1719
+
1720
+ ### 创建锁仓计划 create_restricting_plan
1721
+
1722
+ 创建锁仓计划(4000)
1723
+
1724
+ * 参数
1725
+ * `String`: address ,锁仓释放到账的账户
1726
+ * `Array`: 锁仓计划列表,数组,数组结构为
1727
+ - `Integer`: epoch,锁仓的周期,表示结算周期的倍数。与每个结算周期出块数的乘积表示在目标区块高度上释放锁定的资金。Epoch * 每周期的区块数至少要大于最高不可逆区块高度。
1728
+ - `Integer`: amount, 标识目标区块上待释放的金额 。注意需要大于治理参数中minimumRelease
1729
+
1730
+ * 返回值
1731
+ * `String`: 举报的交易hash
1732
+
1733
+ * 示例
1734
+
1735
+ ```ruby
1736
+ client.ppos.create_restricting_plan(key,"lat10z2enrjz2lk2hz3n9z3l2gmyxujnhuaqklw6dd",[[50,200 * 10**18]])
1737
+ ```
1738
+
1739
+ ### 获取锁仓计划 get_restricting_info
1740
+
1741
+ 获取锁仓计划(4100)
1742
+
1743
+ * 参数
1744
+ * `String`: address 锁仓释放到账的账户
1745
+
1746
+ * 返回值
1747
+ * `String`: balance, 总锁仓余额-已释放金额
1748
+ * `String`: pledge , 质押/抵押金额
1749
+ * `String`: debt , 欠释放金额
1750
+ * `Array`: plans , 锁仓分录信息,json数组:[{"blockNumber":"","amount":""},...,{"blockNumber":"","amount":""}]。其中:
1751
+ blockNumber:`Integer` ,释放区块高度
1752
+ amount:`string(0x十六进制字符串)`,释放金额
1753
+
1754
+ * 示例
1755
+
1756
+ ```ruby
1757
+ client.ppos.get_restricting_info("lat10z2enrjz2lk2hz3n9z3l2gmyxujnhuaqklw6dd")
1758
+
1759
+ =>{"Code"=>0, "Ret"=>{"balance"=>"0xad78ebc5ac6200000", "debt"=>"0x0", "plans"=>[{"blockNumber"=>2074750, "amount"=>"0xad78ebc5ac6200000"}], "Pledge"=>"0x0"}}
1760
+ ```
1761
+
1762
+