Class: EvmClient::ContractInitializer
- Inherits:
-
Object
- Object
- EvmClient::ContractInitializer
- Defined in:
- lib/evm_client/contract_initializer.rb
Instance Attribute Summary collapse
-
#abi ⇒ Object
Returns the value of attribute abi.
-
#binary ⇒ Object
Returns the value of attribute binary.
-
#contract ⇒ Object
Returns the value of attribute contract.
-
#libraries ⇒ Object
Returns the value of attribute libraries.
-
#name ⇒ Object
Returns the value of attribute name.
-
#needs_linking ⇒ Object
Returns the value of attribute needs_linking.
-
#project_initializer ⇒ Object
Returns the value of attribute project_initializer.
Instance Method Summary collapse
- #build(connection) ⇒ Object
- #generate_javascripts(path) ⇒ Object
-
#initialize(contract_name, contract, project_initializer) ⇒ ContractInitializer
constructor
A new instance of ContractInitializer.
- #link_libraries ⇒ Object
Constructor Details
#initialize(contract_name, contract, project_initializer) ⇒ ContractInitializer
Returns a new instance of ContractInitializer.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/evm_client/contract_initializer.rb', line 7 def initialize(contract_name, contract, project_initializer) @abi = JSON.parse(contract["abi"]) unless contract.nil? @binary = contract["bin"] unless contract.nil? @name = contract_name @project_initializer = project_initializer matchdata = @binary.scan(/_+[a-zA-Z]+_+/).uniq @needs_linking = matchdata.present? if @needs_linking @libraries = matchdata.collect do |libname| {name: libname.gsub(/_+/,''), sigil: libname} end end end |
Instance Attribute Details
#abi ⇒ Object
Returns the value of attribute abi.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def abi @abi end |
#binary ⇒ Object
Returns the value of attribute binary.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def binary @binary end |
#contract ⇒ Object
Returns the value of attribute contract.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def contract @contract end |
#libraries ⇒ Object
Returns the value of attribute libraries.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def libraries @libraries end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def name @name end |
#needs_linking ⇒ Object
Returns the value of attribute needs_linking.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def needs_linking @needs_linking end |
#project_initializer ⇒ Object
Returns the value of attribute project_initializer.
5 6 7 |
# File 'lib/evm_client/contract_initializer.rb', line 5 def project_initializer @project_initializer end |
Instance Method Details
#build(connection) ⇒ Object
42 43 44 45 |
# File 'lib/evm_client/contract_initializer.rb', line 42 def build(connection) @contract = EvmClient::Contract.new(@name, @binary, @abi, client) @contract.build(connection) end |
#generate_javascripts(path) ⇒ Object
47 48 49 50 |
# File 'lib/evm_client/contract_initializer.rb', line 47 def generate_javascripts(path) data = {name: @name, abi: @abi, binary: @binary} File.open(File.join(path, "#{@name}.json"), 'w') {|f| f.puts data.to_json} end |
#link_libraries ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/evm_client/contract_initializer.rb', line 21 def link_libraries if @needs_linking @libraries.each do |library| name = library[:name] if @project_initializer.libraries[name].nil? ENV['ETHEREUM_DEPLOYER_WAIT_TIME'] ||= "120" wait_time = ENV['ETHEREUM_DEPLOYER_WAIT_TIME'].to_i library_instance = library[:name].constantize.new puts "Deploying library #{name}" library_instance.deploy_and_wait(wait_time) puts "Library deployed at #{library_instance.address}" @project_initializer.libraries[name] = library_instance.address @binary.gsub!(library[:sigil], library_instance.address.gsub(/^0x/,'')) else address = @project_initializer.libraries[name] @binary.gsub!(library[:sigil], address.gsub(/^0x/,'')) end end end end |