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

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
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@taquito/rpc'), require('@taquito/http-utils'), require('@taquito/core'), require('rxjs'), require('rxjs/operators'), require('bignumber.js'), require('@taquito/utils'), require('@taquito/michelson-encoder'), require('@taquito/michel-codec'), require('@taquito/local-forging'), require('@taquito/signer')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@taquito/rpc', '@taquito/http-utils', '@taquito/core', 'rxjs', 'rxjs/operators', 'bignumber.js', '@taquito/utils', '@taquito/michelson-encoder', '@taquito/michel-codec', '@taquito/local-forging', '@taquito/signer'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquito = {}, global.rpc, global.httpUtils, global.core, global.rxjs, global.operators, global.BigNumber, global.utils, global.michelsonEncoder, global.michelCodec, global.localForging, global.taquitoSigner));
5
- })(this, (function (exports, rpc, httpUtils, core, rxjs, operators, BigNumber, utils, michelsonEncoder, michelCodec, localForging, signer) { 'use strict';
5
+ })(this, (function (exports, rpc, httpUtils, core, rxjs, operators, BigNumberJs, utils, michelsonEncoder, michelCodec, localForging, signer) { 'use strict';
6
6
 
7
7
  function formatErrorMessage(error, stringToReplace) {
8
8
  const body = JSON.parse(error.body);
@@ -416,18 +416,19 @@
416
416
  }
417
417
  }
418
418
 
419
+ const BigNumber$8 = BigNumberJs;
419
420
  const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
420
421
  ALLOCATION_BURN: 257,
421
422
  ORIGINATION_BURN: 257,
422
423
  }) => {
423
- BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
424
+ BigNumber$8.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$8.ROUND_UP });
424
425
  const operationResults = flattenOperationResult({ contents: op });
425
- let totalMilliGas = new BigNumber(0);
426
- let totalStorage = new BigNumber(0);
427
- let totalFee = new BigNumber(0);
428
- let totalOriginationBurn = new BigNumber(0);
429
- let totalAllocationBurn = new BigNumber(0);
430
- let totalPaidStorageDiff = new BigNumber(0);
426
+ let totalMilliGas = new BigNumber$8(0);
427
+ let totalStorage = new BigNumber$8(0);
428
+ let totalFee = new BigNumber$8(0);
429
+ let totalOriginationBurn = new BigNumber$8(0);
430
+ let totalAllocationBurn = new BigNumber$8(0);
431
+ let totalPaidStorageDiff = new BigNumber$8(0);
431
432
  operationResults.forEach((result) => {
432
433
  totalFee = totalFee.plus(result.fee || 0);
433
434
  totalOriginationBurn = totalOriginationBurn.plus(Array.isArray(result.originated_contracts)
@@ -449,7 +450,7 @@
449
450
  totalAllocationBurn,
450
451
  totalOriginationBurn,
451
452
  totalPaidStorageDiff,
452
- totalStorageBurn: new BigNumber(totalStorage.multipliedBy(COST_PER_BYTE)),
453
+ totalStorageBurn: new BigNumber$8(totalStorage.multipliedBy(COST_PER_BYTE)),
453
454
  };
454
455
  };
455
456
 
@@ -870,6 +871,10 @@
870
871
  }
871
872
  }
872
873
 
874
+ const isBlockHashIdentifier = (block) => {
875
+ return utils.validateBlock(block) === utils.ValidationResult.VALID;
876
+ };
877
+
873
878
  class OriginationWalletOperation extends WalletOperation {
874
879
  constructor(opHash, context, newHead$) {
875
880
  super(opHash, context, newHead$);
@@ -912,7 +917,10 @@
912
917
  }
913
918
  await this.confirmation();
914
919
  const inclusionBlock = await this.getInclusionBlock();
915
- return this.context.wallet.at(address, undefined, inclusionBlock.header.level);
920
+ if (!isBlockHashIdentifier(inclusionBlock.hash)) {
921
+ throw new OriginationWalletOperationError('Inclusion block hash is invalid');
922
+ }
923
+ return this.context.wallet.at(address, undefined, inclusionBlock.hash);
916
924
  }
917
925
  }
918
926
 
@@ -1148,6 +1156,13 @@
1148
1156
  get includedInBlock() {
1149
1157
  return this._foundAt;
1150
1158
  }
