@taquito/tzip16 24.2.0 → 24.3.0-beta.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/dist/lib/errors.js +10 -10
- package/dist/lib/handlers/http-handler.js +8 -19
- package/dist/lib/handlers/ipfs-handler.js +8 -19
- package/dist/lib/handlers/tezos-storage-handler.js +19 -30
- package/dist/lib/metadata-provider.js +28 -39
- package/dist/lib/tzip16-contract-abstraction.js +82 -121
- package/dist/lib/version.js +2 -2
- package/dist/lib/viewKind/michelson-storage-view.js +53 -64
- package/dist/taquito-tzip16.es6.js +208 -280
- package/dist/taquito-tzip16.es6.js.map +1 -1
- package/dist/taquito-tzip16.umd.js +208 -280
- package/dist/taquito-tzip16.umd.js.map +1 -1
- package/dist/types/errors.d.ts +10 -10
- package/dist/types/handlers/tezos-storage-handler.d.ts +1 -1
- package/dist/types/metadata-provider.d.ts +4 -4
- package/dist/types/tzip16-contract-abstraction.d.ts +1 -1
- package/dist/types/viewKind/michelson-storage-view.d.ts +3 -3
- package/package.json +24 -14
- package/LICENSE +0 -202
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.MichelsonStorageView = void 0;
|
|
13
4
|
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
@@ -32,7 +23,7 @@ class MichelsonStorageView {
|
|
|
32
23
|
};
|
|
33
24
|
}
|
|
34
25
|
/**
|
|
35
|
-
*
|
|
26
|
+
* According to the tzip-16 standard, the following instructions must not be used in the code of the view:
|
|
36
27
|
* 'AMOUNT', 'CREATE_CONTRACT', 'SENDER', 'SET_DELEGATE', 'SOURCE', and 'TRANSFER_TOKENS'
|
|
37
28
|
* The method throw an error if an illegal instruction is found
|
|
38
29
|
*/
|
|
@@ -57,7 +48,7 @@ class MichelsonStorageView {
|
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
/**
|
|
60
|
-
*
|
|
51
|
+
* According to the tzip-16 standard, in the first version of the specification, the instruction SELF should only be used before ADDRESS
|
|
61
52
|
* The method throws an error is the instruction SELF is present, but not followed by ADDRESS
|
|
62
53
|
*/
|
|
63
54
|
illegalUseOfSelfInstruction(code) {
|
|
@@ -75,7 +66,7 @@ class MichelsonStorageView {
|
|
|
75
66
|
}
|
|
76
67
|
}
|
|
77
68
|
/**
|
|
78
|
-
*
|
|
69
|
+
* Loops through the view's code and replace SELF, BALANCE, NOW, and CHAIN_ID with Michelson expressions that match the current context, if applicable.
|
|
79
70
|
*/
|
|
80
71
|
adaptViewCodeToContext(code, contractBalance, blockTimeStamp, chainId) {
|
|
81
72
|
const instructionsToReplace = {
|
|
@@ -119,59 +110,57 @@ class MichelsonStorageView {
|
|
|
119
110
|
const arg = parameterViewSchema.Encode(...args);
|
|
120
111
|
return { arg, viewParameterType };
|
|
121
112
|
}
|
|
122
|
-
executeView(...args) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{ prim: 'PAIR' },
|
|
152
|
-
],
|
|
113
|
+
async executeView(...args) {
|
|
114
|
+
// validate view code against tzip-16 specifications
|
|
115
|
+
this.findForbiddenInstructionInViewCodeError(this.code);
|
|
116
|
+
this.illegalUseOfSelfInstruction(this.code);
|
|
117
|
+
const { arg, viewParameterType } = this.formatArgsAndParameter(args);
|
|
118
|
+
const storageType = this.contract.script.code.find((x) => x.prim === 'storage');
|
|
119
|
+
const storageArgs = storageType.args[0];
|
|
120
|
+
// currentContext
|
|
121
|
+
const storageValue = await this.readProvider.getStorage(this.contract.address, 'head');
|
|
122
|
+
const chainId = await this.readProvider.getChainId();
|
|
123
|
+
const contractBalance = (await this.readProvider.getBalance(this.contract.address, 'head')).toString();
|
|
124
|
+
const blockTimestamp = await this.readProvider.getBlockTimestamp('head');
|
|
125
|
+
const code = this.adaptViewCodeToContext(this.code, contractBalance, blockTimestamp, chainId);
|
|
126
|
+
if (!this.viewParameterType) {
|
|
127
|
+
code.unshift({ prim: 'CDR' });
|
|
128
|
+
}
|
|
129
|
+
const viewScript = {
|
|
130
|
+
script: [
|
|
131
|
+
{ prim: 'parameter', args: [{ prim: 'pair', args: [viewParameterType, storageArgs] }] },
|
|
132
|
+
{ prim: 'storage', args: [{ prim: 'option', args: [this.returnType] }] },
|
|
133
|
+
{
|
|
134
|
+
prim: 'code',
|
|
135
|
+
args: [
|
|
136
|
+
[
|
|
137
|
+
{ prim: 'CAR' },
|
|
138
|
+
code,
|
|
139
|
+
{ prim: 'SOME' },
|
|
140
|
+
{ prim: 'NIL', args: [{ prim: 'operation' }] },
|
|
141
|
+
{ prim: 'PAIR' },
|
|
153
142
|
],
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
storage: { prim: 'None' },
|
|
147
|
+
input: { prim: 'Pair', args: [arg, storageValue] },
|
|
148
|
+
amount: '0',
|
|
149
|
+
chain_id: chainId,
|
|
150
|
+
balance: '0',
|
|
151
|
+
};
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = await this.rpc.runCode(viewScript);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
const failWith = (0, taquito_2.validateAndExtractFailwith)(error);
|
|
158
|
+
throw failWith
|
|
159
|
+
? new taquito_1.ViewSimulationError(`The simulation of the Michelson view failed with: ${JSON.stringify(failWith)}`, this.viewName, failWith, error)
|
|
160
|
+
: error;
|
|
161
|
+
}
|
|
162
|
+
const viewResultSchema = new michelson_encoder_1.ParameterSchema(this.returnType);
|
|
163
|
+
return viewResultSchema.Execute(result.storage.args[0]);
|
|
175
164
|
}
|
|
176
165
|
}
|
|
177
166
|
exports.MichelsonStorageView = MichelsonStorageView;
|