@taquito/michelson-encoder 11.2.0-beta-RC.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -46
- package/dist/lib/version.js +2 -2
- package/dist/lib/version.js.map +1 -1
- package/dist/taquito-michelson-encoder.es6.js +2 -2
- package/dist/taquito-michelson-encoder.es6.js.map +1 -1
- package/dist/taquito-michelson-encoder.umd.js +2 -2
- package/dist/taquito-michelson-encoder.umd.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,66 +1,137 @@
|
|
|
1
1
|
|
|
2
2
|
# Taquito Michelson Encoder package
|
|
3
|
+
*Documentation can be found [here](https://tezostaquito.io/docs/michelson_encoder)*
|
|
4
|
+
*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_michelson_encoder.html)*
|
|
3
5
|
|
|
4
|
-
`@taquito/michelson-encoder` provides a JavaScript abstraction based on a Tezos Smart contracts code, parameters and
|
|
6
|
+
`@taquito/michelson-encoder` provides a JavaScript abstraction based on a Tezos Smart contracts code, parameters, storage, and views.
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
## General Information
|
|
9
|
+
|
|
10
|
+
The Michelson-Encoder package aims to create an abstraction over the Michelson Language. It allows converting Michelson data into javascript-looking objects which are easier to use and reason about.
|
|
11
|
+
|
|
12
|
+
Its integration into the main Taquito package makes it easier to write the storage when deploying a contract and the parameter when calling a contract entry-point or executing a view. It also provides an abstraction on the storage read value of the contract.
|
|
13
|
+
|
|
14
|
+
The `Schema` class is intended to represent the contract storage, while the `ParameterSchema` represents its entry points. The `Execute` method takes a parameter in Michelson format and converts it into the JavaScript abstraction. The `Encode` method does the opposite; it takes a JavaScript object as a parameter and converts it into Michelson data.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
```
|
|
18
|
+
npm i --save @taquito/michelson-encoder
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
7
22
|
|
|
8
23
|
## Example
|
|
9
24
|
|
|
10
|
-
|
|
25
|
+
The constructor of the `Schema` class takes a Michelson type as a parameter which is retrieved from a Tezos Nodes RPC:
|
|
11
26
|
|
|
12
|
-
```
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
"prim": "Pair",
|
|
24
|
-
"args": [
|
|
25
|
-
{ "int": "1000" },
|
|
26
|
-
{
|
|
27
|
-
"prim": "Pair",
|
|
28
|
-
"args": [
|
|
29
|
-
{ "string": "Token B" },
|
|
30
|
-
{
|
|
31
|
-
"prim": "Pair",
|
|
32
|
-
"args": [
|
|
33
|
-
{ "string": "B" },
|
|
34
|
-
{ "string": "tz1ccqAEwfPgeoipnXtjAv1iucrpQv3DFmmS" }
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
27
|
+
```ts
|
|
28
|
+
const storageType = {
|
|
29
|
+
prim: 'pair',
|
|
30
|
+
args: [
|
|
31
|
+
{ prim: 'nat', annots: [ '%stored_counter' ] },
|
|
32
|
+
{
|
|
33
|
+
prim: 'pair',
|
|
34
|
+
args: [
|
|
35
|
+
{ prim: 'nat', annots: [ '%threshold' ] },
|
|
36
|
+
{ prim: 'list', args: [ { prim: 'key' } ], annots: [ '%keys' ] }
|
|
39
37
|
]
|
|
40
|
-
|
|
41
|
-
]
|
|
42
|
-
}
|
|
38
|
+
}
|
|
43
39
|
]
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
};
|
|
41
|
+
const storageSchema = new Schema(storageType);
|
|
46
42
|
```
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
The `Execute` method takes a Michelson value as a parameter and generates an abstraction in the form of a plain old javascript object:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// dataMichelson is the storage of a contract retrieved from the RPC
|
|
48
|
+
const dataMichelson = {
|
|
49
|
+
"prim": "Pair",
|
|
50
|
+
"args": [
|
|
51
|
+
{
|
|
52
|
+
"int": "10"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"prim": "Pair",
|
|
56
|
+
"args": [
|
|
57
|
+
{
|
|
58
|
+
"int": "5"
|
|
59
|
+
},
|
|
60
|
+
[
|
|
61
|
+
{
|
|
62
|
+
"string": "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"string": "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const data = storageSchema.Execute(dataMichelson);
|
|
74
|
+
console.log(data);
|
|
49
75
|
|
|
50
|
-
|
|
76
|
+
/* output:
|
|
51
77
|
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
78
|
+
"stored_counter": "10",
|
|
79
|
+
"threshold": "5",
|
|
80
|
+
"keys": [
|
|
81
|
+
"edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g",
|
|
82
|
+
"edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t"
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
*/
|
|
59
86
|
```
|
|
60
87
|
|
|
61
|
-
|
|
88
|
+
Note that the Michelson type annotations represent the javascript object's keys.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
The `Encode` method takes a javascript object as a parameter and converts it into Michelson:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const data = storageSchema.Encode({
|
|
95
|
+
"stored_counter": "10",
|
|
96
|
+
"threshold": "5",
|
|
97
|
+
"keys": [
|
|
98
|
+
"edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g",
|
|
99
|
+
"edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t"
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log(data);
|
|
104
|
+
|
|
105
|
+
/* output:
|
|
106
|
+
{
|
|
107
|
+
"prim": "Pair",
|
|
108
|
+
"args": [
|
|
109
|
+
{
|
|
110
|
+
"int": "10"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"prim": "Pair",
|
|
114
|
+
"args": [
|
|
115
|
+
{
|
|
116
|
+
"int": "5"
|
|
117
|
+
},
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
"string": "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"string": "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
*/
|
|
131
|
+
```
|
|
132
|
+
## Additional info
|
|
62
133
|
|
|
63
|
-
|
|
134
|
+
See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.
|
|
64
135
|
|
|
65
136
|
## Disclaimer
|
|
66
137
|
|
package/dist/lib/version.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "
|
|
6
|
+
"commitHash": "222db56e9550fff784a819406d8bdc1110787440",
|
|
7
|
+
"version": "12.0.0"
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
package/dist/lib/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,QAAQ;CACtB,CAAC"}
|
|
@@ -3318,8 +3318,8 @@ class ViewSchema {
|
|
|
3318
3318
|
|
|
3319
3319
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
3320
3320
|
const VERSION = {
|
|
3321
|
-
"commitHash": "
|
|
3322
|
-
"version": "
|
|
3321
|
+
"commitHash": "222db56e9550fff784a819406d8bdc1110787440",
|
|
3322
|
+
"version": "12.0.0"
|
|
3323
3323
|
};
|
|
3324
3324
|
|
|
3325
3325
|
/**
|