1159
+ async getInclusionBlock() {
1160
+ const inclusionBlock = await this._includedInBlock.pipe(operators.first()).toPromise();
1161
+ if (!inclusionBlock) {
1162
+ throw new Error('Inclusion block is undefined');
1163
+ }
1164
+ return inclusionBlock;
1165
+ }
1151
1166
  /**
1152
1167
  *
1153
1168
  * @param hash Operation hash
@@ -1161,6 +1176,7 @@
1161
1176
  this.results = results;
1162
1177
  this.context = context;
1163
1178
  this._pollingConfig$ = new rxjs.ReplaySubject(1);
1179
+ this._includedInBlock = new rxjs.ReplaySubject(1);
1164
1180
  this.currentHead$ = this._pollingConfig$.pipe(operators.switchMap((config) => {
1165
1181
  return new rxjs.BehaviorSubject(config).pipe(operators.timeout({
1166
1182
  each: config.timeout * 1000,
@@ -1175,11 +1191,13 @@
1175
1191
  // Observable that emit once operation is seen in a block
1176
1192
  this.confirmed$ = this.currentHead$.pipe(operators.map((head) => {
1177
1193
  for (let i = 3; i >= 0; i--) {
1178
- head.operations[i].forEach((op) => {
1194
+ for (const op of head.operations[i]) {
1179
1195
  if (op.hash === this.hash) {
1180
1196
  this._foundAt = head.header.level;
1197
+ this._includedInBlock.next(head);
1198
+ return this._foundAt;
1181
1199
  }
1182
- });
1200
+ }
1183
1201
  }
1184
1202
  if (head.header.level - this._foundAt >= 0) {
1185
1203
  return this._foundAt;
@@ -1607,6 +1625,12 @@
1607
1625
  };
1608
1626
 
1609
1627
  class Provider {
1628
+ clearRpcCache() {
1629
+ const rpc = this.context.rpc;
1630
+ if (typeof rpc.deleteAllCachedData === 'function') {
1631
+ rpc.deleteAllCachedData();
1632
+ }
1633
+ }
1610
1634
  parseRpcErrors(error) {
1611
1635
  if (!(error instanceof httpUtils.HttpResponseError)) {
1612
1636
  return [];
@@ -1642,7 +1666,7 @@
1642
1666
  }
1643
1667
  }
1644
1668
  }
1645
- parseCounterInThePastAdjustments(error) {
1669
+ parseCounterAdjustments(error) {
1646
1670
  return this.parseRpcErrors(error)
1647
1671
  .filter((value) => {
1648
1672
  const id = value.id;
@@ -1650,7 +1674,8 @@
1650
1674
  const expected = value.expected;
1651
1675
  const found = value.found;
1652
1676
  return (typeof id === 'string' &&
1653
- id.endsWith('contract.counter_in_the_past') &&
1677
+ (id.endsWith('contract.counter_in_the_past') ||
1678
+ id.endsWith('contract.counter_in_the_future')) &&
1654
1679
  typeof contract === 'string' &&
1655
1680
  typeof expected === 'string' &&
1656
1681
  typeof found === 'string');
@@ -1660,7 +1685,7 @@
1660
1685
  expected: BigInt(value.expected),
1661
1686
  found: BigInt(value.found),
1662
1687
  }))
1663
- .filter((value) => value.expected > value.found);
1688
+ .filter((value) => value.expected !== value.found);
1664
1689
  }
1665
1690
  hasGasLimitTooHighAndBlockExhausted(error) {
1666
1691
  const ids = this.parseRpcErrors(error)
@@ -1883,7 +1908,7 @@
1883
1908
  };
1884
1909
  }
1885
1910
  catch (error) {
1886
- const adjustments = this.parseCounterInThePastAdjustments(error);
1911
+ const adjustments = this.parseCounterAdjustments(error);
1887
1912
  const patchedOp = this.patchSimulationCounters(op, adjustments);
1888
1913
  if (patchedOp) {
1889
1914
  try {
@@ -1934,11 +1959,21 @@
1934
1959
  return opRequireReveal;
1935
1960
  }
1936
1961
  async signAndInject(forgedBytes) {
1937
- const signed = await this.signer.sign(forgedBytes.opbytes, new Uint8Array([3]));
1938
- forgedBytes.opbytes = signed.sbytes;
1939
- forgedBytes.opOb.signature = signed.prefixSig;
1962
+ let signedForgedBytes = await this.signForgedBytes(forgedBytes);
1940
1963
  const opResponse = [];
1941
- const results = await this.rpc.preapplyOperations([forgedBytes.opOb]);
1964
+ let results;
1965
+ try {
1966
+ results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
1967
+ }
1968
+ catch (error) {
1969
+ const adjustments = this.parseCounterAdjustments(error);
1970
+ const patchedForgedBytes = await this.patchForgedBytesCounters(signedForgedBytes, adjustments);
1971
+ if (!patchedForgedBytes) {
1972
+ throw error;
1973
+ }
1974
+ signedForgedBytes = await this.signForgedBytes(patchedForgedBytes);
1975
+ results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
1976
+ }
1942
1977
  if (!Array.isArray(results)) {
1943
1978
  throw new TezosPreapplyFailureError(results);
1944
1979
  }
@@ -1951,13 +1986,68 @@
1951
1986
  if (errors.length) {
1952
1987
  throw new TezosOperationError(errors, 'Error occurred during validation simulation of operation', opResponse);
1953
1988
  }
1989
+ const hash = await this.context.injector.inject(signedForgedBytes.opbytes);
1990
+ this.clearRpcCache();
1954
1991
  return {
1955
- hash: await this.context.injector.inject(forgedBytes.opbytes),
1956
- forgedBytes,
1992
+ hash,
1993
+ forgedBytes: signedForgedBytes,
1957
1994
  opResponse,
1958
1995
  context: this.context.clone(),
1959
1996
  };
1960
1997
  }
1998
+ async signForgedBytes(forgedBytes) {
1999
+ const signed = await this.signer.sign(forgedBytes.opbytes, new Uint8Array([3]));
2000
+ return {
2001
+ ...forgedBytes,
2002
+ opbytes: signed.sbytes,
2003
+ opOb: {
2004
+ ...forgedBytes.opOb,
2005
+ signature: signed.prefixSig,
2006
+ },
2007
+ };
2008
+ }
2009
+ async patchForgedBytesCounters(forgedBytes, adjustments) {
2010
+ if (adjustments.length === 0 || !Array.isArray(forgedBytes.opOb.contents)) {
2011
+ return;
2012
+ }
2013
+ const branch = forgedBytes.opOb.branch;
2014
+ if (typeof branch !== 'string') {
2015
+ return;
2016
+ }
2017
+ const contents = forgedBytes.opOb.contents.map((content) => ({ ...content }));
2018
+ let patched = false;
2019
+ for (const adjustment of adjustments) {
2020
+ const delta = adjustment.expected - adjustment.found;
2021
+ for (const content of contents) {
2022
+ const source = content.source;
2023
+ const counter = content.counter;
2024
+ if (source !== adjustment.contract || typeof counter === 'undefined') {
2025
+ continue;
2026
+ }
2027
+ const contentCounter = BigInt(String(counter));
2028
+ if (contentCounter < adjustment.found) {
2029
+ continue;
2030
+ }
2031
+ content.counter = (contentCounter + delta).toString();
2032
+ patched = true;
2033
+ }
2034
+ }
2035
+ if (!patched) {
2036
+ return;
2037
+ }
2038
+ const unsignedOpBytes = await this.context.forger.forge({
2039
+ branch,
2040
+ contents,
2041
+ });
2042
+ return {
2043
+ ...forgedBytes,
2044
+ opbytes: unsignedOpBytes,
2045
+ opOb: {
2046
+ ...forgedBytes.opOb,
2047
+ contents,
2048
+ },
2049
+ };
2050
+ }
1961
2051
  }
1962
2052
 
1963
2053
  /******************************************************************************
@@ -2183,6 +2273,115 @@
2183
2273
  }
2184
2274
  }
2185
2275
 
2276
+ class BigMapAbstraction {
2277
+ constructor(id, schema, provider, defaultBlock) {
2278
+ this.id = id;
2279
+ this.schema = schema;
2280
+ this.provider = provider;
2281
+ this.defaultBlock = defaultBlock;
2282
+ }
2283
+ /**
2284
+ *
2285
+ * Fetch one value in a big map
2286
+ *
2287
+ * @param keyToEncode Key to query (will be encoded properly according to the schema)
2288
+ * @param block optional block level to fetch the values from (head will be use by default)
2289
+ * @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map
2290
+ *
2291
+ */
2292
+ async get(keyToEncode, block) {
2293
+ try {
2294
+ const id = await this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block ?? this.defaultBlock);
2295
+ return id;
2296
+ }
2297
+ catch (e) {
2298
+ if (e instanceof httpUtils.HttpResponseError && e.status === httpUtils.STATUS_CODE.NOT_FOUND) {
2299
+ return undefined;
2300
+ }
2301
+ else {
2302
+ throw e;
2303
+ }
2304
+ }
2305
+ }
2306
+ /**
2307
+ *
2308
+ * Fetch multiple values in a big map
2309
+ * All values will be fetched on the same block level. If a block is specified in the request, the values will be fetched at it.
2310
+ * Otherwise, a first request will be done to the node to fetch the level of the head and all values will be fetched at this level.
2311
+ * If one of the keys does not exist in the big map, its value will be set to undefined.
2312
+ *
2313
+ * @param keysToEncode Array of keys to query (will be encoded properly according to the schema)
2314
+ * @param block optional block level to fetch the values from
2315
+ * @param batchSize optional batch size representing the number of requests to execute in parallel
2316
+ * @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
2317
+ *
2318
+ */
2319
+ async getMultipleValues(keysToEncode, block, batchSize = 5) {
2320
+ return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block ?? this.defaultBlock, batchSize);
2321
+ }
2322
+ toJSON() {
2323
+ return this.id.toString();
2324
+ }
2325
+ toString() {
2326
+ return this.id.toString();
2327
+ }
2328
+ }
2329
+
2330
+ class SaplingStateAbstraction {
2331
+ constructor(id, provider, defaultBlock) {
2332
+ this.id = id;
2333
+ this.provider = provider;
2334
+ this.defaultBlock = defaultBlock;
2335
+ }
2336
+ /**
2337
+ *
2338
+ * Fetch the sapling state
2339
+ *
2340
+ * @param block optional block level to fetch the values from (head will be use by default)
2341
+ * @returns Return a json object of the sapling_state
2342
+ *
2343
+ */
2344
+ async getSaplingDiff(block) {
2345
+ return this.provider.getSaplingDiffByID(this.id.toString(), block ?? this.defaultBlock);
2346
+ }
2347
+ getId() {
2348
+ return this.id.toString();
2349
+ }
2350
+ }
2351
+
2352
+ /**
2353
+ * Override the default michelson encoder semantic to provide richer abstraction over storage properties
2354
+ * @param p StorageProvider (contract API)
2355
+ */
2356
+ // Override the default michelson encoder semantic to provide richer abstraction over storage properties
2357
+ const smartContractAbstractionSemantic = (provider, block) => ({
2358
+ // Provide a specific abstraction for BigMaps
2359
+ big_map: (val, code) => {
2360
+ if (!val || !('int' in val) || val.int === undefined) {
2361
+ // Return an empty object in case of missing big map ID
2362
+ return {};
2363
+ }
2364
+ else {
2365
+ const schema = new michelsonEncoder.Schema(code);
2366
+ return new BigMapAbstraction(new BigNumberJs(val.int), schema, provider, block);
2367
+ }
2368
+ },
2369
+ sapling_state: (val) => {
2370
+ if (!val || !('int' in val) || val.int === undefined) {
2371
+ // Return an empty object in case of missing sapling state ID
2372
+ return {};
2373
+ }
2374
+ else {
2375
+ return new SaplingStateAbstraction(new BigNumberJs(val.int), provider, block);
2376
+ }
2377
+ },
2378
+ /*
2379
+ // TODO: embed useful other abstractions
2380
+ 'contract': () => {},
2381
+ 'address': () => {}
2382
+ */
2383
+ });
2384
+
2186
2385
  /**
2187
2386
  * Utility class to retrieve data from a smart contract's storage without incurring fees via a contract's view method
2188
2387
  */
