Top Level Namespace
Defined Under Namespace
Modules: Teth
Instance Method Summary collapse
- #compile_solidity(file) ⇒ Object
- #get_contract_to_deploy(compiled_object) ⇒ Object
- #get_gas ⇒ Object
- #get_input ⇒ Object
- #get_value ⇒ Object
- #javascript_file_name(file_name) ⇒ Object
- #library_code ⇒ Object
- #process_code(contracts) ⇒ Object
Instance Method Details
#compile_solidity(file) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 8 def compile_solidity(file) json_string = `solc --add-std --optimize --combined-json abi,bin,userdoc,devdoc #{file}` json_string = json_string.gsub("\\n","") begin json_object = JSON.parse(json_string) throw if json_object.nil? puts `solc --optimize --gas #{file}` puts "\n\n" puts "-------------------------------------" json_object["contracts"] rescue puts "Failed to Compile." abort end end |
#get_contract_to_deploy(compiled_object) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 40 def get_contract_to_deploy(compiled_object) return compiled_object.keys[0] if compiled_object.keys.count == 1 puts "Which contract do you want to deploy?" choice = 0 while choice <= 0 || choice > compiled_object.keys.count compiled_object.keys.each.with_index do |key, i| puts "#{(i+1)}. "+key end choice = $stdin.gets.to_i end return compiled_object.keys[choice - 1] end |
#get_gas ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 59 def get_gas gas = 0 while gas == 0 puts "Enter Gas: " gas = $stdin.gets.to_i end gas end |
#get_input ⇒ Object
53 54 55 56 57 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 53 def get_input puts "Enter Input: " input = $stdin.gets input.strip.chomp == "" ? "null" : input end |
#get_value ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 68 def get_value gas = -1 while gas < 0 puts "Enter Value To Be Transferred: " gas = $stdin.gets.to_i end gas end |
#javascript_file_name(file_name) ⇒ Object
35 36 37 38 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 35 def javascript_file_name(file_name) file_name = file_name.split('/')[-1] file_name.split('.')[0] + '_compiled.js' end |
#library_code ⇒ Object
4 5 6 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 4 def library_code 'function create(abiDefinition) { return web3.eth.contract(abiDefinition);}/*function deploy(account, value, gas, contract, code, input) */function deploy() { var account = arguments[0]; var value = arguments[1]; var gas = arguments[2]; var contract = arguments[3]; var code = arguments[4]; var codeString = "contract.new(inputMarker,{from:\'accountMarker\', value: valueMarker, data: \'codeMarker\', gas: gasMarker}, function (e, contract) { if(!e) { if(!contract.address) { console.log(\"Contract transaction send: TransactionHash: \" + contract.transactionHash + \" waiting to be mined...\"); } else { console.log(\"Contract mined! Address: \" + contract.address); } } else { console.log(e) } })"; codeString = codeString.replace("accountMarker", account); codeString = codeString.replace("valueMarker", value); codeString = codeString.replace("codeMarker", code); codeString = codeString.replace("gasMarker", gas); input = "null"; if (arguments.length > 5) { if (arguments[5] != null) { var args = []; for (var i = 5;i < arguments.length; i++) { var val = arguments[i]; if (typeof(val) === \'string\') { val = "\"" + val + "\""; } args.push(val); } input = args.join(","); } } codeString = codeString.replace("inputMarker", input); console.log(input); var instance = eval(codeString); return instance;}function watcher(error, result) { if (!error) { console.log("Result"); console.log(JSON.stringify(result)); return; } console.log("Error" + error);}/*function call(account, gas, func, input) */function call() { var account = "eth.accounts["+arguments[0]+"]"; var gas = arguments[1]; var func = arguments[2]; input = "null"; if (arguments.length > 3) { if (arguments[3] != null) { var args = Array.prototype.slice.call(arguments, 3); input = args.join(","); } } codeString = "func.sendTransaction(inputMarker, gasMarker, {from:accountMarker}, watcher);"; codeString = codeString.replace("accountMarker",account); codeString = codeString.replace("gasMarker",gas); codeString = codeString.replace("inputMarker",input); eval(codeString);}function send(from_index, to, value, gas){ return eth.sendTransaction({from:eth.accounts[from_index], to:to, value:web3.toWei(value,\'ether\'), gas:gas});}function bal() { for (var i = 0; i < eth.accounts.length; i++) { account = eth.accounts[i]; balance = web3.fromWei(eth.getBalance(eth.accounts[i]), \'ether\'); console.log("Index : " + i); console.log("Account : "+ account); console.log("Balance : "+ balance); console.log("\n"); }}' end |
#process_code(contracts) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/teth/templates/bin/solc_helper.rb', line 24 def process_code(contracts) contracts.keys.each.with_index do |key, i| contracts[key]["bin"] = "0x" + contracts[key]["bin"] contracts[key]["abi"] = JSON.parse(contracts[key]["abi"]) contracts[key]["devdoc"] = JSON.parse(contracts[key]["devdoc"]) contracts[key]["userdoc"] = JSON.parse(contracts[key]["userdoc"]) end return contracts end |