From 0290f57bf4d35534e21f46abe432d7d21c6ff980 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 2 Sep 2020 16:23:01 +0200 Subject: [PATCH] prototype auto-generating data token name --- src/data/words.json | 133 +++++++++++++++++++++++++++++++++++ src/datatokens/Datatokens.ts | 28 ++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/data/words.json diff --git a/src/data/words.json b/src/data/words.json new file mode 100644 index 00000000..7ed8ae4c --- /dev/null +++ b/src/data/words.json @@ -0,0 +1,133 @@ +{ + "nouns": [ + "Crab", + "Fish", + "Seal", + "Octopus", + "Shark", + "Seahorse", + "Walrus", + "Starfish", + "Whale", + "Orca", + "Penguin", + "Jellyfish", + "Squid", + "Lobster", + "Pelican", + "Shrimp", + "Oyster", + "Clam", + "Seagull", + "Dolphin", + "Shell", + "Cormorant", + "Otter", + "Pelican", + "Anemone", + "Turtle", + "Coral" + ], + "adjectives": [ + "adamant", + "adroit", + "amatory", + "animistic", + "antic", + "arcadian", + "baleful", + "bellicose", + "bilious", + "boorish", + "calamitous", + "caustic", + "cerulean", + "comely", + "concomitant", + "contumacious", + "corpulent", + "crapulous", + "defamatory", + "didactic", + "dilatory", + "dowdy", + "efficacious", + "effulgent", + "egregious", + "endemic", + "equanimous", + "execrable", + "fastidious", + "feckless", + "fecund", + "friable", + "fulsome", + "garrulous", + "guileless", + "gustatory", + "heuristic", + "histrionic", + "hubristic", + "incendiary", + "insidious", + "insolent", + "intransigent", + "inveterate", + "invidious", + "irksome", + "jejune", + "jocular", + "judicious", + "lachrymose", + "limpid", + "loquacious", + "luminous", + "mannered", + "mendacious", + "meretricious", + "minatory", + "mordant", + "munificent", + "nefarious", + "noxious", + "obtuse", + "parsimonious", + "pendulous", + "pernicious", + "pervasive", + "petulant", + "platitudinous", + "precipitate", + "propitious", + "puckish", + "querulous", + "quiescent", + "rebarbative", + "recalcitant", + "redolent", + "rhadamanthine", + "risible", + "ruminative", + "sagacious", + "salubrious", + "sartorial", + "sclerotic", + "serpentine", + "spasmodic", + "strident", + "taciturn", + "tenacious", + "tremulous", + "trenchant", + "turbulent", + "turgid", + "ubiquitous", + "uxorious", + "verdant", + "voluble", + "voracious", + "wheedling", + "withering", + "zealous" + ] +} diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index b033c95e..63380456 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -4,6 +4,8 @@ import { AbiItem } from 'web3-utils/types' import defaultFactoryABI from '@oceanprotocol/contracts/artifacts/DTFactory.json' import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json' +import wordListDefault from '../data/words.json' + /** * Provides a interface to DataTokens */ @@ -32,6 +34,32 @@ export class DataTokens { this.web3 = web3 } + /** + * Generate new datatoken name & symbol from a word list + * @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-145" + */ + public generateDtName(wordList?: { + nouns: string[] + adjectives: string[] + }): { name: string; symbol: string } { + const list = wordList || wordListDefault + const random1 = Math.floor(Math.random() * list.adjectives.length) + const random2 = Math.floor(Math.random() * list.nouns.length) + const indexNumber = Math.floor(Math.random() * 100) + + // Capitalized adjective & noun + const adjective = list.adjectives[random1].replace(/^\w/, (c) => c.toUpperCase()) + const noun = list.nouns[random2].replace(/^\w/, (c) => c.toUpperCase()) + + const name = `${adjective} ${noun} Token` + // use first 3 letters of name, uppercase it, and add random number + const symbol = `${( + adjective.substring(0, 3) + noun.substring(0, 3) + ).toUpperCase()}-${indexNumber}` + + return { name, symbol } + } + /** * Create new datatoken * @param {String} metaDataStoreURI