-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtackle.yaml
319 lines (278 loc) · 11 KB
/
tackle.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<-:
help: Generate scaffolding or generator for an ICON smart contract
exec:
selection:
->: select What do you want to do?
choices:
# TODO: Change to allow calling in one action (ie *->: or *: {->: ...})
- Create a contract / token: create_contract
- Create another code generator: create_tackle
- Quickly generate all the options: quick_gen
- Run tests: test
action:
->: match {{selection}}
case:
create_contract->: create_contract
create_tackle->: create_tackle
names<_:
help: Private method to maintain naming conventions
github_org->: input What is your github org? --default sudoblockio
project_name->: input What is the name of this project? --default "Big Deal Contract"
project_slug->: var project_name|lower()|replace(' ','-')|replace('_','-')|replace('.','-')|trim()
project_name_camel->: var project_name|title()|replace(' ','')|replace('_','')|replace('-','')|trim()
project_name_snake->: var project_name|lower()|replace(' ','_')|replace('-','_')|trim()
project_dir_name->: var project_name|lower()|replace(' ','-')|replace('_','-')|trim()
project_name_compact->: var project_dir_name|replace('-','')
# This is here as we need a full path to the output files
project_path:
->: path_join
paths:
- {{calling_directory}}
- {{project_slug}}
create_contract<-:
help: Generate scaffolding for an ICON smart contract
exec:
is_token->: confirm Is this a token / NFT?
contract_standard:
->: select What standard do you want to build on? --if is_token --else contract
choices:
- IRC2 Fungible Token: irc2
- IRC3 Non-Fungible Token: irc3
- IRC31 Non-Fungible Token: irc31
# For differentiating between tokens and contracts
contract_class->: literal token --if is_token --else contract
# Call the names function for naming conventions
merge names->: names --merge
github_org->: input What is your org name? --default sudoblockio
contract_path:
- java
- ->: input Top level directory for contract (ie {{path_join(contract_path)}}) - typically com / network / io?
default: com
- ->: input Mid level directory for contract (ie {{path_join(contract_path)}}) - typically your github org name?
default: {{github_org}}
- ->: input Bottom level directory for contract (ie {{path_join(contract_path)}}) - typically your repo name?
default: {{project_name_compact}}
- ->: input Bottom level directory for contract (ie {{path_join(contract_path)}})?
if: confirm('Do you want a fourth level directory?',default=False)
default: lib
# prompts:
# _>: var
# input:
# # Follow up with permissions - ie multi-sig for minting or some contract functionality.
# mintable: Is this token mintable?
# stable: Is this token stable (ie tied to an oracle - Band by default)?
# auto_increment_ids: Do you want the token IDs to auto-increment?
# # Followup?
# burnable: Is this token burnable?
# # Should pausable have additional prompts such as who is able to pause it or just assume owner?
# # Perhaps a followup prompt should ask if pausing permissions should be a multi-sig and implement that.
# pausable: Is this {{contract_class}} pausable?
# # ?
# permit: Is this token permissioned?
# # Can contracts have voting?
# votes: Will there be voting enabled for this token?
# flash_minting: Will there be flash minting enabled for this token?
# # Can contracts be snapshotted -> perhaps some state that is specified?
# snapshots: Will there be snapshotting of this token?
# # ?
# enumerable: Enable enumerable properties - optional interfaces for totalSupply, tokenByIndex, and tokenOfOwnerByIndex?
# # ?
# uri_storage: |
# Will the storage be based on some kind URI? eg ?
#
# features:
# ->: match contract_standard
# case:
# irc2:
# mintable->: confirm {{prompts.mintable}}
# stable->: confirm {{prompts.stable}}
## burnable->: confirm {{prompts.burnable}}
## pausable->: confirm {{prompts.pausable}}
## permit->: confirm {{prompts.permit}}
## votes->: confirm {{prompts.votes}}
## flash_minting->: confirm {{prompts.flash_minting}}
## snapshots->: confirm {{prompts.snapshots}}
# irc3: {}
## mintable->: confirm {{prompts.mintable}}
## auto_increment_ids->: confirm --if mintable --else false {{prompts.auto_increment_ids}}
## burnable->: confirm {{prompts.burnable}}
## pausable->: confirm {{prompts.pausable}}
## votes->: confirm {{prompts.votes}}
## enumerable->: confirm {{prompts.enumerable}}
## uri_storage->: confirm {{prompts.uri_storage}}
# irc31: {}
## mintable->: confirm {{prompts.mintable}}
## auto_increment_ids->: confirm --if mintable --else false {{prompts.auto_increment_ids}}
## burnable->: confirm {{prompts.burnable}}
## pausable->: confirm {{prompts.pausable}}
## votes->: confirm {{prompts.votes}}
## enumerable->: confirm {{prompts.enumerable}}
## uri_storage->: confirm {{prompts.uri_storage}}
# contract: {}
## pausable->: confirm {{prompts.pausable}}
#
# # In order to properly test the file, we need to merge these values separately. This
# # is because the whole `features` key is overriden. Current tackle does not support
# # overriding keys within
# merge features->: var {{features}} --merge
features:
->: features.contract_creation --template {{contract_standard}}
# d->: debug
merge features->: var {{features}} --merge
# Create a license file
license->: tackle robcxyz/tackle-license --output {{project_path}}
# Generate the code
gen boilerplate_>: generate templates/boilerplate {{project_path}}
gen contract main:
_>: generate templates/{{contract_standard}}/{{item}} '{{path_join([project_path,"src",item]+contract_path)}}'
for:
- main
- test
make gradlew executable_>: chmod {{path_join([project_path,'gradlew'])}} "0o775"
compile_enable->: confirm Do you want to compile the {{contract_class}}?
compile contract:
_>: command "./gradlew build"
chdir: {{project_path}}
if: compile_enable
# TODO: Add drogon tests
create_tackle<-:
help: Create a tackle project which you can use to generate more projects.
exec:
# Call the names function for naming conventions
merge names->: names --merge
license->: tackle robcxyz/tackle-license --output {{project_dir_name}}
gen boilerplate_>: generate boilerplate-tackle {{project_dir_name}}
copy_templates:
- src: boilerplate
dst: boilerplate
- src: contract-tackle
dst: contract
copy templates_>: copy {{path_join(['templates',item.src])}} --for copy_templates {{path_join([project_path,'templates',item.dst])}}
test<-:
help: Run tests quickly with the default Python
exec:
cmd:
->: command
command: |
pip install -r requirements-dev.txt
pytest tests
quick_gen<-:
help: Quickly generate all the contracts to `outputs-all` directory
exec:
cmd:
->: command
command: |
pip install -r requirements-dev.txt
pytest . -k test_manual --manual
prompt_feature<-:
help: Helper to prompt for a feature and return a k/v pair of the feature. Meant to be used with merge.
name: str
question: str
templates: dict
# Additional data
template: str
feature_var: str
return: output
exec:
output: {}
status:
->: var " status={{templates[template].status}}"
if: "'status' in templates[template]"
else: ""
enabled->: confirm {{question}}{{status}}
update output->: update output {"{{feature_var}}":"{{enabled}}"}
features<-:
help: For keeping features dry and updating a table with feature status
template_types:
- IRC2
- IRC3
- IRC31
- Contract
template_types_lower:
default:
->: "{{item.lower()}}"
for: template_types
# List of statuses for each feature
status_types:
- "Todo"
- "WIP"
- "Alpha"
- "Beta"
- "v0"
# List of statuses to exclude from prompting
status_disabled:
- "Todo"
# - "WIP" # Should be disabled once more contracts are added
# Get the data from the features.yaml
data->: tackle features.yaml
all_features->: "{{keys(data)}}"
contract_creation<-:
template: str
exec:
check if template allowed_>: assert "{{template in template_types_lower}}"
feature_list:
->: var {{item}} --for all_features
if: template in keys(data[item]['templates']) and data[item]['templates'][template].status not in status_disabled
feature_map: {}
set feature_map:
_>: update feature_map {'{{item}}':'{{data[item]}}'}
for: feature_list
output: {}
set output:
->: update output "{{prompt_feature(template=contract_standard,feature_var=item,**feature_map[item])}}"
for: feature_list
# In order to properly test the file, we need to merge these values separately. This
# is because the whole `features` key is overriden. Current tackle does not support
# overriding keys within
return: output
create_table<-:
help: Update the feature table in the readme
return: output
exec:
columns->: "{{['Features'] + template_types}}"
output: [ ]
contents->:
for: all_features
feature_name->: "{{item}}"
col_data:
->: "{{feature_type.string(**data[feature_name].templates[item])}}"
for: template_types_lower
if: item in keys(data[feature_name].templates)
else: "-"
append to output_>: append output {{col_data}}
rendered:
->: var
input: |
| Features | {% for i in template_types %} {{i}} |{% endfor %}
| --- |{% for i in template_types %} --- | {% endfor %}
{% for feat in all_features %}{% set outer_loop = loop %}| {{feat}} |{% for i in output[outer_loop.index-1] %} {{i}} | {% endfor %}
{% endfor %}
update_section_>: update_section README.md {{rendered}}
feature_type<_:
status: Todo
issue: ""
string<-:
exec:
output:
->: "{{status}}"
if: issue==""
else: "[{{status}}]({{issue}})"
return: output
get_row_data<_:
rows->: list
columns->: list
exec:
output: [ ]
contents->:
for: rows
feature_name->: "{{item}}"
do:
->: "{{data[feature_name].templates[item].status}}"
for: contract_types
if: item in data[feature_name].templates
else:
if issue->:
if:
else:
"-"
merge: append output {{item}} --for do