Skip to content

Commit

Permalink
Merge pull request #14 from Jay-Tezsure/Deploy-a-Contract
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
aditya-tezsure authored Feb 18, 2021
2 parents 9b2aed7 + 3399c53 commit f540c9f
Show file tree
Hide file tree
Showing 15 changed files with 12 additions and 153 deletions.
1 change: 0 additions & 1 deletion lib/chain/tezos/tezos_language_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:tezster_dart/michelson_parser/michelson_parser.dart';

class TezosLanguageUtil {
static String translateMichelsonToMicheline(String code) {
// jsonDecode()
var result = MichelsonParser.parseMichelson(code);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/chain/tezos/tezos_message_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TezosMessageCodec {
}

static String encodeReveal(OperationModel message) {
var hex = TezosMessageUtils.writeInt(107); //sepyTnoitarepo['reveal']);
var hex = TezosMessageUtils.writeInt(107);
hex += TezosMessageUtils.writeAddress(message.source).substring(2);
hex += TezosMessageUtils.writeInt(int.parse(message.fee));
hex += TezosMessageUtils.writeInt(message.counter);
Expand Down
1 change: 0 additions & 1 deletion lib/chain/tezos/tezos_message_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class TezosMessageUtils {
.decode(branch)
.sublist(2, base58.decode(branch).length - 4)
.toList());
// return hex.encode(base58.decode(branch).sublist(2).toList());
}

static String writeInt(int value) {
Expand Down
1 change: 0 additions & 1 deletion lib/chain/tezos/tezos_node_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ class TezosNodeWriter {
var response = await HttpHelper.performPostRequest(server,
'injection/operation?chain=$chainid', hex.encode(opPair['bytes']));
response = response.toString().replaceAll('"', '');
// parseRPCError(response);
return response;
}

Expand Down
14 changes: 1 addition & 13 deletions lib/helper/password_generater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@ import 'dart:math';
import 'package:flutter/cupertino.dart';

class PasswordGenerator {
/// @desc Function to generate password based on some criteria
/// @param bool isWithLetters: password must contain letters
/// @param bool isWithUppercase: password must contain uppercase letters
/// @param bool isWithNumbers: password must contain numbers
/// @param bool isWithSpecial: password must contain special chars
/// @param int length: password length
/// @return string: new password

static String generatePassword(
{@required double length,
bool isWithLetters,
bool isWithUppercase,
bool isWithNumbers,
bool isWithSpecial}) {
//Define the allowed chars to use in the password
String _lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
String _upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String _numbers = "0123456789";
String _special = r'!@#$%^&*()+_-=}{[]|:;"/?.><,`~';

//Create the empty string that will contain the allowed chars
String _allowedChars = "";

//Put chars on the allowed ones based on the input values
_allowedChars += (isWithLetters ? _lowerCaseLetters : '');
_allowedChars += (isWithUppercase ? _upperCaseLetters : '');
_allowedChars += (isWithNumbers ? _numbers : '');
Expand All @@ -34,11 +25,8 @@ class PasswordGenerator {
int i = 0;
String _result = "";

//Create password
while (i < length.round()) {
//Get random int
int randomInt = Random.secure().nextInt(_allowedChars.length);
//Get random char and append it to the password
_result += _allowedChars[randomInt];
i++;
}
Expand Down
35 changes: 2 additions & 33 deletions lib/michelson_parser/grammar/michelin_grammar_tokenizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MichelinGrammarTokenizer {
"text": tokens[numindex].value,
"col": tokens[numindex].columnNumber,
"line": '1',
// 'toString': () => tokens[numindex].value,
}
: null;
numindex++;
Expand Down Expand Up @@ -105,38 +104,9 @@ class MichelinGrammarTokenizer {
}
seq += chunk[j];
}
// if (seq.isNotEmpty) {
// if (tokens.last.type == 'word' &&
// getKeyFromValue(char, isRegex: false) == null) {
// tokens.last = tokens.last..value += char;
// } else if (tokens.last.type == 'number' &&
// getKeyFromValue(char, isRegex: true).key == "number") {
// tokens.last = tokens.last..value += char;
// } else if (isArrayOrStringContaines(seq)) {
// var argSeq = getKeyFromValue(seq);
// tokens.add(GrammarResultModel(argSeq.key, seq)..columnNumber = i);
// i += (seq.length - 1);
// } else {
// if (char != '%') {
// var argSeq = getKeyFromValue(char);
// tokens
// .add(GrammarResultModel(argSeq.key, char)..columnNumber = i);
// }
// }
// }

}
// else if (char == '%' || char == ':') {
// var nextIndex = i + 30;
// if (nextIndex >= chunk.length - 1) nextIndex = chunk.length - 1;
// var data = chunk.substring(
// i,
// nextIndex,
// );
// var endIndex = getEndIndexOfVar(data);
// tokens.add(GrammarResultModel('annot', data.substring(0, endIndex))
// ..columnNumber = i);
// i += endIndex - 1;
// }

else if (char == '"') {
var nextIndex = i + 200;
if (nextIndex >= chunk.length - 1) nextIndex = chunk.length;
Expand Down Expand Up @@ -167,7 +137,6 @@ class MichelinGrammarTokenizer {
var result = false;
var _keys = delimiters.keys.toList();
for (var i = 0; i < _keys.length; i++) {
// var key = _keys[i];
var value = delimiters[_keys[i]];
if (value is List) {
result = value.contains(char);
Expand Down
2 changes: 0 additions & 2 deletions lib/michelson_parser/grammar/michelson_grammar_tokenizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class MichelsonGrammarTokenizer {
"text": tokens[numindex].value,
"col": tokens[numindex].columnNumber,
"line": '1',
// 'toString': () => tokens[numindex].value,
}
: null;
numindex++;
Expand Down Expand Up @@ -159,7 +158,6 @@ class MichelsonGrammarTokenizer {
var result = false;
var _keys = delimiters.keys.toList();
for (var i = 0; i < _keys.length; i++) {
// var key = _keys[i];
var value = delimiters[_keys[i]];
if (value is List) {
result = value.contains(char);
Expand Down
1 change: 0 additions & 1 deletion lib/michelson_parser/michelson_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:tezster_dart/michelson_parser/parser/michelson_grammar.dart';
import 'package:tezster_dart/michelson_parser/parser/nearley.dart';

class MichelsonParser {
/// code = michelson code
static String parseMichelson(String code) {
var parser = Nearley();
parser.parser(Nearley.fromCompiled(MichelsonGrammar().grammar));
Expand Down
26 changes: 0 additions & 26 deletions lib/michelson_parser/parser/micheline_grammar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,32 +358,6 @@ class MichelineGrammar {

getMapValue(d) => d is List ? d[0]['value'].toString() : d['value'];

// interface NearleyToken { value: any;
// [key: string]: any;
// };

// interface NearleyLexer {
// reset: (chunk: string, info: any) => void;
// next: () => NearleyToken | undefined;
// save: () => any;
// formatError: (token: NearleyToken) => string;
// has: (tokenType: string) => boolean;
// };

// interface NearleyRule {
// name: string;
// symbols: NearleySymbol[];
// postprocess?: (d: any[], loc?: number, reject?: {}) => any;
// };

// type NearleySymbol = string | { literal: any } | { test: (token: any) => boolean };

// interface Grammar {
// Lexer: NearleyLexer | undefined;
// ParserRules: NearleyRule[];
// ParserStart: string;
// };

Map<String, dynamic> get grammar => {
'Lexer': lexer,
'ParserRules': [
Expand Down
2 changes: 0 additions & 2 deletions lib/michelson_parser/parser/michelson_grammar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ class MichelsonGrammar {
'macroCADR': macroCADRconst,
'macroDIP': dIPmatcher,
'macroDUP': dUPmatcher,
// 'macroDIP': macroDIPconst,
// 'macroDUP': macroDUPconst,
'macroSETCADR': macroSETCADRconst,
'macroASSERTlist': macroASSERTlistConst,
'constantData': ['Unit', 'True', 'False', 'None', 'instruction'],
Expand Down
41 changes: 5 additions & 36 deletions lib/michelson_parser/parser/nearley.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ class Nearley {
for (var w = scannable.length - 1; 0 <= w; w--) {
var state = scannable[w];
var expect = state.rule.symbols[state.dot];
// Try to consume the token
// either regex or literal

if (expect is RegExp
? expect.hasMatch(value['value'])
: expect['type'] != null
? expect['type'] == token['type']
: expect['literal'] == literal) {
// Add it
var next = state.nextState({
'data': value,
'token': token,
Expand All @@ -86,18 +84,9 @@ class Nearley {
}
}

// Next, for each of the rules, we either
// (a) complete it, and try to see if the reference row expected that
// rule
// (b) predict the next nonterminal it expects by adding that
// nonterminal's start state
// To prevent duplication, we also keep track of rules we have already
// added

nextColumn.process();
table.add(nextColumn);

// If needed, throw an error:
if (nextColumn.states.length == 0) {
var err = new NearleyError(reportError(token));
err.offset = this.current;
Expand All @@ -113,14 +102,12 @@ class Nearley {
this.lexerState = lexer.save();
}

// Incrementally keep track of results
results = this.finish();

return this;
}

finish() {
// Return the possible parsings
var considerations = [];
var start = this.grammar.start;
var column = this.table[this.table.length - 1];
Expand All @@ -138,7 +125,6 @@ class Nearley {
}

reportError(token) {
// var lexerMessage = this.lexer.formatError(token, "Syntax error");
var lines = [];
var tokenDisplay =
(token['type'] != null ? token['type'] + " token: " : "") +
Expand All @@ -159,13 +145,10 @@ class Nearley {
}
}).toList();

// Display a "state stack" for each expectant state
// - which shows you how this state came to be, step by step.
// If there is more than one derivation, we only display the first one.
var stateStacks = expectantStates.map((state) {
return this.buildFirstStateStack(state, []);
}).toList();
// Display each state that is expecting a terminal symbol next.

stateStacks.forEach((stateStack) {
var state = stateStack[0];
var nextSymbol =
Expand All @@ -181,8 +164,7 @@ class Nearley {

String reportLexerError(lexerError) {
var tokenDisplay, lexerMessage;
// Planning to add a token property to moo's thrown error
// even on erroring tokens to be used in error display below

var token = lexerError.token;
if (token) {
tokenDisplay = "input " + jsonEncode(token.text[0]) + " (lexer error)";
Expand Down Expand Up @@ -213,13 +195,11 @@ class Nearley {
lines.add('Unexpected ' +
tokenDisplay +
'. Instead, I was expecting to see one of the following:\n');
// Display a "state stack" for each expectant state
// - which shows you how this state came to be, step by step.
// If there is more than one derivation, we only display the first one.

var stateStacks = expectantStates.map((state) {
return this.buildFirstStateStack(state, []) ?? [state];
});
// Display each state that is expecting a terminal symbol next.

stateStacks.forEach((stateStack) {
var state = stateStack[0];
var nextSymbol = state.rule.symbols[state.dot];
Expand All @@ -234,9 +214,6 @@ class Nearley {

buildFirstStateStack(state, visited) {
if (visited.indexOf(state) != -1) {
// Found cycle, return null
// to eliminate this path from the results, because
// we don't know how to display it meaningfully
return null;
}
if (state.wantedBy.length == 0) {
Expand Down Expand Up @@ -277,7 +254,6 @@ class Nearley {
}

getSymbolLongDisplay(symbol) {
// var type = typeof symbol;
if (symbol is String) {
return symbol;
} else if (symbol is Map) {
Expand Down Expand Up @@ -332,28 +308,23 @@ class Column {
if (state.data != fail) {
var wantBy = state.wantedBy;

// complete
for (var i = wantBy.length - 1; 0 <= i; i--) {
var left = wantBy[i];
this.complete(left, state);
}

// special-case nullables
if (state.reference == index) {
// make sure future predictors of this rule get completed.
var exp = state.rule.name;
this.completed[exp] = this.completed[exp] ?? [];
this.completed[exp].add(state);
}
}
} else {
// queue scannable states
var exp = state.rule.symbols[state.dot];
if (!(exp is String)) {
this.scannable.add(state);
}

// predict
if (_wants[exp] != null) {
_wants[exp].add(state);
if (_completed.containsKey(exp)) {
Expand Down Expand Up @@ -519,8 +490,6 @@ class StreamLexer {
return List.generate(length - s.length + 1, (index) => '').join(" ") + s;
}

// nb. this gets called after consuming the offending token,
// so the culprit is index-1
var buffer = this.buffer;
if (buffer is String) {
var lines = buffer.split("\n").sublist(max(0, this.line - 5), this.line);
Expand Down
20 changes: 1 addition & 19 deletions lib/reporting/conseil_data_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,11 @@ class ConseilDataClient {
static executeEntityQuery(
serverInfo, platform, network, entity, query) async {
var url = '${serverInfo['url']}/v2/data/$platform/$network/$entity';
// log.debug(`ConseilDataClient.executeEntityQuery request: ${url}, ${JSON.stringify(query)}`);

var res = await HttpHelper.performPostRequest(url, '', query, headers: {
'apiKey': serverInfo['apiKey'],
// 'Content-Type': 'application/json',
'cache': 'no-store',
});
return res;
// .then((r) {
// if (!r.ok) {
// // log.error(`ConseilDataClient.executeEntityQuery request: ${url}, ${JSON.stringify(query)}, failed with ${r.statusText}(${r.status})`);
// throw new ConseilErrorTypes_1.ConseilRequestError(
// r.status, r.statusText, url, query);
// }
// return r;
// })
// .then((r) {
// var isJSONResponse = r.headers
// .get('content-type')
// .toLowerCase()
// .includes('application/json');
// var response = isJSONResponse != null ? r.json() : r.text();
// // log.debug(`ConseilDataClient.executeEntityQuery response: ${isJSONResponse ? JSON.stringify(response) : response}`);
// return response;
// });
}
}
Loading

0 comments on commit f540c9f

Please sign in to comment.