Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update newcoin script to auto include coin entry include and creation. #891

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions codegen/bin/newcoin
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.generate_file(templateFile, folder, fileName, coin)
puts "Generated file " + path
end

def self.insert_coint_type(coin)
def self.insert_coin_type(coin)
target_file = "include/TrustWalletCore/TWCoinType.h"
target_line = " TWCoinType#{coin['name']} = #{coin_type(coin['derivationPath'])},\n"
if insert_target_line(target_file, target_line, "};\n")
Expand All @@ -59,23 +59,35 @@ def insert_blockchain_type(coin)
target_file = "include/TrustWalletCore/TWBlockchain.h"
line_number = File.readlines(target_file).count
target_line = " TWBlockchain#{coin['blockchain']} = #{line_number - 17},\n"
puts target_line
insert_target_line(target_file, target_line, "};\n")
end

def insert_coin_entry(coin)
target_file = "src/Coin.cpp"
target_line = "#include \"#{coin['name']}/Entry.h\"\n"
insert_target_line(target_file, target_line, "// end_of_coin_includes_marker_do_not_modify\n")
target_line = " new #{coin['name']}::Entry(),\n"
insert_target_line(target_file, target_line, " }; // end_of_coin_entries_marker_do_not_modify\n")
end

def self.insert_target_line(target_file, target_line, original_line)
lines = File.readlines(target_file)
index = lines.index(target_line)
if index.nil?
index = lines.index(original_line)
lines.insert(index, target_line)
puts "Update #{target_file}"
File.open(target_file, "w+") do |f|
f.puts(lines)
end
if !index.nil?
puts "Line is already present, file: #{target_file} line: '#{target_line}'"
return true
end
return false
index = lines.index(original_line)
if index.nil?
puts "WARNING: Could not find line! file: #{target_file} line: '#{original_line}'"
return false
end
lines.insert(index, target_line)
File.open(target_file, "w+") do |f|
f.puts(lines)
end
puts "Updated file: #{target_file} new line: '#{target_line}'"
return true
end

command_line_args = ARGV
Expand Down Expand Up @@ -109,7 +121,8 @@ coin = coinSelect.first
name = format_name(coin)


insert_coint_type(coin)
insert_coin_type(coin)
insert_coin_entry(coin)

generate_file("newcoin/Address.h.erb", "src/#{name}", "Address.h", coin)
generate_file("newcoin/Address.cpp.erb", "src/#{name}", "Address.cpp", coin)
Expand Down
3 changes: 2 additions & 1 deletion src/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "Waves/Entry.h"
#include "Zcash/Entry.h"
#include "Zilliqa/Entry.h"
// end_of_coin_includes_marker_do_not_modify

using namespace TW;
using namespace std;
Expand Down Expand Up @@ -98,7 +99,7 @@ void setupDispatchers() {
new Waves::Entry(),
new Zcash::Entry(),
new Zilliqa::Entry(),
};
}; // end_of_coin_entries_marker_do_not_modify

dispatchMap.clear();
coinTypes.clear();
Expand Down