@taquito/taquito 24.3.0-beta.2 → 24.3.0-beta.3

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 (49) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/contract/big-map.js +6 -3
  3. package/dist/lib/contract/contract.js +8 -3
  4. package/dist/lib/contract/not-found-retry.js +29 -0
  5. package/dist/lib/contract/rpc-contract-provider.js +28 -18
  6. package/dist/lib/contract/sapling-state-abstraction.js +5 -2
  7. package/dist/lib/contract/semantic.js +4 -4
  8. package/dist/lib/estimate/rpc-estimate-provider.js +2 -0
  9. package/dist/lib/operations/batch-operation.js +3 -2
  10. package/dist/lib/operations/delegate-operation.js +3 -2
  11. package/dist/lib/operations/operations.js +12 -2
  12. package/dist/lib/operations/origination-operation.js +9 -3
  13. package/dist/lib/operations/register-global-constant-operation.js +3 -2
  14. package/dist/lib/operations/reveal-operation.js +3 -2
  15. package/dist/lib/operations/transaction-operation.js +4 -3
  16. package/dist/lib/operations/transfer-ticket-operation.js +3 -2
  17. package/dist/lib/prepare/prepare-provider.js +6 -5
  18. package/dist/lib/provider.js +82 -10
  19. package/dist/lib/read-provider/interface.js +8 -0
  20. package/dist/lib/read-provider/rpc-read-adapter.js +2 -0
  21. package/dist/lib/tz/interface.js +2 -0
  22. package/dist/lib/tz/rpc-tz-provider.js +2 -0
  23. package/dist/lib/version.js +2 -2
  24. package/dist/lib/wallet/origination-operation.js +5 -1
  25. package/dist/lib/wallet/receipt.js +9 -8
  26. package/dist/lib/wallet/wallet.js +18 -7
  27. package/dist/taquito.es6.js +333 -181
  28. package/dist/taquito.es6.js.map +1 -1
  29. package/dist/taquito.min.js +1 -1
  30. package/dist/taquito.umd.js +332 -180
  31. package/dist/taquito.umd.js.map +1 -1
  32. package/dist/types/contract/big-map.d.ts +10 -5
  33. package/dist/types/contract/contract.d.ts +3 -2
  34. package/dist/types/contract/interface.d.ts +5 -4
  35. package/dist/types/contract/not-found-retry.d.ts +3 -0
  36. package/dist/types/contract/rpc-contract-provider.d.ts +5 -4
  37. package/dist/types/contract/sapling-state-abstraction.d.ts +9 -4
  38. package/dist/types/contract/semantic.d.ts +4 -3
  39. package/dist/types/operations/operations.d.ts +4 -1
  40. package/dist/types/operations/transaction-operation.d.ts +2 -2
  41. package/dist/types/provider.d.ts +4 -1
  42. package/dist/types/read-provider/interface.d.ts +5 -1
  43. package/dist/types/read-provider/rpc-read-adapter.d.ts +4 -1
  44. package/dist/types/tz/interface.d.ts +4 -1
  45. package/dist/types/tz/rpc-tz-provider.d.ts +4 -1
  46. package/dist/types/wallet/receipt.d.ts +4 -1
  47. package/dist/types/wallet/wallet.d.ts +1 -0
  48. package/package.json +15 -17
  49. package/signature.json +0 -866
@@ -8,6 +8,12 @@ const prepare_1 = require("./contract/prepare");
8
8
  const rpc_1 = require("@taquito/rpc");
9
9
  const utils_1 = require("@taquito/utils");
