MCPcopy Create free account
hub / github.com/dharmaprotocol/dharmaOS / validateDefinitions

Method validateDefinitions

src/validator.js:240–362  ·  view source on GitHub ↗
(actionScript)

Source from the content-addressed store, hash-verified

238 }
239
240 validateDefinitions(actionScript) {
241 const { name, variables, definitions } = actionScript;
242 const declaredDefinitions = new Set();
243 const declaredContractsAndTokens = new Set();
244 const declaredActions = new Set();
245 for (let [i, definition] of Object.entries(definitions)) {
246 if (
247 !(
248 TYPE_CHECKERS.string(definition) &&
249 (definition.startsWith("Token ") ||
250 definition.startsWith("Contract ") ||
251 definition.startsWith("Function ") ||
252 definition.startsWith("Action "))
253 )
254 ) {
255 throw new Error(
256 `Action script "${name}" definition #${
257 parseInt(i) + 1
258 } does not start with "Token", "Contract", "Function" or "Action" keyword`
259 );
260 }
261
262 // TODO: remove once composability support is fully implemented!
263 if (definition.startsWith("Action")) {
264 throw new Error(
265 `Action script "${name}" contains an "Action" — composability is still under development.`
266 );
267 }
268
269 const splitDefinition = definition.split(" ");
270
271 if (splitDefinition.length < 3) {
272 throw new Error(
273 `Action script "${name}" definition #${
274 parseInt(i) + 1
275 } does not contain enough arguments`
276 );
277 }
278
279 const definitionType = splitDefinition[0];
280 const definitionName = splitDefinition[1];
281
282 if (RESERVED_KEYWORDS.has(definitionName)) {
283 throw new Error(
284 `Action script "${name}" definition "${definitionName}" uses a reserved keyword`
285 );
286 }
287
288 if (declaredDefinitions.has(definitionName)) {
289 throw new Error(
290 `Action script "${name}" definition "${definitionName}" declared more than once`
291 );
292 }
293 declaredDefinitions.add(definitionName);
294
295 if (definitionType === "Token" || definitionType === "Contract") {
296 if (splitDefinition.length !== 3) {
297 throw new Error(

Callers 1

validateActionScriptMethod · 0.95

Calls 1

ensureValidChecksumMethod · 0.45

Tested by

no test coverage detected