@@ -2235,13 +2434,14 @@
2235
2434
  * Smart contract abstraction
2236
2435
  */
2237
2436
  class ContractAbstraction {
2238
- constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider) {
2437
+ constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider, readBlock = 'head') {
2239
2438
  this.address = address;
2240
2439
  this.script = script;
2241
2440
  this.storageProvider = storageProvider;
2242
2441
  this.entrypoints = entrypoints;
2243
2442
  this.rpc = rpc;
2244
2443
  this.readProvider = readProvider;
2444
+ this.readBlock = readBlock;
2245
2445
  /**
2246
2446
  * Contains methods that are implemented by the target Tezos Smart Contract, and offers the user to call the Smart Contract methods as if they were native TS/JS methods.
2247
2447
  * `methodsObject` serves the exact same purpose as the `methods` member. The difference is that it allows passing the parameter in an object format when calling the smart contract method (instead of the flattened representation)
@@ -2325,8 +2525,11 @@
2325
2525
  /**
2326
2526
  * Return a friendly representation of the smart contract storage
2327
2527
  */
2328
- storage() {
2329
- return this.storageProvider.getStorage(this.address, this.schema);
2528
+ async storage() {
2529
+ if (this.readBlock !== 'head') {
2530
+ return this.schema.Execute(this.script.storage, smartContractAbstractionSemantic(this.storageProvider, this.readBlock));
2531
+ }
2532
+ return this.storageProvider.getStorage(this.address, this.schema, this.readBlock);
2330
2533
  }
2331
2534
  }
2332
2535
 
@@ -2428,114 +2631,8 @@
2428
2631
  return (contractAbstraction, context) => functioncomposer2(functioncomposer1(contractAbstraction, context), context);
2429
2632
  }
