klay 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS.txt +5 -4
- data/LICENSE.txt +0 -1
- data/README.md +30 -84
- data/bin/setup +1 -1
- data/klay.gemspec +1 -1
- data/lib/klay/abi/type.rb +8 -8
- data/lib/klay/abi.rb +7 -7
- data/lib/klay/address.rb +5 -5
- data/lib/klay/api.rb +84 -84
- data/lib/klay/chain.rb +2 -2
- data/lib/klay/client/http.rb +2 -2
- data/lib/klay/client/ipc.rb +2 -2
- data/lib/klay/client.rb +18 -18
- data/lib/klay/constant.rb +2 -2
- data/lib/klay/eip712.rb +2 -2
- data/lib/klay/key/decrypter.rb +9 -9
- data/lib/klay/key/encrypter.rb +8 -8
- data/lib/klay/key.rb +12 -12
- data/lib/klay/rlp/decoder.rb +3 -3
- data/lib/klay/rlp/encoder.rb +4 -4
- data/lib/klay/rlp/sedes/big_endian_int.rb +2 -2
- data/lib/klay/rlp/sedes/binary.rb +3 -3
- data/lib/klay/rlp/sedes/list.rb +2 -2
- data/lib/klay/rlp/sedes.rb +6 -6
- data/lib/klay/rlp.rb +4 -4
- data/lib/klay/signature.rb +10 -11
- data/lib/klay/tx/eip1559.rb +9 -9
- data/lib/klay/tx/eip2930.rb +9 -9
- data/lib/klay/tx/legacy.rb +9 -9
- data/lib/klay/tx.rb +7 -7
- data/lib/klay/unit.rb +9 -21
- data/lib/klay/util.rb +5 -5
- data/lib/klay/version.rb +4 -4
- data/lib/klay.rb +3 -3
- metadata +2 -4
- data/.github/workflows/codeql.yml +0 -48
- data/.github/workflows/docs.yml +0 -26
data/lib/klay/tx/eip2930.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
18
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -75,8 +75,8 @@ module Klay
|
|
75
75
|
# @option params [Integer] :nonce the signer nonce.
|
76
76
|
# @option params [Integer] :gas_price the gas price.
|
77
77
|
# @option params [Integer] :gas_limit the gas limit.
|
78
|
-
# @option params [
|
79
|
-
# @option params [
|
78
|
+
# @option params [Klay::Address] :from the sender address.
|
79
|
+
# @option params [Klay::Address] :to the reciever address.
|
80
80
|
# @option params [Integer] :value the transaction value.
|
81
81
|
# @option params [String] :data the transaction data payload.
|
82
82
|
# @option params [Array] :access_list an optional access list.
|
@@ -124,11 +124,11 @@ module Klay
|
|
124
124
|
# Overloads the constructor for decoding raw transactions and creating unsigned copies.
|
125
125
|
konstructor :decode, :unsigned_copy
|
126
126
|
|
127
|
-
# Decodes a raw transaction hex into an {
|
127
|
+
# Decodes a raw transaction hex into an {Klay::Tx::Eip2930}
|
128
128
|
# transaction object.
|
129
129
|
#
|
130
130
|
# @param hex [String] the raw transaction hex-string.
|
131
|
-
# @return [
|
131
|
+
# @return [Klay::Tx::Eip2930] transaction payload.
|
132
132
|
# @raise [TransactionTypeError] if transaction type is invalid.
|
133
133
|
# @raise [ParameterError] if transaction is missing fields.
|
134
134
|
# @raise [DecoderError] if transaction decoding fails.
|
@@ -189,8 +189,8 @@ module Klay
|
|
189
189
|
|
190
190
|
# Creates an unsigned copy of a transaction payload.
|
191
191
|
#
|
192
|
-
# @param tx [
|
193
|
-
# @return [
|
192
|
+
# @param tx [Klay::Tx::Eip2930] an EIP-2930 transaction payload.
|
193
|
+
# @return [Klay::Tx::Eip2930] an unsigned EIP-2930 transaction payload.
|
194
194
|
# @raise [TransactionTypeError] if transaction type does not match.
|
195
195
|
def unsigned_copy(tx)
|
196
196
|
|
@@ -219,7 +219,7 @@ module Klay
|
|
219
219
|
|
220
220
|
# Sign the transaction with a given key.
|
221
221
|
#
|
222
|
-
# @param key [
|
222
|
+
# @param key [Klay::Key] the key-pair to use for signing.
|
223
223
|
# @return [String] a transaction hash.
|
224
224
|
# @raise [Signature::SignatureError] if transaction is already signed.
|
225
225
|
# @raise [Signature::SignatureError] if sender address does not match signing key.
|
data/lib/klay/tx/legacy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
18
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -67,8 +67,8 @@ module Klay
|
|
67
67
|
# @option params [Integer] :nonce the signer nonce.
|
68
68
|
# @option params [Integer] :gas_price the gas price.
|
69
69
|
# @option params [Integer] :gas_limit the gas limit.
|
70
|
-
# @option params [
|
71
|
-
# @option params [
|
70
|
+
# @option params [Klay::Address] :from the sender address.
|
71
|
+
# @option params [Klay::Address] :to the reciever address.
|
72
72
|
# @option params [Integer] :value the transaction value.
|
73
73
|
# @option params [String] :data the transaction data payload.
|
74
74
|
# @param chain_id [Integer] the EIP-155 Chain ID.
|
@@ -113,11 +113,11 @@ module Klay
|
|
113
113
|
# overloads the constructor for decoding raw transactions and creating unsigned copies
|
114
114
|
konstructor :decode, :unsigned_copy
|
115
115
|
|
116
|
-
# Decodes a raw transaction hex into an {
|
116
|
+
# Decodes a raw transaction hex into an {Klay::Tx::Legacy}
|
117
117
|
# transaction object.
|
118
118
|
#
|
119
119
|
# @param hex [String] the raw transaction hex-string.
|
120
|
-
# @return [
|
120
|
+
# @return [Klay::Tx::Legacy] transaction object.
|
121
121
|
# @raise [ParameterError] if transaction misses fields.
|
122
122
|
def decode(hex)
|
123
123
|
bin = Util.hex_to_bin hex
|
@@ -170,8 +170,8 @@ module Klay
|
|
170
170
|
|
171
171
|
# Creates an unsigned copy of a transaction.
|
172
172
|
#
|
173
|
-
# @param tx [
|
174
|
-
# @return [
|
173
|
+
# @param tx [Klay::Tx::Legacy] an legacy transaction object.
|
174
|
+
# @return [Klay::Tx::Legacy] an unsigned transaction object.
|
175
175
|
# @raise [TransactionTypeError] if transaction type does not match.
|
176
176
|
def unsigned_copy(tx)
|
177
177
|
|
@@ -199,7 +199,7 @@ module Klay
|
|
199
199
|
|
200
200
|
# Sign the transaction with a given key.
|
201
201
|
#
|
202
|
-
# @param key [
|
202
|
+
# @param key [Klay::Key] the key-pair to use for signing.
|
203
203
|
# @return [String] a transaction hash.
|
204
204
|
# @raise [Signature::SignatureError] if transaction is already signed.
|
205
205
|
# @raise [Signature::SignatureError] if sender address does not match signing key.
|
data/lib/klay/tx.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -20,7 +20,7 @@ require "klay/tx/eip2930"
|
|
20
20
|
require "klay/tx/legacy"
|
21
21
|
require "klay/unit"
|
22
22
|
|
23
|
-
# Provides the {
|
23
|
+
# Provides the {Klay} module.
|
24
24
|
module Klay
|
25
25
|
|
26
26
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -39,8 +39,8 @@ module Klay
|
|
39
39
|
# The minimum transaction gas limit required for a value transfer.
|
40
40
|
DEFAULT_GAS_LIMIT = 21_000.freeze
|
41
41
|
|
42
|
-
# The "default" transaction gas price of
|
43
|
-
DEFAULT_GAS_PRICE = (
|
42
|
+
# The "default" transaction gas price of 25 GPeb.
|
43
|
+
DEFAULT_GAS_PRICE = (25 * Unit::GPEB).freeze
|
44
44
|
|
45
45
|
# The calldata gas cost of a non-zero byte as per EIP-2028.
|
46
46
|
COST_NON_ZERO_BYTE = 16.freeze
|
@@ -101,7 +101,7 @@ module Klay
|
|
101
101
|
# Decodes a transaction hex of any known type (2, 1, or legacy).
|
102
102
|
#
|
103
103
|
# @param hex [String] the raw transaction hex-string.
|
104
|
-
# @return [
|
104
|
+
# @return [Klay::Tx] transaction payload.
|
105
105
|
# @raise [TransactionTypeError] if the transaction type is unknown.
|
106
106
|
def decode(hex)
|
107
107
|
hex = Util.remove_hex_prefix hex
|
@@ -128,8 +128,8 @@ module Klay
|
|
128
128
|
|
129
129
|
# Creates an unsigned copy of any transaction object.
|
130
130
|
#
|
131
|
-
# @param tx [
|
132
|
-
# @return [
|
131
|
+
# @param tx [Klay::Tx] any transaction payload.
|
132
|
+
# @return [Klay::Tx] an unsigned transaction payload of the same type.
|
133
133
|
# @raise [TransactionTypeError] if the transaction type is unknown.
|
134
134
|
def unsigned_copy(tx)
|
135
135
|
case tx.type
|
data/lib/klay/unit.rb
CHANGED
@@ -14,36 +14,24 @@
|
|
14
14
|
|
15
15
|
require "bigdecimal"
|
16
16
|
|
17
|
-
# Provides the {
|
17
|
+
# Provides the {Klay} module.
|
18
18
|
module Klay
|
19
19
|
|
20
20
|
# Provides constants for common Ethereum units.
|
21
21
|
module Unit
|
22
22
|
extend self
|
23
23
|
|
24
|
-
# Ethereum unit 1
|
25
|
-
|
24
|
+
# Ethereum unit 1 peb := 0.000000000000000001 Klay.
|
25
|
+
PEB = BigDecimal("1e0").freeze
|
26
26
|
|
27
|
-
# Ethereum unit 1
|
28
|
-
|
27
|
+
# Ethereum unit 1 ston := 0.000000001 Klay or 1_000_000_000 peb.
|
28
|
+
STON = BigDecimal("1e9").freeze
|
29
29
|
|
30
|
-
# Ethereum unit 1
|
31
|
-
LOVELACE = BigDecimal("1e6").freeze
|
32
|
-
|
33
|
-
# Ethereum unit 1 shannon := 0.000000001 Ether or 1_000_000_000 wei.
|
34
|
-
SHANNON = BigDecimal("1e9").freeze
|
35
|
-
|
36
|
-
# Ethereum unit 1 szabo := 0.000_001 Ether or 1_000_000_000_000 wei.
|
37
|
-
SZABO = BigDecimal("1e12").freeze
|
38
|
-
|
39
|
-
# Ethereum unit 1 finney := 0.001 Ether or 1_000_000_000_000_000 wei.
|
40
|
-
FINNEY = BigDecimal("1e15").freeze
|
41
|
-
|
42
|
-
# Ethereum unit 1 Ether := 1_000_000_000_000_000_000 wei.
|
30
|
+
# Ethereum unit 1 Klay := 1_000_000_000_000_000_000 peb.
|
43
31
|
ETHER = BigDecimal("1e18").freeze
|
44
32
|
|
45
|
-
# Ethereum unit 1
|
46
|
-
# Same as shannon, but more commonly used (billion
|
47
|
-
|
33
|
+
# Ethereum unit 1 Gpeb := 0.000000001 Ether or 1_000_000_000 peb.
|
34
|
+
# Same as shannon, but more commonly used (billion peb).
|
35
|
+
GPEB = STON.freeze
|
48
36
|
end
|
49
37
|
end
|
data/lib/klay/util.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,18 +14,18 @@
|
|
14
14
|
|
15
15
|
require "digest/keccak"
|
16
16
|
|
17
|
-
# Provides the {
|
17
|
+
# Provides the {Klay} module.
|
18
18
|
module Klay
|
19
19
|
|
20
|
-
# Defines handy tools for the {
|
20
|
+
# Defines handy tools for the {Klay} gem for convenience.
|
21
21
|
module Util
|
22
22
|
extend self
|
23
23
|
|
24
|
-
# Generates an
|
24
|
+
# Generates an Klaytn address from a given compressed or
|
25
25
|
# uncompressed binary or hexadecimal public key string.
|
26
26
|
#
|
27
27
|
# @param str [String] the public key to be converted.
|
28
|
-
# @return [
|
28
|
+
# @return [Klay::Address] an Klaytn address.
|
29
29
|
def public_key_to_address(str)
|
30
30
|
str = hex_to_bin str if is_hex? str
|
31
31
|
bytes = keccak256(str[1..-1])[-20..-1]
|
data/lib/klay/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,9 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
|
-
# Defines the version of the {
|
19
|
-
VERSION = "0.0.
|
18
|
+
# Defines the version of the {Klay} module.
|
19
|
+
VERSION = "0.0.5".freeze
|
20
20
|
end
|
data/lib/klay.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
1
|
+
# Copyright (c) 2016-2022 The Ruby-Klay Contributors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,11 +12,11 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
# Provides the {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
end
|
18
18
|
|
19
|
-
# Loads the {
|
19
|
+
# Loads the {Klay} module classes.
|
20
20
|
require "klay/abi"
|
21
21
|
require "klay/api"
|
22
22
|
require "klay/address"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sehan Park
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: keccak
|
@@ -87,8 +87,6 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".github/workflows/codeql.yml"
|
91
|
-
- ".github/workflows/docs.yml"
|
92
90
|
- ".github/workflows/spec.yml"
|
93
91
|
- ".gitignore"
|
94
92
|
- ".gitmodules"
|
@@ -1,48 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: CodeQL
|
3
|
-
|
4
|
-
on:
|
5
|
-
pull_request:
|
6
|
-
branches:
|
7
|
-
- main
|
8
|
-
push:
|
9
|
-
branches:
|
10
|
-
- main
|
11
|
-
|
12
|
-
jobs:
|
13
|
-
analyze:
|
14
|
-
name: Analyze
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
permissions:
|
17
|
-
actions: read
|
18
|
-
contents: read
|
19
|
-
security-events: write
|
20
|
-
strategy:
|
21
|
-
fail-fast: false
|
22
|
-
matrix:
|
23
|
-
language:
|
24
|
-
- ruby
|
25
|
-
steps:
|
26
|
-
- name: "Checkout repository"
|
27
|
-
uses: actions/checkout@v2
|
28
|
-
- name: "Initialize CodeQL"
|
29
|
-
uses: github/codeql-action/init@v1
|
30
|
-
with:
|
31
|
-
languages: "${{ matrix.language }}"
|
32
|
-
- name: Autobuild
|
33
|
-
uses: github/codeql-action/autobuild@v1
|
34
|
-
- name: "Perform CodeQL Analysis"
|
35
|
-
uses: github/codeql-action/analyze@v1
|
36
|
-
- uses: ruby/setup-ruby@v1
|
37
|
-
with:
|
38
|
-
ruby-version: '2.7'
|
39
|
-
bundler-cache: true
|
40
|
-
- name: "Run rufo code formatting checks"
|
41
|
-
run: |
|
42
|
-
gem install rufo
|
43
|
-
rufo --check ./lib
|
44
|
-
rufo --check ./spec
|
45
|
-
- name: "Run yard documentation checks"
|
46
|
-
run: |
|
47
|
-
gem install yard
|
48
|
-
yard doc --fail-on-warning
|
data/.github/workflows/docs.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: Docs
|
3
|
-
|
4
|
-
on:
|
5
|
-
push:
|
6
|
-
branches:
|
7
|
-
- main
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
docs:
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
steps:
|
13
|
-
- uses: actions/checkout@v2
|
14
|
-
- uses: ruby/setup-ruby@v1
|
15
|
-
with:
|
16
|
-
ruby-version: '2.7'
|
17
|
-
bundler-cache: true
|
18
|
-
- name: Run Yard Doc
|
19
|
-
run: |
|
20
|
-
gem install yard
|
21
|
-
yard doc
|
22
|
-
- name: Deploy GH Pages
|
23
|
-
uses: JamesIves/github-pages-deploy-action@4.1.7
|
24
|
-
with:
|
25
|
-
branch: gh-pages
|
26
|
-
folder: doc/
|