@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.
- package/README.md +1 -1
- package/dist/lib/contract/big-map.js +6 -3
- package/dist/lib/contract/contract.js +8 -3
- package/dist/lib/contract/not-found-retry.js +29 -0
- package/dist/lib/contract/rpc-contract-provider.js +28 -18
- package/dist/lib/contract/sapling-state-abstraction.js +5 -2
- package/dist/lib/contract/semantic.js +4 -4
- package/dist/lib/estimate/rpc-estimate-provider.js +2 -0
- package/dist/lib/operations/batch-operation.js +3 -2
- package/dist/lib/operations/delegate-operation.js +3 -2
- package/dist/lib/operations/operations.js +12 -2
- package/dist/lib/operations/origination-operation.js +9 -3
- package/dist/lib/operations/register-global-constant-operation.js +3 -2
- package/dist/lib/operations/reveal-operation.js +3 -2
- package/dist/lib/operations/transaction-operation.js +4 -3
- package/dist/lib/operations/transfer-ticket-operation.js +3 -2
- package/dist/lib/prepare/prepare-provider.js +6 -5
- package/dist/lib/provider.js +82 -10
- package/dist/lib/read-provider/interface.js +8 -0
- package/dist/lib/read-provider/rpc-read-adapter.js +2 -0
- package/dist/lib/tz/interface.js +2 -0
- package/dist/lib/tz/rpc-tz-provider.js +2 -0
- package/dist/lib/version.js +2 -2
- package/dist/lib/wallet/origination-operation.js +5 -1
- package/dist/lib/wallet/receipt.js +9 -8
- package/dist/lib/wallet/wallet.js +18 -7
- package/dist/taquito.es6.js +333 -181
- package/dist/taquito.es6.js.map +1 -1
- package/dist/taquito.min.js +1 -1
- package/dist/taquito.umd.js +332 -180
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/contract/big-map.d.ts +10 -5
- package/dist/types/contract/contract.d.ts +3 -2
- package/dist/types/contract/interface.d.ts +5 -4
- package/dist/types/contract/not-found-retry.d.ts +3 -0
- package/dist/types/contract/rpc-contract-provider.d.ts +5 -4
- package/dist/types/contract/sapling-state-abstraction.d.ts +9 -4
- package/dist/types/contract/semantic.d.ts +4 -3
- package/dist/types/operations/operations.d.ts +4 -1
- package/dist/types/operations/transaction-operation.d.ts +2 -2
- package/dist/types/provider.d.ts +4 -1
- package/dist/types/read-provider/interface.d.ts +5 -1
- package/dist/types/read-provider/rpc-read-adapter.d.ts +4 -1
- package/dist/types/tz/interface.d.ts +4 -1
- package/dist/types/tz/rpc-tz-provider.d.ts +4 -1
- package/dist/types/wallet/receipt.d.ts +4 -1
- package/dist/types/wallet/wallet.d.ts +1 -0
- package/package.json +15 -17
- package/signature.json +0 -866
package/dist/taquito.es6.js
CHANGED
|
@@ -4,8 +4,8 @@ import { HttpResponseError, STATUS_CODE } from '@taquito/http-utils';
|
|
|
4
4
|
import { TezosToolkitConfigError, ParameterValidationError, RpcError, TaquitoError, NetworkError, InvalidOperationHashError, InvalidViewParameterError, DeprecationError, InvalidChainIdError, PublicKeyNotFoundError, InvalidOperationKindError as InvalidOperationKindError$1, ProhibitedActionError, InvalidProofError, InvalidAddressError, InvalidAmountError, InvalidStakingAddressError, InvalidKeyHashError as InvalidKeyHashError$1, InvalidContractAddressError, InvalidFinalizeUnstakeAmountError } from '@taquito/core';
|
|
5
5
|
import { Observable, ReplaySubject, range, of, combineLatest, from, defer, concat, BehaviorSubject, throwError, EMPTY, Subject, NEVER, timer } from 'rxjs';
|
|
6
6
|
import { first, switchMap, concatMap, endWith, tap, share, map, filter, catchError, distinctUntilChanged, takeWhile, startWith, timeout, mergeMap, shareReplay, takeUntil, retry, exhaustMap, distinctUntilKeyChanged } from 'rxjs/operators';
|
|
7
|
-
import
|
|
8
|
-
import { validateOperation, ValidationResult, format, InvalidOperationKindError, validateAddress, validateChain, validateContractAddress, b58DecodeAndCheckPrefix, publicKeyHashPrefixes, PrefixV2, publicKeyPrefixes, validateKeyHash, InvalidKeyHashError, payloadLength, encodeExpr } from '@taquito/utils';
|
|
7
|
+
import BigNumberJs, { BigNumber as BigNumber$9 } from 'bignumber.js';
|
|
8
|
+
import { validateOperation, ValidationResult, validateBlock, format, InvalidOperationKindError, validateAddress, validateChain, validateContractAddress, b58DecodeAndCheckPrefix, publicKeyHashPrefixes, PrefixV2, publicKeyPrefixes, validateKeyHash, InvalidKeyHashError, payloadLength, encodeExpr } from '@taquito/utils';
|
|
9
9
|
import { Schema, ParameterSchema, ViewSchema, EventSchema, MichelsonMap, Token } from '@taquito/michelson-encoder';
|
|
10
10
|
export { MichelsonMap, Token, UnitValue } from '@taquito/michelson-encoder';
|
|
11
11
|
import { Parser, packDataBytes } from '@taquito/michel-codec';
|
|
@@ -424,18 +424,19 @@ class InvalidEstimateValueError extends ParameterValidationError {
|
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
const BigNumber$8 = BigNumberJs;
|
|
427
428
|
const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
|
|
428
429
|
ALLOCATION_BURN: 257,
|
|
429
430
|
ORIGINATION_BURN: 257,
|
|
430
431
|
}) => {
|
|
431
|
-
BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
|
|
432
|
+
BigNumber$8.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$8.ROUND_UP });
|
|
432
433
|
const operationResults = flattenOperationResult({ contents: op });
|
|
433
|
-
let totalMilliGas = new BigNumber(0);
|
|
434
|
-
let totalStorage = new BigNumber(0);
|
|
435
|
-
let totalFee = new BigNumber(0);
|
|
436
|
-
let totalOriginationBurn = new BigNumber(0);
|
|
437
|
-
let totalAllocationBurn = new BigNumber(0);
|
|
438
|
-
let totalPaidStorageDiff = new BigNumber(0);
|
|
434
|
+
let totalMilliGas = new BigNumber$8(0);
|
|
435
|
+
let totalStorage = new BigNumber$8(0);
|
|
436
|
+
let totalFee = new BigNumber$8(0);
|
|
437
|
+
let totalOriginationBurn = new BigNumber$8(0);
|
|
438
|
+
let totalAllocationBurn = new BigNumber$8(0);
|
|
439
|
+
let totalPaidStorageDiff = new BigNumber$8(0);
|
|
439
440
|
operationResults.forEach((result) => {
|
|
440
441
|
totalFee = totalFee.plus(result.fee || 0);
|
|
441
442
|
totalOriginationBurn = totalOriginationBurn.plus(Array.isArray(result.originated_contracts)
|
|
@@ -457,7 +458,7 @@ const receiptFromOperation = (op, { ALLOCATION_BURN, ORIGINATION_BURN } = {
|
|
|
457
458
|
totalAllocationBurn,
|
|
458
459
|
totalOriginationBurn,
|
|
459
460
|
totalPaidStorageDiff,
|
|
460
|
-
totalStorageBurn: new BigNumber(totalStorage.multipliedBy(COST_PER_BYTE)),
|
|
461
|
+
totalStorageBurn: new BigNumber$8(totalStorage.multipliedBy(COST_PER_BYTE)),
|
|
461
462
|
};
|
|
462
463
|
};
|
|
463
464
|
|
|
@@ -878,6 +879,10 @@ class IncreasePaidStorageWalletOperation extends WalletOperation {
|
|
|
878
879
|
}
|
|
879
880
|
}
|
|
880
881
|
|
|
882
|
+
const isBlockHashIdentifier = (block) => {
|
|
883
|
+
return validateBlock(block) === ValidationResult.VALID;
|
|
884
|
+
};
|
|
885
|
+
|
|
881
886
|
class OriginationWalletOperation extends WalletOperation {
|
|
882
887
|
constructor(opHash, context, newHead$) {
|
|
883
888
|
super(opHash, context, newHead$);
|
|
@@ -920,7 +925,10 @@ class OriginationWalletOperation extends WalletOperation {
|
|
|
920
925
|
}
|
|
921
926
|
await this.confirmation();
|
|
922
927
|
const inclusionBlock = await this.getInclusionBlock();
|
|
923
|
-
|
|
928
|
+
if (!isBlockHashIdentifier(inclusionBlock.hash)) {
|
|
929
|
+
throw new OriginationWalletOperationError('Inclusion block hash is invalid');
|
|
930
|
+
}
|
|
931
|
+
return this.context.wallet.at(address, undefined, inclusionBlock.hash);
|
|
924
932
|
}
|
|
925
933
|
}
|
|
926
934
|
|
|
@@ -1156,6 +1164,13 @@ class Operation {
|
|
|
1156
1164
|
get includedInBlock() {
|
|
1157
1165
|
return this._foundAt;
|
|
1158
1166
|
}
|
|
1167
|
+
async getInclusionBlock() {
|
|
1168
|
+
const inclusionBlock = await this._includedInBlock.pipe(first()).toPromise();
|
|
1169
|
+
if (!inclusionBlock) {
|
|
1170
|
+
throw new Error('Inclusion block is undefined');
|
|
1171
|
+
}
|
|
1172
|
+
return inclusionBlock;
|
|
1173
|
+
}
|
|
1159
1174
|
/**
|
|
1160
1175
|
*
|
|
1161
1176
|
* @param hash Operation hash
|
|
@@ -1169,6 +1184,7 @@ class Operation {
|
|
|
1169
1184
|
this.results = results;
|
|
1170
1185
|
this.context = context;
|
|
1171
1186
|
this._pollingConfig$ = new ReplaySubject(1);
|
|
1187
|
+
this._includedInBlock = new ReplaySubject(1);
|
|
1172
1188
|
this.currentHead$ = this._pollingConfig$.pipe(switchMap((config) => {
|
|
1173
1189
|
return new BehaviorSubject(config).pipe(timeout({
|
|
1174
1190
|
each: config.timeout * 1000,
|
|
@@ -1183,11 +1199,13 @@ class Operation {
|
|
|
1183
1199
|
// Observable that emit once operation is seen in a block
|
|
1184
1200
|
this.confirmed$ = this.currentHead$.pipe(map((head) => {
|
|
1185
1201
|
for (let i = 3; i >= 0; i--) {
|
|
1186
|
-
head.operations[i]
|
|
1202
|
+
for (const op of head.operations[i]) {
|
|
1187
1203
|
if (op.hash === this.hash) {
|
|
1188
1204
|
this._foundAt = head.header.level;
|
|
1205
|
+
this._includedInBlock.next(head);
|
|
1206
|
+
return this._foundAt;
|
|
1189
1207
|
}
|
|
1190
|
-
}
|
|
1208
|
+
}
|
|
1191
1209
|
}
|
|
1192
1210
|
if (head.header.level - this._foundAt >= 0) {
|
|
1193
1211
|
return this._foundAt;
|
|
@@ -1615,6 +1633,12 @@ const createSmartRollupExecuteOutboxMessageOperation = async ({ source, fee, gas
|
|
|
1615
1633
|
};
|
|
1616
1634
|
|
|
1617
1635
|
class Provider {
|
|
1636
|
+
clearRpcCache() {
|
|
1637
|
+
const rpc = this.context.rpc;
|
|
1638
|
+
if (typeof rpc.deleteAllCachedData === 'function') {
|
|
1639
|
+
rpc.deleteAllCachedData();
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1618
1642
|
parseRpcErrors(error) {
|
|
1619
1643
|
if (!(error instanceof HttpResponseError)) {
|
|
1620
1644
|
return [];
|
|
@@ -1650,7 +1674,7 @@ class Provider {
|
|
|
1650
1674
|
}
|
|
1651
1675
|
}
|
|
1652
1676
|
}
|
|
1653
|
-
|
|
1677
|
+
parseCounterAdjustments(error) {
|
|
1654
1678
|
return this.parseRpcErrors(error)
|
|
1655
1679
|
.filter((value) => {
|
|
1656
1680
|
const id = value.id;
|
|
@@ -1658,7 +1682,8 @@ class Provider {
|
|
|
1658
1682
|
const expected = value.expected;
|
|
1659
1683
|
const found = value.found;
|
|
1660
1684
|
return (typeof id === 'string' &&
|
|
1661
|
-
id.endsWith('contract.counter_in_the_past')
|
|
1685
|
+
(id.endsWith('contract.counter_in_the_past') ||
|
|
1686
|
+
id.endsWith('contract.counter_in_the_future')) &&
|
|
1662
1687
|
typeof contract === 'string' &&
|
|
1663
1688
|
typeof expected === 'string' &&
|
|
1664
1689
|
typeof found === 'string');
|
|
@@ -1668,7 +1693,7 @@ class Provider {
|
|
|
1668
1693
|
expected: BigInt(value.expected),
|
|
1669
1694
|
found: BigInt(value.found),
|
|
1670
1695
|
}))
|
|
1671
|
-
.filter((value) => value.expected
|
|
1696
|
+
.filter((value) => value.expected !== value.found);
|
|
1672
1697
|
}
|
|
1673
1698
|
hasGasLimitTooHighAndBlockExhausted(error) {
|
|
1674
1699
|
const ids = this.parseRpcErrors(error)
|
|
@@ -1891,7 +1916,7 @@ class Provider {
|
|
|
1891
1916
|
};
|
|
1892
1917
|
}
|
|
1893
1918
|
catch (error) {
|
|
1894
|
-
const adjustments = this.
|
|
1919
|
+
const adjustments = this.parseCounterAdjustments(error);
|
|
1895
1920
|
const patchedOp = this.patchSimulationCounters(op, adjustments);
|
|
1896
1921
|
if (patchedOp) {
|
|
1897
1922
|
try {
|
|
@@ -1942,11 +1967,21 @@ class Provider {
|
|
|
1942
1967
|
return opRequireReveal;
|
|
1943
1968
|
}
|
|
1944
1969
|
async signAndInject(forgedBytes) {
|
|
1945
|
-
|
|
1946
|
-
forgedBytes.opbytes = signed.sbytes;
|
|
1947
|
-
forgedBytes.opOb.signature = signed.prefixSig;
|
|
1970
|
+
let signedForgedBytes = await this.signForgedBytes(forgedBytes);
|
|
1948
1971
|
const opResponse = [];
|
|
1949
|
-
|
|
1972
|
+
let results;
|
|
1973
|
+
try {
|
|
1974
|
+
results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
|
|
1975
|
+
}
|
|
1976
|
+
catch (error) {
|
|
1977
|
+
const adjustments = this.parseCounterAdjustments(error);
|
|
1978
|
+
const patchedForgedBytes = await this.patchForgedBytesCounters(signedForgedBytes, adjustments);
|
|
1979
|
+
if (!patchedForgedBytes) {
|
|
1980
|
+
throw error;
|
|
1981
|
+
}
|
|
1982
|
+
signedForgedBytes = await this.signForgedBytes(patchedForgedBytes);
|
|
1983
|
+
results = await this.rpc.preapplyOperations([signedForgedBytes.opOb]);
|
|
1984
|
+
}
|
|
1950
1985
|
if (!Array.isArray(results)) {
|
|
1951
1986
|
throw new TezosPreapplyFailureError(results);
|
|
1952
1987
|
}
|
|
@@ -1959,13 +1994,68 @@ class Provider {
|
|
|
1959
1994
|
if (errors.length) {
|
|
1960
1995
|
throw new TezosOperationError(errors, 'Error occurred during validation simulation of operation', opResponse);
|
|
1961
1996
|
}
|
|
1997
|
+
const hash = await this.context.injector.inject(signedForgedBytes.opbytes);
|
|
1998
|
+
this.clearRpcCache();
|
|
1962
1999
|
return {
|
|
1963
|
-
hash
|
|
1964
|
-
forgedBytes,
|
|
2000
|
+
hash,
|
|
2001
|
+
forgedBytes: signedForgedBytes,
|
|
1965
2002
|
opResponse,
|
|
1966
2003
|
context: this.context.clone(),
|
|
1967
2004
|
};
|
|
1968
2005
|
}
|
|
2006
|
+
async signForgedBytes(forgedBytes) {
|
|
2007
|
+
const signed = await this.signer.sign(forgedBytes.opbytes, new Uint8Array([3]));
|
|
2008
|
+
return {
|
|
2009
|
+
...forgedBytes,
|
|
2010
|
+
opbytes: signed.sbytes,
|
|
2011
|
+
opOb: {
|
|
2012
|
+
...forgedBytes.opOb,
|
|
2013
|
+
signature: signed.prefixSig,
|
|
2014
|
+
},
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
async patchForgedBytesCounters(forgedBytes, adjustments) {
|
|
2018
|
+
if (adjustments.length === 0 || !Array.isArray(forgedBytes.opOb.contents)) {
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
const branch = forgedBytes.opOb.branch;
|
|
2022
|
+
if (typeof branch !== 'string') {
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
const contents = forgedBytes.opOb.contents.map((content) => ({ ...content }));
|
|
2026
|
+
let patched = false;
|
|
2027
|
+
for (const adjustment of adjustments) {
|
|
2028
|
+
const delta = adjustment.expected - adjustment.found;
|
|
2029
|
+
for (const content of contents) {
|
|
2030
|
+
const source = content.source;
|
|
2031
|
+
const counter = content.counter;
|
|
2032
|
+
if (source !== adjustment.contract || typeof counter === 'undefined') {
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
const contentCounter = BigInt(String(counter));
|
|
2036
|
+
if (contentCounter < adjustment.found) {
|
|
2037
|
+
continue;
|
|
2038
|
+
}
|
|
2039
|
+
content.counter = (contentCounter + delta).toString();
|
|
2040
|
+
patched = true;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (!patched) {
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
const unsignedOpBytes = await this.context.forger.forge({
|
|
2047
|
+
branch,
|
|
2048
|
+
contents,
|
|
2049
|
+
});
|
|
2050
|
+
return {
|
|
2051
|
+
...forgedBytes,
|
|
2052
|
+
opbytes: unsignedOpBytes,
|
|
2053
|
+
opOb: {
|
|
2054
|
+
...forgedBytes.opOb,
|
|
2055
|
+
contents,
|
|
2056
|
+
},
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
1969
2059
|
}
|
|
1970
2060
|
|
|
1971
2061
|
/******************************************************************************
|
|
@@ -2191,6 +2281,115 @@ class ContractMethodFactory {
|
|
|
2191
2281
|
}
|
|
2192
2282
|
}
|
|
2193
2283
|
|
|
2284
|
+
class BigMapAbstraction {
|
|
2285
|
+
constructor(id, schema, provider, defaultBlock) {
|
|
2286
|
+
this.id = id;
|
|
2287
|
+
this.schema = schema;
|
|
2288
|
+
this.provider = provider;
|
|
2289
|
+
this.defaultBlock = defaultBlock;
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
*
|
|
2293
|
+
* Fetch one value in a big map
|
|
2294
|
+
*
|
|
2295
|
+
* @param keyToEncode Key to query (will be encoded properly according to the schema)
|
|
2296
|
+
* @param block optional block level to fetch the values from (head will be use by default)
|
|
2297
|
+
* @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map
|
|
2298
|
+
*
|
|
2299
|
+
*/
|
|
2300
|
+
async get(keyToEncode, block) {
|
|
2301
|
+
try {
|
|
2302
|
+
const id = await this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block ?? this.defaultBlock);
|
|
2303
|
+
return id;
|
|
2304
|
+
}
|
|
2305
|
+
catch (e) {
|
|
2306
|
+
if (e instanceof HttpResponseError && e.status === STATUS_CODE.NOT_FOUND) {
|
|
2307
|
+
return undefined;
|
|
2308
|
+
}
|
|
2309
|
+
else {
|
|
2310
|
+
throw e;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
*
|
|
2316
|
+
* Fetch multiple values in a big map
|
|
2317
|
+
* 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.
|
|
2318
|
+
* 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.
|
|
2319
|
+
* If one of the keys does not exist in the big map, its value will be set to undefined.
|
|
2320
|
+
*
|
|
2321
|
+
* @param keysToEncode Array of keys to query (will be encoded properly according to the schema)
|
|
2322
|
+
* @param block optional block level to fetch the values from
|
|
2323
|
+
* @param batchSize optional batch size representing the number of requests to execute in parallel
|
|
2324
|
+
* @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
|
|
2325
|
+
*
|
|
2326
|
+
*/
|
|
2327
|
+
async getMultipleValues(keysToEncode, block, batchSize = 5) {
|
|
2328
|
+
return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block ?? this.defaultBlock, batchSize);
|
|
2329
|
+
}
|
|
2330
|
+
toJSON() {
|
|
2331
|
+
return this.id.toString();
|
|
2332
|
+
}
|
|
2333
|
+
toString() {
|
|
2334
|
+
return this.id.toString();
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
class SaplingStateAbstraction {
|
|
2339
|
+
constructor(id, provider, defaultBlock) {
|
|
2340
|
+
this.id = id;
|
|
2341
|
+
this.provider = provider;
|
|
2342
|
+
this.defaultBlock = defaultBlock;
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
*
|
|
2346
|
+
* Fetch the sapling state
|
|
2347
|
+
*
|
|
2348
|
+
* @param block optional block level to fetch the values from (head will be use by default)
|
|
2349
|
+
* @returns Return a json object of the sapling_state
|
|
2350
|
+
*
|
|
2351
|
+
*/
|
|
2352
|
+
async getSaplingDiff(block) {
|
|
2353
|
+
return this.provider.getSaplingDiffByID(this.id.toString(), block ?? this.defaultBlock);
|
|
2354
|
+
}
|
|
2355
|
+
getId() {
|
|
2356
|
+
return this.id.toString();
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* Override the default michelson encoder semantic to provide richer abstraction over storage properties
|
|
2362
|
+
* @param p StorageProvider (contract API)
|
|
2363
|
+
*/
|
|
2364
|
+
// Override the default michelson encoder semantic to provide richer abstraction over storage properties
|
|
2365
|
+
const smartContractAbstractionSemantic = (provider, block) => ({
|
|
2366
|
+
// Provide a specific abstraction for BigMaps
|
|
2367
|
+
big_map: (val, code) => {
|
|
2368
|
+
if (!val || !('int' in val) || val.int === undefined) {
|
|
2369
|
+
// Return an empty object in case of missing big map ID
|
|
2370
|
+
return {};
|
|
2371
|
+
}
|
|
2372
|
+
else {
|
|
2373
|
+
const schema = new Schema(code);
|
|
2374
|
+
return new BigMapAbstraction(new BigNumberJs(val.int), schema, provider, block);
|
|
2375
|
+
}
|
|
2376
|
+
},
|
|
2377
|
+
sapling_state: (val) => {
|
|
2378
|
+
if (!val || !('int' in val) || val.int === undefined) {
|
|
2379
|
+
// Return an empty object in case of missing sapling state ID
|
|
2380
|
+
return {};
|
|
2381
|
+
}
|
|
2382
|
+
else {
|
|
2383
|
+
return new SaplingStateAbstraction(new BigNumberJs(val.int), provider, block);
|
|
2384
|
+
}
|
|
2385
|
+
},
|
|
2386
|
+
/*
|
|
2387
|
+
// TODO: embed useful other abstractions
|
|
2388
|
+
'contract': () => {},
|
|
2389
|
+
'address': () => {}
|
|
2390
|
+
*/
|
|
2391
|
+
});
|
|
2392
|
+
|
|
2194
2393
|
/**
|
|
2195
2394
|
* Utility class to retrieve data from a smart contract's storage without incurring fees via a contract's view method
|
|
2196
2395
|
*/
|
|
@@ -2243,13 +2442,14 @@ const isView = (entrypoint) => {
|
|
|
2243
2442
|
* Smart contract abstraction
|
|
2244
2443
|
*/
|
|
2245
2444
|
class ContractAbstraction {
|
|
2246
|
-
constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider) {
|
|
2445
|
+
constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider, readBlock = 'head') {
|
|
2247
2446
|
this.address = address;
|
|
2248
2447
|
this.script = script;
|
|
2249
2448
|
this.storageProvider = storageProvider;
|
|
2250
2449
|
this.entrypoints = entrypoints;
|
|
2251
2450
|
this.rpc = rpc;
|
|
2252
2451
|
this.readProvider = readProvider;
|
|
2452
|
+
this.readBlock = readBlock;
|
|
2253
2453
|
/**
|
|
2254
2454
|
* 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.
|
|
2255
2455
|
* `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)
|
|
@@ -2333,8 +2533,11 @@ class ContractAbstraction {
|
|
|
2333
2533
|
/**
|
|
2334
2534
|
* Return a friendly representation of the smart contract storage
|
|
2335
2535
|
*/
|
|
2336
|
-
storage() {
|
|
2337
|
-
|
|
2536
|
+
async storage() {
|
|
2537
|
+
if (this.readBlock !== 'head') {
|
|
2538
|
+
return this.schema.Execute(this.script.storage, smartContractAbstractionSemantic(this.storageProvider, this.readBlock));
|
|
2539
|
+
}
|
|
2540
|
+
return this.storageProvider.getStorage(this.address, this.schema, this.readBlock);
|
|
2338
2541
|
}
|
|
2339
2542
|
}
|
|
2340
2543
|
|
|
@@ -2436,114 +2639,8 @@ function compose(functioncomposer1, functioncomposer2) {
|
|
|
2436
2639
|
return (contractAbstraction, context) => functioncomposer2(functioncomposer1(contractAbstraction, context), context);
|
|
2437
2640
|
}
|
|
2438
2641
|
|
|
2439
|
-
class SaplingStateAbstraction {
|
|
2440
|
-
constructor(id, provider) {
|
|
2441
|
-
this.id = id;
|
|
2442
|
-
this.provider = provider;
|
|
2443
|
-
}
|
|
2444
|
-
/**
|
|
2445
|
-
*
|
|
2446
|
-
* Fetch the sapling state
|
|
2447
|
-
*
|
|
2448
|
-
* @param block optional block level to fetch the values from (head will be use by default)
|
|
2449
|
-
* @returns Return a json object of the sapling_state
|
|
2450
|
-
*
|
|
2451
|
-
*/
|
|
2452
|
-
async getSaplingDiff(block) {
|
|
2453
|
-
return this.provider.getSaplingDiffByID(this.id.toString(), block);
|
|
2454
|
-
}
|
|
2455
|
-
getId() {
|
|
2456
|
-
return this.id.toString();
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
class BigMapAbstraction {
|
|
2461
|
-
constructor(id, schema, provider) {
|
|
2462
|
-
this.id = id;
|
|
2463
|
-
this.schema = schema;
|
|
2464
|
-
this.provider = provider;
|
|
2465
|
-
}
|
|
2466
|
-
/**
|
|
2467
|
-
*
|
|
2468
|
-
* Fetch one value in a big map
|
|
2469
|
-
*
|
|
2470
|
-
* @param keyToEncode Key to query (will be encoded properly according to the schema)
|
|
2471
|
-
* @param block optional block level to fetch the values from (head will be use by default)
|
|
2472
|
-
* @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map
|
|
2473
|
-
*
|
|
2474
|
-
*/
|
|
2475
|
-
async get(keyToEncode, block) {
|
|
2476
|
-
try {
|
|
2477
|
-
const id = await this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block);
|
|
2478
|
-
return id;
|
|
2479
|
-
}
|
|
2480
|
-
catch (e) {
|
|
2481
|
-
if (e instanceof HttpResponseError && e.status === STATUS_CODE.NOT_FOUND) {
|
|
2482
|
-
return undefined;
|
|
2483
|
-
}
|
|
2484
|
-
else {
|
|
2485
|
-
throw e;
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
/**
|
|
2490
|
-
*
|
|
2491
|
-
* Fetch multiple values in a big map
|
|
2492
|
-
* 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.
|
|
2493
|
-
* 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.
|
|
2494
|
-
* If one of the keys does not exist in the big map, its value will be set to undefined.
|
|
2495
|
-
*
|
|
2496
|
-
* @param keysToEncode Array of keys to query (will be encoded properly according to the schema)
|
|
2497
|
-
* @param block optional block level to fetch the values from
|
|
2498
|
-
* @param batchSize optional batch size representing the number of requests to execute in parallel
|
|
2499
|
-
* @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
|
|
2500
|
-
*
|
|
2501
|
-
*/
|
|
2502
|
-
async getMultipleValues(keysToEncode, block, batchSize = 5) {
|
|
2503
|
-
return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block, batchSize);
|
|
2504
|
-
}
|
|
2505
|
-
toJSON() {
|
|
2506
|
-
return this.id.toString();
|
|
2507
|
-
}
|
|
2508
|
-
toString() {
|
|
2509
|
-
return this.id.toString();
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
/**
|
|
2514
|
-
* Override the default michelson encoder semantic to provide richer abstraction over storage properties
|
|
2515
|
-
* @param p ContractProvider (contract API)
|
|
2516
|
-
*/
|
|
2517
|
-
// Override the default michelson encoder semantic to provide richer abstraction over storage properties
|
|
2518
|
-
const smartContractAbstractionSemantic = (provider) => ({
|
|
2519
|
-
// Provide a specific abstraction for BigMaps
|
|
2520
|
-
big_map: (val, code) => {
|
|
2521
|
-
if (!val || !('int' in val) || val.int === undefined) {
|
|
2522
|
-
// Return an empty object in case of missing big map ID
|
|
2523
|
-
return {};
|
|
2524
|
-
}
|
|
2525
|
-
else {
|
|
2526
|
-
const schema = new Schema(code);
|
|
2527
|
-
return new BigMapAbstraction(new BigNumber(val.int), schema, provider);
|
|
2528
|
-
}
|
|
2529
|
-
},
|
|
2530
|
-
sapling_state: (val) => {
|
|
2531
|
-
if (!val || !('int' in val) || val.int === undefined) {
|
|
2532
|
-
// Return an empty object in case of missing sapling state ID
|
|
2533
|
-
return {};
|
|
2534
|
-
}
|
|
2535
|
-
else {
|
|
2536
|
-
return new SaplingStateAbstraction(new BigNumber(val.int), provider);
|
|
2537
|
-
}
|
|
2538
|
-
},
|
|
2539
|
-
/*
|
|
2540
|
-
// TODO: embed useful other abstractions
|
|
2541
|
-
'contract': () => {},
|
|
2542
|
-
'address': () => {}
|
|
2543
|
-
*/
|
|
2544
|
-
});
|
|
2545
|
-
|
|
2546
2642
|
var _PrepareProvider_counters;
|
|
2643
|
+
const BigNumber$7 = BigNumberJs;
|
|
2547
2644
|
const mergeLimits = (userDefinedLimit, defaultLimits) => {
|
|
2548
2645
|
return {
|
|
2549
2646
|
fee: userDefinedLimit.fee ?? defaultLimits.fee,
|
|
@@ -2570,15 +2667,15 @@ class PrepareProvider extends Provider {
|
|
|
2570
2667
|
async getHeadCounter(pkh) {
|
|
2571
2668
|
return this.context.readProvider.getCounter(pkh, 'head') ?? '0';
|
|
2572
2669
|
}
|
|
2573
|
-
adjustGasForManagerOperations(gasLimitBlock, gaslimitOp, opsNeedingGasLimitPatch, explicitGasLimitTotal = new BigNumber(0)) {
|
|
2670
|
+
adjustGasForManagerOperations(gasLimitBlock, gaslimitOp, opsNeedingGasLimitPatch, explicitGasLimitTotal = new BigNumber$7(0)) {
|
|
2574
2671
|
if (opsNeedingGasLimitPatch <= 0) {
|
|
2575
2672
|
return gaslimitOp;
|
|
2576
2673
|
}
|
|
2577
2674
|
const remainingBlockGas = gasLimitBlock.minus(explicitGasLimitTotal);
|
|
2578
2675
|
if (remainingBlockGas.lte(0)) {
|
|
2579
|
-
return new BigNumber(0);
|
|
2676
|
+
return new BigNumber$7(0);
|
|
2580
2677
|
}
|
|
2581
|
-
return BigNumber.min(gaslimitOp, remainingBlockGas.div(opsNeedingGasLimitPatch).integerValue(BigNumber.ROUND_DOWN));
|
|
2678
|
+
return BigNumber$7.min(gaslimitOp, remainingBlockGas.div(opsNeedingGasLimitPatch).integerValue(BigNumber$7.ROUND_DOWN));
|
|
2582
2679
|
}
|
|
2583
2680
|
getOperationLimits(constants, options = {}) {
|
|
2584
2681
|
const { hard_gas_limit_per_operation, hard_gas_limit_per_block, hard_storage_limit_per_operation, } = constants;
|
|
@@ -2593,7 +2690,7 @@ class PrepareProvider extends Provider {
|
|
|
2593
2690
|
return this.getOperationLimits(constants, {
|
|
2594
2691
|
opsNeedingGasLimitPatch: typeof gasLimit === 'undefined' ? 1 : 0,
|
|
2595
2692
|
explicitGasLimitTotal: revealNeeded
|
|
2596
|
-
? new BigNumber(getRevealGasLimit(publicKeyHash))
|
|
2693
|
+
? new BigNumber$7(getRevealGasLimit(publicKeyHash))
|
|
2597
2694
|
: undefined,
|
|
2598
2695
|
});
|
|
2599
2696
|
}
|
|
@@ -3423,7 +3520,7 @@ class PrepareProvider extends Provider {
|
|
|
3423
3520
|
const { pkh, publicKey } = await this.getKeys();
|
|
3424
3521
|
const protocolConstants = await this.context.readProvider.getProtocolConstants('head');
|
|
3425
3522
|
const revealNeeded = await this.isRevealOpNeeded(batchParams, pkh);
|
|
3426
|
-
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));
|
|
3523
|
+
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));
|
|
3427
3524
|
const DEFAULT_PARAMS = this.getOperationLimits(protocolConstants, {
|
|
3428
3525
|
opsNeedingGasLimitPatch: batchParams.filter((op) => isOpWithFee(op) && typeof op.gasLimit === 'undefined').length,
|
|
3429
3526
|
explicitGasLimitTotal,
|
|
@@ -4430,6 +4527,7 @@ const BATCH_KINDS = [
|
|
|
4430
4527
|
OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE,
|
|
4431
4528
|
];
|
|
4432
4529
|
|
|
4530
|
+
const BigNumber$6 = BigNumberJs;
|
|
4433
4531
|
class BatchOperation extends Operation {
|
|
4434
4532
|
constructor(hash, params, source, raw, results, context) {
|
|
4435
4533
|
super(hash, raw, results, context);
|
|
@@ -4474,8 +4572,8 @@ class BatchOperation extends Operation {
|
|
|
4474
4572
|
return this.sumProp(this.params, 'storage_limit');
|
|
4475
4573
|
}
|
|
4476
4574
|
get consumedGas() {
|
|
4477
|
-
BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
|
|
4478
|
-
return new BigNumber(this.consumedMilliGas).dividedBy(1000).toString();
|
|
4575
|
+
BigNumber$6.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$6.ROUND_UP });
|
|
4576
|
+
return new BigNumber$6(this.consumedMilliGas).dividedBy(1000).toString();
|
|
4479
4577
|
}
|
|
4480
4578
|
get consumedMilliGas() {
|
|
4481
4579
|
return String(this.sumProp(flattenOperationResult({ contents: this.results }), 'consumed_milligas'));
|
|
@@ -4802,6 +4900,7 @@ class RPCBatchProvider {
|
|
|
4802
4900
|
}
|
|
4803
4901
|
}
|
|
4804
4902
|
|
|
4903
|
+
const BigNumber$5 = BigNumber$9;
|
|
4805
4904
|
/**
|
|
4806
4905
|
* Delegation operation provide utility function to fetch newly issued delegation
|
|
4807
4906
|
*
|
|
@@ -4838,9 +4937,9 @@ class DelegateOperation extends Operation {
|
|
|
4838
4937
|
return Number(this.params.storage_limit);
|
|
4839
4938
|
}
|
|
4840
4939
|
get consumedGas() {
|
|
4841
|
-
BigNumber$
|
|
4940
|
+
BigNumber$5.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$5.ROUND_UP });
|
|
4842
4941
|
return this.consumedMilliGas
|
|
4843
|
-
? new BigNumber$
|
|
4942
|
+
? new BigNumber$5(this.consumedMilliGas).dividedBy(1000).toString()
|
|
4844
4943
|
: undefined;
|
|
4845
4944
|
}
|
|
4846
4945
|
get consumedMilliGas() {
|
|
@@ -4851,6 +4950,7 @@ class DelegateOperation extends Operation {
|
|
|
4851
4950
|
}
|
|
4852
4951
|
}
|
|
4853
4952
|
|
|
4953
|
+
const BigNumber$4 = BigNumber$9;
|
|
4854
4954
|
/**
|
|
4855
4955
|
* Origination operation provide utility function to fetch newly originated contract
|
|
4856
4956
|
*
|
|
@@ -4887,9 +4987,9 @@ class OriginationOperation extends Operation {
|
|
|
4887
4987
|
return Number(this.params.storage_limit);
|
|
4888
4988
|
}
|
|
4889
4989
|
get consumedGas() {
|
|
4890
|
-
BigNumber$
|
|
4990
|
+
BigNumber$4.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$4.ROUND_UP });
|
|
4891
4991
|
return this.consumedMilliGas
|
|
4892
|
-
? new BigNumber$
|
|
4992
|
+
? new BigNumber$4(this.consumedMilliGas).dividedBy(1000).toString()
|
|
4893
4993
|
: undefined;
|
|
4894
4994
|
}
|
|
4895
4995
|
get consumedMilliGas() {
|
|
@@ -4918,10 +5018,15 @@ class OriginationOperation extends Operation {
|
|
|
4918
5018
|
if (!Number.isFinite(this.includedInBlock)) {
|
|
4919
5019
|
throw new OriginationOperationError('Confirmation completed but includedInBlock was not set');
|
|
4920
5020
|
}
|
|
4921
|
-
|
|
5021
|
+
const inclusionBlock = await this.getInclusionBlock();
|
|
5022
|
+
if (!isBlockHashIdentifier(inclusionBlock.hash)) {
|
|
5023
|
+
throw new OriginationOperationError('Confirmation completed but includedInBlock was not set');
|
|
5024
|
+
}
|
|
5025
|
+
return this.contractProvider.at(this.contractAddress, undefined, inclusionBlock.hash);
|
|
4922
5026
|
}
|
|
4923
5027
|
}
|
|
4924
5028
|
|
|
5029
|
+
const BigNumber$3 = BigNumber$9;
|
|
4925
5030
|
/**
|
|
4926
5031
|
* RegisterGlobalConstantOperation provides utility functions to fetch a newly issued operation of kind register_global_constant
|
|
4927
5032
|
*/
|
|
@@ -4959,9 +5064,9 @@ class RegisterGlobalConstantOperation extends Operation {
|
|
|
4959
5064
|
return this.operationResults?.errors;
|
|
4960
5065
|
}
|
|
4961
5066
|
get consumedGas() {
|
|
4962
|
-
BigNumber$
|
|
5067
|
+
BigNumber$3.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$3.ROUND_UP });
|
|
4963
5068
|
return this.consumedMilliGas
|
|
4964
|
-
? new BigNumber$
|
|
5069
|
+
? new BigNumber$3(this.consumedMilliGas).dividedBy(1000).toString()
|
|
4965
5070
|
: undefined;
|
|
4966
5071
|
}
|
|
4967
5072
|
get consumedMilliGas() {
|
|
@@ -4969,6 +5074,7 @@ class RegisterGlobalConstantOperation extends Operation {
|
|
|
4969
5074
|
}
|
|
4970
5075
|
}
|
|
4971
5076
|
|
|
5077
|
+
const BigNumber$2 = BigNumber$9;
|
|
4972
5078
|
/**
|
|
4973
5079
|
* Reveal operation provides utility functions to fetch a newly issued revelation
|
|
4974
5080
|
*/
|
|
@@ -5019,8 +5125,8 @@ class RevealOperation extends Operation {
|
|
|
5019
5125
|
}, 0);
|
|
5020
5126
|
}
|
|
5021
5127
|
get consumedGas() {
|
|
5022
|
-
BigNumber$
|
|
5023
|
-
return new BigNumber$
|
|
5128
|
+
BigNumber$2.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$2.ROUND_UP });
|
|
5129
|
+
return new BigNumber$2(this.consumedMilliGas).dividedBy(1000).toString();
|
|
5024
5130
|
}
|
|
5025
5131
|
get consumedMilliGas() {
|
|
5026
5132
|
return String(this.sumProp(flattenOperationResult({ contents: this.operationResults }), 'consumed_milligas'));
|
|
@@ -5036,6 +5142,7 @@ class RevealOperation extends Operation {
|
|
|
5036
5142
|
}
|
|
5037
5143
|
}
|
|
5038
5144
|
|
|
5145
|
+
const BigNumber$1 = BigNumberJs;
|
|
5039
5146
|
/**
|
|
5040
5147
|
* Transaction operation provides utility functions to fetch a newly issued transaction
|
|
5041
5148
|
*
|
|
@@ -5063,7 +5170,7 @@ class TransactionOperation extends Operation {
|
|
|
5063
5170
|
}
|
|
5064
5171
|
}
|
|
5065
5172
|
get amount() {
|
|
5066
|
-
return new BigNumber(this.params.amount);
|
|
5173
|
+
return new BigNumber$1(this.params.amount);
|
|
5067
5174
|
}
|
|
5068
5175
|
get destination() {
|
|
5069
5176
|
return this.params.destination;
|
|
@@ -5083,8 +5190,8 @@ class TransactionOperation extends Operation {
|
|
|
5083
5190
|
}, 0);
|
|
5084
5191
|
}
|
|
5085
5192
|
get consumedGas() {
|
|
5086
|
-
BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
|
|
5087
|
-
return new BigNumber(this.consumedMilliGas).dividedBy(1000).toString();
|
|
5193
|
+
BigNumber$1.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber$1.ROUND_UP });
|
|
5194
|
+
return new BigNumber$1(this.consumedMilliGas).dividedBy(1000).toString();
|
|
5088
5195
|
}
|
|
5089
5196
|
get consumedMilliGas() {
|
|
5090
5197
|
return String(this.sumProp(flattenOperationResult({ contents: this.operationResults }), 'consumed_milligas'));
|
|
@@ -5100,6 +5207,7 @@ class TransactionOperation extends Operation {
|
|
|
5100
5207
|
}
|
|
5101
5208
|
}
|
|
5102
5209
|
|
|
5210
|
+
const BigNumber = BigNumber$9;
|
|
5103
5211
|
/**
|
|
5104
5212
|
*
|
|
5105
5213
|
* Transfer tickets from a Tezos address (tz1, tz2 or tz3) to a smart contract address (KT1) (everything on layer 1 at this step)
|
|
@@ -5131,9 +5239,9 @@ class TransferTicketOperation extends Operation {
|
|
|
5131
5239
|
return Number(this.params.storage_limit);
|
|
5132
5240
|
}
|
|
5133
5241
|
get consumedGas() {
|
|
5134
|
-
BigNumber
|
|
5242
|
+
BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_UP });
|
|
5135
5243
|
return this.consumedMilliGas
|
|
5136
|
-
? new BigNumber
|
|
5244
|
+
? new BigNumber(this.consumedMilliGas).dividedBy(1000).toString()
|
|
5137
5245
|
: undefined;
|
|
5138
5246
|
}
|
|
5139
5247
|
get consumedMilliGas() {
|
|
@@ -5499,6 +5607,30 @@ class SmartRollupExecuteOutboxMessageOperation extends Operation {
|
|
|
5499
5607
|
}
|
|
5500
5608
|
}
|
|
5501
5609
|
|
|
5610
|
+
const CONTRACT_READ_RETRY_DELAYS_MS = [0, 200, 400, 800];
|
|
5611
|
+
const sleep = (durationMs) => new Promise((resolve) => {
|
|
5612
|
+
setTimeout(resolve, durationMs);
|
|
5613
|
+
});
|
|
5614
|
+
const isNotFoundError = (error) => error instanceof HttpResponseError && error.status === STATUS_CODE.NOT_FOUND;
|
|
5615
|
+
const retryOnNotFound = async (read, retryDelaysMs = CONTRACT_READ_RETRY_DELAYS_MS) => {
|
|
5616
|
+
let lastError;
|
|
5617
|
+
for (const delayMs of retryDelaysMs) {
|
|
5618
|
+
if (delayMs > 0) {
|
|
5619
|
+
await sleep(delayMs);
|
|
5620
|
+
}
|
|
5621
|
+
try {
|
|
5622
|
+
return await read();
|
|
5623
|
+
}
|
|
5624
|
+
catch (error) {
|
|
5625
|
+
if (!isNotFoundError(error)) {
|
|
5626
|
+
throw error;
|
|
5627
|
+
}
|
|
5628
|
+
lastError = error;
|
|
5629
|
+
}
|
|
5630
|
+
}
|
|
5631
|
+
throw lastError;
|
|
5632
|
+
};
|
|
5633
|
+
|
|
5502
5634
|
class RpcContractProvider extends Provider {
|
|
5503
5635
|
constructor(context, estimator) {
|
|
5504
5636
|
super(context);
|
|
@@ -5515,12 +5647,14 @@ class RpcContractProvider extends Provider {
|
|
|
5515
5647
|
* @throws {@link InvalidContractAddressError}
|
|
5516
5648
|
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
|
|
5517
5649
|
*/
|
|
5518
|
-
async getStorage(contract, schema) {
|
|
5650
|
+
async getStorage(contract, schema, block = 'head') {
|
|
5519
5651
|
const contractValidation = validateContractAddress(contract);
|
|
5520
5652
|
if (contractValidation !== ValidationResult.VALID) {
|
|
5521
5653
|
throw new InvalidContractAddressError(contract, contractValidation);
|
|
5522
5654
|
}
|
|
5523
|
-
const script =
|
|
5655
|
+
const script = block === 'head'
|
|
5656
|
+
? await retryOnNotFound(() => this.context.readProvider.getScript(contract, 'head'))
|
|
5657
|
+
: await this.context.readProvider.getScript(contract, block);
|
|
5524
5658
|
if (!schema) {
|
|
5525
5659
|
schema = script;
|
|
5526
5660
|
}
|
|
@@ -5531,7 +5665,7 @@ class RpcContractProvider extends Provider {
|
|
|
5531
5665
|
else {
|
|
5532
5666
|
contractSchema = Schema.fromRPCResponse({ script: schema });
|
|
5533
5667
|
}
|
|
5534
|
-
return contractSchema.Execute(script.storage, smartContractAbstractionSemantic(this)); // Cast into T because only the caller can know the true type of the storage
|
|
5668
|
+
return contractSchema.Execute(script.storage, smartContractAbstractionSemantic(this, block)); // Cast into T because only the caller can know the true type of the storage
|
|
5535
5669
|
}
|
|
5536
5670
|
/**
|
|
5537
5671
|
*
|
|
@@ -5548,10 +5682,9 @@ class RpcContractProvider extends Provider {
|
|
|
5548
5682
|
const { key, type } = schema.EncodeBigMapKey(keyToEncode);
|
|
5549
5683
|
const { packed } = await this.context.packer.packData({ data: key, type });
|
|
5550
5684
|
const encodedExpr = encodeExpr(packed);
|
|
5551
|
-
const
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
return schema.ExecuteOnBigMapValue(bigMapValue, smartContractAbstractionSemantic(this));
|
|
5685
|
+
const requestedBlock = block ?? 'head';
|
|
5686
|
+
const bigMapValue = await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, requestedBlock);
|
|
5687
|
+
return schema.ExecuteOnBigMapValue(bigMapValue, smartContractAbstractionSemantic(this, requestedBlock));
|
|
5555
5688
|
}
|
|
5556
5689
|
/**
|
|
5557
5690
|
*
|
|
@@ -5611,11 +5744,8 @@ class RpcContractProvider extends Provider {
|
|
|
5611
5744
|
* @param block optional block level to fetch the value from
|
|
5612
5745
|
*
|
|
5613
5746
|
*/
|
|
5614
|
-
async getSaplingDiffByID(id, block) {
|
|
5615
|
-
|
|
5616
|
-
? await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
|
|
5617
|
-
: await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
|
|
5618
|
-
return saplingState;
|
|
5747
|
+
async getSaplingDiffByID(id, block = 'head') {
|
|
5748
|
+
return this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block);
|
|
5619
5749
|
}
|
|
5620
5750
|
/**
|
|
5621
5751
|
*
|
|
@@ -6115,17 +6245,28 @@ class RpcContractProvider extends Provider {
|
|
|
6115
6245
|
catch (error) {
|
|
6116
6246
|
// Shadownet's rolling nodes occasionally 404 a just-originated contract at the exact
|
|
6117
6247
|
// inclusion level even after confirmation. Retry at head so the contract abstraction still
|
|
6118
|
-
// resolves once the node's contract index catches up.
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
contractState = await loadContractState('head');
|
|
6248
|
+
// resolves once the node's contract index catches up. The head index can lag briefly too,
|
|
6249
|
+
// so give it a few bounded retries before surfacing the 404.
|
|
6250
|
+
if (block !== 'head' && isNotFoundError(error)) {
|
|
6251
|
+
contractState = await retryOnNotFound(() => loadContractState('head'));
|
|
6123
6252
|
}
|
|
6124
6253
|
else {
|
|
6125
6254
|
throw error;
|
|
6126
6255
|
}
|
|
6127
6256
|
}
|
|
6128
|
-
const abs = new ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider);
|
|
6257
|
+
const abs = new ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider, 'head');
|
|
6258
|
+
return contractAbstractionComposer(abs, this.context);
|
|
6259
|
+
}
|
|
6260
|
+
async atExactBlock(address, contractAbstractionComposer = (x) => x, block) {
|
|
6261
|
+
const addressValidation = validateContractAddress(address);
|
|
6262
|
+
if (addressValidation !== ValidationResult.VALID) {
|
|
6263
|
+
throw new InvalidContractAddressError(address, addressValidation);
|
|
6264
|
+
}
|
|
6265
|
+
const rpc = this.context.withExtensions().rpc;
|
|
6266
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
6267
|
+
const script = await readProvider.getScript(address, block);
|
|
6268
|
+
const entrypoints = await rpc.getEntrypoints(address, { block: String(block) });
|
|
6269
|
+
const abs = new ContractAbstraction(address, script, this, this, entrypoints, rpc, readProvider, block);
|
|
6129
6270
|
return contractAbstractionComposer(abs, this.context);
|
|
6130
6271
|
}
|
|
6131
6272
|
/**
|
|
@@ -6566,17 +6707,28 @@ class Wallet {
|
|
|
6566
6707
|
// Newly originated contracts can be visible at the operation's inclusion level in one RPC
|
|
6567
6708
|
// call and still lag on another endpoint of the same rolling node. Retry at head so
|
|
6568
6709
|
// wallet op.contract() behaves like octez-client, which resolves the originated contract
|
|
6569
|
-
// after confirmation instead of pinning itself to a stale context forever.
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
contractState = await loadContractState('head');
|
|
6710
|
+
// after confirmation instead of pinning itself to a stale context forever. The head index
|
|
6711
|
+
// can lag briefly as well, so bound a few retries there too.
|
|
6712
|
+
if (block !== 'head' && isNotFoundError(error)) {
|
|
6713
|
+
contractState = await retryOnNotFound(() => loadContractState('head'));
|
|
6574
6714
|
}
|
|
6575
6715
|
else {
|
|
6576
6716
|
throw error;
|
|
6577
6717
|
}
|
|
6578
6718
|
}
|
|
6579
|
-
const abs = new ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider);
|
|
6719
|
+
const abs = new ContractAbstraction(address, contractState.script, this, this.context.contract, contractState.entrypoints, rpc, readProvider, 'head');
|
|
6720
|
+
return contractAbstractionComposer(abs, this.context);
|
|
6721
|
+
}
|
|
6722
|
+
async atExactBlock(address, contractAbstractionComposer = (x) => x, block) {
|
|
6723
|
+
const addressValidation = validateContractAddress(address);
|
|
6724
|
+
if (addressValidation !== ValidationResult.VALID) {
|
|
6725
|
+
throw new InvalidContractAddressError(address, addressValidation);
|
|
6726
|
+
}
|
|
6727
|
+
const rpc = this.context.withExtensions().rpc;
|
|
6728
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
6729
|
+
const script = await readProvider.getScript(address, block);
|
|
6730
|
+
const entrypoints = await rpc.getEntrypoints(address, { block: String(block) });
|
|
6731
|
+
const abs = new ContractAbstraction(address, script, this, this.context.contract, entrypoints, rpc, readProvider, block);
|
|
6580
6732
|
return contractAbstractionComposer(abs, this.context);
|
|
6581
6733
|
}
|
|
6582
6734
|
}
|
|
@@ -7217,7 +7369,7 @@ class PollingSubscribeProvider {
|
|
|
7217
7369
|
const constants = await this.context.readProvider.getProtocolConstants('head');
|
|
7218
7370
|
const blockTime = constants.minimal_block_delay
|
|
7219
7371
|
? constants.minimal_block_delay.multipliedBy(1000)
|
|
7220
|
-
: new
|
|
7372
|
+
: new BigNumberJs(defaultIntervalTestnetsMainnet);
|
|
7221
7373
|
const confirmationPollingInterval = blockTime.dividedBy(3);
|
|
7222
7374
|
this.config.pollingIntervalMilliseconds =
|
|
7223
7375
|
confirmationPollingInterval.toNumber() === 0
|
|
@@ -7421,8 +7573,8 @@ class Context {
|
|
|
7421
7573
|
|
|
7422
7574
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
7423
7575
|
const VERSION = {
|
|
7424
|
-
"commitHash": "
|
|
7425
|
-
"version": "24.3.0-beta.
|
|
7576
|
+
"commitHash": "768729af84b0c773f536e6fbb3acb02ab656d88d",
|
|
7577
|
+
"version": "24.3.0-beta.4"
|
|
7426
7578
|
};
|
|
7427
7579
|
|
|
7428
7580
|
/**
|