2430
2633
 
2431
- class SaplingStateAbstraction {
2432
- constructor(id, provider) {
2433
- this.id = id;
2434
- this.provider = provider;
2435
- }
2436
- /**
2437
- *
2438
- * Fetch the sapling state
2439
- *
2440
- * @param block optional block level to fetch the values from (head will be use by default)
2441
- * @returns Return a json object of the sapling_state
2442
- *
2443
- */
2444
- async getSaplingDiff(block) {
2445
- return this.provider.getSaplingDiffByID(this.id.toString(), block);
2446
- }
2447
- getId() {
2448
- return this.id.toString();
2449
- }
2450
- }
2451
-
2452
- class BigMapAbstraction {
2453
- constructor(id, schema, provider) {
2454
- this.id = id;
2455
- this.schema = schema;
2456
- this.provider = provider;
2457
- }
2458
- /**
2459
- *
2460
- * Fetch one value in a big map
2461
- *
2462
- * @param keyToEncode Key to query (will be encoded properly according to the schema)
2463
- * @param block optional block level to fetch the values from (head will be use by default)
2464
- * @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map
2465
- *
2466
- */
2467
- async get(keyToEncode, block) {
2468
- try {
2469
- const id = await this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block);
2470
- return id;
2471
- }
2472
- catch (e) {
2473
- if (e instanceof httpUtils.HttpResponseError && e.status === httpUtils.STATUS_CODE.NOT_FOUND) {
2474
- return undefined;
2475
- }
2476
- else {
2477
- throw e;
2478
- }
2479
- }
2480
- }
2481
- /**
2482
- *
2483
- * Fetch multiple values in a big map
2484
- * All values will be fetched on the same block level. If a block is specified in the request, the values will be fetched at it.
2485
- * Otherwise, a first request will be done to the node to fetch the level of the head and all values will be fetched at this level.
2486
- * If one of the keys does not exist in the big map, its value will be set to undefined.
2487
- *
2488
- * @param keysToEncode Array of keys to query (will be encoded properly according to the schema)
2489
- * @param block optional block level to fetch the values from
2490
- * @param batchSize optional batch size representing the number of requests to execute in parallel
2491
- * @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
2492
- *
2493
- */
2494
- async getMultipleValues(keysToEncode, block, batchSize = 5) {
2495
- return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block, batchSize);
2496
- }
2497
- toJSON() {
2498
- return this.id.toString();
2499
- }
2500
- toString() {
2501
- return this.id.toString();
2502
- }
2503
- }
2504
-
2505
- /**
2506
- * Override the default michelson encoder semantic to provide richer abstraction over storage properties
2507
- * @param p ContractProvider (contract API)
2508
- */
2509
- // Override the default michelson encoder semantic to provide richer abstraction over storage properties
2510
- const smartContractAbstractionSemantic = (provider) => ({
2511
- // Provide a specific abstraction for BigMaps
2512
- big_map: (val, code) => {
2513
- if (!val || !('int' in val) || val.int === undefined) {
2514
- // Return an empty object in case of missing big map ID
2515
- return {};
2516
- }
2517
- else {
2518
- const schema = new michelsonEncoder.Schema(code);
2519
- return new BigMapAbstraction(new BigNumber(val.int), schema, provider);
2520
- }
2521
- },
2522
- sapling_state: (val) => {
2523
- if (!val || !('int' in val) || val.int === undefined) {
2524
- // Return an empty object in case of missing sapling state ID
2525
- return {};
2526
- }
2527
- else {
2528
- return new SaplingStateAbstraction(new BigNumber(val.int), provider);
2529
- }
2530
- },
2531
- /*
2532
- // TODO: embed useful other abstractions
2533
- 'contract': () => {},
2534
- 'address': () => {}
2535
- */
2536
- });
2537
-
2538
2634
  var _PrepareProvider_counters;
