@taquito/taquito 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/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
|
@@ -1,18 +1,10 @@
|
|
|
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.Wallet = exports.WalletOperationBatch = void 0;
|
|
13
4
|
const contract_1 = require("../contract/contract");
|
|
14
5
|
const types_1 = require("../operations/types");
|
|
15
6
|
const core_1 = require("@taquito/core");
|
|
7
|
+
const http_utils_1 = require("@taquito/http-utils");
|
|
16
8
|
const utils_1 = require("@taquito/utils");
|
|
17
9
|
class WalletOperationBatch {
|
|
18
10
|
constructor(walletProvider, context) {
|
|
@@ -21,7 +13,7 @@ class WalletOperationBatch {
|
|
|
21
13
|
this.operations = [];
|
|
22
14
|
}
|
|
23
15
|
/**
|
|
24
|
-
*
|
|
16
|
+
* Add a transaction operation to the batch
|
|
25
17
|
* @param params Transfer operation parameter
|
|
26
18
|
*/
|
|
27
19
|
withTransfer(params) {
|
|
@@ -29,11 +21,11 @@ class WalletOperationBatch {
|
|
|
29
21
|
if (toValidation !== utils_1.ValidationResult.VALID) {
|
|
30
22
|
throw new core_1.InvalidAddressError(params.to, toValidation);
|
|
31
23
|
}
|
|
32
|
-
this.operations.push(
|
|
24
|
+
this.operations.push({ kind: types_1.OpKind.TRANSACTION, ...params });
|
|
33
25
|
return this;
|
|
34
26
|
}
|
|
35
27
|
/**
|
|
36
|
-
*
|
|
28
|
+
* Add a contract call to the batch
|
|
37
29
|
* @param params Call a contract method
|
|
38
30
|
* @param options Generic operation parameters
|
|
39
31
|
*/
|
|
@@ -41,84 +33,81 @@ class WalletOperationBatch {
|
|
|
41
33
|
return this.withTransfer(params.toTransferParams(options));
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
|
-
*
|
|
36
|
+
* Add a delegation operation to the batch
|
|
45
37
|
* @param params Delegation operation parameter
|
|
46
38
|
*/
|
|
47
39
|
withDelegation(params) {
|
|
48
|
-
|
|
49
|
-
const delegateValidation = (0, utils_1.validateAddress)((_a = params.delegate) !== null && _a !== void 0 ? _a : '');
|
|
40
|
+
const delegateValidation = (0, utils_1.validateAddress)(params.delegate ?? '');
|
|
50
41
|
if (params.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
|
|
51
42
|
throw new core_1.InvalidAddressError(params.delegate, delegateValidation);
|
|
52
43
|
}
|
|
53
|
-
this.operations.push(
|
|
44
|
+
this.operations.push({ kind: types_1.OpKind.DELEGATION, ...params });
|
|
54
45
|
return this;
|
|
55
46
|
}
|
|
56
47
|
/**
|
|
57
|
-
*
|
|
48
|
+
* Add an origination operation to the batch
|
|
58
49
|
* @param params Origination operation parameter
|
|
59
50
|
*/
|
|
60
51
|
withOrigination(params) {
|
|
61
|
-
this.operations.push(
|
|
52
|
+
this.operations.push({ kind: types_1.OpKind.ORIGINATION, ...params });
|
|
62
53
|
return this;
|
|
63
54
|
}
|
|
64
55
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param
|
|
56
|
+
* Add an IncreasePaidStorage operation to the batch
|
|
57
|
+
* @param params IncreasePaidStorage operation parameter
|
|
67
58
|
*/
|
|
68
59
|
withIncreasePaidStorage(params) {
|
|
69
60
|
const destinationValidation = (0, utils_1.validateAddress)(params.destination);
|
|
70
61
|
if (destinationValidation !== utils_1.ValidationResult.VALID) {
|
|
71
62
|
throw new core_1.InvalidAddressError(params.destination, destinationValidation);
|
|
72
63
|
}
|
|
73
|
-
this.operations.push(
|
|
64
|
+
this.operations.push({ kind: types_1.OpKind.INCREASE_PAID_STORAGE, ...params });
|
|
74
65
|
return this;
|
|
75
66
|
}
|
|
76
67
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param
|
|
68
|
+
* Add an TransferTicket operation to the batch
|
|
69
|
+
* @param params TransferTicket operation parameter
|
|
79
70
|
*/
|
|
80
71
|
withTransferTicket(params) {
|
|
81
72
|
const destinationValidation = (0, utils_1.validateAddress)(params.destination);
|
|
82
73
|
if (destinationValidation !== utils_1.ValidationResult.VALID) {
|
|
83
74
|
throw new core_1.InvalidAddressError(params.destination, destinationValidation);
|
|
84
75
|
}
|
|
85
|
-
this.operations.push(
|
|
76
|
+
this.operations.push({ kind: types_1.OpKind.TRANSFER_TICKET, ...params });
|
|
86
77
|
return this;
|
|
87
78
|
}
|
|
88
79
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param
|
|
80
|
+
* Add a RegisterGlobalConstant operation to the batch
|
|
81
|
+
* @param params RegisterGlobalConstant operation parameter
|
|
91
82
|
*/
|
|
92
83
|
withRegisterGlobalConstant(params) {
|
|
93
|
-
this.operations.push(
|
|
84
|
+
this.operations.push({ kind: types_1.OpKind.REGISTER_GLOBAL_CONSTANT, ...params });
|
|
94
85
|
return this;
|
|
95
86
|
}
|
|
96
|
-
mapOperation(param) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
});
|
|
87
|
+
async mapOperation(param) {
|
|
88
|
+
switch (param.kind) {
|
|
89
|
+
case types_1.OpKind.TRANSACTION:
|
|
90
|
+
return this.walletProvider.mapTransferParamsToWalletParams(async () => param);
|
|
91
|
+
case types_1.OpKind.ORIGINATION:
|
|
92
|
+
return this.walletProvider.mapOriginateParamsToWalletParams(async () => this.context.parser.prepareCodeOrigination({
|
|
93
|
+
...param,
|
|
94
|
+
}));
|
|
95
|
+
case types_1.OpKind.DELEGATION:
|
|
96
|
+
return this.walletProvider.mapDelegateParamsToWalletParams(async () => param);
|
|
97
|
+
case types_1.OpKind.INCREASE_PAID_STORAGE:
|
|
98
|
+
return this.walletProvider.mapIncreasePaidStorageWalletParams(async () => param);
|
|
99
|
+
case types_1.OpKind.REGISTER_GLOBAL_CONSTANT:
|
|
100
|
+
return this.walletProvider.mapRegisterGlobalConstantParamsToWalletParams(async () => param);
|
|
101
|
+
case types_1.OpKind.TRANSFER_TICKET:
|
|
102
|
+
return this.walletProvider.mapTransferTicketParamsToWalletParams(async () => param);
|
|
103
|
+
default:
|
|
104
|
+
throw new core_1.InvalidOperationKindError(JSON.stringify(param.kind));
|
|
105
|
+
}
|
|
117
106
|
}
|
|
118
107
|
/**
|
|
119
|
-
*
|
|
108
|
+
* Add a group operation to the batch. Operation will be applied in the order they are in the params array
|
|
120
109
|
* @param params Operations parameter
|
|
121
|
-
* @throws
|
|
110
|
+
* @throws InvalidOperationKindError
|
|
122
111
|
*/
|
|
123
112
|
with(params) {
|
|
124
113
|
for (const param of params) {
|
|
@@ -148,17 +137,15 @@ class WalletOperationBatch {
|
|
|
148
137
|
return this;
|
|
149
138
|
}
|
|
150
139
|
/**
|
|
151
|
-
*
|
|
140
|
+
* Submit batch operation to wallet
|
|
152
141
|
*/
|
|
153
|
-
send() {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return this.context.operationFactory.createBatchOperation(opHash);
|
|
161
|
-
});
|
|
142
|
+
async send() {
|
|
143
|
+
const ops = [];
|
|
144
|
+
for (const op of this.operations) {
|
|
145
|
+
ops.push(await this.mapOperation(op));
|
|
146
|
+
}
|
|
147
|
+
const opHash = await this.walletProvider.sendOperations(ops);
|
|
148
|
+
return this.context.operationFactory.createBatchOperation(opHash);
|
|
162
149
|
}
|
|
163
150
|
}
|
|
164
151
|
exports.WalletOperationBatch = WalletOperationBatch;
|
|
@@ -175,108 +162,103 @@ class Wallet {
|
|
|
175
162
|
return this.context.walletProvider;
|
|
176
163
|
}
|
|
177
164
|
/**
|
|
178
|
-
*
|
|
165
|
+
* Retrieve the PKH of the account that is currently in use by the wallet
|
|
179
166
|
* @param option Option to use while fetching the PKH.
|
|
180
167
|
* If forceRefetch is specified the wallet provider implementation will refetch the PKH from the wallet
|
|
181
168
|
*/
|
|
182
|
-
pkh() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return this._pkh;
|
|
188
|
-
});
|
|
169
|
+
async pkh({ forceRefetch } = {}) {
|
|
170
|
+
if (!this._pkh || forceRefetch) {
|
|
171
|
+
this._pkh = await this.walletProvider.getPKH();
|
|
172
|
+
}
|
|
173
|
+
return this._pkh;
|
|
189
174
|
}
|
|
190
175
|
/**
|
|
191
|
-
*
|
|
176
|
+
* Retrieve the PK of the account that is currently in use by the wallet
|
|
192
177
|
* @param option Option to use while fetching the PK.
|
|
193
178
|
* If forceRefetch is specified the wallet provider implementation will refetch the PK from the wallet
|
|
194
179
|
*/
|
|
195
|
-
pk() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return this._pk;
|
|
201
|
-
});
|
|
180
|
+
async pk({ forceRefetch } = {}) {
|
|
181
|
+
if (!this._pk || forceRefetch) {
|
|
182
|
+
this._pk = await this.walletProvider.getPK();
|
|
183
|
+
}
|
|
184
|
+
return this._pk;
|
|
202
185
|
}
|
|
203
186
|
/**
|
|
204
|
-
*
|
|
187
|
+
* Originate a new contract according to the script in parameters.
|
|
205
188
|
* @returns a OriginationWalletOperation promise object when followed by .send()
|
|
206
|
-
* @param
|
|
189
|
+
* @param params Originate operation parameter
|
|
207
190
|
*/
|
|
208
191
|
originate(params) {
|
|
209
|
-
return this.walletCommand(() =>
|
|
210
|
-
const mappedParams =
|
|
211
|
-
|
|
192
|
+
return this.walletCommand(async () => {
|
|
193
|
+
const mappedParams = await this.walletProvider.mapOriginateParamsToWalletParams(() => this.context.parser.prepareCodeOrigination({
|
|
194
|
+
...params,
|
|
195
|
+
}));
|
|
196
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
212
197
|
return this.context.operationFactory.createOriginationOperation(opHash);
|
|
213
|
-
})
|
|
198
|
+
});
|
|
214
199
|
}
|
|
215
200
|
/**
|
|
216
|
-
*
|
|
201
|
+
* Set the delegate for a contract.
|
|
217
202
|
* @returns a WalletDelegateParams promise object when followed by .send()
|
|
218
|
-
* @param
|
|
203
|
+
* @param params operation parameter
|
|
219
204
|
*/
|
|
220
205
|
setDelegate(params) {
|
|
221
|
-
|
|
222
|
-
const delegateValidation = (0, utils_1.validateAddress)((_a = params.delegate) !== null && _a !== void 0 ? _a : '');
|
|
206
|
+
const delegateValidation = (0, utils_1.validateAddress)(params.delegate ?? '');
|
|
223
207
|
if (params.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
|
|
224
208
|
throw new core_1.InvalidAddressError(params.delegate, delegateValidation);
|
|
225
209
|
}
|
|
226
|
-
return this.walletCommand(() =>
|
|
227
|
-
const mappedParams =
|
|
228
|
-
const opHash =
|
|
210
|
+
return this.walletCommand(async () => {
|
|
211
|
+
const mappedParams = await this.walletProvider.mapDelegateParamsToWalletParams(async () => params);
|
|
212
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
229
213
|
return this.context.operationFactory.createDelegationOperation(opHash);
|
|
230
|
-
})
|
|
214
|
+
});
|
|
231
215
|
}
|
|
232
216
|
/**
|
|
233
|
-
*
|
|
217
|
+
* failing_noop operation that is guaranteed to fail. DISCLAIMER: Not all wallets support signing failing_noop operations.
|
|
234
218
|
* @returns Signature for a failing_noop
|
|
235
219
|
* @param params operation parameter
|
|
236
220
|
*/
|
|
237
|
-
signFailingNoop(params) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
contents: [op],
|
|
247
|
-
});
|
|
248
|
-
const signature = yield this.walletProvider.sign(forgedBytes, Uint8Array.from([3]));
|
|
249
|
-
return {
|
|
250
|
-
signature,
|
|
251
|
-
bytes: forgedBytes,
|
|
252
|
-
signedContent: {
|
|
253
|
-
branch: hash,
|
|
254
|
-
contents: [
|
|
255
|
-
{
|
|
256
|
-
kind: types_1.OpKind.FAILING_NOOP,
|
|
257
|
-
arbitrary: params.arbitrary,
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
};
|
|
221
|
+
async signFailingNoop(params) {
|
|
222
|
+
const op = {
|
|
223
|
+
kind: types_1.OpKind.FAILING_NOOP,
|
|
224
|
+
arbitrary: params.arbitrary,
|
|
225
|
+
};
|
|
226
|
+
const hash = await this.context.readProvider.getBlockHash(params.basedOnBlock);
|
|
227
|
+
const forgedBytes = await this.context.forger.forge({
|
|
228
|
+
branch: hash,
|
|
229
|
+
contents: [op],
|
|
262
230
|
});
|
|
231
|
+
const signature = await this.walletProvider.sign(forgedBytes, Uint8Array.from([3]));
|
|
232
|
+
return {
|
|
233
|
+
signature,
|
|
234
|
+
bytes: forgedBytes,
|
|
235
|
+
signedContent: {
|
|
236
|
+
branch: hash,
|
|
237
|
+
contents: [
|
|
238
|
+
{
|
|
239
|
+
kind: types_1.OpKind.FAILING_NOOP,
|
|
240
|
+
arbitrary: params.arbitrary,
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
};
|
|
263
245
|
}
|
|
264
246
|
/**
|
|
265
|
-
*
|
|
247
|
+
* Register the current address as delegate.
|
|
266
248
|
* @returns a DelegationWalletOperation promise object when followed by .send()
|
|
267
249
|
*/
|
|
268
250
|
registerDelegate() {
|
|
269
|
-
return this.walletCommand(() =>
|
|
270
|
-
const mappedParams =
|
|
271
|
-
const delegate =
|
|
251
|
+
return this.walletCommand(async () => {
|
|
252
|
+
const mappedParams = await this.walletProvider.mapDelegateParamsToWalletParams(async () => {
|
|
253
|
+
const delegate = await this.pkh();
|
|
272
254
|
return { delegate };
|
|
273
|
-
})
|
|
274
|
-
const opHash =
|
|
255
|
+
});
|
|
256
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
275
257
|
return this.context.operationFactory.createDelegationOperation(opHash);
|
|
276
|
-
})
|
|
258
|
+
});
|
|
277
259
|
}
|
|
278
260
|
/**
|
|
279
|
-
*
|
|
261
|
+
* Transfer tezos tokens from current address to a specific address or call a smart contract.
|
|
280
262
|
* @returns a TransactionWalletOperation promise object when followed by .send()
|
|
281
263
|
* @param params operation parameter
|
|
282
264
|
*/
|
|
@@ -285,14 +267,14 @@ class Wallet {
|
|
|
285
267
|
if (toValidation !== utils_1.ValidationResult.VALID) {
|
|
286
268
|
throw new core_1.InvalidAddressError(params.to, toValidation);
|
|
287
269
|
}
|
|
288
|
-
return this.walletCommand(() =>
|
|
289
|
-
const mappedParams =
|
|
290
|
-
const opHash =
|
|
270
|
+
return this.walletCommand(async () => {
|
|
271
|
+
const mappedParams = await this.walletProvider.mapTransferParamsToWalletParams(async () => params);
|
|
272
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
291
273
|
return this.context.operationFactory.createTransactionOperation(opHash);
|
|
292
|
-
})
|
|
274
|
+
});
|
|
293
275
|
}
|
|
294
276
|
/**
|
|
295
|
-
*
|
|
277
|
+
* Transfer tezos tickets from current address to a specific address or a smart contract
|
|
296
278
|
* @returns a TransferTicketWalletOperation promise object when followed by .send()
|
|
297
279
|
* @param params operation parameter
|
|
298
280
|
*/
|
|
@@ -301,21 +283,21 @@ class Wallet {
|
|
|
301
283
|
if (toValidation !== utils_1.ValidationResult.VALID) {
|
|
302
284
|
throw new core_1.InvalidAddressError(params.destination, toValidation);
|
|
303
285
|
}
|
|
304
|
-
return this.walletCommand(() =>
|
|
305
|
-
const mappedParams =
|
|
306
|
-
const opHash =
|
|
286
|
+
return this.walletCommand(async () => {
|
|
287
|
+
const mappedParams = await this.walletProvider.mapTransferTicketParamsToWalletParams(async () => params);
|
|
288
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
307
289
|
return this.context.operationFactory.createTransferTicketOperation(opHash);
|
|
308
|
-
})
|
|
290
|
+
});
|
|
309
291
|
}
|
|
310
292
|
/**
|
|
311
|
-
*
|
|
293
|
+
* Stake a given amount for the source address
|
|
312
294
|
* @returns a TransactionWalletOperation promise object when followed by .send()
|
|
313
|
-
* @param Stake pseudo-operation parameter
|
|
295
|
+
* @param params Stake pseudo-operation parameter
|
|
314
296
|
*/
|
|
315
297
|
stake(params) {
|
|
316
|
-
return this.walletCommand(() =>
|
|
317
|
-
const mappedParams =
|
|
318
|
-
const source =
|
|
298
|
+
return this.walletCommand(async () => {
|
|
299
|
+
const mappedParams = await this.walletProvider.mapStakeParamsToWalletParams(async () => {
|
|
300
|
+
const source = await this.pkh();
|
|
319
301
|
if (!params.to) {
|
|
320
302
|
params.to = source;
|
|
321
303
|
}
|
|
@@ -324,22 +306,22 @@ class Wallet {
|
|
|
324
306
|
}
|
|
325
307
|
params.parameter = { entrypoint: 'stake', value: { prim: 'Unit' } };
|
|
326
308
|
return params;
|
|
327
|
-
})
|
|
328
|
-
const opHash =
|
|
309
|
+
});
|
|
310
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
329
311
|
return this.context.operationFactory.createTransactionOperation(opHash);
|
|
330
|
-
})
|
|
312
|
+
});
|
|
331
313
|
}
|
|
332
314
|
/**
|
|
333
|
-
*
|
|
315
|
+
* Unstake the given amount. If "everything" is given as amount, unstakes everything from the staking balance.
|
|
334
316
|
* Unstaked tez remains frozen for a set amount of cycles (the slashing period) after the operation. Once this period is over,
|
|
335
317
|
* the operation "finalize unstake" must be called for the funds to appear in the liquid balance.
|
|
336
318
|
* @returns a TransactionWalletOperation promise object when followed by .send()
|
|
337
|
-
* @param Unstake pseudo-operation parameter
|
|
319
|
+
* @param params Unstake pseudo-operation parameter
|
|
338
320
|
*/
|
|
339
321
|
unstake(params) {
|
|
340
|
-
return this.walletCommand(() =>
|
|
341
|
-
const mappedParams =
|
|
342
|
-
const source =
|
|
322
|
+
return this.walletCommand(async () => {
|
|
323
|
+
const mappedParams = await this.walletProvider.mapUnstakeParamsToWalletParams(async () => {
|
|
324
|
+
const source = await this.pkh();
|
|
343
325
|
if (!params.to) {
|
|
344
326
|
params.to = source;
|
|
345
327
|
}
|
|
@@ -348,20 +330,20 @@ class Wallet {
|
|
|
348
330
|
}
|
|
349
331
|
params.parameter = { entrypoint: 'unstake', value: { prim: 'Unit' } };
|
|
350
332
|
return params;
|
|
351
|
-
})
|
|
352
|
-
const opHash =
|
|
353
|
-
return
|
|
354
|
-
})
|
|
333
|
+
});
|
|
334
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
335
|
+
return await this.context.operationFactory.createTransactionOperation(opHash);
|
|
336
|
+
});
|
|
355
337
|
}
|
|
356
338
|
/**
|
|
357
|
-
*
|
|
339
|
+
* Transfer all the finalizable unstaked funds of the source to their liquid balance
|
|
358
340
|
* @returns a TransactionWalletOperation promise object when followed by .send()
|
|
359
|
-
* @param Finalize_unstake pseudo-operation parameter
|
|
341
|
+
* @param params Finalize_unstake pseudo-operation parameter
|
|
360
342
|
*/
|
|
361
343
|
finalizeUnstake(params) {
|
|
362
|
-
return this.walletCommand(() =>
|
|
363
|
-
const mappedParams =
|
|
364
|
-
const source =
|
|
344
|
+
return this.walletCommand(async () => {
|
|
345
|
+
const mappedParams = await this.walletProvider.mapFinalizeUnstakeParamsToWalletParams(async () => {
|
|
346
|
+
const source = await this.pkh();
|
|
365
347
|
if (!params.to) {
|
|
366
348
|
params.to = source;
|
|
367
349
|
}
|
|
@@ -373,13 +355,13 @@ class Wallet {
|
|
|
373
355
|
}
|
|
374
356
|
params.parameter = { entrypoint: 'finalize_unstake', value: { prim: 'Unit' } };
|
|
375
357
|
return params;
|
|
376
|
-
})
|
|
377
|
-
const opHash =
|
|
378
|
-
return
|
|
379
|
-
})
|
|
358
|
+
});
|
|
359
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
360
|
+
return await this.context.operationFactory.createTransactionOperation(opHash);
|
|
361
|
+
});
|
|
380
362
|
}
|
|
381
363
|
/**
|
|
382
|
-
*
|
|
364
|
+
* Increase the paid storage of a smart contract.
|
|
383
365
|
* @returns a IncreasePaidStorageWalletOperation promise object when followed by .send()
|
|
384
366
|
* @param params operation parameter
|
|
385
367
|
*/
|
|
@@ -388,26 +370,26 @@ class Wallet {
|
|
|
388
370
|
if (destinationValidation !== utils_1.ValidationResult.VALID) {
|
|
389
371
|
throw new core_1.InvalidAddressError(params.destination, destinationValidation);
|
|
390
372
|
}
|
|
391
|
-
return this.walletCommand(() =>
|
|
392
|
-
const mappedParams =
|
|
393
|
-
const opHash =
|
|
373
|
+
return this.walletCommand(async () => {
|
|
374
|
+
const mappedParams = await this.walletProvider.mapIncreasePaidStorageWalletParams(async () => params);
|
|
375
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
394
376
|
return this.context.operationFactory.createIncreasePaidStorageOperation(opHash);
|
|
395
|
-
})
|
|
377
|
+
});
|
|
396
378
|
}
|
|
397
379
|
/**
|
|
398
|
-
*
|
|
380
|
+
* Register a Micheline expression in a global table of constants.
|
|
399
381
|
* @returns a RegisterGlobalConstantWalletOperation promise object when followed by .send()
|
|
400
382
|
* @param params operation parameter
|
|
401
383
|
*/
|
|
402
384
|
registerGlobalConstant(params) {
|
|
403
|
-
return this.walletCommand(() =>
|
|
404
|
-
const mappedParams =
|
|
405
|
-
const opHash =
|
|
385
|
+
return this.walletCommand(async () => {
|
|
386
|
+
const mappedParams = await this.walletProvider.mapRegisterGlobalConstantParamsToWalletParams(async () => params);
|
|
387
|
+
const opHash = await this.walletProvider.sendOperations([mappedParams]);
|
|
406
388
|
return this.context.operationFactory.createRegisterGlobalConstantOperation(opHash);
|
|
407
|
-
})
|
|
389
|
+
});
|
|
408
390
|
}
|
|
409
391
|
/**
|
|
410
|
-
*
|
|
392
|
+
* Create a batch of operation
|
|
411
393
|
* @returns A batch object from which we can add more operation or send a command to the wallet to execute the batch
|
|
412
394
|
* @param params List of operation to initialize the batch with
|
|
413
395
|
*/
|
|
@@ -419,24 +401,45 @@ class Wallet {
|
|
|
419
401
|
return batch;
|
|
420
402
|
}
|
|
421
403
|
/**
|
|
422
|
-
*
|
|
404
|
+
* Create an smart contract abstraction for the address specified. Calling entrypoints with the returned
|
|
423
405
|
* smart contract abstraction will leverage the wallet provider to make smart contract calls
|
|
424
406
|
* @param address Smart contract address
|
|
425
|
-
* @throws
|
|
407
|
+
* @throws InvalidContractAddressError If the contract address is not valid
|
|
426
408
|
*/
|
|
427
|
-
at(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
409
|
+
async at(address, contractAbstractionComposer = (x) => x, block = 'head') {
|
|
410
|
+
const addressValidation = (0, utils_1.validateContractAddress)(address);
|
|
411
|
+
if (addressValidation !== utils_1.ValidationResult.VALID) {
|
|
412
|
+
throw new core_1.InvalidContractAddressError(address, addressValidation);
|
|
413
|
+
}
|
|
414
|
+
const rpc = this.context.withExtensions().rpc;
|
|
415
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
416
|
+
const loadContractState = async (requestedBlock) => {
|
|
417
|
+
const script = await readProvider.getScript(address, requestedBlock);
|
|
418
|
+
const entrypoints = requestedBlock === 'head'
|
|
419
|
+
? await readProvider.getEntrypoints(address)
|
|
420
|
+
: await rpc.getEntrypoints(address, { block: String(requestedBlock) });
|
|
421
|
+
return { script, entrypoints };
|
|
422
|
+
};
|
|
423
|
+
let contractState;
|
|
424
|
+
try {
|
|
425
|
+
contractState = await loadContractState(block);
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
// Newly originated contracts can be visible at the operation's inclusion level in one RPC
|
|
429
|
+
// call and still lag on another endpoint of the same rolling node. Retry at head so
|
|
430
|
+
// wallet op.contract() behaves like octez-client, which resolves the originated contract
|
|
431
|
+
// after confirmation instead of pinning itself to a stale context forever.
|
|
432
|
+
if (block !== 'head' &&
|
|
433
|
+
error instanceof http_utils_1.HttpResponseError &&
|
|
434
|
+
error.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
|
|
435
|
+
contractState = await loadContractState('head');
|
|
432
436
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
437
|
+
else {
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const abs = new contract_1.ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider);
|
|
442
|
+
return contractAbstractionComposer(abs, this.context);
|
|
440
443
|
}
|
|
441
444
|
}
|
|
442
445
|
exports.Wallet = Wallet;
|