eth 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af4a4068c445fcbb0ec94375ffdf650894464bf62d69dd7a14af232452c3af3c
4
- data.tar.gz: a962fe008b6ecb75bdc5a70c9363aa31f95d84f82359da53e7195544bbcb9db2
3
+ metadata.gz: 62da01e731dd3a73a356760ac971250f193142090876e62567d73cbb5664213d
4
+ data.tar.gz: 8a951b1b585acd7b58dc327f122dbdd4787145fefbe09d71f1aa4d127787e99e
5
5
  SHA512:
6
- metadata.gz: d909d4249f0f7a72cae28c0f4208e1aa8c8ba69779149a20ececf4a53cd6186b43062d7a9aa5921e3c3fee9f3e014df8e6dd01586c0651f714d9bca47a4953da
7
- data.tar.gz: ad74d13143142ab3cf71cadfa79cbd1a7a9cf2628c0b5b6e279edd4385b20764b837e14b0f8f7f24d55884893a7b79b4c1323f89aca66adfa40eb6af8bd4db41
6
+ metadata.gz: fd1ca2d9f89a545f20cf23a9cff62a83bfe20514b69cb14aac88f08cd101a8bb9e26ba700539259c16d64ee2a3cbae46adf7bedd18b66835785ad701fd515681
7
+ data.tar.gz: a1f51f0dac47d8ce7a4ccd3df0d3decfdb0847df36a4b16587b5dd9ae217aee7375e952207d00611bcb487647ff152d958d4709ebf8b429ec0235220f45d35bd
@@ -0,0 +1,18 @@
1
+ ---
2
+ updates:
3
+ -
4
+ directory: /
5
+ labels:
6
+ - dependencies
7
+ package-ecosystem: bundler
8
+ schedule:
9
+ interval: weekly
10
+ versioning-strategy: increase
11
+ -
12
+ directory: /
13
+ labels:
14
+ - operations
15
+ package-ecosystem: github-actions
16
+ schedule:
17
+ interval: monthly
18
+ version: 2
@@ -24,15 +24,15 @@ jobs:
24
24
  - ruby
25
25
  steps:
26
26
  - name: "Checkout repository"
27
- uses: actions/checkout@v2
27
+ uses: actions/checkout@v3
28
28
  - name: "Initialize CodeQL"
29
- uses: github/codeql-action/init@v1
29
+ uses: github/codeql-action/init@v2
30
30
  with:
31
31
  languages: "${{ matrix.language }}"
32
32
  - name: Autobuild
33
- uses: github/codeql-action/autobuild@v1
33
+ uses: github/codeql-action/autobuild@v2
34
34
  - name: "Perform CodeQL Analysis"
35
- uses: github/codeql-action/analyze@v1
35
+ uses: github/codeql-action/analyze@v2
36
36
  - uses: ruby/setup-ruby@v1
37
37
  with:
38
38
  ruby-version: '2.7'
@@ -10,7 +10,7 @@ jobs:
10
10
  docs:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
13
+ - uses: actions/checkout@v3
14
14
  - uses: ruby/setup-ruby@v1
15
15
  with:
16
16
  ruby-version: '2.7'
@@ -20,7 +20,7 @@ jobs:
20
20
  gem install yard
21
21
  yard doc
22
22
  - name: Deploy GH Pages
23
- uses: JamesIves/github-pages-deploy-action@4.1.7
23
+ uses: JamesIves/github-pages-deploy-action@v4.3.3
24
24
  with:
25
25
  branch: gh-pages
26
26
  folder: doc/
@@ -21,7 +21,7 @@ jobs:
21
21
  os: [ubuntu-latest, macos-latest]
22
22
  ruby: ['2.7', '3.1']
23
23
  steps:
24
- - uses: actions/checkout@v2
24
+ - uses: actions/checkout@v3
25
25
  - uses: ruby/setup-ruby@v1
26
26
  with:
27
27
  ruby-version: ${{ matrix.ruby }}