2635
+ const BigNumber$7 = BigNumberJs;
2539
2636
  const mergeLimits = (userDefinedLimit, defaultLimits) => {
2540
2637
  return {
2541
2638
  fee: userDefinedLimit.fee ?? defaultLimits.fee,
@@ -2562,15 +2659,15 @@
2562
2659
  async getHeadCounter(pkh) {
2563
2660
  return this.context.readProvider.getCounter(pkh, 'head') ?? '0';
2564
2661
  }
2565
- adjustGasForManagerOperations(gasLimitBlock, gaslimitOp, opsNeedingGasLimitPatch, explicitGasLimitTotal = new BigNumber(0)) {
2662
+ adjustGasForManagerOperations(gasLimitBlock, gaslimitOp, opsNeedingGasLimitPatch, explicitGasLimitTotal = new BigNumber$7(0)) {
2566
2663
  if (opsNeedingGasLimitPatch <= 0) {
2567
2664
  return gaslimitOp;
2568
2665
  }
2569
2666
  const remainingBlockGas = gasLimitBlock.minus(explicitGasLimitTotal);
2570
2667
  if (remainingBlockGas.lte(0)) {
2571
- return new BigNumber(0);
2668
+ return new BigNumber$7(0);
2572
2669
  }
2573
- return BigNumber.min(gaslimitOp, remainingBlockGas.div(opsNeedingGasLimitPatch).integerValue(BigNumber.ROUND_DOWN));
2670
+ return BigNumber$7.min(gaslimitOp, remainingBlockGas.div(opsNeedingGasLimitPatch).integerValue(BigNumber$7.ROUND_DOWN));
2574
2671
  }
2575
2672
  getOperationLimits(constants, options = {}) {
2576
2673
  const { hard_gas_limit_per_operation, hard_gas_limit_per_block, hard_storage_limit_per_operation, } = constants;
@@ -2585,7 +2682,7 @@
2585
2682
  return this.getOperationLimits(constants, {
2586
2683
  opsNeedingGasLimitPatch: typeof gasLimit === 'undefined' ? 1 : 0,
2587
2684
  explicitGasLimitTotal: revealNeeded
2588
- ? new BigNumber(getRevealGasLimit(publicKeyHash))
2685
+ ? new BigNumber$7(getRevealGasLimit(publicKeyHash))
2589
2686
  : undefined,
2590
2687
  });
2591
2688
  }
@@ -3415,7 +3512,7 @@
3415
3512
  const { pkh, publicKey } = await this.getKeys();
3416
3513
  const protocolConstants = await this.context.readProvider.getProtocolConstants('head');
3417
3514
  const revealNeeded = await this.isRevealOpNeeded(batchParams, pkh);
3418
- const explicitGasLimitTotal = batchParams.reduce((acc, op) => isOpWithFee(op) && typeof op.gasLimit !== 'undefined' ? acc.plus(op.gasLimit) : acc, revealNeeded ? new BigNumber(getRevealGasLimit(pkh)) : new BigNumber(0));
3515
+ const explicitGasLimitTotal = batchParams.reduce((acc, op) => isOpWithFee(op) && typeof op.gasLimit !== 'undefined' ? acc.plus(op.gasLimit) : acc, revealNeeded ? new BigNumber$7(getRevealGasLimit(pkh)) : new BigNumber$7(0));
3419
3516
  const DEFAULT_PARAMS = this.getOperationLimits(protocolConstants, {
3420
3517
  opsNeedingGasLimitPatch: batchParams.filter((op) => isOpWithFee(op) && typeof op.gasLimit === 'undefined').length,
3421
3518
  explicitGasLimitTotal,
@@ -4422,6 +4519,7 @@
4422
4519
  rpc.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE,
4423
4520
  ];
4424
4521
 
4522
+ const BigNumber$6 = BigNumberJs;
4425
4523
  class BatchOperation extends Operation {
4426
4524
  constructor(hash, params, source, raw, results, context) {
4427
4525
  super(hash, raw, results, context);
@@ -4466,8 +4564,8 @@
4466
4564
  return this.sumProp(this.params, 'storage_limit');
4467
4565
  }
4468
4566
  get consumedGas() {
4469
- BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
4470
- return new BigNumber(this.consumedMilliGas).dividedBy(1000).toString();
4567
+ BigNumber$6.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$6.ROUND_UP });
4568
+ return new BigNumber$6(this.consumedMilliGas).dividedBy(1000).toString();
4471
4569
  }
4472
4570
  get consumedMilliGas() {
4473
4571
  return String(this.sumProp(flattenOperationResult({ contents: this.results }), 'consumed_milligas'));
@@ -4794,6 +4892,7 @@
4794
4892
  }
4795
4893
  }
4796
4894
 
4895
+ const BigNumber$5 = BigNumberJs.BigNumber;
4797
4896
  /**
4798
4897
  * Delegation operation provide utility function to fetch newly issued delegation
4799
4898
  *
@@ -4830,9 +4929,9 @@
4830
4929
  return Number(this.params.storage_limit);
4831
4930
  }
4832
4931
  get consumedGas() {
4833
- BigNumber.BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.BigNumber.ROUND_UP });
4932
+ BigNumber$5.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$5.ROUND_UP });
4834
4933
  return this.consumedMilliGas
4835
- ? new BigNumber.BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
4934
+ ? new BigNumber$5(this.consumedMilliGas).dividedBy(1000).toString()
4836
4935
  : undefined;
4837
4936
  }
4838
4937
  get consumedMilliGas() {
@@ -4843,6 +4942,7 @@
4843
4942
  }
4844
4943
  }
4845
4944
 
4945
+ const BigNumber$4 = BigNumberJs.BigNumber;
4846
4946
  /**
4847
4947
  * Origination operation provide utility function to fetch newly originated contract
4848
4948
  *
@@ -4879,9 +4979,9 @@
4879
4979
  return Number(this.params.storage_limit);
4880
4980
  }
4881
4981
  get consumedGas() {
4882
- BigNumber.BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.BigNumber.ROUND_UP });
4982
+ BigNumber$4.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$4.ROUND_UP });
4883
4983
  return this.consumedMilliGas
4884
- ? new BigNumber.BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
4984
+ ? new BigNumber$4(this.consumedMilliGas).dividedBy(1000).toString()
4885
4985
  : undefined;
4886
4986
  }
4887
4987
  get consumedMilliGas() {
@@ -4910,10 +5010,15 @@
4910
5010
  if (!Number.isFinite(this.includedInBlock)) {
4911
5011
  throw new OriginationOperationError('Confirmation completed but includedInBlock was not set');
4912
5012
  }
4913
- return this.contractProvider.at(this.contractAddress, undefined, this.includedInBlock);
5013
+ const inclusionBlock = await this.getInclusionBlock();
5014
+ if (!isBlockHashIdentifier(inclusionBlock.hash)) {
5015
+ throw new OriginationOperationError('Confirmation completed but includedInBlock was not set');
5016
+ }
5017
+ return this.contractProvider.at(this.contractAddress, undefined, inclusionBlock.hash);
4914
5018
  }
4915
5019
  }
4916
5020
 
5021
+ const BigNumber$3 = BigNumberJs.BigNumber;
4917
5022
  /**
4918
5023
  * RegisterGlobalConstantOperation provides utility functions to fetch a newly issued operation of kind register_global_constant
4919
5024
  */
@@ -4951,9 +5056,9 @@
4951
5056
  return this.operationResults?.errors;
4952
5057
  }
4953
5058
  get consumedGas() {
4954
- BigNumber.BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.BigNumber.ROUND_UP });
5059
+ BigNumber$3.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$3.ROUND_UP });
4955
5060
  return this.consumedMilliGas
