Skip to content

Commit

Permalink
Merge branch 'main' into q9f/abi/eip712
Browse files Browse the repository at this point in the history
  • Loading branch information
q9f authored Jan 3, 2025
2 parents 767ad18 + 8a7e9e9 commit b83660f
Show file tree
Hide file tree
Showing 73 changed files with 92,484 additions and 270 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ jobs:
- ruby
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: "Initialize CodeQL"
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: "${{ matrix.language }}"
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3
- name: "Perform CodeQL Analysis"
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.4'
bundler-cache: true
- name: "Run rufo code formatting checks"
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.4'
bundler-cache: true
- name: Run Yard Doc
run: |
gem install yard
yard doc
- name: Deploy GH Pages
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.7.2
with:
branch: gh-pages
folder: doc/
18 changes: 11 additions & 7 deletions .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-12]
ruby: ['3.0', '3.1', '3.2']
os: [ubuntu-latest, macos-latest]
ruby: ['3.3', '3.4']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: false
- name: MacOs Dependencies
run: |
brew tap ethereum/ethereum
brew install --verbose pkg-config automake autogen ethereum solidity
brew install --verbose pkg-config automake autogen geth solidity
if: startsWith(matrix.os, 'macOS')
- name: Ubuntu Dependencies
run: |
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum solc libyaml-dev
sudo apt-get install geth solc
if: startsWith(matrix.os, 'Ubuntu')
- name: Run Geth
run: |
Expand All @@ -49,5 +49,9 @@ jobs:
run: |
bundle exec rspec
env:
COVERAGE: true
INFURA_TOKEN: ${{ secrets.INFURA_TOKEN }}
DRPC_TOKEN: ${{ secrets.DRPC_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
76 changes: 75 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,80 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.5.13]
### Changed
* Eth/api: update to latest available go-ethereum apis [#301](https://github.com/q9f/eth.rb/pull/301)
* Eth/chain: update ids [#300](https://github.com/q9f/eth.rb/pull/300)
* Spec: update ethereum/tests fixtures [#303](https://github.com/q9f/eth.rb/pull/303)
* Ci: fix codecov uploader [#302](https://github.com/q9f/eth.rb/pull/302)
* Eth/tx: only enforce block gas limit on mainnet [#299](https://github.com/q9f/eth.rb/pull/299)
* Eth/util: fix single-byte hex-string nibbles [#298](https://github.com/q9f/eth.rb/pull/298)
* Eth/address: rename null address to zero address [#297](https://github.com/q9f/eth.rb/pull/297)
* Eth/address: add support to check for the ethereum "null address" [#296](https://github.com/q9f/eth.rb/pull/296)
* Build(deps): bump codecov/codecov-action from 4 to 5 [#295](https://github.com/q9f/eth.rb/pull/295)
* Build(deps): bump JamesIves/github-pages-deploy-action [#294](https://github.com/q9f/eth.rb/pull/294)
* Build(deps): bump JamesIves/github-pages-deploy-action [#288](https://github.com/q9f/eth.rb/pull/288)
* Eth/client: always return hash even if transaction didn't succeed [#284](https://github.com/q9f/eth.rb/pull/284)
* Eth/chain: update list of chains [#283](https://github.com/q9f/eth.rb/pull/283)
* Fix undefined method `raise_error' for an instance of Eth::Tx::Eip1559 (NoMethodError) [#282](https://github.com/q9f/eth.rb/pull/282)
* Gem: bump version to 0.5.13 [#281](https://github.com/q9f/eth.rb/pull/281)

## [0.5.12]
### Added
* Allow to call JSON RPC with custom block number [#268](https://github.com/q9f/eth.rb/pull/268)
* Support tuple params in EventLog [#276](https://github.com/q9f/eth.rb/pull/276)

### Changed
* Eth: update version [#280](https://github.com/q9f/eth.rb/pull/280)
* Eth/abi: fix negative integer coding [#279](https://github.com/q9f/eth.rb/pull/279)
* Support negative number from JSON RPC [#267](https://github.com/q9f/eth.rb/pull/267)
* Abi/event: confirm decoding tuples works [#278](https://github.com/q9f/eth.rb/pull/278)
* Allow to call JSON RPC with custom block number [#268](https://github.com/q9f/eth.rb/pull/268)
* Gem: run rufo [#277](https://github.com/q9f/eth.rb/pull/277)
* Fix event signature [#250](https://github.com/q9f/eth.rb/pull/250)
* Support tuple params in EventLog [#276](https://github.com/q9f/eth.rb/pull/276)
* Ci: update ruby version [#271](https://github.com/q9f/eth.rb/pull/271)
* Eth/api: remove coinbase as default account [#269](https://github.com/q9f/eth.rb/pull/269)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.5.0 to 4.6.1 [#275](https://github.com/q9f/eth.rb/pull/275)
* Build(deps): bump github/codeql-action from 2 to 3 [#257](https://github.com/q9f/eth.rb/pull/257)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.3 to 4.5.0 [#256](https://github.com/q9f/eth.rb/pull/256)
* Fix typo in contract_spec.rb [#253](https://github.com/q9f/eth.rb/pull/253)
* Eth/eip721: fix data type bug for bytes, fix #251 [#252](https://github.com/q9f/eth.rb/pull/252)
* Ci: unpatch geth [#248](https://github.com/q9f/eth.rb/pull/248)
* Build(deps): bump actions/checkout from 3 to 4 [#246](https://github.com/q9f/eth.rb/pull/246)

## [0.5.11]
### Added
* Eth/abi: allow encoding address types [#242](https://github.com/q9f/eth.rb/pull/242)
* Eth/solidity: enable --via-ir [#232](https://github.com/q9f/eth.rb/pull/232)
* Checking userinfo with the uri method [#233](https://github.com/q9f/eth.rb/pull/233)
* Eth/abi: add abicoder gem tests collection [#218](https://github.com/q9f/eth.rb/pull/218)
* Manual default_account [#215](https://github.com/q9f/eth.rb/pull/215)
* Add moonbeam networks in [#209](https://github.com/q9f/eth.rb/pull/209)

### Changed
* Spec: run rufo [#245](https://github.com/q9f/eth.rb/pull/245)
* Fix the decoding of unsigned transactions [#243](https://github.com/q9f/eth.rb/pull/243)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.2 to 4.4.3 [#244](https://github.com/q9f/eth.rb/pull/244)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.1 to 4.4.2 [#240](https://github.com/q9f/eth.rb/pull/240)
* Eth/tx: update tx initcode cost for shanghai [#237](https://github.com/q9f/eth.rb/pull/237)
* Eth/client: remove default gas limit attribute [#235](https://github.com/q9f/eth.rb/pull/235)
* Docs: minor fixups [#229](https://github.com/q9f/eth.rb/pull/229)
* Eth/contract: ensure contract name is title case [#228](https://github.com/q9f/eth.rb/pull/228)
* Deps: require forwardable for contracts [#227](https://github.com/q9f/eth.rb/pull/227)
* Ens/resolver: remove pending for etc coin type [#219](https://github.com/q9f/eth.rb/pull/219)
* Deps: update secp256k1 to 6 [#214](https://github.com/q9f/eth.rb/pull/214)
* Eth/solidity: add docs for solc path override [#213](https://github.com/q9f/eth.rb/pull/213)
* Manually overwrite solc path [#212](https://github.com/q9f/eth.rb/pull/212)
* Abi.decoder handles arrays of string and bytes [#207](https://github.com/q9f/eth.rb/pull/207)
* Eth/util: fix compressed public key to address in [#206](https://github.com/q9f/eth.rb/pull/206)
* Eth/api: update execution apis to latest spec [#204](https://github.com/q9f/eth.rb/pull/204)
* Eth/abi: split abi class into encoder and decoder [#203](https://github.com/q9f/eth.rb/pull/203)
* Eth/client: deduplicate code [#202](https://github.com/q9f/eth.rb/pull/202)
* Eth/client: rewrite send to send_request [#201](https://github.com/q9f/eth.rb/pull/201)
* Docs: update changelog for 0.5.10 [#200](https://github.com/q9f/eth.rb/pull/200)
* Tested with Ruby 3.2 [#199](https://github.com/q9f/eth.rb/pull/199)

## [0.5.10]
### Added
* Eth/client: add transfer_erc20 function [#197](https://github.com/q9f/eth.rb/pull/197)
Expand All @@ -19,7 +93,7 @@ All notable changes to this project will be documented in this file.

## [0.5.9]
### Added
* Eth/abi: dynamic struct encoding (#135) [#185](https://github.com/q9f/eth.rb/pull/185)
* Eth/abi: dynamic struct encoding [#135](https://github.com/q9f/eth.rb/pull/135) [#185](https://github.com/q9f/eth.rb/pull/185)
* Eth/client: support camel case (convert before sending the tx) [#172](https://github.com/q9f/eth.rb/pull/172)
* Eth/client: add `tx_succeeded?` [#173](https://github.com/q9f/eth.rb/pull/173)

Expand Down
16 changes: 8 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
source "https://rubygems.org"

group :test, :development do
gem "bundler", "~> 2.2"
gem "codecov", "~> 0.6"
gem "pry", "~> 0.14"
gem "rake", "~> 13.0"
gem "rdoc", "~> 6.4"
gem "rspec", "~> 3.11"
gem "rufo", "~> 0.13"
gem "simplecov", "~> 0.21"
gem "bundler", "~> 2.4"
gem "pry", "~> 0.15"
gem "rake", "~> 13.2"
gem "rdoc", "~> 6.9"
gem "rspec", "~> 3.13"
gem "rufo", "~> 0.18"
gem "simplecov", "~> 0.22"
gem "simplecov-cobertura", "~> 2.1"
gem "yard", "~> 0.9"
end

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright (c) 2016-2023 The Ruby-Eth Contributors
Copyright (c) 2016-2025 The Ruby-Eth Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The test suite expects working local HTTP and IPC endpoints with a prefunded dev
geth --dev --http --ipcpath /tmp/geth.ipc &
```

It also expects an `$INFURA_TOKEN` in environment to test some ENS queries on mainnet.
It also expects an `$DRPC_TOKEN` in environment to test some ENS queries on mainnet.

To run tests, simply use `rspec`. Note, that the Ethereum test fixtures are also required.

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Supported Versions

Ruby Ethereum 0.5.0 is a complete rewrite of the old `eth` 0.4.x gem.
Ruby Ethereum 0.5.x is a complete rewrite of the old `eth` 0.4.x gem.
It also contains modules from `abi`, `rlp` and the `ethereum` gem.

None of these gems are maintained anymore except for `eth` 0.5.0 and
Expand Down
8 changes: 7 additions & 1 deletion eth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep %r{^(test|spec|features)/}

spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = ">= 2.7", "< 4.0"
spec.required_ruby_version = ">= 3.0", "< 4.0"

# bigdecimal for big decimals ;)
spec.add_dependency "bigdecimal", "~> 3.1"

# forwardable for contracts meta programming
spec.add_dependency "forwardable", "~> 1.3"

# keccak for hashing everything in ethereum
spec.add_dependency "keccak", "~> 1.3"
Expand Down
2 changes: 1 addition & 1 deletion lib/eth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016-2023 The Ruby-Eth Contributors
# Copyright (c) 2016-2025 The Ruby-Eth Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
29 changes: 27 additions & 2 deletions lib/eth/abi.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016-2023 The Ruby-Eth Contributors
# Copyright (c) 2016-2025 The Ruby-Eth Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,8 +38,12 @@ class ValueOutOfBounds < StandardError; end
#
# @param types [Array] types to be ABI-encoded.
# @param args [Array] values to be ABI-encoded.
# @param packed [Bool] set true to return packed encoding (default: `false`).
# @return [String] the encoded ABI data.
def encode(types, args)
def encode(types, args, packed = false)
return solidity_packed(types, args) if packed
types = [types] unless types.instance_of? Array
args = [args] unless args.instance_of? Array

# parse all types
parsed_types = types.map { |t| Type === t ? t : Type.parse(t) }
Expand All @@ -64,6 +68,26 @@ def encode(types, args)
"#{head}#{tail}"
end

# Encodes Application Binary Interface (ABI) data in non-standard packed mode.
# It accepts multiple arguments and encodes using the head/tail mechanism.
#
# @param types [Array] types to be ABI-encoded.
# @param args [Array] values to be ABI-encoded.
# @return [String] the encoded packed ABI data.
# @raise [ArgumentError] if types and args are of different size.
def solidity_packed(types, args)
raise ArgumentError, "Types and values must be the same length" if types.length != args.length

# We do not use the type system for packed encoding but want to call the parser once
# to enforce the type validation.
_ = types.map { |t| Type === t ? t : Type.parse(t) }

packed = types.zip(args).map do |type, arg|
Abi::Packed::Encoder.type(type, arg)
end.join
packed.force_encoding(Encoding::ASCII_8BIT)
end

# Decodes Application Binary Interface (ABI) data. It accepts multiple
# arguments and decodes using the head/tail mechanism.
#
Expand Down Expand Up @@ -123,6 +147,7 @@ def decode(types, data)
end
end

require "eth/abi/packed/encoder"
require "eth/abi/decoder"
require "eth/abi/encoder"
require "eth/abi/event"
Expand Down
24 changes: 21 additions & 3 deletions lib/eth/abi/decoder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2016-2023 The Ruby-Eth Contributors
# Copyright (c) 2016-2025 The Ruby-Eth Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,6 +51,24 @@ def type(type, arg)
type(Type.parse(type.base_type), arg[pointer + 32, Util.ceil32(data_l) + 32])
end
end
elsif type.base_type == "tuple"
offset = 0
data = {}
raise DecodingError, "Cannot decode tuples without known components" if type.components.nil?
type.components.each do |c|
if c.dynamic?
pointer = Util.deserialize_big_endian_to_int arg[offset, 32] # Pointer to the size of the array's element
data_len = Util.deserialize_big_endian_to_int arg[pointer, 32] # length of the element

data[c.name] = type(c, arg[pointer, Util.ceil32(data_len) + 32])
offset += 32
else
size = c.size
data[c.name] = type(c, arg[offset, size])
offset += size
end
end
data
elsif type.dynamic?
l = Util.deserialize_big_endian_to_int arg[0, 32]
nested_sub = type.nested_sub
Expand Down Expand Up @@ -84,7 +102,7 @@ def primitive_type(type, data)
when "address"

# decoded address with 0x-prefix
"0x#{Util.bin_to_hex data[12..-1]}"
Address.new(Util.bin_to_hex data[12..-1]).to_s.downcase
when "string", "bytes"
if type.sub_type.empty?
size = Util.deserialize_big_endian_to_int data[0, 32]
Expand All @@ -106,7 +124,7 @@ def primitive_type(type, data)
Util.deserialize_big_endian_to_int data
when "int"
u = Util.deserialize_big_endian_to_int data
i = u >= 2 ** (type.sub_type.to_i - 1) ? (u - 2 ** type.sub_type.to_i) : u
i = u >= 2 ** (type.sub_type.to_i - 1) ? (u - 2 ** 256) : u

# decoded integer
i
Expand Down
Loading

0 comments on commit b83660f

Please sign in to comment.