Skip to content

Instantly share code, notes, and snippets.

@freehere107
Last active April 1, 2026 14:49
Show Gist options
  • Select an option

  • Save freehere107/3bcd359dd78ded7c08756304d12db84f to your computer and use it in GitHub Desktop.

Select an option

Save freehere107/3bcd359dd78ded7c08756304d12db84f to your computer and use it in GitHub Desktop.
convert wasm contract to standard_input_json.json
# Convert wasm contract to standard_input_json
# Example
# python convert.py --manifest xx.toml
import argparse
import os
import json
parser = argparse.ArgumentParser(description='Print all files in the specified directory')
parser.add_argument('--manifest', type=str, default="Cargo.toml", help='manifest path')
parser.add_argument('--exclude', type=str, nargs='+', default=[], help='exclude folder')
args = parser.parse_args()
extension = ["rs", "toml"]
exclude = [".idea", ".git", "target"] + args.exclude
includeFiles = ["Cargo.lock"]
inputJson = {
"manifest-path": args.manifest,
"contracts": {}
}
for root, dirs, files in os.walk("."):
dirs[:] = [d for d in dirs if d not in exclude]
for file in files:
if file.endswith(tuple(extension)) or file in includeFiles:
filePath = os.path.join(root, file)
with open(filePath, 'r') as f:
contents = f.read()
if contents == "":
continue
inputJson["contracts"][filePath.lstrip("./")] = contents
print(json.dumps(inputJson, sort_keys=True, indent=4, separators=(',', ':')))
@Cplus360
Copy link
Copy Markdown

Viewing

@rgray058683-collab
Copy link
Copy Markdown

Love it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment