@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.
Files changed (129) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/batch/rpc-batch-provider.js +91 -83
  3. package/dist/lib/context.js +22 -26
  4. package/dist/lib/contract/big-map.js +16 -29
  5. package/dist/lib/contract/contract-methods/contract-method-object-param.js +7 -7
  6. package/dist/lib/contract/contract-methods/contract-on-chain-view.js +31 -44
  7. package/dist/lib/contract/contract.js +21 -32
  8. package/dist/lib/contract/errors.js +9 -9
  9. package/dist/lib/contract/prepare.js +36 -45
  10. package/dist/lib/contract/rpc-contract-provider.js +426 -475
  11. package/dist/lib/contract/sapling-state-abstraction.js +3 -14
  12. package/dist/lib/contract/semantic.js +2 -2
  13. package/dist/lib/errors.js +3 -3
  14. package/dist/lib/estimate/errors.js +1 -1
  15. package/dist/lib/estimate/estimate.js +66 -20
  16. package/dist/lib/estimate/rpc-estimate-provider.js +427 -460
  17. package/dist/lib/forger/composite-forger.js +16 -27
  18. package/dist/lib/forger/errors.js +2 -2
  19. package/dist/lib/forger/taquito-local-forger.js +9 -22
  20. package/dist/lib/global-constants/default-global-constants-provider.js +8 -19
  21. package/dist/lib/global-constants/errors.js +2 -2
  22. package/dist/lib/global-constants/noop-global-constants-provider.js +2 -13
  23. package/dist/lib/import-key.js +23 -34
  24. package/dist/lib/injector/rpc-injector.js +13 -24
  25. package/dist/lib/operations/ballot-operation.js +2 -3
  26. package/dist/lib/operations/delegate-operation.js +5 -8
  27. package/dist/lib/operations/drain-delegate-operation.js +1 -1
  28. package/dist/lib/operations/errors.js +9 -6
  29. package/dist/lib/operations/increase-paid-storage-operation.js +4 -7
  30. package/dist/lib/operations/operations.js +100 -30
  31. package/dist/lib/operations/origination-operation.js +16 -27
  32. package/dist/lib/operations/proposals-operation.js +2 -3
  33. package/dist/lib/operations/register-global-constant-operation.js +4 -7
  34. package/dist/lib/operations/reveal-operation.js +1 -1
  35. package/dist/lib/operations/smart-rollup-add-messages-operation.js +4 -7
  36. package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +4 -7
  37. package/dist/lib/operations/smart-rollup-originate-operation.js +4 -7
  38. package/dist/lib/operations/transaction-operation.js +2 -2
  39. package/dist/lib/operations/transfer-ticket-operation.js +4 -6
  40. package/dist/lib/operations/types.js +17 -19
  41. package/dist/lib/operations/update-companion-key-operation.js +4 -7
  42. package/dist/lib/operations/update-consensus-key-operation.js +4 -7
  43. package/dist/lib/packer/michel-codec-packer.js +3 -14
  44. package/dist/lib/packer/rpc-packer.js +2 -13
  45. package/dist/lib/parser/michel-codec-parser.js +82 -107
  46. package/dist/lib/parser/noop-parser.js +2 -13
  47. package/dist/lib/prepare/prepare-provider.js +780 -744
  48. package/dist/lib/provider.js +322 -128
  49. package/dist/lib/read-provider/rpc-read-adapter.js +76 -121
  50. package/dist/lib/signer/errors.js +1 -1
  51. package/dist/lib/signer/noop.js +9 -26
  52. package/dist/lib/subscribe/errors.js +2 -2
  53. package/dist/lib/subscribe/polling-subcribe-provider.js +35 -38
  54. package/dist/lib/taquito.js +33 -33
  55. package/dist/lib/tz/rpc-tz-provider.js +27 -44
  56. package/dist/lib/version.js +2 -2
  57. package/dist/lib/wallet/batch-operation.js +32 -45
  58. package/dist/lib/wallet/delegation-operation.js +25 -40
  59. package/dist/lib/wallet/errors.js +15 -3
  60. package/dist/lib/wallet/increase-paid-storage-operation.js +25 -40
  61. package/dist/lib/wallet/legacy.js +28 -63
  62. package/dist/lib/wallet/operation-factory.js +27 -56
  63. package/dist/lib/wallet/operation.js +123 -59
  64. package/dist/lib/wallet/origination-operation.js +34 -46
  65. package/dist/lib/wallet/register-global-constant-operation.js +26 -43
  66. package/dist/lib/wallet/transaction-operation.js +21 -36
  67. package/dist/lib/wallet/transfer-ticket-operation.js +21 -36
  68. package/dist/lib/wallet/wallet.js +187 -184
  69. package/dist/taquito.es6.js +3424 -3197
  70. package/dist/taquito.es6.js.map +1 -1
  71. package/dist/taquito.min.js +1 -1
  72. package/dist/taquito.umd.js +7930 -7701
  73. package/dist/taquito.umd.js.map +1 -1
  74. package/dist/types/batch/rpc-batch-provider.d.ts +18 -18
  75. package/dist/types/context.d.ts +4 -4
  76. package/dist/types/contract/big-map.d.ts +3 -3
  77. package/dist/types/contract/contract-methods/contract-method-interface.d.ts +4 -4
  78. package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +6 -6
  79. package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +3 -3
  80. package/dist/types/contract/contract.d.ts +6 -6
  81. package/dist/types/contract/errors.d.ts +11 -11
  82. package/dist/types/contract/interface.d.ts +42 -42
  83. package/dist/types/contract/rpc-contract-provider.d.ts +44 -43
  84. package/dist/types/contract/sapling-state-abstraction.d.ts +1 -1
  85. package/dist/types/contract/semantic.d.ts +2 -2
  86. package/dist/types/errors.d.ts +5 -5
  87. package/dist/types/estimate/errors.d.ts +1 -1
  88. package/dist/types/estimate/estimate-provider-interface.d.ts +81 -84
  89. package/dist/types/estimate/estimate.d.ts +28 -11
  90. package/dist/types/estimate/rpc-estimate-provider.d.ts +34 -30
  91. package/dist/types/forger/errors.d.ts +2 -2
  92. package/dist/types/global-constants/default-global-constants-provider.d.ts +2 -2
  93. package/dist/types/global-constants/errors.d.ts +2 -2
  94. package/dist/types/global-constants/interface-global-constants-provider.d.ts +1 -1
  95. package/dist/types/import-key.d.ts +2 -2
  96. package/dist/types/operations/ballot-operation.d.ts +1 -1
  97. package/dist/types/operations/delegate-operation.d.ts +2 -2
  98. package/dist/types/operations/drain-delegate-operation.d.ts +1 -1
  99. package/dist/types/operations/errors.d.ts +5 -5
  100. package/dist/types/operations/failing-noop-operation.d.ts +1 -1
  101. package/dist/types/operations/increase-paid-storage-operation.d.ts +1 -1
  102. package/dist/types/operations/operations.d.ts +2 -2
  103. package/dist/types/operations/origination-operation.d.ts +5 -5
  104. package/dist/types/operations/proposals-operation.d.ts +1 -1
  105. package/dist/types/operations/register-global-constant-operation.d.ts +2 -2
  106. package/dist/types/operations/reveal-operation.d.ts +1 -1
  107. package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +1 -1
  108. package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +1 -1
  109. package/dist/types/operations/smart-rollup-originate-operation.d.ts +1 -1
  110. package/dist/types/operations/transaction-operation.d.ts +2 -2
  111. package/dist/types/operations/transfer-ticket-operation.d.ts +2 -2
  112. package/dist/types/operations/types.d.ts +387 -25
  113. package/dist/types/operations/update-companion-key-operation.d.ts +1 -1
  114. package/dist/types/operations/update-consensus-key-operation.d.ts +1 -1
  115. package/dist/types/prepare/interface.d.ts +32 -33
  116. package/dist/types/prepare/prepare-provider.d.ts +34 -60
  117. package/dist/types/provider.d.ts +7 -1
  118. package/dist/types/read-provider/interface.d.ts +21 -21
  119. package/dist/types/read-provider/rpc-read-adapter.d.ts +22 -22
  120. package/dist/types/signer/errors.d.ts +1 -1
  121. package/dist/types/signer/noop.d.ts +1 -1
  122. package/dist/types/subscribe/errors.d.ts +2 -2
  123. package/dist/types/taquito.d.ts +33 -33
  124. package/dist/types/wallet/errors.d.ts +10 -2
  125. package/dist/types/wallet/interface.d.ts +13 -13
  126. package/dist/types/wallet/operation.d.ts +4 -3
  127. package/dist/types/wallet/wallet.d.ts +36 -35
  128. package/package.json +27 -15
  129. 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
- * @description Add a transaction operation to the batch
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(Object.assign({ kind: types_1.OpKind.TRANSACTION }, params));
24
+ this.operations.push({ kind: types_1.OpKind.TRANSACTION, ...params });
33
25
  return this;
34
26
  }
35
27
  /**
36
- * @description Add a contract call to the batch
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
- * @description Add a delegation operation to the batch
36
+ * Add a delegation operation to the batch
45
37
  * @param params Delegation operation parameter
46
38
  */
47
39
  withDelegation(params) {
48
- var _a;
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(Object.assign({ kind: types_1.OpKind.DELEGATION }, params));
44
+ this.operations.push({ kind: types_1.OpKind.DELEGATION, ...params });
54
45
  return this;
55
46
  }
56
47
  /**
57
- * @description Add an origination operation to the batch
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(Object.assign({ kind: types_1.OpKind.ORIGINATION }, params));
52
+ this.operations.push({ kind: types_1.OpKind.ORIGINATION, ...params });
62
53
  return this;
63
54
  }
64
55
  /**
65
- * @description Add an IncreasePaidStorage operation to the batch
66
- * @param param IncreasePaidStorage operation parameter
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(Object.assign({ kind: types_1.OpKind.INCREASE_PAID_STORAGE }, params));
64
+ this.operations.push({ kind: types_1.OpKind.INCREASE_PAID_STORAGE, ...params });
74
65
  return this;
75
66
  }
76
67
  /**
77
- * @description Add an TransferTicket operation to the batch
78
- * @param param TransferTicket operation parameter
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(Object.assign({ kind: types_1.OpKind.TRANSFER_TICKET }, params));
76
+ this.operations.push({ kind: types_1.OpKind.TRANSFER_TICKET, ...params });
86
77
  return this;
87
78
  }
88
79
  /**
89
- * @description Add a RegisterGlobalConstant operation to the batch
90
- * @param param RegisterGlobalConstant operation parameter
80
+ * Add a RegisterGlobalConstant operation to the batch
81
+ * @param params RegisterGlobalConstant operation parameter
91
82
  */
