Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/scan/webpack-dev-s…
Browse files Browse the repository at this point in the history
…erver-3.11.0
  • Loading branch information
Kanisorn Thongprapaisaeng authored May 11, 2020
2 parents 4f48706 + b02f375 commit f0e9407
Show file tree
Hide file tree
Showing 12 changed files with 484 additions and 425 deletions.
8 changes: 5 additions & 3 deletions chain/scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set -eo pipefail
proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
protoc \
-I. \
--gocosmos_out=plugins=interfacetype,paths=source_relative:. \
$(find "${dir}" -name '*.proto')
-I. \
--gocosmos_out=plugins=interfacetype,paths=source_relative:. \
$(find "${dir}" -name '*.proto')

./scripts/protoconstructorgen.py ${dir}
done
52 changes: 52 additions & 0 deletions chain/scripts/protoconstructorgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3


import os
import re
import sys


PATTERN = re.compile(r"type (\w+) struct {")


def process_file(w, filepath):
with open(filepath, "r") as r:
content = "\n".join(r.readlines())
for match in re.finditer(PATTERN, content):
typename = match.group(1)
w.write("\n")
w.write("func New{}(\n".format(typename))
start = match.end() + 1
end = start + content[start:].index("}") - 1
members = []
for rawline in content[start:end].split("\n"):
line = rawline.strip()
if line == "" or line.startswith("//"):
continue
tokens = line.split()
members.append((tokens[0], tokens[1]))
max_key_length = max(map(lambda mem: len(mem[0]), members))
for (key, ty) in members:
w.write("\t{} {},\n".format(key, ty))
w.write(") {} {{\n".format(typename))
w.write("\treturn {}{{\n".format(typename))
for (key, _) in members:
w.write("\t\t{}:{} {},\n".format(key, " " * (max_key_length - len(key)), key))
w.write("\t}\n")
w.write("}\n")


def main(path):
with open(os.path.join(path, "constructors.go"), "w") as w:
w.write("// Code generated by protoconstructorgen.py. DO NOT EDIT.\n")
w.write("package {}\n".format(os.path.basename(path)))
w.write("\n")
w.write('import github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"\n')

for filename in os.listdir(path):
if filename.endswith(".pb.go"):
process_file(w, os.path.join(path, filename))


if __name__ == "__main__":
main(sys.argv[1])
296 changes: 296 additions & 0 deletions chain/x/oracle/types/constructors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions chain/x/oracle/types/data_source.go

This file was deleted.

Loading

0 comments on commit f0e9407

Please sign in to comment.