[EOSIO/eos] Ricardian contracts import/export script (#3625)

jeffreyssmith2nd requested changes on this pull request.

> @@ -0,0 +1,20 @@
+# Purpose
+The `recardeos.py` imports or exports recardian contracts to and from a contracts abi

This file has a lot `recardeos` and `recardian`, where they should be `ricardeos` and `ricardian`

> @@ -0,0 +1,164 @@
+#!/usr/bin/env python3
+
+import json
+import sys
+import os.path
+import fnmatch
+
+def add_ricardian_contracts_to_actions(source_abi_directory, contract_name, abi_actions):
+ abi_actions_with_ricardian_contracts = []
+
+ for abi_action in abi_actions:
+ action_name = abi_action[«name»]
+ contract_action_filename = f'{contract_name}-{action_name}-rc.md’

This will need to be the old `format` since they use 3.3 in some of their builders.

> +#!/usr/bin/env python3
+
+import json
+import sys
+import os.path
+import fnmatch
+
+def add_ricardian_contracts_to_actions(source_abi_directory, contract_name, abi_actions):
+ abi_actions_with_ricardian_contracts = []
+
+ for abi_action in abi_actions:
+ action_name = abi_action[«name»]
+ contract_action_filename = f'{contract_name}-{action_name}-rc.md’
+
+ # check for rc file
+ rcContractPath = os.path.join(source_abi_directory, contract_action_filename)

Probably should be snake case `rc_contract_path`

> +
+ abi_actions_with_ricardian_contracts.append(abi_action)
+
+ return abi_actions_with_ricardian_contracts
+
+def create_ricardian_clauses_list(source_abi_directory, contract_name):
+ clause_file_pattern = ‘*-clause*-rc.md’
+ clause_files = fnmatch.filter(os.listdir(source_abi_directory), clause_file_pattern)
+
+ clause_prefix = ‘clause-‘
+ clause_postfix = ‘-rc.md’
+
+ abi_ricardian_clauses = []
+
+ for clause_file_name in clause_files:
+ rcContractPath = os.path.join(source_abi_directory, clause_file_name)

same as above

> + contract_name = os.path.split(source_abi)[1].rpartition(«.»)[0]
+
+ print(‘Creating {output_abi} with ricardian contracts included’.format(output_abi = output_abi))
+
+ with open(source_abi, ‘r’) as source_abi_file:
+ source_abi_json = json.load(source_abi_file)
+
+ source_abi_json[‘actions’] = add_ricardian_contracts_to_actions(source_abi_directory, contract_name, source_abi_json[‘actions’])
+ source_abi_json[‘ricardian_clauses’] = create_ricardian_clauses_list(source_abi_directory, contract_name)
+
+ with open(output_abi, ‘w’) as output_abi_file:
+ json.dump(source_abi_json, output_abi_file, indent=2)
+
+def import_ricardian_to_abi(source_abi, output_abi):
+ if not os.path.exists(source_abi):
+ print(f’Source ABI not found in {source_abi}’)

same as above

Добавить комментарий