92
83
  withRegisterGlobalConstant(params) {
93
- this.operations.push(Object.assign({ kind: types_1.OpKind.REGISTER_GLOBAL_CONSTANT }, params));
84
+ this.operations.push({ kind: types_1.OpKind.REGISTER_GLOBAL_CONSTANT, ...params });
94
85
  return this;
95
86
  }
96
- mapOperation(param) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- switch (param.kind) {
99
- case types_1.OpKind.TRANSACTION:
100
- return this.walletProvider.mapTransferParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return param; }));
101
- case types_1.OpKind.ORIGINATION:
102
- return this.walletProvider.mapOriginateParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () {
103
- return this.context.parser.prepareCodeOrigination(Object.assign({}, param));
104
- }));
105
- case types_1.OpKind.DELEGATION:
106
- return this.walletProvider.mapDelegateParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return param; }));
107
- case types_1.OpKind.INCREASE_PAID_STORAGE:
108
- return this.walletProvider.mapIncreasePaidStorageWalletParams(() => __awaiter(this, void 0, void 0, function* () { return param; }));
109
- case types_1.OpKind.REGISTER_GLOBAL_CONSTANT:
110
- return this.walletProvider.mapRegisterGlobalConstantParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return param; }));
111
- case types_1.OpKind.TRANSFER_TICKET:
112
- return this.walletProvider.mapTransferTicketParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return param; }));
113
- default:
114
- throw new core_1.InvalidOperationKindError(JSON.stringify(param.kind));
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
- * @description Add a group operation to the batch. Operation will be applied in the order they are in the params array
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 {@link InvalidOperationKindError}
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
- * @description Submit batch operation to wallet
140
+ * Submit batch operation to wallet
152
141
  */