4956
- ? new BigNumber.BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
5061
+ ? new BigNumber$3(this.consumedMilliGas).dividedBy(1000).toString()
4957
5062
  : undefined;
4958
5063
  }
4959
5064
  get consumedMilliGas() {
@@ -4961,6 +5066,7 @@
4961
5066
  }
4962
5067
  }
4963
5068
 
5069
+ const BigNumber$2 = BigNumberJs.BigNumber;
4964
5070
  /**
4965
5071
  * Reveal operation provides utility functions to fetch a newly issued revelation
4966
5072
  */
@@ -5011,8 +5117,8 @@
5011
5117
  }, 0);
5012
5118
  }
5013
5119
  get consumedGas() {
5014
- BigNumber.BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.BigNumber.ROUND_UP });
5015
- return new BigNumber.BigNumber(this.consumedMilliGas).dividedBy(1000).toString();
5120
+ BigNumber$2.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$2.ROUND_UP });
5121
+ return new BigNumber$2(this.consumedMilliGas).dividedBy(1000).toString();
5016
5122
  }
5017
5123
  get consumedMilliGas() {
5018
5124
  return String(this.sumProp(flattenOperationResult({ contents: this.operationResults }), 'consumed_milligas'));
@@ -5028,6 +5134,7 @@
5028
5134
  }
5029
5135
  }
5030
5136
 