10
10
  class Provider {
11
+ clearRpcCache() {
12
+ const rpc = this.context.rpc;
13
+ if (typeof rpc.deleteAllCachedData === 'function') {
14
+ rpc.deleteAllCachedData();
15
+ }
16
+ }
11
17
  parseRpcErrors(error) {
12
18
  if (!(error instanceof http_utils_1.HttpResponseError)) {
13
19
  return [];
@@ -43,7 +49,7 @@ class Provider {
43
49
  }
44
50
  }
45
51
  }
46
- parseCounterInThePastAdjustments(error) {
52
+ parseCounterAdjustments(error) {
47
53
  return this.parseRpcErrors(error)
48
54
  .filter((value) => {
49
55
  const id = value.id;
@@ -51,7 +57,8 @@ class Provider {
51
57
  const expected = value.expected;
52
58
  const found = value.found;
53
59
  return (typeof id === 'string' &&
54
- id.endsWith('contract.counter_in_the_past') &&
60
+ (id.endsWith('contract.counter_in_the_past') ||
61
+ id.endsWith('contract.counter_in_the_future')) &&
55
62
  typeof contract === 'string' &&
56
63
  typeof expected === 'string' &&
57
64
  typeof found === 'string');
@@ -61,7 +68,7 @@ class Provider {
61
68
  expected: BigInt(value.expected),
62
69
  found: BigInt(value.found),
63
70
  }))
64
- .filter((value) => value.expected > value.found);
71
+ .filter((value) => value.expected !== value.found);
65
72
  }
66
73
  hasGasLimitTooHighAndBlockExhausted(error) {
67
74
  const ids = this.parseRpcErrors(error)
@@ -284,7 +291,7 @@ class Provider {
284
291
  };
285
292
  }
286
293
  catch (error) {
287
- const adjustments = this.parseCounterInThePastAdjustments(error);
294
+ const adjustments = this.parseCounterAdjustments(error);
288
295
  const patchedOp = this.patchSimulationCounters(op, adjustments);
289
296
  if (patchedOp) {
290
297
  try {
@@ -335,11 +342,21 @@ class Provider {
335
342
  return opRequireReveal;
336
343
  }
337
344
  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;
345
+ let signedForgedBytes = await this.signForgedBytes(forgedBytes);
341
346
  const opResponse = [];
342
- const results = await this.rpc.preapplyOperations([forgedBytes.opOb]);
347
+ let results;
348
+ try {
349
+ results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
350
+ }
351
+ catch (error) {
352
+ const adjustments = this.parseCounterAdjustments(error);
353
+ const patchedForgedBytes = await this.patchForgedBytesCounters(signedForgedBytes, adjustments);
354
+ if (!patchedForgedBytes) {
355
+ throw error;
356
+ }
357
+ signedForgedBytes = await this.signForgedBytes(patchedForgedBytes);
358
+ results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
359
+ }
343
360
  if (!Array.isArray(results)) {
344
361
  throw new errors_1.TezosPreapplyFailureError(results);
345
362
  }
@@ -352,12 +369,67 @@ class Provider {
352
369
  if (errors.length) {
353
370
  throw new errors_1.TezosOperationError(errors, 'Error occurred during validation simulation of operation', opResponse);
354
371
  }
372
+ const hash = await this.context.injector.inject(signedForgedBytes.opbytes);
373
+ this.clearRpcCache();
355
374
  return {
356
- hash: await this.context.injector.inject(forgedBytes.opbytes),
357
- forgedBytes,
375
+ hash,
376
+ forgedBytes: signedForgedBytes,
358
377
  opResponse,
359
378
  context: this.context.clone(),
360
379
  };
361
380
  }
381
+ async signForgedBytes(forgedBytes) {
382
+ const signed = await this.signer.sign(forgedBytes.opbytes, new Uint8Array([3]));
383
+ return {
384
+ ...forgedBytes,
385
+ opbytes: signed.sbytes,
386
+ opOb: {
387
+ ...forgedBytes.opOb,
388
+ signature: signed.prefixSig,
389
+ },
390
+ };
391
+ }
392
+ async patchForgedBytesCounters(forgedBytes, adjustments) {
393
+ if (adjustments.length === 0 || !Array.isArray(forgedBytes.opOb.contents)) {
394
+ return;
395
+ }
396
+ const branch = forgedBytes.opOb.branch;
397
+ if (typeof branch !== 'string') {
398
+ return;
399
+ }
400
+ const contents = forgedBytes.opOb.contents.map((content) => ({ ...content }));
401
+ let patched = false;
402
+ for (const adjustment of adjustments) {
403
+ const delta = adjustment.expected - adjustment.found;
404
+ for (const content of contents) {
405
+ const source = content.source;
406
+ const counter = content.counter;
407
+ if (source !== adjustment.contract || typeof counter === 'undefined') {
408
+ continue;
409
+ }
410
+ const contentCounter = BigInt(String(counter));
411
+ if (contentCounter < adjustment.found) {
412
+ continue;
413
+ }
414
+ content.counter = (contentCounter + delta).toString();
415
+ patched = true;
416
+ }
417
+ }
418
+ if (!patched) {
419
+ return;
420
+ }
421
+ const unsignedOpBytes = await this.context.forger.forge({
422
+ branch,
423
+ contents,
424
+ });
425
+ return {
426
+ ...forgedBytes,
427
+ opbytes: unsignedOpBytes,
428
+ opOb: {
429
+ ...forgedBytes.opOb,
430
+ contents,
431
+ },
432
+ };
433
+ }
362
434
  }
363
435
  exports.Provider = Provider;
@@ -1,2 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBlockHashIdentifier = void 0;
4
+ const utils_1 = require("@taquito/utils");
5
+ const bignumber_js_1 = require("bignumber.js");
6
+ const BigNumber = bignumber_js_1.default;
7
+ const isBlockHashIdentifier = (block) => {
8
+ return (0, utils_1.validateBlock)(block) === utils_1.ValidationResult.VALID;
9
+ };
10
+ exports.isBlockHashIdentifier = isBlockHashIdentifier;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcReadAdapter = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ const BigNumber = bignumber_js_1.default;
4
6
  /**
5
7
  * Converts calls from TzReadProvider into calls to the wrapped RpcClient in a format it can understand.
6
8
  */
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bignumber_js_1 = require("bignumber.js");
4
+ const BigNumber = bignumber_js_1.default;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcTzProvider = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ const BigNumber = bignumber_js_1.default;
4
6
  const operations_1 = require("../operations/operations");
5
7
  const utils_1 = require("@taquito/utils");
6
8
  const core_1 = require("@taquito/core");
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
5
5
  exports.VERSION = {
6
- "commitHash": "fb73f1546d3dff2fbba7741ca6006680212bef16",
7
- "version": "24.3.0-beta.2"
6
+ "commitHash": "a312cd3f4fc0ab0fb3351bfffe6ad855772cb077",
7
+ "version": "24.3.0-beta.3"
8
8
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OriginationWalletOperation = void 0;
4
4
  const rpc_1 = require("@taquito/rpc");
5
+ const interface_1 = require("../read-provider/interface");
5
6
  const types_1 = require("../operations/types");
6
7
  const operation_1 = require("./operation");
7
8
  const errors_1 = require("./errors");
@@ -47,7 +48,10 @@ class OriginationWalletOperation extends operation_1.WalletOperation {
47
48
  }
48
49
  await this.confirmation();
49
50
  const inclusionBlock = await this.getInclusionBlock();
50
- return this.context.wallet.at(address, undefined, inclusionBlock.header.level);
51
+ if (!(0, interface_1.isBlockHashIdentifier)(inclusionBlock.hash)) {
52
+ throw new errors_1.OriginationWalletOperationError('Inclusion block hash is invalid');
53
+ }
54
+ return this.context.wallet.at(address, undefined, inclusionBlock.hash);
51
55
  }
52
56
  }
53
57
  exports.OriginationWalletOperation = OriginationWalletOperation;
@@ -2,20 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.receiptFromOperation = void 0;
4
4
  const bignumber_js_1 = require("bignumber.js");
5
+ const BigNumber = bignumber_js_1.default;
5
6
  const constants_1 = require("../constants");
6
7
  const errors_1 = require("../operations/errors");
7
8
  const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
8
9
  ALLOCATION_BURN: 257,
9
10
  ORIGINATION_BURN: 257,
10
11
  }) => {
11
- bignumber_js_1.default.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: bignumber_js_1.default.ROUND_UP });
12
+ BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
12
13
  const operationResults = (0, errors_1.flattenOperationResult)({ contents: op });
13
- let totalMilliGas = new bignumber_js_1.default(0);
14
- let totalStorage = new bignumber_js_1.default(0);
15
- let totalFee = new bignumber_js_1.default(0);
16
- let totalOriginationBurn = new bignumber_js_1.default(0);
17
- let totalAllocationBurn = new bignumber_js_1.default(0);
18
- let totalPaidStorageDiff = new bignumber_js_1.default(0);
14
+ let totalMilliGas = new BigNumber(0);
15
+ let totalStorage = new BigNumber(0);
16
+ let totalFee = new BigNumber(0);
17
+ let totalOriginationBurn = new BigNumber(0);
18
+ let totalAllocationBurn = new BigNumber(0);
19
+ let totalPaidStorageDiff = new BigNumber(0);
19
20
  operationResults.forEach((result) => {
20
21
  totalFee = totalFee.plus(result.fee || 0);
21
22
  totalOriginationBurn = totalOriginationBurn.plus(Array.isArray(result.originated_contracts)
@@ -37,7 +38,7 @@ const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
37
38
  totalAllocationBurn,
38
39
  totalOriginationBurn,
39
40
  totalPaidStorageDiff,
40
- totalStorageBurn: new bignumber_js_1.default(totalStorage.multipliedBy(constants_1.COST_PER_BYTE)),
41
+ totalStorageBurn: new BigNumber(totalStorage.multipliedBy(constants_1.COST_PER_BYTE)),
41
42
  };
42
43
  };
43
44
  exports.receiptFromOperation = receiptFromOperation;
@@ -4,8 +4,8 @@ exports.Wallet = exports.WalletOperationBatch = void 0;
4
4
  const contract_1 = require("../contract/contract");
5
5
  const types_1 = require("../operations/types");
6
6
  const core_1 = require("@taquito/core");
7
- const http_utils_1 = require("@taquito/http-utils");
8
7
  const utils_1 = require("@taquito/utils");
8
+ const not_found_retry_1 = require("../contract/not-found-retry");
9
9
  class WalletOperationBatch {
10
10
  constructor(walletProvider, context) {
11
11
  this.walletProvider = walletProvider;
@@ -428,17 +428,28 @@ class Wallet {
428
428
  // Newly originated contracts can be visible at the operation's inclusion level in one RPC
429
429
  // call and still lag on another endpoint of the same rolling node. Retry at head so
430
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');
431
+ // after confirmation instead of pinning itself to a stale context forever. The head index
432
+ // can lag briefly as well, so bound a few retries there too.
433
+ if (block !== 'head' && (0, not_found_retry_1.isNotFoundError)(error)) {
434
+ contractState = await (0, not_found_retry_1.retryOnNotFound)(() => loadContractState('head'));
436
435
  }
437
436
  else {
438
437
  throw error;
439
438
  }
440
439
  }
441
- const abs = new contract_1.ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider);
440
+ const abs = new contract_1.ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider, 'head');
441
+ return contractAbstractionComposer(abs, this.context);
442
+ }
443
+ async atExactBlock(address, contractAbstractionComposer = (x) => x, block) {
444
+ const addressValidation = (0, utils_1.validateContractAddress)(address);
445
+ if (addressValidation !== utils_1.ValidationResult.VALID) {
446
+ throw new core_1.InvalidContractAddressError(address, addressValidation);
447
+ }
448
+ const rpc = this.context.withExtensions().rpc;
449
+ const readProvider = this.context.withExtensions().readProvider;
450
+ const script = await readProvider.getScript(address, block);
451
+ const entrypoints = await rpc.getEntrypoints(address, { block: String(block) });
452
+ const abs = new contract_1.ContractAbstraction(address, script, this, this.context.contract, entrypoints, rpc, readProvider, block);
442
453
  return contractAbstractionComposer(abs, this.context);
443
454
  }
444
455
  }