153
- send() {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- const ops = [];
156
- for (const op of this.operations) {
157
- ops.push(yield this.mapOperation(op));
158
- }
159
- const opHash = yield this.walletProvider.sendOperations(ops);
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
- * @description Retrieve the PKH of the account that is currently in use by the wallet
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
- return __awaiter(this, arguments, void 0, function* ({ forceRefetch } = {}) {
184
- if (!this._pkh || forceRefetch) {
185
- this._pkh = yield this.walletProvider.getPKH();
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
- * @description Retrieve the PK of the account that is currently in use by the wallet
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
- return __awaiter(this, arguments, void 0, function* ({ forceRefetch } = {}) {
197
- if (!this._pk || forceRefetch) {
198
- this._pk = yield this.walletProvider.getPK();
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
- * @description Originate a new contract according to the script in parameters.
187
+ * Originate a new contract according to the script in parameters.
205
188
  * @returns a OriginationWalletOperation promise object when followed by .send()
206
- * @param originateParams Originate operation parameter
189
+ * @param params Originate operation parameter
207
190
  */
208
191
  originate(params) {
209
- return this.walletCommand(() => __awaiter(this, void 0, void 0, function* () {
210
- const mappedParams = yield this.walletProvider.mapOriginateParamsToWalletParams(() => this.context.parser.prepareCodeOrigination(Object.assign({}, params)));
211
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description Set the delegate for a contract.
201
+ * Set the delegate for a contract.
217
202
  * @returns a WalletDelegateParams promise object when followed by .send()
218
- * @param delegateParams operation parameter
203
+ * @param params operation parameter
219
204
  */
220
205
  setDelegate(params) {
221
- var _a;
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(() => __awaiter(this, void 0, void 0, function* () {
227
- const mappedParams = yield this.walletProvider.mapDelegateParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return params; }));
228
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description failing_noop operation that is guaranteed to fail. DISCLAIMER: Not all wallets support signing failing_noop operations.
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
- return __awaiter(this, void 0, void 0, function* () {
239
- const op = {
240
- kind: types_1.OpKind.FAILING_NOOP,
241
- arbitrary: params.arbitrary,
242
- };
243
- const hash = yield this.context.readProvider.getBlockHash(params.basedOnBlock);
244
- const forgedBytes = yield this.context.forger.forge({
245
- branch: hash,
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
- * @description Register the current address as delegate.
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(() => __awaiter(this, void 0, void 0, function* () {
270
- const mappedParams = yield this.walletProvider.mapDelegateParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () {
271
- const delegate = yield this.pkh();
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 = yield this.walletProvider.sendOperations([mappedParams]);
255
+ });
256
+ const opHash = await this.walletProvider.sendOperations([mappedParams]);
275
257
  return this.context.operationFactory.createDelegationOperation(opHash);
276
- }));
258
+ });
277
259
  }
278
260
  /**
279
- * @description Transfer tezos tokens from current address to a specific address or call a smart contract.
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(() => __awaiter(this, void 0, void 0, function* () {
289
- const mappedParams = yield this.walletProvider.mapTransferParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return params; }));
290
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description Transfer tezos tickets from current address to a specific address or a smart contract
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(() => __awaiter(this, void 0, void 0, function* () {
305
- const mappedParams = yield this.walletProvider.mapTransferTicketParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return params; }));
306
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description Stake a given amount for the source address
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(() => __awaiter(this, void 0, void 0, function* () {
317
- const mappedParams = yield this.walletProvider.mapStakeParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () {
318
- const source = yield this.pkh();
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 = yield this.walletProvider.sendOperations([mappedParams]);
309
+ });
310
+ const opHash = await this.walletProvider.sendOperations([mappedParams]);
329
311
  return this.context.operationFactory.createTransactionOperation(opHash);
330
- }));
312
+ });
331
313
  }
332
314
  /**
333
- * @description Unstake the given amount. If "everything" is given as amount, unstakes everything from the staking balance.
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(() => __awaiter(this, void 0, void 0, function* () {
341
- const mappedParams = yield this.walletProvider.mapUnstakeParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () {
342
- const source = yield this.pkh();
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 = yield this.walletProvider.sendOperations([mappedParams]);
353
- return yield this.context.operationFactory.createTransactionOperation(opHash);
354
- }));
333
+ });
334
+ const opHash = await this.walletProvider.sendOperations([mappedParams]);
335
+ return await this.context.operationFactory.createTransactionOperation(opHash);
336
+ });
355
337
  }
356
338
  /**
357
- * @description Transfer all the finalizable unstaked funds of the source to their liquid balance
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(() => __awaiter(this, void 0, void 0, function* () {
363
- const mappedParams = yield this.walletProvider.mapFinalizeUnstakeParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () {
364
- const source = yield this.pkh();
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 = yield this.walletProvider.sendOperations([mappedParams]);
378
- return yield this.context.operationFactory.createTransactionOperation(opHash);
379
- }));
358
+ });
359
+ const opHash = await this.walletProvider.sendOperations([mappedParams]);
360
+ return await this.context.operationFactory.createTransactionOperation(opHash);
361
+ });
380
362
  }
381
363
  /**
382
- * @description Increase the paid storage of a smart contract.
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(() => __awaiter(this, void 0, void 0, function* () {
392
- const mappedParams = yield this.walletProvider.mapIncreasePaidStorageWalletParams(() => __awaiter(this, void 0, void 0, function* () { return params; }));
393
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description Register a Micheline expression in a global table of constants.
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(() => __awaiter(this, void 0, void 0, function* () {
404
- const mappedParams = yield this.walletProvider.mapRegisterGlobalConstantParamsToWalletParams(() => __awaiter(this, void 0, void 0, function* () { return params; }));
405
- const opHash = yield this.walletProvider.sendOperations([mappedParams]);
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
- * @description Create a batch of operation
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
- * @description Create an smart contract abstraction for the address specified. Calling entrypoints with the returned
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 {@link InvalidContractAddressError} If the contract address is not valid
407
+ * @throws InvalidContractAddressError If the contract address is not valid
426
408
  */
427
- at(address_1) {
428
- return __awaiter(this, arguments, void 0, function* (address, contractAbstractionComposer = (x) => x) {
429
- const addressValidation = (0, utils_1.validateContractAddress)(address);
430
- if (addressValidation !== utils_1.ValidationResult.VALID) {
431
- throw new core_1.InvalidContractAddressError(address, addressValidation);
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
- const rpc = this.context.withExtensions().rpc;
434
- const readProvider = this.context.withExtensions().readProvider;
435
- const script = yield readProvider.getScript(address, 'head');
436
- const entrypoints = yield readProvider.getEntrypoints(address);
437
- const abs = new contract_1.ContractAbstraction(address, script, this, this.context.contract, entrypoints, rpc, readProvider);
438
- return contractAbstractionComposer(abs, this.context);
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;