data/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.5.4]
5
+ ### Added
6
+ - Eth/client: method for eip-1271 ([#80](https://github.com/q9f/eth.rb/pull/80))
7
+
8
+ ### Changed
9
+ - Docs: update changelog ([#77](https://github.com/q9f/eth.rb/pull/77))
10
+ - Gem: bump version to 0.5.4 ([#78](https://github.com/q9f/eth.rb/pull/78))
11
+ - Ci: bump ruby version to 3.1 on ci ([#79](https://github.com/q9f/eth.rb/pull/79))
12
+ - Fix typos ([#81](https://github.com/q9f/eth.rb/pull/81))
13
+ - Eth/contract: allow creating from file, abi, bin ([#83](https://github.com/q9f/eth.rb/pull/83))
14
+ - Eth/client: fix account requirement for client.call() ([#85](https://github.com/q9f/eth.rb/pull/85))
15
+ - Add dependency support for openssl 2.2 and greater, including 3.x ([#88](https://github.com/q9f/eth.rb/pull/88))
16
+
4
17
  ## [0.5.3]
5
18
  ### Added
6
19
  - Smart contract support ([#68](https://github.com/q9f/eth.rb/pull/68))
data/lib/eth/abi.rb CHANGED
@@ -346,6 +346,8 @@ module Eth
346
346
  # Properly encodes byte-strings.
347
347
  def encode_bytes(arg, type)
348
348
  raise EncodingError, "Expecting String: #{arg}" unless arg.instance_of? String
349
+ arg = handle_hex_string arg, type
350
+
349
351
  if type.sub_type.empty?
350
352
  size = Util.zpad_int arg.size
351
353
  padding = Constant::BYTE_ZERO * (Util.ceil32(arg.size) - arg.size)
@@ -404,5 +406,23 @@ module Eth
404
406
  raise EncodingError, "Could not parse address: #{arg}"
405
407
  end
406
408
  end
409
+
410
+ # The ABI encoder needs to be able to determine between a hex `"123"`
411
+ # and a binary `"123"` string.
412
+ def handle_hex_string(arg, type)
413
+ if Util.is_prefixed? arg or
414
+ (arg.size === type.sub_type.to_i * 2 and Util.is_hex? arg)
415
+
416
+ # There is no way telling whether a string is hex or binary with certainty
417
+ # in Ruby. Therefore, we assume a `0x` prefix to indicate a hex string.
418
+ # Additionally, if the string size is exactly the double of the expected
419
+ # binary size, we can assume a hex value.
420
+ return Util.hex_to_bin arg
421
+ else
422
+
423
+ # Everything else will be assumed binary or raw string.
424
+ return arg.b
425
+ end
426
+ end
407
427
  end
408
428
  end
data/lib/eth/chain.rb CHANGED
@@ -41,6 +41,9 @@ module Eth
41
41
  # Chain ID for Gnosis mainnet.
42
42
  XDAI = 100.freeze
43
43
 
44
+ # Chain ID for the Polygon Matic mainnet.
45
+ MATIC = 137.freeze
46
+
44
47
  # Chain ID for Arbitrum mainnet.
45
48
  ARBITRUM = 42161.freeze
46
49
 
@@ -77,6 +80,9 @@ module Eth
77
80
  # Chain ID for Optimistic Goerli testnet.
78
81
  GOERLI_OPTIMISM = 420.freeze
79
82
 
83
+ # Chain ID for the Polygon Mumbai testnet.
84
+ MUMBAI = 80001.freeze
85
+
80
86
  # Chain ID for Arbitrum Rinkeby testnet.
81
87
  RINKEBY_ARBITRUM = 421611.freeze
82
88
 
data/lib/eth/client.rb CHANGED
@@ -154,16 +154,14 @@ module Eth
154
154
  #
155
155
  # @overload deploy(contract)
156
156
  # @param contract [Eth::Contract] contracts to deploy.
157
- # @overload deploy(contract, sender_key)
157
+ # @overload deploy(contract, *args, **kwargs)
158
158
  # @param contract [Eth::Contract] contracts to deploy.
159
- # @param sender_key [Eth::Key] the sender private key.
160
- # @overload deploy(contract, sender_key, legacy)
161
- # @param contract [Eth::Contract] contracts to deploy.
162
- # @param sender_key [Eth::Key] the sender private key.
163
- # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
159
+ # *args Optional variable constructor parameter list
160
+ # **sender_key [Eth::Key] the sender private key.
161
+ # **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
164
162
  # @return [String] the contract address.
165
- def deploy_and_wait(contract, sender_key: nil, legacy: false)
166
- hash = wait_for_tx(deploy(contract, sender_key: sender_key, legacy: legacy))
163
+ def deploy_and_wait(contract, *args, **kwargs)
164
+ hash = wait_for_tx(deploy(contract, *args, **kwargs))
167
165
  addr = eth_get_transaction_receipt(hash)["result"]["contractAddress"]
168
166
  contract.address = Address.new(addr).to_s
169
167
  end
@@ -173,25 +171,28 @@ module Eth
173
171
  #
174
172
  # @overload deploy(contract)
175
173
  # @param contract [Eth::Contract] contracts to deploy.
176
- # @overload deploy(contract, sender_key)
174
+ # @overload deploy(contract, *args, **kwargs)
177
175
  # @param contract [Eth::Contract] contracts to deploy.
178
- # @param sender_key [Eth::Key] the sender private key.
179
- # @overload deploy(contract, sender_key, legacy)
180
- # @param contract [Eth::Contract] contracts to deploy.
181
- # @param sender_key [Eth::Key] the sender private key.
182
- # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
176
+ # *args Optional variable constructor parameter list
177
+ # **sender_key [Eth::Key] the sender private key.
178
+ # **legacy [Boolean] enables legacy transactions (pre-EIP-1559).
183
179
  # @return [String] the transaction hash.
184
180
  # @raise [ArgumentError] in case the contract does not have any source.
185
- def deploy(contract, sender_key: nil, legacy: false)
181
+ def deploy(contract, *args, **kwargs)
186
182
  raise ArgumentError, "Cannot deploy contract without source or binary!" if contract.bin.nil?
183
+ raise ArgumentError, "Missing contract constructor params!" if contract.constructor_inputs.length != args.length
187
184
  gas_limit = Tx.estimate_intrinsic_gas(contract.bin) + Tx::CREATE_GAS
185
+ data = contract.bin
186
+ unless args.empty?
187
+ data += encode_constructor_params(contract, args)
188
+ end
188
189
  params = {
189
190
  value: 0,
190
191
  gas_limit: gas_limit,
191
192
  chain_id: chain_id,
192
- data: contract.bin,
193
+ data: data,
193
194
  }
194
- if legacy
195
+ if kwargs[:legacy]
195
196
  params.merge!({
196
197
  gas_price: max_fee_per_gas,
197
198
  })
@@ -201,17 +202,17 @@ module Eth
201
202
  max_gas_fee: max_fee_per_gas,
202
203
  })
203
204
  end
204
- unless sender_key.nil?
205
- # use the provided key as sender and signer
205
+ unless kwargs[:sender_key].nil?
206
+ # Uses the provided key as sender and signer
206
207
  params.merge!({
207
- from: sender_key.address,
208
- nonce: get_nonce(sender_key.address),
208
+ from: kwargs[:sender_key].address,
209
+ nonce: get_nonce(kwargs[:sender_key].address),
209
210
  })
210
211
  tx = Eth::Tx.new(params)
211
- tx.sign sender_key
212
+ tx.sign kwargs[:sender_key]
212
213
  return eth_send_raw_transaction(tx.hex)["result"]
213
214
  else
214
- # use the default account as sender and external signer
215
+ # Uses the default account as sender and external signer
215
216
  params.merge!({
216
217
  from: default_account,
217
218
  nonce: get_nonce(default_account),
@@ -241,7 +242,7 @@ module Eth
241
242
  func = contract.functions.select { |func| func.name == function_name }[0]
242
243
  raise ArgumentError, "function_name does not exist!" if func.nil?
243
244
  output = call_raw(contract, func, *args, **kwargs)
244
- if output.length == 1
245
+ if output&.length == 1
245
246
  return output[0]
246
247
  else
247
248
  return output
@@ -412,7 +413,7 @@ module Eth
412
413
  })
413
414
  end
414
415
  unless kwargs[:sender_key].nil?
415
- # use the provided key as sender and signer
416
+ # Uses the provided key as sender and signer
416
417
  params.merge!({
417
418
  from: kwargs[:sender_key].address,
418
419
  nonce: get_nonce(kwargs[:sender_key].address),
@@ -422,6 +423,7 @@ module Eth
422
423
  end
423
424
  raw_result = eth_call(params)["result"]
424
425
  types = func.outputs.map { |i| i.type }
426
+ return nil if raw_result == "0x"
425
427
  Eth::Abi.decode(types, raw_result)
426
428
  end
427
429
 
@@ -432,6 +434,12 @@ module Eth
432
434
  "0x" + fun.signature + (encoded_str.empty? ? "0" * 64 : encoded_str)
433
435
  end
434
436
 
437
+ # Encodes constructor params
438
+ def encode_constructor_params(contract, args)
439
+ types = contract.constructor_inputs.map { |input| input.type }
440
+ Util.bin_to_hex(Eth::Abi.encode(types, args))
441
+ end
442
+
435
443
  # Prepares parameters and sends the command to the client.
436
444
  def send_command(command, args)
437
445
  args << "latest" if ["eth_getBalance", "eth_call"].include? command
@@ -469,3 +477,7 @@ module Eth
469
477
  end
470
478
  end
471
479
  end
480
+
481
+ # Load the client/* libraries
482
+ require "eth/client/http"
483
+ require "eth/client/ipc"
@@ -16,6 +16,7 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
+
19
20
  # Provide classes for contract event.
20
21
  class Contract::Event
21
22
  attr_accessor :name, :signature, :input_types, :inputs, :event_string, :address
@@ -16,6 +16,7 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
+
19
20
  # Provides the methods for smart contract function.
20
21
  class Contract::Function
21
22
  attr_accessor :name, :inputs, :outputs, :signature, :constant, :function_string
@@ -36,7 +37,7 @@ module Eth
36
37
  @signature = self.class.encoded_function_signature(@function_string)
37
38
  end
38
39
 
39
- # Create function strings.
40
+ # Creates function strings.
40
41
  #
41
42
  # @param name [String] function name.
42
43
  # @param inputs [Array<Eth::Contract::FunctionInput>] function input class list.
@@ -45,12 +46,12 @@ module Eth
45
46
  "#{name}(#{inputs.collect { |x| x.type }.join(",")})"
46
47
  end
47
48
 
48
- # encode function signature.
49
+ # Encodes a function signature.
49
50
  #
50
51
  # @param signature [String] function signature.
51
52
  # @return [String] encoded function signature string.
52
53
  def self.encoded_function_signature(signature)
53
- Digest::Keccak.hexdigest(signature, 256)[0..7]
54
+ Util.bin_to_hex Util.keccak256(signature)[0..3]
54
55
  end
55
56
  end
56
57
  end
@@ -16,6 +16,7 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
+
19
20
  # Provide classes for contract function input.
20
21
  class Contract::FunctionInput
21
22
  attr_accessor :type, :name
@@ -28,7 +29,7 @@ module Eth
28
29
  @name = data["name"]
29
30
  end
30
31
 
31
- # Returns types like uint256
32
+ # Returns complete types with subtypes, e.g., `uint256`.
32
33
  def type
33
34
  @type.base_type + @type.sub_type
34
35
  end
@@ -16,15 +16,20 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
+
19
20
  # Provide classes for contract function output.
20
21
  class Contract::FunctionOutput
21
22
  attr_accessor :type, :name
22
23
 
24
+ # Constructor of the {Eth::Contract::FunctionOutput} class.
25
+ #
26
+ # @param data [Hash] contract abi data.
23
27
  def initialize(data)
24
28
  @type = Eth::Abi::Type.parse(data["type"])
25
29
  @name = data["name"]
26
30
  end
27
31
 
32
+ # Returns complete types with subtypes, e.g., `uint256`.
28
33
  def type
29
34
  @type.base_type + @type.sub_type
30
35
  end
@@ -16,6 +16,7 @@
16
16
 
17
17
  # Provides the {Eth} module.
18
18
  module Eth
19
+
19
20
  # Provide classes for contract initializer.
20
21
  class Contract::Initializer
21
22
  attr_accessor :contracts, :file
@@ -36,7 +37,7 @@ module Eth
36
37
  end
37
38
  end
38
39
 
39
- # Build and return all contracts.
40
+ # Builds and returns all contracts.
40
41
  def build_all
41
42
  @contracts.each do |contract|
42
43
  contract.build
data/lib/eth/contract.rb CHANGED
@@ -109,6 +109,7 @@ module Eth
109
109
  def_delegators :parent, :events
110
110
  def_delegators :parent, :address, :address=
111
111
  def_delegator :parent, :functions
112
+ def_delegator :parent, :constructor_inputs
112
113
  define_method :parent do
113
114
  parent
114
115
  end
@@ -133,3 +134,10 @@ module Eth
133
134
  end
134
135
  end
135
136
  end
137
+
138
+ # Load the contract/* libraries
139
+ require "eth/contract/event"
140
+ require "eth/contract/function"
141
+ require "eth/contract/function_input"
142
+ require "eth/contract/function_output"
143
+ require "eth/contract/initializer"
data/lib/eth/version.rb CHANGED
@@ -16,5 +16,5 @@
16
16
  module Eth
17
17
 
18
18
  # Defines the version of the {Eth} module.
19
- VERSION = "0.5.4".freeze
19
+ VERSION = "0.5.5".freeze
20
20
  end
data/lib/eth.rb CHANGED
@@ -23,14 +23,7 @@ require "eth/address"
23
23
  require "eth/chain"
24
24
  require "eth/constant"
25
25
  require "eth/contract"
26
- require "eth/contract/event"
27
- require "eth/contract/function"
28
- require "eth/contract/function_input"
29
- require "eth/contract/function_output"
30
- require "eth/contract/initializer"
31
26
  require "eth/client"
32
- require "eth/client/http"
33
- require "eth/client/ipc"
34
27
  require "eth/eip712"
35
28
  require "eth/key"
36
29
  require "eth/rlp"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ellis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-05-16 00:00:00.000000000 Z
12
+ date: 2022-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: keccak
@@ -95,6 +95,7 @@ executables: []
95
95
  extensions: []
96
96
  extra_rdoc_files: []
97
97
  files:
98
+ - ".github/dependabot.yml"
98
99
  - ".github/workflows/codeql.yml"
99
100
  - ".github/workflows/docs.yml"
100
101
  - ".github/workflows/spec.yml"