@@ -7,17 +7,35 @@ def library_code
7
7
end
8
8
9
9
10
- def compile_solidity ( code )
11
- json_string = `curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_compileSolidity","params":["#{ code } "],"id":1}' http://127.0.0.1:8100`
12
- json_object = JSON . parse ( json_string )
13
- compiled_object = json_object [ 'result' ]
14
- puts json_object if compiled_object . nil?
15
- compiled_object
10
+ def compile_solidity ( file )
11
+ puts `solc --optimize --gas #{ file } `
12
+ puts "\n \n "
13
+ json_string = `solc --add-std --optimize --combined-json abi,bin,userdoc,devdoc #{ file } `
14
+ json_string = json_string . gsub ( "\\ n" , "" )
15
+ begin
16
+ json_object = JSON . parse ( json_string )
17
+ throw if json_object . nil?
18
+ json_object [ "contracts" ]
19
+ rescue
20
+ puts json_string
21
+ puts "Failed to Compile"
22
+ abort
23
+ end
16
24
end
17
25
18
26
def deploy_contract ( code )
19
27
end
20
28
29
+ def process_code ( contracts )
30
+ contracts . keys . each . with_index do |key , i |
31
+ contracts [ key ] [ "bin" ] = "0x" + contracts [ key ] [ "bin" ]
32
+ contracts [ key ] [ "abi" ] = JSON . parse ( contracts [ key ] [ "abi" ] )
33
+ contracts [ key ] [ "devdoc" ] = JSON . parse ( contracts [ key ] [ "devdoc" ] )
34
+ contracts [ key ] [ "userdoc" ] = JSON . parse ( contracts [ key ] [ "userdoc" ] )
35
+ end
36
+ return contracts
37
+ end
38
+
21
39
22
40
def javascript_file_name ( file_name )
23
41
file_name . split ( '.' ) [ 0 ] + '_compiled.js'
@@ -61,9 +79,9 @@ def get_value
61
79
end
62
80
63
81
file_name = ARGV [ 0 ]
64
- code = File . read ( file_name ) . gsub ( "\n " , '' )
65
82
66
- compiled_object = compile_solidity ( code )
83
+ compiled_object = compile_solidity ( file_name )
84
+ compiled_object = process_code ( compiled_object )
67
85
javascript_file_name = javascript_file_name ( file_name )
68
86
69
87
current_contract = get_contract_to_deploy ( compiled_object )
@@ -78,8 +96,8 @@ input = get_input
78
96
79
97
File . open ( javascript_file_name , 'w' ) do |f |
80
98
f . write ( "#{ library_code } ;\n var #{ compiled_variable_name } = #{ compiled_object . to_json } ;" )
81
- f . write ( "#{ contract_variable_name } = create(#{ compiled_variable_name } .#{ current_contract } .info.abiDefinition );" )
82
- f . write ( "#{ contract_instance_variable_name } = deploy(eth.coinbase,#{ value } ,#{ gas } ,#{ contract_variable_name } ,#{ compiled_variable_name } .#{ current_contract } .code ,#{ input } );" )
99
+ f . write ( "#{ contract_variable_name } = create(#{ compiled_variable_name } .#{ current_contract } .abi );" )
100
+ f . write ( "#{ contract_instance_variable_name } = deploy(eth.coinbase,#{ value } ,#{ gas } ,#{ contract_variable_name } ,#{ compiled_variable_name } .#{ current_contract } .bin ,#{ input } );" )
83
101
f . write ( "console.log('Compiled Object : #{ compiled_variable_name } ');" )
84
102
f . write ( "console.log('Contract : #{ contract_variable_name } ');" )
85
103
f . write ( "console.log('Contract Instance : #{ contract_instance_variable_name } ');" )
0 commit comments