5137
+ const BigNumber$1 = BigNumberJs;
5031
5138
  /**
5032
5139
  * Transaction operation provides utility functions to fetch a newly issued transaction
5033
5140
  *
@@ -5055,7 +5162,7 @@
5055
5162
  }
5056
5163
  }
5057
5164
  get amount() {
5058
- return new BigNumber(this.params.amount);
5165
+ return new BigNumber$1(this.params.amount);
5059
5166
  }
5060
5167
  get destination() {
5061
5168
  return this.params.destination;
@@ -5075,8 +5182,8 @@
5075
5182
  }, 0);
5076
5183
  }
5077
5184
  get consumedGas() {
5078
- BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
5079
- return new BigNumber(this.consumedMilliGas).dividedBy(1000).toString();
5185
+ BigNumber$1.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$1.ROUND_UP });
5186
+ return new BigNumber$1(this.consumedMilliGas).dividedBy(1000).toString();
5080
5187
  }
5081
5188
  get consumedMilliGas() {
5082
5189
  return String(this.sumProp(flattenOperationResult({ contents: this.operationResults }), 'consumed_milligas'));
@@ -5092,6 +5199,7 @@
5092
5199
  }
5093
5200
  }
5094
5201
 
5202
+ const BigNumber = BigNumberJs.BigNumber;
5095
5203
  /**
5096
5204
  *
5097
5205
  * Transfer tickets from a Tezos address (tz1, tz2 or tz3) to a smart contract address (KT1) (everything on layer 1 at this step)
@@ -5123,9 +5231,9 @@
5123
5231
  return Number(this.params.storage_limit);
5124
5232
  }
5125
5233
  get consumedGas() {
5126
- BigNumber.BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.BigNumber.ROUND_UP });
5234
+ BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
5127
5235
  return this.consumedMilliGas
5128
- ? new BigNumber.BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
5236
+ ? new BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
5129
5237
  : undefined;
5130
5238
  }
5131
5239
  get consumedMilliGas() {
@@ -5491,6 +5599,30 @@
5491
5599
  }
5492
5600
  }
5493
5601
 
5602
+ const CONTRACT_READ_RETRY_DELAYS_MS = [0, 200, 400, 800];
5603
+ const sleep = (durationMs) => new Promise((resolve) => {
5604
+ setTimeout(resolve, durationMs);
5605
+ });
5606
+ const isNotFoundError = (error) => error instanceof httpUtils.HttpResponseError && error.status === httpUtils.STATUS_CODE.NOT_FOUND;
5607
+ const retryOnNotFound = async (read, retryDelaysMs = CONTRACT_READ_RETRY_DELAYS_MS) => {
5608
+ let lastError;
5609
+ for (const delayMs of retryDelaysMs) {
5610
+ if (delayMs > 0) {
5611
+ await sleep(delayMs);
5612
+ }
5613
+ try {
5614
+ return await read();
5615
+ }
5616
+ catch (error) {
5617
+ if (!isNotFoundError(error)) {
5618
+ throw error;
5619
+ }
5620
+ lastError = error;
5621
+ }
5622
+ }
5623
+ throw lastError;
5624
+ };
5625
+
5494
5626
  class RpcContractProvider extends Provider {
5495
5627
  constructor(context, estimator) {
5496
5628
  super(context);
@@ -5507,12 +5639,14 @@
5507
5639
  * @throws {@link InvalidContractAddressError}
5508
5640
  * @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
5509
5641
  */
