Skip to content

Commit

Permalink
style(all-packages): Add prettier config to the project and fix style…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
carte7000 committed Aug 21, 2019
1 parent 1216794 commit b97c878
Show file tree
Hide file tree
Showing 36 changed files with 398 additions and 388 deletions.
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
endOfLine: 'lf',
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
};
26 changes: 13 additions & 13 deletions packages/tezos-ts-michelson-encoder/src/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from "buffer";
const bs58check = require("bs58check");
import { Buffer } from 'buffer';
const bs58check = require('bs58check');
export function b58cencode(payload: string, prefix: Uint8Array) {
const payloadAr = Uint8Array.from(Buffer.from(payload, "hex"));
const payloadAr = Uint8Array.from(Buffer.from(payload, 'hex'));

const n = new Uint8Array(prefix.length + payloadAr.length);
n.set(prefix);
Expand All @@ -17,33 +17,33 @@ export function b58decode(payload: string) {
const hexParts = [] as any[];
for (let i = 0; i < byteArray.length; i++) {
let hex = byteArray[i].toString(16);
let paddedHex = ("00" + hex).slice(-2);
let paddedHex = ('00' + hex).slice(-2);
hexParts.push(paddedHex);
}
return hexParts.join("");
return hexParts.join('');
};

const prefix = {
[new Uint8Array([6, 161, 159]).toString()]: "0000",
[new Uint8Array([6, 161, 161]).toString()]: "0001",
[new Uint8Array([6, 161, 164]).toString()]: "0002"
[new Uint8Array([6, 161, 159]).toString()]: '0000',
[new Uint8Array([6, 161, 161]).toString()]: '0001',
[new Uint8Array([6, 161, 164]).toString()]: '0002',
};

let pref = prefix[new Uint8Array(buf.slice(0, 3)).toString()];
if (pref) {
const hex = buf2hex(buf.slice(3));
return pref + hex;
} else {
return "01" + buf2hex(buf.slice(3, 42)) + "00";
return '01' + buf2hex(buf.slice(3, 42)) + '00';
}
}

