@taquito/taquito 24.2.0 → 24.3.0-beta.1
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 +1 -1
- package/dist/lib/batch/rpc-batch-provider.js +91 -83
- package/dist/lib/context.js +22 -26
- package/dist/lib/contract/big-map.js +16 -29
- package/dist/lib/contract/contract-methods/contract-method-object-param.js +7 -7
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +31 -44
- package/dist/lib/contract/contract.js +21 -32
- package/dist/lib/contract/errors.js +9 -9
- package/dist/lib/contract/prepare.js +36 -45
- package/dist/lib/contract/rpc-contract-provider.js +426 -475
- package/dist/lib/contract/sapling-state-abstraction.js +3 -14
- package/dist/lib/contract/semantic.js +2 -2
- package/dist/lib/errors.js +3 -3
- package/dist/lib/estimate/errors.js +1 -1
- package/dist/lib/estimate/estimate.js +66 -20
- package/dist/lib/estimate/rpc-estimate-provider.js +427 -460
- package/dist/lib/forger/composite-forger.js +16 -27
- package/dist/lib/forger/errors.js +2 -2
- package/dist/lib/forger/taquito-local-forger.js +9 -22
- package/dist/lib/global-constants/default-global-constants-provider.js +8 -19
- package/dist/lib/global-constants/errors.js +2 -2
- package/dist/lib/global-constants/noop-global-constants-provider.js +2 -13
- package/dist/lib/import-key.js +23 -34
- package/dist/lib/injector/rpc-injector.js +13 -24
- package/dist/lib/operations/ballot-operation.js +2 -3
- package/dist/lib/operations/delegate-operation.js +5 -8
- package/dist/lib/operations/drain-delegate-operation.js +1 -1
- package/dist/lib/operations/errors.js +9 -6
- package/dist/lib/operations/increase-paid-storage-operation.js +4 -7
- package/dist/lib/operations/operations.js +100 -30
- package/dist/lib/operations/origination-operation.js +16 -27
- package/dist/lib/operations/proposals-operation.js +2 -3
- package/dist/lib/operations/register-global-constant-operation.js +4 -7
- package/dist/lib/operations/reveal-operation.js +1 -1
- package/dist/lib/operations/smart-rollup-add-messages-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-originate-operation.js +4 -7
- package/dist/lib/operations/transaction-operation.js +2 -2
- package/dist/lib/operations/transfer-ticket-operation.js +4 -6
- package/dist/lib/operations/types.js +17 -19
- package/dist/lib/operations/update-companion-key-operation.js +4 -7
- package/dist/lib/operations/update-consensus-key-operation.js +4 -7
- package/dist/lib/packer/michel-codec-packer.js +3 -14
- package/dist/lib/packer/rpc-packer.js +2 -13
- package/dist/lib/parser/michel-codec-parser.js +82 -107
- package/dist/lib/parser/noop-parser.js +2 -13
- package/dist/lib/prepare/prepare-provider.js +780 -744
- package/dist/lib/provider.js +322 -128
- package/dist/lib/read-provider/rpc-read-adapter.js +76 -121
- package/dist/lib/signer/errors.js +1 -1
- package/dist/lib/signer/noop.js +9 -26
- package/dist/lib/subscribe/errors.js +2 -2
- package/dist/lib/subscribe/polling-subcribe-provider.js +35 -38
- package/dist/lib/taquito.js +33 -33
- package/dist/lib/tz/rpc-tz-provider.js +27 -44
- package/dist/lib/version.js +2 -2
- package/dist/lib/wallet/batch-operation.js +32 -45
- package/dist/lib/wallet/delegation-operation.js +25 -40
- package/dist/lib/wallet/errors.js +15 -3
- package/dist/lib/wallet/increase-paid-storage-operation.js +25 -40
- package/dist/lib/wallet/legacy.js +28 -63
- package/dist/lib/wallet/operation-factory.js +27 -56
- package/dist/lib/wallet/operation.js +123 -59
- package/dist/lib/wallet/origination-operation.js +34 -46
- package/dist/lib/wallet/register-global-constant-operation.js +26 -43
- package/dist/lib/wallet/transaction-operation.js +21 -36
- package/dist/lib/wallet/transfer-ticket-operation.js +21 -36
- package/dist/lib/wallet/wallet.js +187 -184
- package/dist/taquito.es6.js +3424 -3197
- package/dist/taquito.es6.js.map +1 -1
- package/dist/taquito.min.js +1 -1
- package/dist/taquito.umd.js +7930 -7701
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/batch/rpc-batch-provider.d.ts +18 -18
- package/dist/types/context.d.ts +4 -4
- package/dist/types/contract/big-map.d.ts +3 -3
- package/dist/types/contract/contract-methods/contract-method-interface.d.ts +4 -4
- package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +6 -6
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +3 -3
- package/dist/types/contract/contract.d.ts +6 -6
- package/dist/types/contract/errors.d.ts +11 -11
- package/dist/types/contract/interface.d.ts +42 -42
- package/dist/types/contract/rpc-contract-provider.d.ts +44 -43
- package/dist/types/contract/sapling-state-abstraction.d.ts +1 -1
- package/dist/types/contract/semantic.d.ts +2 -2
- package/dist/types/errors.d.ts +5 -5
- package/dist/types/estimate/errors.d.ts +1 -1
- package/dist/types/estimate/estimate-provider-interface.d.ts +81 -84
- package/dist/types/estimate/estimate.d.ts +28 -11
- package/dist/types/estimate/rpc-estimate-provider.d.ts +34 -30
- package/dist/types/forger/errors.d.ts +2 -2
- package/dist/types/global-constants/default-global-constants-provider.d.ts +2 -2
- package/dist/types/global-constants/errors.d.ts +2 -2
- package/dist/types/global-constants/interface-global-constants-provider.d.ts +1 -1
- package/dist/types/import-key.d.ts +2 -2
- package/dist/types/operations/ballot-operation.d.ts +1 -1
- package/dist/types/operations/delegate-operation.d.ts +2 -2
- package/dist/types/operations/drain-delegate-operation.d.ts +1 -1
- package/dist/types/operations/errors.d.ts +5 -5
- package/dist/types/operations/failing-noop-operation.d.ts +1 -1
- package/dist/types/operations/increase-paid-storage-operation.d.ts +1 -1
- package/dist/types/operations/operations.d.ts +2 -2
- package/dist/types/operations/origination-operation.d.ts +5 -5
- package/dist/types/operations/proposals-operation.d.ts +1 -1
- package/dist/types/operations/register-global-constant-operation.d.ts +2 -2
- package/dist/types/operations/reveal-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-originate-operation.d.ts +1 -1
- package/dist/types/operations/transaction-operation.d.ts +2 -2
- package/dist/types/operations/transfer-ticket-operation.d.ts +2 -2
- package/dist/types/operations/types.d.ts +387 -25
- package/dist/types/operations/update-companion-key-operation.d.ts +1 -1
- package/dist/types/operations/update-consensus-key-operation.d.ts +1 -1
- package/dist/types/prepare/interface.d.ts +32 -33
- package/dist/types/prepare/prepare-provider.d.ts +34 -60
- package/dist/types/provider.d.ts +7 -1
- package/dist/types/read-provider/interface.d.ts +21 -21
- package/dist/types/read-provider/rpc-read-adapter.d.ts +22 -22
- package/dist/types/signer/errors.d.ts +1 -1
- package/dist/types/signer/noop.d.ts +1 -1
- package/dist/types/subscribe/errors.d.ts +2 -2
- package/dist/types/taquito.d.ts +33 -33
- package/dist/types/wallet/errors.d.ts +10 -2
- package/dist/types/wallet/interface.d.ts +13 -13
- package/dist/types/wallet/operation.d.ts +4 -3
- package/dist/types/wallet/wallet.d.ts +36 -35
- package/package.json +27 -15
- package/LICENSE +0 -202
package/dist/lib/provider.js
CHANGED
|
@@ -1,32 +1,183 @@
|
|
|
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
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.Provider = void 0;
|
|
4
|
+
const http_utils_1 = require("@taquito/http-utils");
|
|
24
5
|
const types_1 = require("./operations/types");
|
|
25
6
|
const errors_1 = require("./operations/errors");
|
|
26
7
|
const prepare_1 = require("./contract/prepare");
|
|
27
8
|
const rpc_1 = require("@taquito/rpc");
|
|
28
9
|
const utils_1 = require("@taquito/utils");
|
|
29
10
|
class Provider {
|
|
11
|
+
parseRpcErrors(error) {
|
|
12
|
+
if (!(error instanceof http_utils_1.HttpResponseError)) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = JSON.parse(error.body);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
if (!Array.isArray(parsed)) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
return parsed.filter((value) => {
|
|
26
|
+
return typeof value === 'object' && value !== null;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
toBigInt(value) {
|
|
30
|
+
if (typeof value === 'bigint') {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value)) {
|
|
34
|
+
return BigInt(value);
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === 'string' && /^-?\d+$/.test(value)) {
|
|
37
|
+
return BigInt(value);
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'object' && value !== null && 'toString' in value) {
|
|
40
|
+
const normalized = value.toString();
|
|
41
|
+
if (/^-?\d+$/.test(normalized)) {
|
|
42
|
+
return BigInt(normalized);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
parseCounterInThePastAdjustments(error) {
|
|
47
|
+
return this.parseRpcErrors(error)
|
|
48
|
+
.filter((value) => {
|
|
49
|
+
const id = value.id;
|
|
50
|
+
const contract = value.contract;
|
|
51
|
+
const expected = value.expected;
|
|
52
|
+
const found = value.found;
|
|
53
|
+
return (typeof id === 'string' &&
|
|
54
|
+
id.endsWith('contract.counter_in_the_past') &&
|
|
55
|
+
typeof contract === 'string' &&
|
|
56
|
+
typeof expected === 'string' &&
|
|
57
|
+
typeof found === 'string');
|
|
58
|
+
})
|
|
59
|
+
.map((value) => ({
|
|
60
|
+
contract: value.contract,
|
|
61
|
+
expected: BigInt(value.expected),
|
|
62
|
+
found: BigInt(value.found),
|
|
63
|
+
}))
|
|
64
|
+
.filter((value) => value.expected > value.found);
|
|
65
|
+
}
|
|
66
|
+
hasGasLimitTooHighAndBlockExhausted(error) {
|
|
67
|
+
const ids = this.parseRpcErrors(error)
|
|
68
|
+
.map((value) => value.id)
|
|
69
|
+
.filter((value) => typeof value === 'string');
|
|
70
|
+
return (ids.some((id) => id.endsWith('gas_limit_too_high')) &&
|
|
71
|
+
ids.some((id) => id.endsWith('gas_exhausted.block')));
|
|
72
|
+
}
|
|
73
|
+
async patchSimulationGasLimits(op, error, gasLimitPatchableIndexes) {
|
|
74
|
+
if (!this.hasGasLimitTooHighAndBlockExhausted(error)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!Array.isArray(op.operation.contents)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const constants = await this.context.readProvider.getProtocolConstants('head');
|
|
81
|
+
const hardGasLimitPerOperation = this.toBigInt(constants.hard_gas_limit_per_operation);
|
|
82
|
+
const hardGasLimitPerBlock = this.toBigInt(constants.hard_gas_limit_per_block);
|
|
83
|
+
const zero = BigInt(0);
|
|
84
|
+
if (typeof hardGasLimitPerOperation === 'undefined' ||
|
|
85
|
+
typeof hardGasLimitPerBlock === 'undefined' ||
|
|
86
|
+
hardGasLimitPerOperation <= zero ||
|
|
87
|
+
hardGasLimitPerBlock <= zero) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const contents = op.operation.contents.map((content) => ({ ...content }));
|
|
91
|
+
const adjustableIndexes = gasLimitPatchableIndexes && gasLimitPatchableIndexes.length > 0
|
|
92
|
+
? gasLimitPatchableIndexes.filter((index) => index >= 0 && index < contents.length)
|
|
93
|
+
: [];
|
|
94
|
+
let explicitGasLimitTotal = zero;
|
|
95
|
+
for (const [index, content] of contents.entries()) {
|
|
96
|
+
const kind = content.kind;
|
|
97
|
+
const gasLimit = this.toBigInt(content.gas_limit);
|
|
98
|
+
if (typeof gasLimit === 'undefined') {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (adjustableIndexes.length === 0) {
|
|
102
|
+
if (kind !== 'reveal' && gasLimit >= hardGasLimitPerOperation) {
|
|
103
|
+
adjustableIndexes.push(index);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (adjustableIndexes.includes(index)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
explicitGasLimitTotal += gasLimit;
|
|
111
|
+
}
|
|
112
|
+
if (adjustableIndexes.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Mirror octez-client's `may_patch_limits` logic in injection.ml:
|
|
116
|
+
// only rebalance manager operations whose gas limit was auto-assigned for
|
|
117
|
+
// simulation, while treating reveal and user-specified gas limits as already
|
|
118
|
+
// consuming part of the block budget.
|
|
119
|
+
const remainingBlockGas = hardGasLimitPerBlock - explicitGasLimitTotal;
|
|
120
|
+
const evenlyDistributedGas = remainingBlockGas > zero ? remainingBlockGas / BigInt(adjustableIndexes.length) : zero;
|
|
121
|
+
const patchedGasLimit = evenlyDistributedGas > hardGasLimitPerOperation
|
|
122
|
+
? hardGasLimitPerOperation
|
|
123
|
+
: evenlyDistributedGas;
|
|
124
|
+
let patched = false;
|
|
125
|
+
for (const index of adjustableIndexes) {
|
|
126
|
+
const content = contents[index];
|
|
127
|
+
const currentGasLimit = this.toBigInt(content.gas_limit);
|
|
128
|
+
if (currentGasLimit === patchedGasLimit) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
contents[index].gas_limit = patchedGasLimit.toString();
|
|
132
|
+
patched = true;
|
|
133
|
+
}
|
|
134
|
+
if (!patched) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...op,
|
|
139
|
+
operation: {
|
|
140
|
+
...op.operation,
|
|
141
|
+
contents,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
patchSimulationCounters(op, adjustments) {
|
|
146
|
+
if (adjustments.length === 0) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (!Array.isArray(op.operation.contents)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const contents = op.operation.contents.map((content) => ({ ...content }));
|
|
153
|
+
let patched = false;
|
|
154
|
+
for (const adjustment of adjustments) {
|
|
155
|
+
const delta = adjustment.expected - adjustment.found;
|
|
156
|
+
for (const content of contents) {
|
|
157
|
+
const source = content.source;
|
|
158
|
+
const counter = content.counter;
|
|
159
|
+
if (source !== adjustment.contract || typeof counter === 'undefined') {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const contentCounter = BigInt(String(counter));
|
|
163
|
+
if (contentCounter < adjustment.found) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
content.counter = (contentCounter + delta).toString();
|
|
167
|
+
patched = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!patched) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...op,
|
|
175
|
+
operation: {
|
|
176
|
+
...op.operation,
|
|
177
|
+
contents,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
30
181
|
get rpc() {
|
|
31
182
|
return this.context.rpc;
|
|
32
183
|
}
|
|
@@ -36,98 +187,143 @@ class Provider {
|
|
|
36
187
|
constructor(context) {
|
|
37
188
|
this.context = context;
|
|
38
189
|
}
|
|
39
|
-
forge(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
});
|
|
190
|
+
async forge({ opOb: { branch, contents, protocol }, counter }) {
|
|
191
|
+
const forgedBytes = await this.context.forger.forge({ branch, contents });
|
|
192
|
+
return {
|
|
193
|
+
opbytes: forgedBytes,
|
|
194
|
+
opOb: {
|
|
195
|
+
branch,
|
|
196
|
+
contents,
|
|
197
|
+
protocol,
|
|
198
|
+
},
|
|
199
|
+
counter,
|
|
200
|
+
};
|
|
52
201
|
}
|
|
53
|
-
estimate(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
storageLimit: calculatedStorage,
|
|
78
|
-
};
|
|
79
|
-
});
|
|
202
|
+
async estimate({ fee, gasLimit, storageLimit, ...rest }, estimator) {
|
|
203
|
+
let calculatedFee = fee;
|
|
204
|
+
let calculatedGas = gasLimit;
|
|
205
|
+
let calculatedStorage = storageLimit;
|
|
206
|
+
if (calculatedFee && calculatedFee % 1 !== 0) {
|
|
207
|
+
throw new errors_1.InvalidEstimateValueError(`Fee value must not be a decimal: ${calculatedFee}`);
|
|
208
|
+
}
|
|
209
|
+
if (calculatedGas && calculatedGas % 1 !== 0) {
|
|
210
|
+
throw new errors_1.InvalidEstimateValueError(`Gas Limit value must not be a decimal: ${calculatedGas}`);
|
|
211
|
+
}
|
|
212
|
+
if (calculatedStorage && calculatedStorage % 1 !== 0) {
|
|
213
|
+
throw new errors_1.InvalidEstimateValueError(`Storage Limit value must not be a decimal: ${calculatedStorage}`);
|
|
214
|
+
}
|
|
215
|
+
if (fee === undefined || gasLimit === undefined || storageLimit === undefined) {
|
|
216
|
+
const estimation = await estimator({ fee, gasLimit, storageLimit, ...rest });
|
|
217
|
+
calculatedFee ?? (calculatedFee = estimation.suggestedFeeMutez);
|
|
218
|
+
calculatedGas ?? (calculatedGas = estimation.gasLimit);
|
|
219
|
+
calculatedStorage ?? (calculatedStorage = estimation.storageLimit);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
fee: calculatedFee,
|
|
223
|
+
gasLimit: calculatedGas,
|
|
224
|
+
storageLimit: calculatedStorage,
|
|
225
|
+
};
|
|
80
226
|
}
|
|
81
|
-
getRPCOp(param) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
227
|
+
async getRPCOp(param) {
|
|
228
|
+
switch (param.kind) {
|
|
229
|
+
case rpc_1.OpKind.TRANSACTION:
|
|
230
|
+
return (0, prepare_1.createTransferOperation)({
|
|
231
|
+
...param,
|
|
232
|
+
});
|
|
233
|
+
case rpc_1.OpKind.ORIGINATION:
|
|
234
|
+
return (0, prepare_1.createOriginationOperation)(await this.context.parser.prepareCodeOrigination({
|
|
235
|
+
...param,
|
|
236
|
+
}));
|
|
237
|
+
case rpc_1.OpKind.DELEGATION:
|
|
238
|
+
return (0, prepare_1.createSetDelegateOperation)({
|
|
239
|
+
...param,
|
|
240
|
+
});
|
|
241
|
+
case rpc_1.OpKind.REGISTER_GLOBAL_CONSTANT:
|
|
242
|
+
return (0, prepare_1.createRegisterGlobalConstantOperation)({
|
|
243
|
+
...param,
|
|
244
|
+
});
|
|
245
|
+
case rpc_1.OpKind.INCREASE_PAID_STORAGE:
|
|
246
|
+
return (0, prepare_1.createIncreasePaidStorageOperation)({
|
|
247
|
+
...param,
|
|
248
|
+
});
|
|
249
|
+
case rpc_1.OpKind.UPDATE_CONSENSUS_KEY:
|
|
250
|
+
return (0, prepare_1.createUpdateConsensusKeyOperation)({
|
|
251
|
+
...param,
|
|
252
|
+
});
|
|
253
|
+
case rpc_1.OpKind.UPDATE_COMPANION_KEY:
|
|
254
|
+
return (0, prepare_1.createUpdateCompanionKeyOperation)({
|
|
255
|
+
...param,
|
|
256
|
+
});
|
|
257
|
+
case rpc_1.OpKind.TRANSFER_TICKET:
|
|
258
|
+
return (0, prepare_1.createTransferTicketOperation)({
|
|
259
|
+
...param,
|
|
260
|
+
});
|
|
261
|
+
case rpc_1.OpKind.SMART_ROLLUP_ADD_MESSAGES:
|
|
262
|
+
return (0, prepare_1.createSmartRollupAddMessagesOperation)({
|
|
263
|
+
...param,
|
|
264
|
+
});
|
|
265
|
+
case rpc_1.OpKind.SMART_ROLLUP_ORIGINATE:
|
|
266
|
+
return (0, prepare_1.createSmartRollupOriginateOperation)({
|
|
267
|
+
...param,
|
|
268
|
+
});
|
|
269
|
+
case rpc_1.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE:
|
|
270
|
+
return (0, prepare_1.createSmartRollupExecuteOutboxMessageOperation)({
|
|
271
|
+
...param,
|
|
272
|
+
});
|
|
273
|
+
default:
|
|
274
|
+
throw new utils_1.InvalidOperationKindError(param.kind);
|
|
275
|
+
}
|
|
110
276
|
}
|
|
111
|
-
simulate(op) {
|
|
112
|
-
|
|
277
|
+
async simulate(op, preparedOperation) {
|
|
278
|
+
const gasLimitPatchableIndexes = preparedOperation?.simulation?.gasLimitPatchableIndexes;
|
|
279
|
+
try {
|
|
113
280
|
return {
|
|
114
|
-
opResponse:
|
|
281
|
+
opResponse: await this.rpc.simulateOperation(op),
|
|
115
282
|
op,
|
|
116
283
|
context: this.context.clone(),
|
|
117
284
|
};
|
|
118
|
-
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const adjustments = this.parseCounterInThePastAdjustments(error);
|
|
288
|
+
const patchedOp = this.patchSimulationCounters(op, adjustments);
|
|
289
|
+
if (patchedOp) {
|
|
290
|
+
try {
|
|
291
|
+
return {
|
|
292
|
+
opResponse: await this.rpc.simulateOperation(patchedOp),
|
|
293
|
+
op: patchedOp,
|
|
294
|
+
context: this.context.clone(),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
catch (counterRetryError) {
|
|
298
|
+
const gasPatchedOp = await this.patchSimulationGasLimits(patchedOp, counterRetryError, gasLimitPatchableIndexes);
|
|
299
|
+
if (!gasPatchedOp) {
|
|
300
|
+
throw counterRetryError;
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
opResponse: await this.rpc.simulateOperation(gasPatchedOp),
|
|
304
|
+
op: gasPatchedOp,
|
|
305
|
+
context: this.context.clone(),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const gasPatchedOp = await this.patchSimulationGasLimits(op, error, gasLimitPatchableIndexes);
|
|
310
|
+
if (!gasPatchedOp) {
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
opResponse: await this.rpc.simulateOperation(gasPatchedOp),
|
|
315
|
+
op: gasPatchedOp,
|
|
316
|
+
context: this.context.clone(),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
119
319
|
}
|
|
120
|
-
isRevealOpNeeded(op, pkh) {
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
: true;
|
|
125
|
-
});
|
|
320
|
+
async isRevealOpNeeded(op, pkh) {
|
|
321
|
+
return !(await this.isAccountRevealRequired(pkh)) || !this.isRevealRequiredForOpType(op)
|
|
322
|
+
? false
|
|
323
|
+
: true;
|
|
126
324
|
}
|
|
127
|
-
isAccountRevealRequired(publicKeyHash) {
|
|
128
|
-
return
|
|
129
|
-
return !(yield this.context.readProvider.isAccountRevealed(publicKeyHash, 'head'));
|
|
130
|
-
});
|
|
325
|
+
async isAccountRevealRequired(publicKeyHash) {
|
|
326
|
+
return !(await this.context.readProvider.isAccountRevealed(publicKeyHash, 'head'));
|
|
131
327
|
}
|
|
132
328
|
isRevealRequiredForOpType(op) {
|
|
133
329
|
let opRequireReveal = false;
|
|
@@ -138,32 +334,30 @@ class Provider {
|
|
|
138
334
|
}
|
|
139
335
|
return opRequireReveal;
|
|
140
336
|
}
|
|
141
|
-
signAndInject(forgedBytes) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
for (let
|
|
152
|
-
|
|
153
|
-
opResponse.push(results[i].contents[j]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const errors = (0, errors_1.flattenErrors)(results);
|
|
157
|
-
if (errors.length) {
|
|
158
|
-
throw new errors_1.TezosOperationError(errors, 'Error occurred during validation simulation of operation', opResponse);
|
|
337
|
+
async signAndInject(forgedBytes) {
|
|
338
|
+
const signed = await this.signer.sign(forgedBytes.opbytes, new Uint8Array([3]));
|
|
339
|
+
forgedBytes.opbytes = signed.sbytes;
|
|
340
|
+
forgedBytes.opOb.signature = signed.prefixSig;
|
|
341
|
+
const opResponse = [];
|
|
342
|
+
const results = await this.rpc.preapplyOperations([forgedBytes.opOb]);
|
|
343
|
+
if (!Array.isArray(results)) {
|
|
344
|
+
throw new errors_1.TezosPreapplyFailureError(results);
|
|
345
|
+
}
|
|
346
|
+
for (let i = 0; i < results.length; i++) {
|
|
347
|
+
for (let j = 0; j < results[i].contents.length; j++) {
|
|
348
|
+
opResponse.push(results[i].contents[j]);
|
|
159
349
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
350
|
+
}
|
|
351
|
+
const errors = (0, errors_1.flattenErrors)(results);
|
|
352
|
+
if (errors.length) {
|
|
353
|
+
throw new errors_1.TezosOperationError(errors, 'Error occurred during validation simulation of operation', opResponse);
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
hash: await this.context.injector.inject(forgedBytes.opbytes),
|
|
357
|
+
forgedBytes,
|
|
358
|
+
opResponse,
|
|
359
|
+
context: this.context.clone(),
|
|
360
|
+
};
|
|
167
361
|
}
|
|
168
362
|
}
|
|
169
363
|
exports.Provider = Provider;
|