5510
- async getStorage(contract, schema) {
5642
+ async getStorage(contract, schema, block = 'head') {
5511
5643
  const contractValidation = utils.validateContractAddress(contract);
5512
5644
  if (contractValidation !== utils.ValidationResult.VALID) {
5513
5645
  throw new core.InvalidContractAddressError(contract, contractValidation);
5514
5646
  }
5515
- const script = await this.context.readProvider.getScript(contract, 'head');
5647
+ const script = block === 'head'
5648
+ ? await retryOnNotFound(() => this.context.readProvider.getScript(contract, 'head'))
5649
+ : await this.context.readProvider.getScript(contract, block);
5516
5650
  if (!schema) {
5517
5651
  schema = script;
5518
5652
  }
@@ -5523,7 +5657,7 @@
5523
5657
  else {
5524
5658
  contractSchema = michelsonEncoder.Schema.fromRPCResponse({ script: schema });
5525
5659
  }
5526
- return contractSchema.Execute(script.storage, smartContractAbstractionSemantic(this)); // Cast into T because only the caller can know the true type of the storage
5660
+ return contractSchema.Execute(script.storage, smartContractAbstractionSemantic(this, block)); // Cast into T because only the caller can know the true type of the storage
5527
5661
  }
5528
5662
  /**
5529
5663
  *
@@ -5540,10 +5674,9 @@
5540
5674
  const { key, type } = schema.EncodeBigMapKey(keyToEncode);
5541
5675
  const { packed } = await this.context.packer.packData({ data: key, type });
5542
5676
  const encodedExpr = utils.encodeExpr(packed);
5543
- const bigMapValue = block
5544
- ? await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, block)
5545
- : await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, 'head');
5546
- return schema.ExecuteOnBigMapValue(bigMapValue, smartContractAbstractionSemantic(this));
5677
+ const requestedBlock = block ?? 'head';
5678
+ const bigMapValue = await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, requestedBlock);
5679
+ return schema.ExecuteOnBigMapValue(bigMapValue, smartContractAbstractionSemantic(this, requestedBlock));
5547
5680
  }
5548
5681
  /**
5549
5682
  *
@@ -5603,11 +5736,8 @@
5603
5736
  * @param block optional block level to fetch the value from
5604
5737
  *
5605
5738
  */
5606
- async getSaplingDiffByID(id, block) {
5607
- const saplingState = block
5608
- ? await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
5609
- : await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
5610
- return saplingState;
5739
+ async getSaplingDiffByID(id, block = 'head') {
5740
+ return this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block);
5611
5741
  }
5612
5742
  /**
5613
5743
  *
@@ -6107,17 +6237,28 @@
6107
6237
  catch (error) {
6108
6238
  // Shadownet's rolling nodes occasionally 404 a just-originated contract at the exact
6109
6239
  // inclusion level even after confirmation. Retry at head so the contract abstraction still
6110
- // resolves once the node's contract index catches up.
6111
- if (block !== 'head' &&
6112
- error instanceof httpUtils.HttpResponseError &&
6113
- error.status === httpUtils.STATUS_CODE.NOT_FOUND) {
6114
- contractState = await loadContractState('head');
6240
+ // resolves once the node's contract index catches up. The head index can lag briefly too,
6241
+ // so give it a few bounded retries before surfacing the 404.
6242
+ if (block !== 'head' && isNotFoundError(error)) {
6243
+ contractState = await retryOnNotFound(() => loadContractState('head'));
6115
6244
  }
6116
6245
  else {
6117
6246
  throw error;
6118
6247
  }
6119
6248
  }
6120
- const abs = new ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider);
6249
+ const abs = new ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider, 'head');
6250
+ return contractAbstractionComposer(abs, this.context);
6251
+ }
6252
+ async atExactBlock(address, contractAbstractionComposer = (x) => x, block) {
6253
+ const addressValidation = utils.validateContractAddress(address);
6254
+ if (addressValidation !== utils.ValidationResult.VALID) {
6255
+ throw new core.InvalidContractAddressError(address, addressValidation);
6256
+ }
6257
+ const rpc = this.context.withExtensions().rpc;
6258
+ const readProvider = this.context.withExtensions().readProvider;
6259
+ const script = await readProvider.getScript(address, block);
6260
+ const entrypoints = await rpc.getEntrypoints(address, { block: String(block) });
6261
+ const abs = new ContractAbstraction(address, script, this, this, entrypoints, rpc, readProvider, block);
6121
6262
  return contractAbstractionComposer(abs, this.context);
6122
6263
  }
6123
6264
  /**
@@ -6558,17 +6699,28 @@
6558
6699
  // Newly originated contracts can be visible at the operation's inclusion level in one RPC
6559
6700
  // call and still lag on another endpoint of the same rolling node. Retry at head so
6560
6701
  // wallet op.contract() behaves like octez-client, which resolves the originated contract
6561
- // after confirmation instead of pinning itself to a stale context forever.
6562
- if (block !== 'head' &&
6563
- error instanceof httpUtils.HttpResponseError &&
6564
- error.status === httpUtils.STATUS_CODE.NOT_FOUND) {
6565
- contractState = await loadContractState('head');
6702
+ // after confirmation instead of pinning itself to a stale context forever. The head index
6703
+ // can lag briefly as well, so bound a few retries there too.
6704
+ if (block !== 'head' && isNotFoundError(error)) {
6705
+ contractState = await retryOnNotFound(() => loadContractState('head'));
6566
6706
  }
6567
6707
  else {
6568
6708
  throw error;
6569
6709
  }
6570
6710
  }
6571
- const abs = new ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider);
6711
+ const abs = new ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider, 'head');
6712
+ return contractAbstractionComposer(abs, this.context);
6713
+ }
6714
+ async atExactBlock(address, contractAbstractionComposer = (x) => x, block) {
6715
+ const addressValidation = utils.validateContractAddress(address);
6716
+ if (addressValidation !== utils.ValidationResult.VALID) {
6717
+ throw new core.InvalidContractAddressError(address, addressValidation);
6718
+ }
6719
+ const rpc = this.context.withExtensions().rpc;
6720
+ const readProvider = this.context.withExtensions().readProvider;
6721
+ const script = await readProvider.getScript(address, block);
6722
+ const entrypoints = await rpc.getEntrypoints(address, { block: String(block) });
6723
+ const abs = new ContractAbstraction(address, script, this, this.context.contract, entrypoints, rpc, readProvider, block);
6572
6724
  return contractAbstractionComposer(abs, this.context);
6573
6725
  }
6574
6726
  }
@@ -7209,7 +7361,7 @@
7209
7361
  const constants = await this.context.readProvider.getProtocolConstants('head');
7210
7362
  const blockTime = constants.minimal_block_delay
7211
7363
  ? constants.minimal_block_delay.multipliedBy(1000)
7212
- : new BigNumber(defaultIntervalTestnetsMainnet);
7364
+ : new BigNumberJs(defaultIntervalTestnetsMainnet);
7213
7365
  const confirmationPollingInterval = blockTime.dividedBy(3);
7214
7366
  this.config.pollingIntervalMilliseconds =
7215
7367
  confirmationPollingInterval.toNumber() === 0
@@ -7413,8 +7565,8 @@
7413
7565
 
7414
7566
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
7415
7567
  const VERSION = {
7416
- "commitHash": "fb73f1546d3dff2fbba7741ca6006680212bef16",
7417
- "version": "24.3.0-beta.2"
7568
+ "commitHash": "768729af84b0c773f536e6fbb3acb02ab656d88d",
7569
+ "version": "24.3.0-beta.4"
7418
7570
  };
7419
7571
 
7420
7572
  /**