Skip to content

Commit

Permalink
feat: Adds missing instructions and exposes converter API
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Jan 30, 2022
1 parent bd8e120 commit 176a532
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tezwell/michelson-sdk",
"version": "0.1.0",
"version": "0.2.0",
"description": "Michelson SDK",
"keywords": [
"Tezos",
Expand All @@ -20,6 +20,7 @@
"module": "index.js",
"exports": {
".": "./index.js",
"./converter": "./converter/index.js",
"./core": "./core/index.js",
"./literal": "./core/literal.js",
"./type": "./core/type.js"
Expand Down
8 changes: 7 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const DIST_FOLDER = './dist';

// Build steps
cleanUP();
generateBundle(['./src/index.ts', './src/core/index.ts', './src/core/type.ts', './src/core/literal.ts']);
generateBundle([
'./src/index.ts',
'./src/converter/index.ts',
'./src/core/index.ts',
'./src/core/type.ts',
'./src/core/literal.ts',
]);

/**
* Produces the js bundle
Expand Down
97 changes: 93 additions & 4 deletions src/core/enums/prim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,100 @@ export enum Prim {
code = 'code',
// Instructions
DROP = 'DROP',
CDR = 'CDR',
NIL = 'NIL',
DUP = 'DUP',
SWAP = 'SWAP',
DIG = 'DIG',
DUG = 'DUG',
PUSH = 'PUSH',
SOME = 'SOME',
NONE = 'NONE',
UNIT = 'UNIT',
NEVER = 'NEVER',
IF_NONE = 'IF_NONE',
PAIR = 'PAIR',
CAR = 'CAR',
CDR = 'CDR',
UNPAIR = 'UNPAIR',
PUSH = 'PUSH',
LAMBDA = 'LAMBDA',
LEFT = 'LEFT',
RIGHT = 'RIGHT',
IF_LEFT = 'IF_LEFT',
NIL = 'NIL',
CONS = 'CONS',
IF_CONS = 'IF_CONS',
SIZE = 'SIZE',
EMPTY_SET = 'EMPTY_SET',
EMPTY_MAP = 'EMPTY_MAP',
EMPTY_BIG_MAP = 'EMPTY_BIG_MAP',
MAP = 'MAP',
ITER = 'ITER',
MEM = 'MEM',
GET = 'GET',
UPDATE = 'UPDATE',
IF = 'IF',
LOOP = 'LOOP',
LOOP_LEFT = 'LOOP_LEFT',
LAMBDA = 'LAMBDA',
EXEC = 'EXEC',
APPLY = 'APPLY',
DIP = 'DIP',
FAILWITH = 'FAILWITH',
CAST = 'CAST',
RENAME = 'RENAME',
CONCAT = 'CONCAT',
SLICE = 'SLICE',
PACK = 'PACK',
UNPACK = 'UNPACK',
ADD = 'ADD',
SUB = 'SUB',
MUL = 'MUL',
EDIV = 'EDIV',
ABS = 'ABS',
ISNAT = 'ISNAT',
INT = 'INT',
NEG = 'NEG',
LSL = 'LSL',
LSR = 'LSR',
OR = 'OR',
AND = 'AND',
XOR = 'XOR',
NOT = 'NOT',
COMPARE = 'COMPARE',
EQ = 'EQ',
NEQ = 'NEQ',
LT = 'LT',
GT = 'GT',
LE = 'LE',
GE = 'GE',
SELF = 'SELF',
SELF_ADDRESS = 'SELF_ADDRESS',
CONTRACT = 'CONTRACT',
TRANSFER_TOKENS = 'TRANSFER_TOKENS',
SET_DELEGATE = 'SET_DELEGATE',
CREATE_CONTRACT = 'CREATE_CONTRACT',
IMPLICIT_ACCOUNT = 'IMPLICIT_ACCOUNT',
VOTING_POWER = 'VOTING_POWER',
NOW = 'NOW',
LEVEL = 'LEVEL',
AMOUNT = 'AMOUNT',
BALANCE = 'BALANCE',
CHECK_SIGNATURE = 'CHECK_SIGNATURE',
BLAKE2B = 'BLAKE2B',
KECCAK = 'KECCAK',
SHA3 = 'SHA3',
SHA256 = 'SHA256',
SHA512 = 'SHA512',
HASH_KEY = 'HASH_KEY',
SOURCE = 'SOURCE',
SENDER = 'SENDER',
ADDRESS = 'ADDRESS',
CHAIN_ID = 'CHAIN_ID',
TOTAL_VOTING_POWER = 'TOTAL_VOTING_POWER',
PAIRING_CHECK = 'PAIRING_CHECK',
SAPLING_EMPTY_STATE = 'SAPLING_EMPTY_STATE',
SAPLING_VERIFY_UPDATE = 'SAPLING_VERIFY_UPDATE',
TICKET = 'TICKET',
READ_TICKET = 'READ_TICKET',
SPLIT_TICKET = 'SPLIT_TICKET',
JOIN_TICKETS = 'JOIN_TICKETS',
OPEN_CHEST = 'OPEN_CHEST',
}
10 changes: 5 additions & 5 deletions src/core/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {
TPair,
TMap,
TOr,
TLambda,
//
buildRecordVariantType,
} from './type';
import { Prim } from './enums/prim';
import Utils, { composeRightCombLayout } from '../misc/utils';
import Converter from '../../src/converter';
import { TLambda } from '.';

export class Michelson_Literal implements IValue {
private prim: PrimValue;
Expand Down Expand Up @@ -117,7 +117,7 @@ export class Michelson_Literal_C1 implements IValue {
case Prim.Left:
case Prim.Right:
return `(${this.#prim} ${this.#elements.map((v) => v.toMicheline()).join(' ')})`;
case Prim.Elt:
case Prim.list:
return `{ ${this.#elements.map((v) => v.toMicheline()).join(' ; ')} }`;
}

Expand All @@ -134,7 +134,7 @@ export class Michelson_Literal_C1 implements IValue {
prim: this.#prim,
args: this.#elements.map((v) => v.toJSON()),
};
case Prim.Elt:
case Prim.list:
return this.#elements.map((v) => v.toJSON());
}

Expand Down Expand Up @@ -251,9 +251,9 @@ export const Bool = (value: boolean) => new Michelson_Literal(value ? Prim.True
export const Unit = () => new Michelson_Literal(Prim.Unit, TUnit());
// Containers
export const List = (elements: IValue[], innerType: IType) =>
new Michelson_Literal_C1(Prim.Elt, TList(innerType), elements);
new Michelson_Literal_C1(Prim.list, TList(innerType), elements);
export const Set = (elements: IValue[], innerType: IType) =>
new Michelson_Literal_C1(Prim.Elt, TSet(innerType), elements);
new Michelson_Literal_C1(Prim.list, TSet(innerType), elements);
export const None = (innerType: IType) => new Michelson_Literal(Prim.None, TOption(innerType));
export const Some = (element: IValue) => new Michelson_Literal_C1(Prim.Some, TOption(element.type), [element]);
export const Pair = (left: IValue, right: IValue) =>
Expand Down
1 change: 1 addition & 0 deletions src/typings/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type PrimValue =
| Prim.int
| Prim.string
| Prim.bytes
| Prim.list
| Prim.Unit
| Prim.Some
| Prim.None
Expand Down

0 comments on commit 176a532

Please sign in to comment.