export function encodePubKey(value: string) {
if (value.substring(0, 2) === "00") {
if (value.substring(0, 2) === '00') {
const prefix: { [key: string]: Uint8Array } = {
"0000": new Uint8Array([6, 161, 159]),
"0001": new Uint8Array([6, 161, 161]),
"0002": new Uint8Array([6, 161, 164])
'0000': new Uint8Array([6, 161, 159]),
'0001': new Uint8Array([6, 161, 161]),
'0002': new Uint8Array([6, 161, 164]),
};

return b58cencode(value.substring(4), prefix[value.substring(0, 4)]);
Expand Down
6 changes: 3 additions & 3 deletions packages/tezos-ts-michelson-encoder/src/schema/parameter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createToken } from "../tokens/createToken";
import { Token } from "../tokens/token";
import { createToken } from '../tokens/createToken';
import { Token } from '../tokens/token';

export class ParameterSchema {
private root: Token;

static fromRPCResponse(val: any) {
return new ParameterSchema(val.script.code.find((x: any) => x.prim === "parameter")!.args[0]);
return new ParameterSchema(val.script.code.find((x: any) => x.prim === 'parameter')!.args[0]);
}

constructor(val: any) {
Expand Down
24 changes: 12 additions & 12 deletions packages/tezos-ts-michelson-encoder/src/schema/storage.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Token } from "../tokens/token";
import { Token } from '../tokens/token';

import { BigMapToken } from "../tokens/bigmap";
import { BigMapToken } from '../tokens/bigmap';

import { createToken } from "../tokens/createToken";
import { createToken } from '../tokens/createToken';

import { RpcTransaction } from "./model";
import { RpcTransaction } from './model';

export class Schema {
private root: Token;
private bigMap?: BigMapToken;

static fromRPCResponse(val: any) {
return new Schema(val.script.code.find((x: any) => x.prim === "storage")!.args[0]);
return new Schema(val.script.code.find((x: any) => x.prim === 'storage')!.args[0]);
}

constructor(val: any) {
this.root = createToken(val, 0);

if (val.prim === "pair" && val.args[0].prim === "big_map") {
if (val.prim === 'pair' && val.args[0].prim === 'big_map') {
this.bigMap = new BigMapToken(val.args[0], 0, createToken);
}
}
Expand All @@ -28,23 +28,23 @@ export class Schema {

ExecuteOnBigMapDiff(diff: any) {
if (!this.bigMap) {
throw new Error("No big map schema");
throw new Error('No big map schema');
}

return this.bigMap.Execute(diff);
}

ExecuteOnBigMapValue(key: any) {
if (!this.bigMap) {
throw new Error("No big map schema");
throw new Error('No big map schema');
}

return this.bigMap.ValueSchema.Execute(key);
}

EncodeBigMapKey(key: string) {
if (!this.bigMap) {
throw new Error("No big map schema");
throw new Error('No big map schema');
}

return this.bigMap.KeySchema.ToBigMapKey(key);
Expand All @@ -56,19 +56,19 @@ export class Schema {

ComputeState(tx: RpcTransaction[], state: any) {
if (!this.bigMap) {
throw new Error("No big map schema");
throw new Error('No big map schema');
}

const bigMap = tx.reduce((prev, current) => {
return {
...prev,
...this.ExecuteOnBigMapDiff(current.contents[0].metadata.operation_result.big_map_diff)
...this.ExecuteOnBigMapDiff(current.contents[0].metadata.operation_result.big_map_diff),
};
}, {});

return {
...this.Execute(state),
[this.bigMap.annot]: bigMap
[this.bigMap.annot]: bigMap,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./schema/storage";
export * from "./schema/parameter";
export * from './schema/storage';
export * from './schema/parameter';
10 changes: 5 additions & 5 deletions packages/tezos-ts-michelson-encoder/src/tokens/bigmap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Token, TokenFactory, ComparableToken } from "./token";
import { encodePubKey } from "../encoding";
import { Token, TokenFactory, ComparableToken } from './token';
import { encodePubKey } from '../encoding';

export class BigMapToken extends Token {
static prim = "big_map";
static prim = 'big_map';
constructor(
protected val: { prim: string; args: any[]; annots: any[] },
protected idx: number,
Expand All @@ -21,15 +21,15 @@ export class BigMapToken extends Token {

public ExtractSchema() {
return {
[this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema()
[this.KeySchema.ExtractSchema()]: this.ValueSchema.ExtractSchema(),
};
}

public Execute(val: any[]) {
return val.reduce((prev, current) => {
return {
...prev,
[encodePubKey(current.key.bytes)]: this.ValueSchema.Execute(current.value)
[encodePubKey(current.key.bytes)]: this.ValueSchema.Execute(current.value),
};
}, {});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { b58decode, encodePubKey } from "../../encoding";
import { Token, TokenFactory, ComparableToken } from '../token';
import { b58decode, encodePubKey } from '../../encoding';

export class AddressToken extends Token implements ComparableToken {
static prim = "address";
static prim = 'address';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -16,7 +16,7 @@ export class AddressToken extends Token implements ComparableToken {
const decoded = b58decode(val);
return {
key: { bytes: decoded },
type: { prim: "bytes" }
type: { prim: 'bytes' },
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory } from "../token";
import { Token, TokenFactory } from '../token';

export class BoolToken extends Token {
static prim = "bool";
static prim = 'bool';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class BytesToken extends Token implements ComparableToken {
static prim = "bytes";
static prim = 'bytes';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -14,7 +14,7 @@ export class BytesToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { bytes: val },
type: { prim: BytesToken.prim }
type: { prim: BytesToken.prim },
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class IntToken extends Token implements ComparableToken {
static prim = "int";
static prim = 'int';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -22,7 +22,7 @@ export class IntToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { int: val },
type: { prim: IntToken.prim }
type: { prim: IntToken.prim },
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class MutezToken extends Token implements ComparableToken {
static prim = "mutez";
static prim = 'mutez';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -22,7 +22,7 @@ export class MutezToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { int: val },
type: { prim: MutezToken.prim }
type: { prim: MutezToken.prim },
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class NatToken extends Token implements ComparableToken {
static prim = "nat";
static prim = 'nat';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -22,7 +22,7 @@ export class NatToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { int: val },
type: { prim: NatToken.prim }
type: { prim: NatToken.prim },
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class StringToken extends Token implements ComparableToken {
static prim = "string";
static prim = 'string';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -27,7 +27,7 @@ export class StringToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { string: val },
type: { prim: StringToken.prim }
type: { prim: StringToken.prim },
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory, ComparableToken } from "../token";
import { Token, TokenFactory, ComparableToken } from '../token';

export class TimestampToken extends Token implements ComparableToken {
static prim = "timestamp";
static prim = 'timestamp';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -27,7 +27,7 @@ export class TimestampToken extends Token implements ComparableToken {
public ToBigMapKey(val: string) {
return {
key: { timestamp: val },
type: { prim: TimestampToken.prim }
type: { prim: TimestampToken.prim },
};
}
}
6 changes: 3 additions & 3 deletions packages/tezos-ts-michelson-encoder/src/tokens/contract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory } from "./token";
import { Token, TokenFactory } from './token';

export class ContractToken extends Token {
static prim = "contract";
static prim = 'contract';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand All @@ -12,7 +12,7 @@ export class ContractToken extends Token {
}

public Execute() {
return "";
return '';
}

public ExtractSchema() {
Expand Down
4 changes: 2 additions & 2 deletions packages/tezos-ts-michelson-encoder/src/tokens/createToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tokens } from "./tokens";
import { Token } from "./token";
import { tokens } from './tokens';
import { Token } from './token';

export function createToken(val: any, idx: number): Token {
const t = tokens.find(x => x.prim === val.prim);
Expand Down
4 changes: 2 additions & 2 deletions packages/tezos-ts-michelson-encoder/src/tokens/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token, TokenFactory } from "./token";
import { Token, TokenFactory } from './token';

export class ListToken extends Token {
static prim = "list";
static prim = 'list';

constructor(
protected val: { prim: string; args: any[]; annots: any[] },
Expand Down
Loading

0 comments on commit b97c878

Please sign in to comment.