Module: ABI::Helpers

Included in:
Utils
Defined in:
lib/abiparser/utils.rb

Constant Summary collapse

SIGHASH_RX =
/\A
(0x)?
(?<sighash>[0-9a-f]{8})
\z/ix

Instance Method Summary collapse

Instance Method Details

#support?(selectors, sig) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/abiparser/utils.rb', line 10

def support?( selectors, sig )
  if sig.is_a?( Interface )
    iface = sig
    iface.selectors.each do |sighash|
        unless selectors.include?( sighash )
          puts "  sighash >#{sighash}< not found in interface"
          return false
        end
    end
    true
  else
    sighash =  if m=SIGHASH_RX.match( sig )
                m[:sighash].downcase  ## assume it's sighash (hexstring)
               else
                ## for convenience allow (white)spaces; auto-strip - why? why not?
                sig = sig.gsub( /[ \r\t\n]/, '' )
                keccak256( sig )[0,4].hexdigest
               end

    selectors.include?( sighash ) ? true : false
  end
end