@taquito/taquito 11.2.0 → 12.0.0-beta-RC.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/batch/rpc-batch-provider.js.map +1 -1
- package/dist/lib/constants.js +1 -13
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context.js +25 -45
- package/dist/lib/context.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-method-factory.js +2 -2
- package/dist/lib/contract/contract-methods/contract-method-factory.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +6 -5
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js.map +1 -1
- package/dist/lib/contract/contract.js +40 -66
- package/dist/lib/contract/contract.js.map +1 -1
- package/dist/lib/contract/lambda-view.js +4 -0
- package/dist/lib/contract/lambda-view.js.map +1 -1
- package/dist/lib/contract/rpc-contract-provider.js +12 -14
- package/dist/lib/contract/rpc-contract-provider.js.map +1 -1
- package/dist/lib/estimate/error.js +11 -0
- package/dist/lib/estimate/error.js.map +1 -0
- package/dist/lib/estimate/estimate-provider-interface.js +3 -0
- package/dist/lib/estimate/estimate-provider-interface.js.map +1 -0
- package/dist/lib/{contract → estimate}/estimate.js +4 -3
- package/dist/lib/estimate/estimate.js.map +1 -0
- package/dist/lib/estimate/index.js +18 -0
- package/dist/lib/estimate/index.js.map +1 -0
- package/dist/lib/{contract → estimate}/naive-estimate-provider.js +0 -0
- package/dist/lib/estimate/naive-estimate-provider.js.map +1 -0
- package/dist/lib/{contract → estimate}/rpc-estimate-provider.js +54 -35
- package/dist/lib/estimate/rpc-estimate-provider.js.map +1 -0
- package/dist/lib/forger/taquito-local-forger.js +35 -0
- package/dist/lib/forger/taquito-local-forger.js.map +1 -0
- package/dist/lib/operations/operation-emitter.js +10 -22
- package/dist/lib/operations/operation-emitter.js.map +1 -1
- package/dist/lib/operations/operations.js +11 -37
- package/dist/lib/operations/operations.js.map +1 -1
- package/dist/lib/operations/origination-operation.js +2 -2
- package/dist/lib/operations/origination-operation.js.map +1 -1
- package/dist/lib/parser/michel-codec-parser.js +5 -2
- package/dist/lib/parser/michel-codec-parser.js.map +1 -1
- package/dist/lib/{forger → read-provider}/interface.js +0 -0
- package/dist/lib/read-provider/interface.js.map +1 -0
- package/dist/lib/read-provider/rpc-read-adapter.js +199 -0
- package/dist/lib/read-provider/rpc-read-adapter.js.map +1 -0
- package/dist/lib/subscribe/create-observable-from-subscription.js +22 -0
- package/dist/lib/subscribe/create-observable-from-subscription.js.map +1 -0
- package/dist/lib/subscribe/polling-subcribe-provider.js +94 -0
- package/dist/lib/subscribe/polling-subcribe-provider.js.map +1 -0
- package/dist/lib/taquito.js +63 -26
- package/dist/lib/taquito.js.map +1 -1
- package/dist/lib/tz/rpc-tz-provider.js +2 -2
- package/dist/lib/tz/rpc-tz-provider.js.map +1 -1
- package/dist/lib/version.js +2 -2
- package/dist/lib/version.js.map +1 -1
- package/dist/lib/wallet/delegation-operation.js +2 -2
- package/dist/lib/wallet/delegation-operation.js.map +1 -1
- package/dist/lib/wallet/operation-factory.js +10 -24
- package/dist/lib/wallet/operation-factory.js.map +1 -1
- package/dist/lib/wallet/operation.js +4 -4
- package/dist/lib/wallet/operation.js.map +1 -1
- package/dist/lib/wallet/wallet.js +4 -8
- package/dist/lib/wallet/wallet.js.map +1 -1
- package/dist/taquito.es6.js +745 -664
- package/dist/taquito.es6.js.map +1 -1
- package/dist/taquito.min.js +2 -0
- package/dist/taquito.min.js.LICENSE.txt +27 -0
- package/dist/taquito.umd.js +749 -665
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/batch/rpc-batch-provider.d.ts +2 -1
- package/dist/types/constants.d.ts +0 -11
- package/dist/types/context.d.ts +16 -23
- package/dist/types/contract/contract-methods/contract-method-factory.d.ts +2 -1
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +3 -2
- package/dist/types/contract/contract.d.ts +9 -15
- package/dist/types/contract/interface.d.ts +0 -58
- package/dist/types/contract/lambda-view.d.ts +4 -0
- package/dist/types/contract/rpc-contract-provider.d.ts +2 -1
- package/dist/types/estimate/error.d.ts +4 -0
- package/dist/types/estimate/estimate-provider-interface.d.ts +60 -0
- package/dist/types/{contract → estimate}/estimate.d.ts +0 -0
- package/dist/types/estimate/index.d.ts +5 -0
- package/dist/types/{contract → estimate}/naive-estimate-provider.d.ts +1 -1
- package/dist/types/{contract → estimate}/rpc-estimate-provider.d.ts +2 -1
- package/dist/types/forger/composite-forger.d.ts +1 -1
- package/dist/types/forger/rpc-forger.d.ts +1 -1
- package/dist/types/forger/taquito-local-forger.d.ts +8 -0
- package/dist/types/operations/operation-emitter.d.ts +2 -2
- package/dist/types/operations/operations.d.ts +1 -4
- package/dist/types/operations/origination-operation.d.ts +1 -1
- package/dist/types/operations/types.d.ts +1 -1
- package/dist/types/read-provider/interface.d.ts +113 -0
- package/dist/types/read-provider/rpc-read-adapter.d.ts +112 -0
- package/dist/types/signer/interface.d.ts +1 -1
- package/dist/types/subscribe/create-observable-from-subscription.d.ts +4 -0
- package/dist/types/subscribe/interface.d.ts +2 -1
- package/dist/types/subscribe/polling-subcribe-provider.d.ts +22 -0
- package/dist/types/taquito.d.ts +23 -9
- package/dist/types/wallet/delegation-operation.d.ts +2 -2
- package/dist/types/wallet/operation-factory.d.ts +2 -3
- package/dist/types/wallet/operation.d.ts +2 -1
- package/package.json +8 -7
- package/dist/lib/contract/estimate.js.map +0 -1
- package/dist/lib/contract/naive-estimate-provider.js.map +0 -1
- package/dist/lib/contract/rpc-estimate-provider.js.map +0 -1
- package/dist/lib/forger/interface.js.map +0 -1
- package/dist/lib/subscribe/polling-provider.js +0 -40
- package/dist/lib/subscribe/polling-provider.js.map +0 -1
- package/dist/types/forger/interface.d.ts +0 -9
- package/dist/types/subscribe/polling-provider.d.ts +0 -10
package/dist/taquito.es6.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { OpKind, RpcClient } from '@taquito/rpc';
|
|
2
2
|
export { OpKind } from '@taquito/rpc';
|
|
3
|
-
import { ReplaySubject, defer,
|
|
4
|
-
import {
|
|
3
|
+
import { Observable, ReplaySubject, defer, throwError, of, EMPTY, combineLatest, from, range, concat, Subject, NEVER, BehaviorSubject, timer } from 'rxjs';
|
|
4
|
+
import { switchMap, timeoutWith, shareReplay, map, filter, first, catchError, tap, distinctUntilChanged, takeWhile, startWith, concatMap, retry, takeUntil, pluck, distinctUntilKeyChanged, publish, refCount } from 'rxjs/operators';
|
|
5
5
|
import { Schema, ParameterSchema, ViewSchema, MichelsonMap } from '@taquito/michelson-encoder';
|
|
6
6
|
export { MichelsonMap, UnitValue } from '@taquito/michelson-encoder';
|
|
7
7
|
import BigNumber from 'bignumber.js';
|
|
8
|
-
import { validateOperation, ValidationResult, InvalidOperationHashError, validateAddress, InvalidAddressError, validateKeyHash, InvalidKeyHashError, validateContractAddress, InvalidContractAddressError, encodeExpr } from '@taquito/utils';
|
|
8
|
+
import { validateOperation, ValidationResult, InvalidOperationHashError, validateAddress, InvalidAddressError, validateKeyHash, InvalidKeyHashError, validateContractAddress, InvalidContractAddressError, validateChain, encodeExpr } from '@taquito/utils';
|
|
9
9
|
import { HttpResponseError, STATUS_CODE } from '@taquito/http-utils';
|
|
10
10
|
import { Parser, packDataBytes } from '@taquito/michel-codec';
|
|
11
|
+
import { LocalForger } from '@taquito/local-forging';
|
|
11
12
|
|
|
12
13
|
/*! *****************************************************************************
|
|
13
14
|
Copyright (c) Microsoft Corporation.
|
|
@@ -46,15 +47,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
class RpcForger {
|
|
50
|
-
constructor(context) {
|
|
51
|
-
this.context = context;
|
|
52
|
-
}
|
|
53
|
-
forge({ branch, contents }) {
|
|
54
|
-
return this.context.rpc.forgeOperations({ branch, contents });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
50
|
class RpcInjector {
|
|
59
51
|
constructor(context) {
|
|
60
52
|
this.context = context;
|
|
@@ -96,6 +88,23 @@ class NoopSigner {
|
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
|
|
91
|
+
function createObservableFromSubscription(sub) {
|
|
92
|
+
return new Observable((subscriber) => {
|
|
93
|
+
sub.on('data', (data) => {
|
|
94
|
+
subscriber.next(data);
|
|
95
|
+
});
|
|
96
|
+
sub.on('error', (error) => {
|
|
97
|
+
subscriber.error(error);
|
|
98
|
+
});
|
|
99
|
+
sub.on('close', () => {
|
|
100
|
+
subscriber.complete();
|
|
101
|
+
});
|
|
102
|
+
return () => {
|
|
103
|
+
sub.close();
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
99
108
|
var DEFAULT_GAS_LIMIT;
|
|
100
109
|
(function (DEFAULT_GAS_LIMIT) {
|
|
101
110
|
DEFAULT_GAS_LIMIT[DEFAULT_GAS_LIMIT["DELEGATION"] = 10600] = "DELEGATION";
|
|
@@ -145,18 +154,6 @@ const protocols = {
|
|
|
145
154
|
'013': [Protocols.Psithaca2],
|
|
146
155
|
'014': [Protocols.ProtoALpha],
|
|
147
156
|
};
|
|
148
|
-
var DefaultLambdaAddresses;
|
|
149
|
-
(function (DefaultLambdaAddresses) {
|
|
150
|
-
DefaultLambdaAddresses["MAINNET"] = "KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE";
|
|
151
|
-
DefaultLambdaAddresses["CARTHAGENET"] = "KT1VAy1o1FGiXYfD3YT7x7k5eF5HSHhmc1u6";
|
|
152
|
-
DefaultLambdaAddresses["DELPHINET"] = "KT19abMFs3haqyKYwqdLjK9GbtofryZLvpiK";
|
|
153
|
-
DefaultLambdaAddresses["EDONET"] = "KT1A64nVZDccAHGAsf1ZyVajXZcbiwjV3SnN";
|
|
154
|
-
DefaultLambdaAddresses["FLORENCENET"] = "KT1KCe3YqGnudsiCWb5twbe2DH5T3EMdLpSE";
|
|
155
|
-
DefaultLambdaAddresses["GRANADANET"] = "KT1BCun2vsA4GBQvsKAuGD5x873MfW2jsN9z";
|
|
156
|
-
DefaultLambdaAddresses["HANGZHOUNET"] = "KT1PWtBAr1hjK9M9s9oZNZFbfzPdkkD6PSJR";
|
|
157
|
-
DefaultLambdaAddresses["ITHACANET"] = "KT1CsEGfRHWeuUQFh9LfVFLVMbm7DFBuHPPU";
|
|
158
|
-
DefaultLambdaAddresses["ITHACANET2"] = "KT1H2a5vGkMLFGBPMs6oRRJshCvYeXSBSadn";
|
|
159
|
-
})(DefaultLambdaAddresses || (DefaultLambdaAddresses = {}));
|
|
160
157
|
var ChainIds;
|
|
161
158
|
(function (ChainIds) {
|
|
162
159
|
ChainIds["MAINNET"] = "NetXdQprcVkpaWU";
|
|
@@ -489,35 +486,11 @@ class Operation {
|
|
|
489
486
|
this.results = results;
|
|
490
487
|
this.context = context;
|
|
491
488
|
this._pollingConfig$ = new ReplaySubject(1);
|
|
492
|
-
this.
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (!this._currentHeadPromise) {
|
|
496
|
-
this._currentHeadPromise = this.context.rpc.getBlock();
|
|
497
|
-
timer(1000)
|
|
498
|
-
.pipe(first())
|
|
499
|
-
.subscribe(() => {
|
|
500
|
-
this._currentHeadPromise = undefined;
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
return from(this._currentHeadPromise);
|
|
504
|
-
});
|
|
505
|
-
// Polling observable that emit until timeout is reached
|
|
506
|
-
this.polling$ = defer(() => this._pollingConfig$.pipe(tap(({ timeout, interval }) => {
|
|
507
|
-
if (timeout <= 0) {
|
|
508
|
-
throw new Error('Timeout must be more than 0');
|
|
509
|
-
}
|
|
510
|
-
if (interval <= 0) {
|
|
511
|
-
throw new Error('Interval must be more than 0');
|
|
512
|
-
}
|
|
513
|
-
}), map((config) => (Object.assign(Object.assign({}, config), { timeoutAt: Math.ceil(config.timeout / config.interval) + 1, count: 0 }))), switchMap((config) => timer(0, config.interval * 1000).pipe(mapTo(config))), tap((config) => {
|
|
514
|
-
config.count++;
|
|
515
|
-
if (config.count > config.timeoutAt) {
|
|
516
|
-
throw new Error(`Confirmation polling timed out`);
|
|
517
|
-
}
|
|
518
|
-
})));
|
|
489
|
+
this.currentHead$ = this._pollingConfig$.pipe(switchMap((config) => {
|
|
490
|
+
return defer(() => createObservableFromSubscription(this.context.stream.subscribeBlock('head'))).pipe(timeoutWith(config.timeout * 1000, throwError(new Error('Confirmation polling timed out'))));
|
|
491
|
+
}), shareReplay({ refCount: true }));
|
|
519
492
|
// Observable that emit once operation is seen in a block
|
|
520
|
-
this.confirmed$ = this.
|
|
493
|
+
this.confirmed$ = this.currentHead$.pipe(map((head) => {
|
|
521
494
|
for (let i = 3; i >= 0; i--) {
|
|
522
495
|
head.operations[i].forEach((op) => {
|
|
523
496
|
if (op.hash === this.hash) {
|
|
@@ -533,9 +506,11 @@ class Operation {
|
|
|
533
506
|
if (validateOperation(this.hash) !== ValidationResult.VALID) {
|
|
534
507
|
throw new InvalidOperationHashError(`Invalid Operation Hash: ${this.hash}`);
|
|
535
508
|
}
|
|
536
|
-
this.confirmed
|
|
509
|
+
this.confirmed$
|
|
510
|
+
.pipe(first(), catchError(() => {
|
|
537
511
|
return of(EMPTY);
|
|
538
|
-
}))
|
|
512
|
+
}))
|
|
513
|
+
.subscribe();
|
|
539
514
|
}
|
|
540
515
|
get includedInBlock() {
|
|
541
516
|
return this._foundAt;
|
|
@@ -565,26 +540,21 @@ class Operation {
|
|
|
565
540
|
/**
|
|
566
541
|
*
|
|
567
542
|
* @param confirmations [0] Number of confirmation to wait for
|
|
568
|
-
* @param interval [10] Polling interval
|
|
569
543
|
* @param timeout [180] Timeout
|
|
570
544
|
*/
|
|
571
|
-
confirmation(confirmations,
|
|
545
|
+
confirmation(confirmations, timeout) {
|
|
572
546
|
return __awaiter(this, void 0, void 0, function* () {
|
|
573
547
|
if (typeof confirmations !== 'undefined' && confirmations < 1) {
|
|
574
548
|
throw new Error('Confirmation count must be at least 1');
|
|
575
549
|
}
|
|
576
|
-
const confirmationPollingIntervalSecond = this.context.config.confirmationPollingIntervalSecond !== undefined
|
|
577
|
-
? this.context.config.confirmationPollingIntervalSecond
|
|
578
|
-
: yield this.context.getConfirmationPollingInterval();
|
|
579
550
|
const { defaultConfirmationCount, confirmationPollingTimeoutSecond } = this.context.config;
|
|
580
551
|
this._pollingConfig$.next({
|
|
581
|
-
interval: interval || confirmationPollingIntervalSecond,
|
|
582
552
|
timeout: timeout || confirmationPollingTimeoutSecond,
|
|
583
553
|
});
|
|
584
554
|
const conf = confirmations !== undefined ? confirmations : defaultConfirmationCount;
|
|
585
555
|
return new Promise((resolve, reject) => {
|
|
586
556
|
this.confirmed$
|
|
587
|
-
.pipe(switchMap(() => this.
|
|
557
|
+
.pipe(switchMap(() => this.currentHead$), filter((head) => head.header.level - this._foundAt >= conf - 1), first())
|
|
588
558
|
.subscribe((_) => {
|
|
589
559
|
resolve(this._foundAt + (conf - 1));
|
|
590
560
|
}, reject);
|
|
@@ -655,9 +625,7 @@ class OperationEmitter {
|
|
|
655
625
|
}
|
|
656
626
|
isAccountRevealRequired(publicKeyHash) {
|
|
657
627
|
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
-
|
|
659
|
-
const haveManager = manager && typeof manager === 'object' ? !!manager.key : !!manager;
|
|
660
|
-
return !haveManager;
|
|
628
|
+
return !(yield this.context.readProvider.isAccountRevealed(publicKeyHash, 'head'));
|
|
661
629
|
});
|
|
662
630
|
}
|
|
663
631
|
isRevealRequiredForOpType(op) {
|
|
@@ -670,12 +638,12 @@ class OperationEmitter {
|
|
|
670
638
|
return opRequireReveal;
|
|
671
639
|
}
|
|
672
640
|
// Originally from sotez (Copyright (c) 2018 Andrew Kishino)
|
|
673
|
-
prepareOperation({ operation, source,
|
|
641
|
+
prepareOperation({ operation, source }, pkh) {
|
|
674
642
|
return __awaiter(this, void 0, void 0, function* () {
|
|
675
643
|
const counters = {};
|
|
676
644
|
let ops = [];
|
|
677
|
-
const
|
|
678
|
-
const
|
|
645
|
+
const blockHashPromise = this.context.readProvider.getBlockHash('head~2');
|
|
646
|
+
const blockProtoPromise = this.context.readProvider.getNextProtocol('head');
|
|
679
647
|
if (Array.isArray(operation)) {
|
|
680
648
|
ops = [...operation];
|
|
681
649
|
}
|
|
@@ -683,27 +651,19 @@ class OperationEmitter {
|
|
|
683
651
|
ops = [operation];
|
|
684
652
|
}
|
|
685
653
|
// Implicit account who emit the operation
|
|
686
|
-
const publicKeyHash = yield this.signer.publicKeyHash();
|
|
654
|
+
const publicKeyHash = pkh ? pkh : yield this.signer.publicKeyHash();
|
|
687
655
|
let counterPromise = Promise.resolve(undefined);
|
|
688
656
|
for (let i = 0; i < ops.length; i++) {
|
|
689
657
|
if (isOpRequireReveal(ops[i]) || ops[i].kind === 'reveal') {
|
|
690
|
-
|
|
691
|
-
counterPromise = Promise.resolve(counter);
|
|
658
|
+
counterPromise = this.context.readProvider.getCounter(publicKeyHash, 'head');
|
|
692
659
|
break;
|
|
693
660
|
}
|
|
694
661
|
}
|
|
695
|
-
const [
|
|
696
|
-
|
|
697
|
-
|
|
662
|
+
const [hash, protocol, headCounter] = yield Promise.all([
|
|
663
|
+
blockHashPromise,
|
|
664
|
+
blockProtoPromise,
|
|
698
665
|
counterPromise,
|
|
699
666
|
]);
|
|
700
|
-
if (!header) {
|
|
701
|
-
throw new Error('Unable to fetch latest block header');
|
|
702
|
-
}
|
|
703
|
-
if (!metadata) {
|
|
704
|
-
throw new Error('Unable to fetch latest metadata');
|
|
705
|
-
}
|
|
706
|
-
const head = header;
|
|
707
667
|
const counter = parseInt(headCounter || '0', 10);
|
|
708
668
|
if (!counters[publicKeyHash] || counters[publicKeyHash] < counter) {
|
|
709
669
|
counters[publicKeyHash] = counter;
|
|
@@ -745,12 +705,10 @@ class OperationEmitter {
|
|
|
745
705
|
throw new Error('Unsupported operation');
|
|
746
706
|
}
|
|
747
707
|
});
|
|
748
|
-
const branch = head.hash;
|
|
749
708
|
const contents = constructOps(ops);
|
|
750
|
-
const protocol = metadata.next_protocol;
|
|
751
709
|
return {
|
|
752
710
|
opOb: {
|
|
753
|
-
branch,
|
|
711
|
+
branch: hash,
|
|
754
712
|
contents,
|
|
755
713
|
protocol,
|
|
756
714
|
},
|
|
@@ -1135,7 +1093,7 @@ class WalletOperation {
|
|
|
1135
1093
|
if (!this._included) {
|
|
1136
1094
|
return 0;
|
|
1137
1095
|
}
|
|
1138
|
-
return combineLatest([this._includedInBlock, from(this.context.
|
|
1096
|
+
return combineLatest([this._includedInBlock, from(this.context.readProvider.getBlock('head'))])
|
|
1139
1097
|
.pipe(map(([foundAtBlock, head]) => {
|
|
1140
1098
|
return head.header.level - foundAtBlock.header.level + 1;
|
|
1141
1099
|
}), first())
|
|
@@ -1148,15 +1106,15 @@ class WalletOperation {
|
|
|
1148
1106
|
if (!this._included) {
|
|
1149
1107
|
return true;
|
|
1150
1108
|
}
|
|
1151
|
-
const
|
|
1109
|
+
const tipBlockHeaderLevel = yield this.context.readProvider.getBlockLevel(tipBlockIdentifier);
|
|
1152
1110
|
const inclusionBlock = yield this._includedInBlock.pipe(first()).toPromise();
|
|
1153
|
-
const levelDiff =
|
|
1111
|
+
const levelDiff = tipBlockHeaderLevel - inclusionBlock.header.level;
|
|
1154
1112
|
// Block produced before the operation is included are assumed to be part of the current branch
|
|
1155
1113
|
if (levelDiff <= 0) {
|
|
1156
1114
|
return true;
|
|
1157
1115
|
}
|
|
1158
1116
|
const tipBlockLevel = Math.min(inclusionBlock.header.level + levelDiff, inclusionBlock.header.level + MAX_BRANCH_ANCESTORS);
|
|
1159
|
-
const blocks = new Set(yield this.context.
|
|
1117
|
+
const blocks = new Set(yield this.context.readProvider.getLiveBlocks(tipBlockLevel));
|
|
1160
1118
|
return blocks.has(inclusionBlock.hash);
|
|
1161
1119
|
});
|
|
1162
1120
|
}
|
|
@@ -1231,13 +1189,13 @@ class DelegationWalletOperation extends WalletOperation {
|
|
|
1231
1189
|
revealOperation() {
|
|
1232
1190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1233
1191
|
const operationResult = yield this.operationResults();
|
|
1234
|
-
return operationResult.find(x => x.kind === OpKind.REVEAL);
|
|
1192
|
+
return operationResult.find((x) => x.kind === OpKind.REVEAL);
|
|
1235
1193
|
});
|
|
1236
1194
|
}
|
|
1237
1195
|
delegationOperation() {
|
|
1238
1196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1239
1197
|
const operationResult = yield this.operationResults();
|
|
1240
|
-
return operationResult.find(x => x.kind === OpKind.DELEGATION);
|
|
1198
|
+
return operationResult.find((x) => x.kind === OpKind.DELEGATION);
|
|
1241
1199
|
});
|
|
1242
1200
|
}
|
|
1243
1201
|
status() {
|
|
@@ -1325,21 +1283,8 @@ class TransactionWalletOperation extends WalletOperation {
|
|
|
1325
1283
|
}
|
|
1326
1284
|
}
|
|
1327
1285
|
|
|
1328
|
-
const
|
|
1329
|
-
|
|
1330
|
-
return defer(() => {
|
|
1331
|
-
if (!subject) {
|
|
1332
|
-
subject = new ReplaySubject();
|
|
1333
|
-
source.pipe(first()).subscribe(subject);
|
|
1334
|
-
cacheUntilObs.pipe(first()).subscribe(() => {
|
|
1335
|
-
subject = null;
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
return subject;
|
|
1339
|
-
});
|
|
1340
|
-
};
|
|
1341
|
-
const createNewPollingBasedHeadObservable = (pollingTimer, sharedHeadOb, context, scheduler) => {
|
|
1342
|
-
return pollingTimer.pipe(switchMap(() => sharedHeadOb), distinctUntilKeyChanged('hash'), timeoutWith(context.config.confirmationPollingTimeoutSecond * 1000, throwError(new Error('Confirmation polling timed out')), scheduler), shareReplay({
|
|
1286
|
+
const createNewPollingBasedHeadObservable = (sharedHeadOb, context, scheduler) => {
|
|
1287
|
+
return sharedHeadOb.pipe(timeoutWith(context.config.confirmationPollingTimeoutSecond * 1000, throwError(new Error('Confirmation polling timed out')), scheduler), shareReplay({
|
|
1343
1288
|
refCount: true,
|
|
1344
1289
|
scheduler,
|
|
1345
1290
|
}));
|
|
@@ -1348,23 +1293,22 @@ class OperationFactory {
|
|
|
1348
1293
|
constructor(context) {
|
|
1349
1294
|
this.context = context;
|
|
1350
1295
|
// Cache the last block for one second across all operations
|
|
1351
|
-
this.sharedHeadObs = defer(() =>
|
|
1296
|
+
this.sharedHeadObs = defer(() => {
|
|
1297
|
+
return createObservableFromSubscription(this.context.stream.subscribeBlock('head'));
|
|
1298
|
+
});
|
|
1352
1299
|
}
|
|
1353
1300
|
createNewHeadObservable() {
|
|
1354
1301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1355
|
-
|
|
1356
|
-
? this.context.config.confirmationPollingIntervalSecond
|
|
1357
|
-
: yield this.context.getConfirmationPollingInterval();
|
|
1358
|
-
return createNewPollingBasedHeadObservable(timer(0, confirmationPollingIntervalSecond * 1000), this.sharedHeadObs, this.context);
|
|
1302
|
+
return createNewPollingBasedHeadObservable(this.sharedHeadObs, this.context);
|
|
1359
1303
|
});
|
|
1360
1304
|
}
|
|
1361
1305
|
createPastBlockWalker(startBlock, count = 1) {
|
|
1362
|
-
return from(this.context.
|
|
1306
|
+
return from(this.context.readProvider.getBlock(startBlock)).pipe(switchMap((block) => {
|
|
1363
1307
|
if (count === 1) {
|
|
1364
1308
|
return of(block);
|
|
1365
1309
|
}
|
|
1366
1310
|
return range(block.header.level, count - 1).pipe(startWith(block), concatMap((level) => __awaiter(this, void 0, void 0, function* () {
|
|
1367
|
-
return this.context.
|
|
1311
|
+
return this.context.readProvider.getBlock(typeof level === 'number' ? level : level.header.level);
|
|
1368
1312
|
})));
|
|
1369
1313
|
}));
|
|
1370
1314
|
}
|
|
@@ -1414,7 +1358,7 @@ class RpcTzProvider extends OperationEmitter {
|
|
|
1414
1358
|
if (validateAddress(address) !== ValidationResult.VALID) {
|
|
1415
1359
|
throw new InvalidAddressError(`Invalid address: ${address}`);
|
|
1416
1360
|
}
|
|
1417
|
-
return this.
|
|
1361
|
+
return this.context.readProvider.getBalance(address, 'head');
|
|
1418
1362
|
});
|
|
1419
1363
|
}
|
|
1420
1364
|
getDelegate(address) {
|
|
@@ -1422,7 +1366,7 @@ class RpcTzProvider extends OperationEmitter {
|
|
|
1422
1366
|
if (validateAddress(address) !== ValidationResult.VALID) {
|
|
1423
1367
|
throw new InvalidAddressError(`Invalid address: ${address}`);
|
|
1424
1368
|
}
|
|
1425
|
-
return this.
|
|
1369
|
+
return this.context.readProvider.getDelegate(address, 'head');
|
|
1426
1370
|
});
|
|
1427
1371
|
}
|
|
1428
1372
|
activate(pkh, secret) {
|
|
@@ -1514,7 +1458,8 @@ class Estimate {
|
|
|
1514
1458
|
return this.roundUp(Number(this._milligasLimit) / 1000 + GAS_BUFFER);
|
|
1515
1459
|
}
|
|
1516
1460
|
get operationFeeMutez() {
|
|
1517
|
-
return ((Number(this._milligasLimit) / 1000 + GAS_BUFFER) * MINIMAL_FEE_PER_GAS_MUTEZ +
|
|
1461
|
+
return ((Number(this._milligasLimit) / 1000 + GAS_BUFFER) * MINIMAL_FEE_PER_GAS_MUTEZ +
|
|
1462
|
+
Number(this.opSize) * MINIMAL_FEE_PER_BYTE_MUTEZ);
|
|
1518
1463
|
}
|
|
1519
1464
|
roundUp(nanotez) {
|
|
1520
1465
|
return Math.ceil(Number(nanotez));
|
|
@@ -1556,7 +1501,7 @@ class Estimate {
|
|
|
1556
1501
|
let opSize = 0;
|
|
1557
1502
|
let minimalFeePerStorageByteMutez = 0;
|
|
1558
1503
|
let baseFeeMutez;
|
|
1559
|
-
estimateProperties.forEach(estimate => {
|
|
1504
|
+
estimateProperties.forEach((estimate) => {
|
|
1560
1505
|
milligasLimit += estimate.milligasLimit;
|
|
1561
1506
|
storageLimit += estimate.storageLimit;
|
|
1562
1507
|
opSize += estimate.opSize;
|
|
@@ -1568,7 +1513,14 @@ class Estimate {
|
|
|
1568
1513
|
return new Estimate(milligasLimit, storageLimit, opSize, minimalFeePerStorageByteMutez, baseFeeMutez);
|
|
1569
1514
|
}
|
|
1570
1515
|
static createArrayEstimateInstancesFromProperties(estimateProperties) {
|
|
1571
|
-
return estimateProperties.map(x => new Estimate(x.milligasLimit, x.storageLimit, x.opSize, x.minimalFeePerStorageByteMutez, x.baseFeeMutez));
|
|
1516
|
+
return estimateProperties.map((x) => new Estimate(x.milligasLimit, x.storageLimit, x.opSize, x.minimalFeePerStorageByteMutez, x.baseFeeMutez));
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
class RevealEstimateError extends Error {
|
|
1521
|
+
constructor() {
|
|
1522
|
+
super('Unable to estimate the reveal operation, the public key is unknown');
|
|
1523
|
+
this.name = 'Reveal Estimate Error';
|
|
1572
1524
|
}
|
|
1573
1525
|
}
|
|
1574
1526
|
|
|
@@ -1592,10 +1544,21 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1592
1544
|
this.ORIGINATION_STORAGE = 257;
|
|
1593
1545
|
this.OP_SIZE_REVEAL = 128;
|
|
1594
1546
|
}
|
|
1547
|
+
getKeys() {
|
|
1548
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1549
|
+
const isSignerConfigured = this.context.isAnySignerConfigured();
|
|
1550
|
+
return {
|
|
1551
|
+
publicKeyHash: isSignerConfigured
|
|
1552
|
+
? yield this.signer.publicKeyHash()
|
|
1553
|
+
: yield this.context.walletProvider.getPKH(),
|
|
1554
|
+
publicKey: isSignerConfigured ? yield this.signer.publicKey() : undefined,
|
|
1555
|
+
};
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1595
1558
|
// Maximum values defined by the protocol
|
|
1596
1559
|
getAccountLimits(pkh, constants, numberOfOps) {
|
|
1597
1560
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1598
|
-
const balance = yield this.
|
|
1561
|
+
const balance = yield this.context.readProvider.getBalance(pkh, 'head');
|
|
1599
1562
|
const { hard_gas_limit_per_operation, hard_gas_limit_per_block, hard_storage_limit_per_operation, cost_per_byte, } = constants;
|
|
1600
1563
|
return {
|
|
1601
1564
|
fee: 0,
|
|
@@ -1655,13 +1618,13 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1655
1618
|
};
|
|
1656
1619
|
}
|
|
1657
1620
|
}
|
|
1658
|
-
prepareEstimate(params, constants) {
|
|
1621
|
+
prepareEstimate(params, constants, pkh) {
|
|
1659
1622
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1660
|
-
const prepared = yield this.prepareOperation(params);
|
|
1623
|
+
const prepared = yield this.prepareOperation(params, pkh);
|
|
1661
1624
|
const { opbytes, opOb: { branch, contents }, } = yield this.forge(prepared);
|
|
1662
1625
|
const operation = {
|
|
1663
1626
|
operation: { branch, contents, signature: SIGNATURE_STUB },
|
|
1664
|
-
chain_id: yield this.
|
|
1627
|
+
chain_id: yield this.context.readProvider.getChainId(),
|
|
1665
1628
|
};
|
|
1666
1629
|
const { opResponse } = yield this.simulate(operation);
|
|
1667
1630
|
const { cost_per_byte } = constants;
|
|
@@ -1695,13 +1658,13 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1695
1658
|
originate(_a) {
|
|
1696
1659
|
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
1697
1660
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1698
|
-
const
|
|
1699
|
-
const protocolConstants = yield this.
|
|
1700
|
-
const DEFAULT_PARAMS = yield this.getAccountLimits(
|
|
1661
|
+
const { publicKeyHash } = yield this.getKeys();
|
|
1662
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1663
|
+
const DEFAULT_PARAMS = yield this.getAccountLimits(publicKeyHash, protocolConstants);
|
|
1701
1664
|
const op = yield createOriginationOperation(yield this.context.parser.prepareCodeOrigination(Object.assign(Object.assign({}, rest), mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS))));
|
|
1702
|
-
const isRevealNeeded = yield this.isRevealOpNeeded([op],
|
|
1703
|
-
const ops = isRevealNeeded ? yield this.addRevealOp([op],
|
|
1704
|
-
const estimateProperties = yield this.prepareEstimate({ operation: ops, source:
|
|
1665
|
+
const isRevealNeeded = yield this.isRevealOpNeeded([op], publicKeyHash);
|
|
1666
|
+
const ops = isRevealNeeded ? yield this.addRevealOp([op], publicKeyHash) : op;
|
|
1667
|
+
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: publicKeyHash }, protocolConstants, publicKeyHash);
|
|
1705
1668
|
if (isRevealNeeded) {
|
|
1706
1669
|
estimateProperties.shift();
|
|
1707
1670
|
}
|
|
@@ -1725,13 +1688,13 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1725
1688
|
if (rest.source && validateAddress(rest.source) !== ValidationResult.VALID) {
|
|
1726
1689
|
throw new InvalidAddressError(`Invalid 'source' address: ${rest.source}`);
|
|
1727
1690
|
}
|
|
1728
|
-
const pkh = yield this.
|
|
1729
|
-
const protocolConstants = yield this.
|
|
1691
|
+
const pkh = (yield this.getKeys()).publicKeyHash;
|
|
1692
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1730
1693
|
const DEFAULT_PARAMS = yield this.getAccountLimits(pkh, protocolConstants);
|
|
1731
1694
|
const op = yield createTransferOperation(Object.assign(Object.assign({}, rest), mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS)));
|
|
1732
1695
|
const isRevealNeeded = yield this.isRevealOpNeeded([op], pkh);
|
|
1733
1696
|
const ops = isRevealNeeded ? yield this.addRevealOp([op], pkh) : op;
|
|
1734
|
-
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants);
|
|
1697
|
+
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants, pkh);
|
|
1735
1698
|
if (isRevealNeeded) {
|
|
1736
1699
|
estimateProperties.shift();
|
|
1737
1700
|
}
|
|
@@ -1755,14 +1718,14 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1755
1718
|
if (rest.delegate && validateAddress(rest.delegate) !== ValidationResult.VALID) {
|
|
1756
1719
|
throw new InvalidAddressError(`Invalid delegate address: ${rest.delegate}`);
|
|
1757
1720
|
}
|
|
1758
|
-
const pkh = yield this.
|
|
1721
|
+
const pkh = (yield this.getKeys()).publicKeyHash;
|
|
1759
1722
|
const sourceOrDefault = rest.source || pkh;
|
|
1760
|
-
const protocolConstants = yield this.
|
|
1723
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1761
1724
|
const DEFAULT_PARAMS = yield this.getAccountLimits(sourceOrDefault, protocolConstants);
|
|
1762
1725
|
const op = yield createSetDelegateOperation(Object.assign(Object.assign({}, rest), mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS)));
|
|
1763
1726
|
const isRevealNeeded = yield this.isRevealOpNeeded([op], pkh);
|
|
1764
1727
|
const ops = isRevealNeeded ? yield this.addRevealOp([op], pkh) : op;
|
|
1765
|
-
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants);
|
|
1728
|
+
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants, pkh);
|
|
1766
1729
|
if (isRevealNeeded) {
|
|
1767
1730
|
estimateProperties.shift();
|
|
1768
1731
|
}
|
|
@@ -1777,10 +1740,10 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1777
1740
|
*/
|
|
1778
1741
|
batch(params) {
|
|
1779
1742
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1780
|
-
const
|
|
1743
|
+
const { publicKeyHash } = yield this.getKeys();
|
|
1781
1744
|
let operations = [];
|
|
1782
|
-
const protocolConstants = yield this.
|
|
1783
|
-
const DEFAULT_PARAMS = yield this.getAccountLimits(
|
|
1745
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1746
|
+
const DEFAULT_PARAMS = yield this.getAccountLimits(publicKeyHash, protocolConstants, params.length);
|
|
1784
1747
|
for (const param of params) {
|
|
1785
1748
|
switch (param.kind) {
|
|
1786
1749
|
case OpKind.TRANSACTION:
|
|
@@ -1802,9 +1765,9 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1802
1765
|
throw new Error(`Unsupported operation kind: ${param.kind}`);
|
|
1803
1766
|
}
|
|
1804
1767
|
}
|
|
1805
|
-
const isRevealNeeded = yield this.isRevealOpNeeded(operations,
|
|
1806
|
-
operations = isRevealNeeded ? yield this.addRevealOp(operations,
|
|
1807
|
-
const estimateProperties = yield this.prepareEstimate({ operation: operations, source:
|
|
1768
|
+
const isRevealNeeded = yield this.isRevealOpNeeded(operations, publicKeyHash);
|
|
1769
|
+
operations = isRevealNeeded ? yield this.addRevealOp(operations, publicKeyHash) : operations;
|
|
1770
|
+
const estimateProperties = yield this.prepareEstimate({ operation: operations, source: publicKeyHash }, protocolConstants, publicKeyHash);
|
|
1808
1771
|
return Estimate.createArrayEstimateInstancesFromProperties(estimateProperties);
|
|
1809
1772
|
});
|
|
1810
1773
|
}
|
|
@@ -1818,13 +1781,13 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1818
1781
|
*/
|
|
1819
1782
|
registerDelegate(params) {
|
|
1820
1783
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1821
|
-
const pkh = yield this.
|
|
1822
|
-
const protocolConstants = yield this.
|
|
1784
|
+
const pkh = (yield this.getKeys()).publicKeyHash;
|
|
1785
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1823
1786
|
const DEFAULT_PARAMS = yield this.getAccountLimits(pkh, protocolConstants);
|
|
1824
1787
|
const op = yield createRegisterDelegateOperation(Object.assign(Object.assign({}, params), DEFAULT_PARAMS), pkh);
|
|
1825
1788
|
const isRevealNeeded = yield this.isRevealOpNeeded([op], pkh);
|
|
1826
1789
|
const ops = isRevealNeeded ? yield this.addRevealOp([op], pkh) : op;
|
|
1827
|
-
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants);
|
|
1790
|
+
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants, pkh);
|
|
1828
1791
|
if (isRevealNeeded) {
|
|
1829
1792
|
estimateProperties.shift();
|
|
1830
1793
|
}
|
|
@@ -1841,12 +1804,15 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1841
1804
|
*/
|
|
1842
1805
|
reveal(params) {
|
|
1843
1806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1844
|
-
const
|
|
1845
|
-
if (
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
const
|
|
1807
|
+
const { publicKeyHash, publicKey } = yield this.getKeys();
|
|
1808
|
+
if (!publicKey) {
|
|
1809
|
+
throw new RevealEstimateError();
|
|
1810
|
+
}
|
|
1811
|
+
if (yield this.isAccountRevealRequired(publicKeyHash)) {
|
|
1812
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1813
|
+
const DEFAULT_PARAMS = yield this.getAccountLimits(publicKeyHash, protocolConstants);
|
|
1814
|
+
const op = yield createRevealOperation(Object.assign(Object.assign({}, params), DEFAULT_PARAMS), publicKeyHash, publicKey);
|
|
1815
|
+
const estimateProperties = yield this.prepareEstimate({ operation: op, source: publicKeyHash }, protocolConstants, publicKeyHash);
|
|
1850
1816
|
return Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
1851
1817
|
}
|
|
1852
1818
|
});
|
|
@@ -1862,13 +1828,13 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1862
1828
|
registerGlobalConstant(_a) {
|
|
1863
1829
|
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
1864
1830
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1865
|
-
const pkh = yield this.
|
|
1866
|
-
const protocolConstants = yield this.
|
|
1831
|
+
const pkh = (yield this.getKeys()).publicKeyHash;
|
|
1832
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
1867
1833
|
const DEFAULT_PARAMS = yield this.getAccountLimits(pkh, protocolConstants);
|
|
1868
1834
|
const op = yield createRegisterGlobalConstantOperation(Object.assign(Object.assign({}, rest), mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS)));
|
|
1869
1835
|
const isRevealNeeded = yield this.isRevealOpNeeded([op], pkh);
|
|
1870
1836
|
const ops = isRevealNeeded ? yield this.addRevealOp([op], pkh) : op;
|
|
1871
|
-
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants);
|
|
1837
|
+
const estimateProperties = yield this.prepareEstimate({ operation: ops, source: pkh }, protocolConstants, pkh);
|
|
1872
1838
|
if (isRevealNeeded) {
|
|
1873
1839
|
estimateProperties.shift();
|
|
1874
1840
|
}
|
|
@@ -1877,6 +1843,10 @@ class RPCEstimateProvider extends OperationEmitter {
|
|
|
1877
1843
|
}
|
|
1878
1844
|
addRevealOp(op, pkh) {
|
|
1879
1845
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1846
|
+
const { publicKey } = yield this.getKeys();
|
|
1847
|
+
if (!publicKey) {
|
|
1848
|
+
throw new RevealEstimateError();
|
|
1849
|
+
}
|
|
1880
1850
|
op.unshift(yield createRevealOperation(Object.assign({
|
|
1881
1851
|
fee: DEFAULT_FEE.REVEAL,
|
|
1882
1852
|
gasLimit: DEFAULT_GAS_LIMIT.REVEAL,
|
|
@@ -1996,12 +1966,12 @@ class OriginationOperation extends Operation {
|
|
|
1996
1966
|
/**
|
|
1997
1967
|
* @description Provide the contract abstract of the newly originated contract
|
|
1998
1968
|
*/
|
|
1999
|
-
contract(confirmations,
|
|
1969
|
+
contract(confirmations, timeout) {
|
|
2000
1970
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2001
1971
|
if (!this.contractAddress) {
|
|
2002
1972
|
throw new Error('No contract was originated in this operation');
|
|
2003
1973
|
}
|
|
2004
|
-
yield this.confirmation(confirmations,
|
|
1974
|
+
yield this.confirmation(confirmations, timeout);
|
|
2005
1975
|
return this.contractProvider.at(this.contractAddress);
|
|
2006
1976
|
});
|
|
2007
1977
|
}
|
|
@@ -2495,9 +2465,6 @@ class Wallet {
|
|
|
2495
2465
|
return this.walletCommand(() => __awaiter(this, void 0, void 0, function* () {
|
|
2496
2466
|
const mappedParams = yield this.walletProvider.mapOriginateParamsToWalletParams(() => this.context.parser.prepareCodeOrigination(Object.assign({}, params)));
|
|
2497
2467
|
const opHash = yield this.walletProvider.sendOperations([mappedParams]);
|
|
2498
|
-
if (!this.context.proto) {
|
|
2499
|
-
this.context.proto = (yield this.context.rpc.getBlock()).protocol;
|
|
2500
|
-
}
|
|
2501
2468
|
return this.context.operationFactory.createOriginationOperation(opHash);
|
|
2502
2469
|
}));
|
|
2503
2470
|
}
|
|
@@ -2582,11 +2549,10 @@ class Wallet {
|
|
|
2582
2549
|
throw new InvalidContractAddressError(`Invalid contract address: ${address}`);
|
|
2583
2550
|
}
|
|
2584
2551
|
const rpc = this.context.withExtensions().rpc;
|
|
2585
|
-
const
|
|
2586
|
-
const
|
|
2587
|
-
const
|
|
2588
|
-
const
|
|
2589
|
-
const abs = new ContractAbstraction(address, script, this, this.context.contract, entrypoints, chainId, rpc);
|
|
2552
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
2553
|
+
const script = yield readProvider.getScript(address, 'head');
|
|
2554
|
+
const entrypoints = yield readProvider.getEntrypoints(address);
|
|
2555
|
+
const abs = new ContractAbstraction(address, script, this, this.context.contract, entrypoints, rpc, readProvider);
|
|
2590
2556
|
return contractAbstractionComposer(abs, this.context);
|
|
2591
2557
|
});
|
|
2592
2558
|
}
|
|
@@ -2713,12 +2679,12 @@ const runCodeHelper = (viewArgsType, viewReturnType, contractStorageType, viewIn
|
|
|
2713
2679
|
};
|
|
2714
2680
|
};
|
|
2715
2681
|
class OnChainView {
|
|
2716
|
-
constructor(_rpc, _contractAddress, _smartContractViewSchema, _contractStorageType,
|
|
2682
|
+
constructor(_rpc, _readProvider, _contractAddress, _smartContractViewSchema, _contractStorageType, _args = 'Unit') {
|
|
2717
2683
|
this._rpc = _rpc;
|
|
2684
|
+
this._readProvider = _readProvider;
|
|
2718
2685
|
this._contractAddress = _contractAddress;
|
|
2719
2686
|
this._smartContractViewSchema = _smartContractViewSchema;
|
|
2720
2687
|
this._contractStorageType = _contractStorageType;
|
|
2721
|
-
this._contractStorageValue = _contractStorageValue;
|
|
2722
2688
|
this._args = _args;
|
|
2723
2689
|
}
|
|
2724
2690
|
/**
|
|
@@ -2738,9 +2704,10 @@ class OnChainView {
|
|
|
2738
2704
|
executeView(executionContext) {
|
|
2739
2705
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2740
2706
|
this.verifyContextExecution(executionContext);
|
|
2741
|
-
const balance = (yield this.
|
|
2742
|
-
const chainId = yield this.
|
|
2743
|
-
|
|
2707
|
+
const balance = (yield this._readProvider.getBalance(this._contractAddress, 'head')).toString();
|
|
2708
|
+
const chainId = yield this._readProvider.getChainId();
|
|
2709
|
+
const storage = yield this._readProvider.getStorage(this._contractAddress, 'head');
|
|
2710
|
+
return this.executeViewAndDecodeResult(runCodeHelper(this._smartContractViewSchema.viewArgsType, this._smartContractViewSchema.viewReturnType, this._contractStorageType, this.adaptViewCodeToContext(this._smartContractViewSchema.instructions, executionContext.viewCaller, balance), this.transformArgsToMichelson(), storage, balance, chainId, executionContext.source));
|
|
2744
2711
|
});
|
|
2745
2712
|
}
|
|
2746
2713
|
verifyContextExecution(executionContext) {
|
|
@@ -2824,247 +2791,8 @@ class ContractMethodFactory {
|
|
|
2824
2791
|
createContractMethodObjectParam(smartContractMethodSchema, smartContractMethodName, args, isMultipleEntrypoint = true, isAnonymous = false) {
|
|
2825
2792
|
return new ContractMethodObject(this.provider, this.contractAddress, smartContractMethodSchema, smartContractMethodName, args, isMultipleEntrypoint, isAnonymous);
|
|
2826
2793
|
}
|
|
2827
|
-
createContractViewObjectParam(rpc, smartContractViewSchema, contractStorageType,
|
|
2828
|
-
return new OnChainView(rpc, this.contractAddress, smartContractViewSchema, contractStorageType,
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
|
|
2832
|
-
class LambdaView {
|
|
2833
|
-
constructor(lambdaContract, viewContract, viewMethod = 'default', contractParameter = { prim: 'Unit' }) {
|
|
2834
|
-
this.lambdaContract = lambdaContract;
|
|
2835
|
-
this.viewContract = viewContract;
|
|
2836
|
-
this.viewMethod = viewMethod;
|
|
2837
|
-
this.contractParameter = contractParameter;
|
|
2838
|
-
this.voidLambda = this.createVoidLambda();
|
|
2839
|
-
}
|
|
2840
|
-
execute() {
|
|
2841
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2842
|
-
try {
|
|
2843
|
-
yield this.lambdaContract.methods.default(this.voidLambda).send();
|
|
2844
|
-
}
|
|
2845
|
-
catch (ex) {
|
|
2846
|
-
if (ex instanceof TezosOperationError) {
|
|
2847
|
-
const lastError = ex.errors[ex.errors.length - 1];
|
|
2848
|
-
const failedWith = lastError.with;
|
|
2849
|
-
return failedWith;
|
|
2850
|
-
}
|
|
2851
|
-
else {
|
|
2852
|
-
throw ex;
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
});
|
|
2856
|
-
}
|
|
2857
|
-
createVoidLambda() {
|
|
2858
|
-
const [parameter, callback] = this.getView();
|
|
2859
|
-
let contractArgs = [
|
|
2860
|
-
{
|
|
2861
|
-
prim: 'pair',
|
|
2862
|
-
args: [parameter, { prim: 'contract', args: [callback] }],
|
|
2863
|
-
},
|
|
2864
|
-
];
|
|
2865
|
-
if (this.viewMethod === 'default') {
|
|
2866
|
-
contractArgs = [{ string: '%default' }].concat(contractArgs);
|
|
2867
|
-
}
|
|
2868
|
-
return [
|
|
2869
|
-
{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: '0' }] },
|
|
2870
|
-
{ prim: 'NONE', args: [{ prim: 'key_hash' }] },
|
|
2871
|
-
{
|
|
2872
|
-
prim: 'CREATE_CONTRACT',
|
|
2873
|
-
args: [
|
|
2874
|
-
[
|
|
2875
|
-
{ prim: 'parameter', args: [callback] },
|
|
2876
|
-
{ prim: 'storage', args: [{ prim: 'unit' }] },
|
|
2877
|
-
{
|
|
2878
|
-
prim: 'code',
|
|
2879
|
-
args: [[{ prim: 'CAR' }, { prim: 'FAILWITH' }]],
|
|
2880
|
-
},
|
|
2881
|
-
],
|
|
2882
|
-
],
|
|
2883
|
-
},
|
|
2884
|
-
{
|
|
2885
|
-
prim: 'DIP',
|
|
2886
|
-
args: [
|
|
2887
|
-
[
|
|
2888
|
-
{
|
|
2889
|
-
prim: 'DIP',
|
|
2890
|
-
args: [
|
|
2891
|
-
[
|
|
2892
|
-
{
|
|
2893
|
-
prim: 'LAMBDA',
|
|
2894
|
-
args: [
|
|
2895
|
-
{
|
|
2896
|
-
prim: 'pair',
|
|
2897
|
-
args: [{ prim: 'address' }, { prim: 'unit' }],
|
|
2898
|
-
},
|
|
2899
|
-
{
|
|
2900
|
-
prim: 'pair',
|
|
2901
|
-
args: [{ prim: 'list', args: [{ prim: 'operation' }] }, { prim: 'unit' }],
|
|
2902
|
-
},
|
|
2903
|
-
[
|
|
2904
|
-
{ prim: 'CAR' },
|
|
2905
|
-
{ prim: 'CONTRACT', args: [callback] },
|
|
2906
|
-
{
|
|
2907
|
-
prim: 'IF_NONE',
|
|
2908
|
-
args: [
|
|
2909
|
-
[
|
|
2910
|
-
{
|
|
2911
|
-
prim: 'PUSH',
|
|
2912
|
-
args: [{ prim: 'string' }, { string: `Callback type unmatched` }],
|
|
2913
|
-
},
|
|
2914
|
-
{ prim: 'FAILWITH' },
|
|
2915
|
-
],
|
|
2916
|
-
[],
|
|
2917
|
-
],
|
|
2918
|
-
},
|
|
2919
|
-
{
|
|
2920
|
-
prim: 'PUSH',
|
|
2921
|
-
args: [parameter, this.contractParameter],
|
|
2922
|
-
},
|
|
2923
|
-
{ prim: 'PAIR' },
|
|
2924
|
-
{
|
|
2925
|
-
prim: 'DIP',
|
|
2926
|
-
args: [
|
|
2927
|
-
[
|
|
2928
|
-
{
|
|
2929
|
-
prim: 'PUSH',
|
|
2930
|
-
args: [
|
|
2931
|
-
{ prim: 'address' },
|
|
2932
|
-
{ string: `${this.viewContract.address}%${this.viewMethod}` },
|
|
2933
|
-
],
|
|
2934
|
-
},
|
|
2935
|
-
{ prim: 'DUP' },
|
|
2936
|
-
{ prim: 'CONTRACT', args: contractArgs },
|
|
2937
|
-
{
|
|
2938
|
-
prim: 'IF_NONE',
|
|
2939
|
-
args: [
|
|
2940
|
-
[
|
|
2941
|
-
{
|
|
2942
|
-
prim: 'PUSH',
|
|
2943
|
-
args: [
|
|
2944
|
-
{ prim: 'string' },
|
|
2945
|
-
{ string: `Contract does not exist` },
|
|
2946
|
-
],
|
|
2947
|
-
},
|
|
2948
|
-
{ prim: 'FAILWITH' },
|
|
2949
|
-
],
|
|
2950
|
-
[{ prim: 'DIP', args: [[{ prim: 'DROP' }]] }],
|
|
2951
|
-
],
|
|
2952
|
-
},
|
|
2953
|
-
{
|
|
2954
|
-
prim: 'PUSH',
|
|
2955
|
-
args: [{ prim: 'mutez' }, { int: '0' }],
|
|
2956
|
-
},
|
|
2957
|
-
],
|
|
2958
|
-
],
|
|
2959
|
-
},
|
|
2960
|
-
{ prim: 'TRANSFER_TOKENS' },
|
|
2961
|
-
{
|
|
2962
|
-
prim: 'DIP',
|
|
2963
|
-
args: [[{ prim: 'NIL', args: [{ prim: 'operation' }] }]],
|
|
2964
|
-
},
|
|
2965
|
-
{ prim: 'CONS' },
|
|
2966
|
-
{ prim: 'DIP', args: [[{ prim: 'UNIT' }]] },
|
|
2967
|
-
{ prim: 'PAIR' },
|
|
2968
|
-
],
|
|
2969
|
-
],
|
|
2970
|
-
},
|
|
2971
|
-
],
|
|
2972
|
-
],
|
|
2973
|
-
},
|
|
2974
|
-
{ prim: 'APPLY' },
|
|
2975
|
-
{
|
|
2976
|
-
prim: 'DIP',
|
|
2977
|
-
args: [
|
|
2978
|
-
[
|
|
2979
|
-
{
|
|
2980
|
-
prim: 'PUSH',
|
|
2981
|
-
args: [{ prim: 'address' }, { string: this.lambdaContract.address }],
|
|
2982
|
-
},
|
|
2983
|
-
{ prim: 'DUP' },
|
|
2984
|
-
{
|
|
2985
|
-
prim: 'CONTRACT',
|
|
2986
|
-
args: [
|
|
2987
|
-
{
|
|
2988
|
-
prim: 'lambda',
|
|
2989
|
-
args: [
|
|
2990
|
-
{ prim: 'unit' },
|
|
2991
|
-
{
|
|
2992
|
-
prim: 'pair',
|
|
2993
|
-
args: [
|
|
2994
|
-
{ prim: 'list', args: [{ prim: 'operation' }] },
|
|
2995
|
-
{ prim: 'unit' },
|
|
2996
|
-
],
|
|
2997
|
-
},
|
|
2998
|
-
],
|
|
2999
|
-
},
|
|
3000
|
-
],
|
|
3001
|
-
},
|
|
3002
|
-
{
|
|
3003
|
-
prim: 'IF_NONE',
|
|
3004
|
-
args: [
|
|
3005
|
-
[
|
|
3006
|
-
{
|
|
3007
|
-
prim: 'PUSH',
|
|
3008
|
-
args: [{ prim: 'string' }, { string: `Contract does not exists` }],
|
|
3009
|
-
},
|
|
3010
|
-
{ prim: 'FAILWITH' },
|
|
3011
|
-
],
|
|
3012
|
-
[{ prim: 'DIP', args: [[{ prim: 'DROP' }]] }],
|
|
3013
|
-
],
|
|
3014
|
-
},
|
|
3015
|
-
{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: '0' }] },
|
|
3016
|
-
],
|
|
3017
|
-
],
|
|
3018
|
-
},
|
|
3019
|
-
{ prim: 'TRANSFER_TOKENS' },
|
|
3020
|
-
{
|
|
3021
|
-
prim: 'DIP',
|
|
3022
|
-
args: [[{ prim: 'NIL', args: [{ prim: 'operation' }] }]],
|
|
3023
|
-
},
|
|
3024
|
-
{ prim: 'CONS' },
|
|
3025
|
-
],
|
|
3026
|
-
],
|
|
3027
|
-
},
|
|
3028
|
-
{ prim: 'CONS' },
|
|
3029
|
-
{ prim: 'DIP', args: [[{ prim: 'UNIT' }]] },
|
|
3030
|
-
{ prim: 'PAIR' },
|
|
3031
|
-
];
|
|
3032
|
-
}
|
|
3033
|
-
getView() {
|
|
3034
|
-
const entrypoints = this.viewContract.entrypoints.entrypoints;
|
|
3035
|
-
const entrypoint = entrypoints[this.viewMethod];
|
|
3036
|
-
if (!entrypoint) {
|
|
3037
|
-
throw Error(`Contract at ${this.viewContract.address} does not have entrypoint: ${this.viewMethod}`);
|
|
3038
|
-
}
|
|
3039
|
-
if (!('prim' in entrypoint) || !entrypoint.args) {
|
|
3040
|
-
// TODO: Enhance this error message to be more descriptive
|
|
3041
|
-
throw Error('Entrypoint args undefined');
|
|
3042
|
-
}
|
|
3043
|
-
const args = Array.from(entrypoint.args);
|
|
3044
|
-
const [parameter, callbackContract] = args;
|
|
3045
|
-
if ('annots' in parameter) {
|
|
3046
|
-
delete parameter['annots'];
|
|
3047
|
-
}
|
|
3048
|
-
if (!('prim' in callbackContract) || !callbackContract.args) {
|
|
3049
|
-
// TODO: Enhance this error message to be more descriptive
|
|
3050
|
-
throw Error('Callback contract args undefined');
|
|
3051
|
-
}
|
|
3052
|
-
let message;
|
|
3053
|
-
if (entrypoint.prim !== 'pair') {
|
|
3054
|
-
message = `Expected {'prim': 'pair', ..} but found {'prim': ${entrypoint.prim}, ..}`;
|
|
3055
|
-
}
|
|
3056
|
-
else if (args.length !== 2) {
|
|
3057
|
-
message = `Expected an Array of length 2, but found: ${args}`;
|
|
3058
|
-
}
|
|
3059
|
-
else if (callbackContract.prim !== 'contract') {
|
|
3060
|
-
message = `Expected a {prim: 'contract', ...}, but found: ${callbackContract.prim}`;
|
|
3061
|
-
}
|
|
3062
|
-
else if (callbackContract.args && callbackContract.args.length !== 1) {
|
|
3063
|
-
message = `Expected a single argument to 'contract', but found: ${callbackContract.args}`;
|
|
3064
|
-
}
|
|
3065
|
-
if (message)
|
|
3066
|
-
throw Error(message);
|
|
3067
|
-
return [parameter, callbackContract.args[0]];
|
|
2794
|
+
createContractViewObjectParam(rpc, readProvider, smartContractViewSchema, contractStorageType, viewArgs) {
|
|
2795
|
+
return new OnChainView(rpc, readProvider, this.contractAddress, smartContractViewSchema, contractStorageType, viewArgs);
|
|
3068
2796
|
}
|
|
3069
2797
|
}
|
|
3070
2798
|
|
|
@@ -3073,55 +2801,31 @@ const DEFAULT_SMART_CONTRACT_METHOD_NAME = 'default';
|
|
|
3073
2801
|
* @description Utility class to retrieve data from a smart contract's storage without incurring fees via a contract's view method
|
|
3074
2802
|
*/
|
|
3075
2803
|
class ContractView {
|
|
3076
|
-
constructor(currentContract,
|
|
2804
|
+
constructor(currentContract, name, callbackParametersSchema, parameterSchema, args, rpc, readProvider) {
|
|
3077
2805
|
this.currentContract = currentContract;
|
|
3078
|
-
this.provider = provider;
|
|
3079
2806
|
this.name = name;
|
|
3080
|
-
this.chainId = chainId;
|
|
3081
2807
|
this.callbackParametersSchema = callbackParametersSchema;
|
|
3082
2808
|
this.parameterSchema = parameterSchema;
|
|
3083
2809
|
this.args = args;
|
|
2810
|
+
this.rpc = rpc;
|
|
2811
|
+
this.readProvider = readProvider;
|
|
3084
2812
|
}
|
|
3085
|
-
|
|
3086
|
-
*
|
|
3087
|
-
* @description Find which lambda contract to use based on the current network,
|
|
3088
|
-
* encode parameters to Michelson,
|
|
3089
|
-
* create an instance of Lambdaview to retrieve data, and
|
|
3090
|
-
* Decode Michelson response
|
|
3091
|
-
*
|
|
3092
|
-
* @param Options Address of a lambda contract (sandbox users)
|
|
3093
|
-
*/
|
|
3094
|
-
read(customLambdaAddress) {
|
|
2813
|
+
read(chainId) {
|
|
3095
2814
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
if (customLambdaAddress) {
|
|
3099
|
-
lambdaAddress = customLambdaAddress;
|
|
3100
|
-
}
|
|
3101
|
-
else if (this.chainId === ChainIds.GRANADANET) {
|
|
3102
|
-
lambdaAddress = DefaultLambdaAddresses.GRANADANET;
|
|
3103
|
-
}
|
|
3104
|
-
else if (this.chainId === ChainIds.HANGZHOUNET) {
|
|
3105
|
-
lambdaAddress = DefaultLambdaAddresses.HANGZHOUNET;
|
|
3106
|
-
}
|
|
3107
|
-
else if (this.chainId === ChainIds.ITHACANET) {
|
|
3108
|
-
lambdaAddress = DefaultLambdaAddresses.ITHACANET;
|
|
2815
|
+
if (validateContractAddress(chainId) == ValidationResult.VALID) {
|
|
2816
|
+
throw new Error(`Since version 12, the lambda view no longer depends on a lambda contract. The read method no longer accepts a contract address as a parameter.`);
|
|
3109
2817
|
}
|
|
3110
|
-
else if (
|
|
3111
|
-
|
|
2818
|
+
else if (chainId && validateChain(chainId) !== ValidationResult.VALID) {
|
|
2819
|
+
throw new Error('ChainId is invalid');
|
|
3112
2820
|
}
|
|
3113
|
-
else if (this.chainId === ChainIds.MAINNET) {
|
|
3114
|
-
lambdaAddress = DefaultLambdaAddresses.MAINNET;
|
|
3115
|
-
}
|
|
3116
|
-
else {
|
|
3117
|
-
throw new UndefinedLambdaContractError();
|
|
3118
|
-
}
|
|
3119
|
-
const lambdaContract = yield this.provider.at(lambdaAddress);
|
|
3120
2821
|
const arg = this.parameterSchema.Encode(...this.args);
|
|
3121
|
-
const
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
2822
|
+
const result = yield this.rpc.runView({
|
|
2823
|
+
contract: this.currentContract.address,
|
|
2824
|
+
entrypoint: this.name,
|
|
2825
|
+
input: arg,
|
|
2826
|
+
chain_id: chainId ? chainId : yield this.readProvider.getChainId(),
|
|
2827
|
+
});
|
|
2828
|
+
return this.callbackParametersSchema.Execute(result.data);
|
|
3125
2829
|
});
|
|
3126
2830
|
}
|
|
3127
2831
|
}
|
|
@@ -3142,17 +2846,17 @@ const isView = (entrypoint) => {
|
|
|
3142
2846
|
}
|
|
3143
2847
|
return isView;
|
|
3144
2848
|
};
|
|
3145
|
-
const isContractProvider = (variableToCheck) => variableToCheck.contractProviderTypeSymbol !== undefined;
|
|
3146
2849
|
/**
|
|
3147
2850
|
* @description Smart contract abstraction
|
|
3148
2851
|
*/
|
|
3149
2852
|
class ContractAbstraction {
|
|
3150
|
-
constructor(address, script, provider, storageProvider, entrypoints,
|
|
2853
|
+
constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider) {
|
|
3151
2854
|
this.address = address;
|
|
3152
2855
|
this.script = script;
|
|
3153
2856
|
this.storageProvider = storageProvider;
|
|
3154
2857
|
this.entrypoints = entrypoints;
|
|
3155
|
-
this.
|
|
2858
|
+
this.rpc = rpc;
|
|
2859
|
+
this.readProvider = readProvider;
|
|
3156
2860
|
/**
|
|
3157
2861
|
* @description 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.
|
|
3158
2862
|
* NB: if the contract contains annotation it will include named properties; if not it will be indexed by a number.
|
|
@@ -3182,11 +2886,11 @@ class ContractAbstraction {
|
|
|
3182
2886
|
this.parameterSchema = ParameterSchema.fromRPCResponse({ script: this.script });
|
|
3183
2887
|
this.viewSchema = ViewSchema.fromRPCResponse({ script: this.script });
|
|
3184
2888
|
if (this.viewSchema.length !== 0) {
|
|
3185
|
-
this._initializeOnChainViews(this, rpc, this.viewSchema);
|
|
2889
|
+
this._initializeOnChainViews(this, rpc, this.readProvider, this.viewSchema);
|
|
3186
2890
|
}
|
|
3187
|
-
this._initializeMethods(this,
|
|
2891
|
+
this._initializeMethods(this, this.entrypoints.entrypoints, this.rpc, this.readProvider);
|
|
3188
2892
|
}
|
|
3189
|
-
_initializeMethods(currentContract,
|
|
2893
|
+
_initializeMethods(currentContract, entrypoints, rpc, readProvider) {
|
|
3190
2894
|
const parameterSchema = this.parameterSchema;
|
|
3191
2895
|
const keys = Object.keys(entrypoints);
|
|
3192
2896
|
if (parameterSchema.isMultipleEntryPoint) {
|
|
@@ -3198,20 +2902,18 @@ class ContractAbstraction {
|
|
|
3198
2902
|
this.methodsObject[smartContractMethodName] = function (args) {
|
|
3199
2903
|
return currentContract.contractMethodFactory.createContractMethodObjectParam(smartContractMethodSchema, smartContractMethodName, args);
|
|
3200
2904
|
};
|
|
3201
|
-
if (
|
|
3202
|
-
|
|
3203
|
-
const
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
this.views[smartContractMethodName] = view;
|
|
3214
|
-
}
|
|
2905
|
+
if (isView(entrypoints[smartContractMethodName])) {
|
|
2906
|
+
const view = function (...args) {
|
|
2907
|
+
const entrypointParamWithoutCallback = entrypoints[smartContractMethodName]
|
|
2908
|
+
.args[0];
|
|
2909
|
+
const smartContractMethodSchemaWithoutCallback = new ParameterSchema(entrypointParamWithoutCallback);
|
|
2910
|
+
const parametersCallback = entrypoints[smartContractMethodName].args[1]
|
|
2911
|
+
.args[0];
|
|
2912
|
+
const smartContractMethodCallbackSchema = new ParameterSchema(parametersCallback);
|
|
2913
|
+
validateArgs(args, smartContractMethodSchemaWithoutCallback, smartContractMethodName);
|
|
2914
|
+
return new ContractView(currentContract, smartContractMethodName, smartContractMethodCallbackSchema, smartContractMethodSchemaWithoutCallback, args, rpc, readProvider);
|
|
2915
|
+
};
|
|
2916
|
+
this.views[smartContractMethodName] = view;
|
|
3215
2917
|
}
|
|
3216
2918
|
});
|
|
3217
2919
|
// Deal with methods with no annotations which were not discovered by the RPC endpoint
|
|
@@ -3231,17 +2933,17 @@ class ContractAbstraction {
|
|
|
3231
2933
|
this.methods[DEFAULT_SMART_CONTRACT_METHOD_NAME] = function (...args) {
|
|
3232
2934
|
return currentContract.contractMethodFactory.createContractMethodFlatParams(smartContractMethodSchema, DEFAULT_SMART_CONTRACT_METHOD_NAME, args, false);
|
|
3233
2935
|
};
|
|
3234
|
-
this.methodsObject[DEFAULT_SMART_CONTRACT_METHOD_NAME] =
|
|
3235
|
-
|
|
3236
|
-
|
|
2936
|
+
this.methodsObject[DEFAULT_SMART_CONTRACT_METHOD_NAME] =
|
|
2937
|
+
function (args) {
|
|
2938
|
+
return currentContract.contractMethodFactory.createContractMethodObjectParam(smartContractMethodSchema, DEFAULT_SMART_CONTRACT_METHOD_NAME, args, false);
|
|
2939
|
+
};
|
|
3237
2940
|
}
|
|
3238
2941
|
}
|
|
3239
|
-
_initializeOnChainViews(currentContract, rpc, allContractViews) {
|
|
2942
|
+
_initializeOnChainViews(currentContract, rpc, readProvider, allContractViews) {
|
|
3240
2943
|
const storageType = this.schema.val;
|
|
3241
|
-
const storageValue = this.script.storage;
|
|
3242
2944
|
allContractViews.forEach((viewSchema) => {
|
|
3243
2945
|
this.contractViews[viewSchema.viewName] = function (args) {
|
|
3244
|
-
return currentContract.contractMethodFactory.createContractViewObjectParam(rpc, viewSchema, storageType,
|
|
2946
|
+
return currentContract.contractMethodFactory.createContractViewObjectParam(rpc, readProvider, viewSchema, storageType, args);
|
|
3245
2947
|
};
|
|
3246
2948
|
});
|
|
3247
2949
|
}
|
|
@@ -3395,8 +3097,9 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3395
3097
|
if (validateContractAddress(contract) !== ValidationResult.VALID) {
|
|
3396
3098
|
throw new InvalidContractAddressError(`Invalid contract address: ${contract}`);
|
|
3397
3099
|
}
|
|
3100
|
+
const script = yield this.context.readProvider.getScript(contract, 'head');
|
|
3398
3101
|
if (!schema) {
|
|
3399
|
-
schema =
|
|
3102
|
+
schema = script;
|
|
3400
3103
|
}
|
|
3401
3104
|
let contractSchema;
|
|
3402
3105
|
if (Schema.isSchema(schema)) {
|
|
@@ -3405,8 +3108,7 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3405
3108
|
else {
|
|
3406
3109
|
contractSchema = Schema.fromRPCResponse({ script: schema });
|
|
3407
3110
|
}
|
|
3408
|
-
|
|
3409
|
-
return contractSchema.Execute(storage, smartContractAbstractionSemantic(this)); // Cast into T because only the caller can know the true type of the storage
|
|
3111
|
+
return contractSchema.Execute(script.storage, smartContractAbstractionSemantic(this)); // Cast into T because only the caller can know the true type of the storage
|
|
3410
3112
|
});
|
|
3411
3113
|
}
|
|
3412
3114
|
/**
|
|
@@ -3458,8 +3160,8 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3458
3160
|
const { packed } = yield this.context.packer.packData({ data: key, type });
|
|
3459
3161
|
const encodedExpr = encodeExpr(packed);
|
|
3460
3162
|
const bigMapValue = block
|
|
3461
|
-
? yield this.context.
|
|
3462
|
-
: yield this.context.
|
|
3163
|
+
? yield this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, block)
|
|
3164
|
+
: yield this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, 'head');
|
|
3463
3165
|
return schema.ExecuteOnBigMapValue(bigMapValue, smartContractAbstractionSemantic(this));
|
|
3464
3166
|
});
|
|
3465
3167
|
}
|
|
@@ -3498,11 +3200,10 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3498
3200
|
});
|
|
3499
3201
|
}
|
|
3500
3202
|
getBlockForRequest(keys, block) {
|
|
3501
|
-
var _a;
|
|
3502
3203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3503
3204
|
return keys.length === 1 || typeof block !== 'undefined'
|
|
3504
3205
|
? block
|
|
3505
|
-
:
|
|
3206
|
+
: yield this.context.readProvider.getBlockLevel('head');
|
|
3506
3207
|
});
|
|
3507
3208
|
}
|
|
3508
3209
|
getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
|
|
@@ -3531,8 +3232,8 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3531
3232
|
getSaplingDiffByID(id, block) {
|
|
3532
3233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3533
3234
|
const saplingState = block
|
|
3534
|
-
? yield this.context.
|
|
3535
|
-
: yield this.context.
|
|
3235
|
+
? yield this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
|
|
3236
|
+
: yield this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
|
|
3536
3237
|
return saplingState;
|
|
3537
3238
|
});
|
|
3538
3239
|
}
|
|
@@ -3709,11 +3410,10 @@ class RpcContractProvider extends OperationEmitter {
|
|
|
3709
3410
|
throw new InvalidContractAddressError(`Invalid contract address: ${address}`);
|
|
3710
3411
|
}
|
|
3711
3412
|
const rpc = this.context.withExtensions().rpc;
|
|
3712
|
-
const
|
|
3713
|
-
const
|
|
3714
|
-
const
|
|
3715
|
-
const
|
|
3716
|
-
const abs = new ContractAbstraction(address, script, this, this, entrypoints, chainId, rpc);
|
|
3413
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
3414
|
+
const script = yield readProvider.getScript(address, 'head');
|
|
3415
|
+
const entrypoints = yield readProvider.getEntrypoints(address);
|
|
3416
|
+
const abs = new ContractAbstraction(address, script, this, this, entrypoints, rpc, readProvider);
|
|
3717
3417
|
return contractAbstractionComposer(abs, this.context);
|
|
3718
3418
|
});
|
|
3719
3419
|
}
|
|
@@ -3740,8 +3440,11 @@ class MichelCodecParser {
|
|
|
3740
3440
|
}
|
|
3741
3441
|
getNextProto() {
|
|
3742
3442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3743
|
-
|
|
3744
|
-
|
|
3443
|
+
if (!this.context.proto) {
|
|
3444
|
+
const nextProto = yield this.context.readProvider.getNextProtocol('head');
|
|
3445
|
+
this.context.proto = nextProto;
|
|
3446
|
+
}
|
|
3447
|
+
return this.context.proto;
|
|
3745
3448
|
});
|
|
3746
3449
|
}
|
|
3747
3450
|
parseScript(src) {
|
|
@@ -3881,175 +3584,189 @@ class NoopGlobalConstantsProvider {
|
|
|
3881
3584
|
}
|
|
3882
3585
|
}
|
|
3883
3586
|
|
|
3884
|
-
const defaultConfigConfirmation = {
|
|
3885
|
-
defaultConfirmationCount: 1,
|
|
3886
|
-
confirmationPollingTimeoutSecond: 180,
|
|
3887
|
-
};
|
|
3888
|
-
const defaultConfigStreamer = {
|
|
3889
|
-
streamerPollingIntervalMilliseconds: 20000,
|
|
3890
|
-
shouldObservableSubscriptionRetry: false,
|
|
3891
|
-
observableSubscriptionRetryFunction: retry(),
|
|
3892
|
-
};
|
|
3893
3587
|
/**
|
|
3894
|
-
* @description
|
|
3588
|
+
* @description Converts calls from TzReadProvider into calls to the wrapped RpcClient in a format it can understand.
|
|
3895
3589
|
*/
|
|
3896
|
-
class
|
|
3897
|
-
constructor(
|
|
3898
|
-
this.
|
|
3899
|
-
this._signer = _signer;
|
|
3900
|
-
this._proto = _proto;
|
|
3901
|
-
this._config = _config;
|
|
3902
|
-
this.providerDecorator = [];
|
|
3903
|
-
this.tz = new RpcTzProvider(this);
|
|
3904
|
-
this.estimate = new RPCEstimateProvider(this);
|
|
3905
|
-
this.contract = new RpcContractProvider(this, this.estimate);
|
|
3906
|
-
this.batch = new RPCBatchProvider(this, this.estimate);
|
|
3907
|
-
this.wallet = new Wallet(this);
|
|
3908
|
-
/**
|
|
3909
|
-
* @description Applies the decorators on a cloned instance of the context and returned this cloned instance.
|
|
3910
|
-
* The decorators are functions that inject logic into the context.
|
|
3911
|
-
* They are provided by the extensions set on the TezosToolkit by calling the registerProviderDecorator method.
|
|
3912
|
-
*/
|
|
3913
|
-
this.withExtensions = () => {
|
|
3914
|
-
let clonedContext = this.clone();
|
|
3915
|
-
this.providerDecorator.forEach((decorator) => {
|
|
3916
|
-
clonedContext = decorator(clonedContext);
|
|
3917
|
-
});
|
|
3918
|
-
return clonedContext;
|
|
3919
|
-
};
|
|
3920
|
-
if (typeof this._rpc === 'string') {
|
|
3921
|
-
this._rpcClient = new RpcClient(this._rpc);
|
|
3922
|
-
}
|
|
3923
|
-
else {
|
|
3924
|
-
this._rpcClient = this._rpc;
|
|
3925
|
-
}
|
|
3926
|
-
this._forger = forger ? forger : new RpcForger(this);
|
|
3927
|
-
this._injector = injector ? injector : new RpcInjector(this);
|
|
3928
|
-
this.operationFactory = new OperationFactory(this);
|
|
3929
|
-
this._walletProvider = wallet ? wallet : new LegacyWalletProvider(this);
|
|
3930
|
-
this._parser = parser ? parser : new MichelCodecParser(this);
|
|
3931
|
-
this._packer = packer ? packer : new RpcPacker(this);
|
|
3932
|
-
this._globalConstantsProvider = globalConstantsProvider
|
|
3933
|
-
? globalConstantsProvider
|
|
3934
|
-
: new NoopGlobalConstantsProvider();
|
|
3590
|
+
class RpcReadAdapter {
|
|
3591
|
+
constructor(context) {
|
|
3592
|
+
this.context = context;
|
|
3935
3593
|
}
|
|
3936
|
-
|
|
3937
|
-
|
|
3594
|
+
/**
|
|
3595
|
+
* @description Access the balance of a contract.
|
|
3596
|
+
* @param address address from which we want to retrieve the balance
|
|
3597
|
+
* @param block from which we want to retrieve the balance
|
|
3598
|
+
* @returns the balance in mutez
|
|
3599
|
+
*/
|
|
3600
|
+
getBalance(address, block) {
|
|
3601
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3602
|
+
return this.context.rpc.getBalance(address, { block: String(block) });
|
|
3603
|
+
});
|
|
3938
3604
|
}
|
|
3939
|
-
|
|
3940
|
-
|
|
3605
|
+
/**
|
|
3606
|
+
* @description Access the delegate of a contract, if any.
|
|
3607
|
+
* @param address contract address from which we want to retrieve the delegate (baker)
|
|
3608
|
+
* @param block from which we want to retrieve the delegate
|
|
3609
|
+
* @returns the public key hash of the delegate or null if no delegate
|
|
3610
|
+
*/
|
|
3611
|
+
getDelegate(address, block) {
|
|
3612
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3613
|
+
return this.context.rpc.getDelegate(address, { block: String(block) });
|
|
3614
|
+
});
|
|
3941
3615
|
}
|
|
3942
|
-
|
|
3943
|
-
|
|
3616
|
+
/**
|
|
3617
|
+
* @description Access the next protocol hash
|
|
3618
|
+
* @param block from which we want to retrieve the next protocol hash
|
|
3619
|
+
*/
|
|
3620
|
+
getNextProtocol(block) {
|
|
3621
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3622
|
+
const protocols = yield this.context.rpc.getProtocols({ block: String(block) });
|
|
3623
|
+
return protocols.next_protocol;
|
|
3624
|
+
});
|
|
3944
3625
|
}
|
|
3945
|
-
|
|
3946
|
-
|
|
3626
|
+
/**
|
|
3627
|
+
* @description Access protocol constants used in Taquito
|
|
3628
|
+
* @param block from which we want to retrieve the constants
|
|
3629
|
+
*/
|
|
3630
|
+
getProtocolConstants(block) {
|
|
3631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3632
|
+
const { time_between_blocks, minimal_block_delay, hard_gas_limit_per_operation, hard_gas_limit_per_block, hard_storage_limit_per_operation, cost_per_byte, } = yield this.context.rpc.getConstants({ block: String(block) });
|
|
3633
|
+
return {
|
|
3634
|
+
time_between_blocks,
|
|
3635
|
+
minimal_block_delay,
|
|
3636
|
+
hard_gas_limit_per_operation,
|
|
3637
|
+
hard_gas_limit_per_block,
|
|
3638
|
+
hard_storage_limit_per_operation,
|
|
3639
|
+
cost_per_byte,
|
|
3640
|
+
};
|
|
3641
|
+
});
|
|
3947
3642
|
}
|
|
3948
|
-
|
|
3949
|
-
|
|
3643
|
+
/**
|
|
3644
|
+
* @description Access the script (code and storage) of a smart contract
|
|
3645
|
+
* @param contract contract address from which we want to retrieve the script
|
|
3646
|
+
* @param block from which we want to retrieve the storage value
|
|
3647
|
+
* @returns Note: The code must be in the JSON format and not contain global constant
|
|
3648
|
+
*/
|
|
3649
|
+
getScript(contract, block) {
|
|
3650
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3651
|
+
return this.context.rpc.getNormalizedScript(contract, { unparsing_mode: 'Readable' }, { block: String(block) });
|
|
3652
|
+
});
|
|
3950
3653
|
}
|
|
3951
|
-
|
|
3952
|
-
|
|
3654
|
+
/**
|
|
3655
|
+
* @description Access the storage value of a contract
|
|
3656
|
+
* @param contract contract address from which we want to retrieve the storage
|
|
3657
|
+
* @param block from which we want to retrieve the storage value
|
|
3658
|
+
*/
|
|
3659
|
+
getStorage(contract, block) {
|
|
3660
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3661
|
+
return this.context.rpc.getStorage(contract, { block: String(block) });
|
|
3662
|
+
});
|
|
3953
3663
|
}
|
|
3954
|
-
|
|
3955
|
-
|
|
3664
|
+
/**
|
|
3665
|
+
* @description Access the block hash
|
|
3666
|
+
*/
|
|
3667
|
+
getBlockHash(block) {
|
|
3668
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3669
|
+
const { hash } = yield this.context.rpc.getBlockHeader({ block: String(block) });
|
|
3670
|
+
return hash;
|
|
3671
|
+
});
|
|
3956
3672
|
}
|
|
3957
|
-
|
|
3958
|
-
|
|
3673
|
+
/**
|
|
3674
|
+
* @description Access the block level
|
|
3675
|
+
*/
|
|
3676
|
+
getBlockLevel(block) {
|
|
3677
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3678
|
+
const { level } = yield this.context.rpc.getBlockHeader({ block: String(block) });
|
|
3679
|
+
return level;
|
|
3680
|
+
});
|
|
3959
3681
|
}
|
|
3960
|
-
|
|
3961
|
-
|
|
3682
|
+
/**
|
|
3683
|
+
* @description Access the counter of an address
|
|
3684
|
+
* @param pkh from which we want to retrieve the counter
|
|
3685
|
+
* @param block from which we want to retrieve the counter
|
|
3686
|
+
*/
|
|
3687
|
+
getCounter(pkh, block) {
|
|
3688
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3689
|
+
const { counter } = yield this.context.rpc.getContract(pkh, { block: String(block) });
|
|
3690
|
+
return counter || '0';
|
|
3691
|
+
});
|
|
3962
3692
|
}
|
|
3963
|
-
|
|
3964
|
-
|
|
3693
|
+
/**
|
|
3694
|
+
* @description Access the timestamp of a block
|
|
3695
|
+
* @param block from which we want to retrieve the timestamp
|
|
3696
|
+
* @returns date ISO format zero UTC offset ("2022-01-19T22:37:07Z")
|
|
3697
|
+
*/
|
|
3698
|
+
getBlockTimestamp(block) {
|
|
3699
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3700
|
+
const { timestamp } = yield this.context.rpc.getBlockHeader({ block: String(block) });
|
|
3701
|
+
return timestamp;
|
|
3702
|
+
});
|
|
3965
3703
|
}
|
|
3966
|
-
|
|
3967
|
-
|
|
3704
|
+
/**
|
|
3705
|
+
* @description Access the value associated with a key in a big map.
|
|
3706
|
+
* @param bigMapQuery Big Map ID and Expression hash to query (A b58check encoded Blake2b hash of the expression)
|
|
3707
|
+
* @param block from which we want to retrieve the big map value
|
|
3708
|
+
*/
|
|
3709
|
+
getBigMapValue(bigMapQuery, block) {
|
|
3710
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3711
|
+
return this.context.rpc.getBigMapExpr(bigMapQuery.id, bigMapQuery.expr, {
|
|
3712
|
+
block: String(block),
|
|
3713
|
+
});
|
|
3714
|
+
});
|
|
3968
3715
|
}
|
|
3969
|
-
|
|
3970
|
-
|
|
3716
|
+
/**
|
|
3717
|
+
* @description Access the value associated with a sapling state ID.
|
|
3718
|
+
* @param id Sapling state ID
|
|
3719
|
+
* @param block from which we want to retrieve the sapling state
|
|
3720
|
+
*/
|
|
3721
|
+
getSaplingDiffById(saplingStateQuery, block) {
|
|
3722
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3723
|
+
return this.context.rpc.getSaplingDiffById(saplingStateQuery.id, { block: String(block) });
|
|
3724
|
+
});
|
|
3971
3725
|
}
|
|
3972
|
-
|
|
3973
|
-
|
|
3726
|
+
/**
|
|
3727
|
+
* @description Return the list of entrypoints of the contract
|
|
3728
|
+
* @param contract address of the contract we want to get the entrypoints of
|
|
3729
|
+
*/
|
|
3730
|
+
getEntrypoints(contract) {
|
|
3731
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3732
|
+
return this.context.rpc.getEntrypoints(contract);
|
|
3733
|
+
});
|
|
3974
3734
|
}
|
|
3975
|
-
|
|
3976
|
-
|
|
3735
|
+
/**
|
|
3736
|
+
* @description Access the chain id
|
|
3737
|
+
*/
|
|
3738
|
+
getChainId() {
|
|
3739
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3740
|
+
return this.context.rpc.getChainId();
|
|
3741
|
+
});
|
|
3977
3742
|
}
|
|
3978
|
-
|
|
3979
|
-
|
|
3743
|
+
/**
|
|
3744
|
+
* @description Indicate if an account is revealed
|
|
3745
|
+
* @param publicKeyHash of the account
|
|
3746
|
+
* @param block from which we want to know if the account is revealed
|
|
3747
|
+
*/
|
|
3748
|
+
isAccountRevealed(publicKeyHash, block) {
|
|
3749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3750
|
+
const manager = yield this.context.rpc.getManagerKey(publicKeyHash, { block: String(block) });
|
|
3751
|
+
const haveManager = manager && typeof manager === 'object' ? !!manager.key : !!manager;
|
|
3752
|
+
return haveManager;
|
|
3753
|
+
});
|
|
3980
3754
|
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
}
|
|
3990
|
-
set packer(value) {
|
|
3991
|
-
this._packer = value;
|
|
3992
|
-
}
|
|
3993
|
-
get globalConstantsProvider() {
|
|
3994
|
-
return this._globalConstantsProvider;
|
|
3995
|
-
}
|
|
3996
|
-
set globalConstantsProvider(value) {
|
|
3997
|
-
this._globalConstantsProvider = value;
|
|
3998
|
-
}
|
|
3999
|
-
isAnyProtocolActive(protocol = []) {
|
|
4000
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4001
|
-
if (this._proto) {
|
|
4002
|
-
return protocol.includes(this._proto);
|
|
4003
|
-
}
|
|
4004
|
-
else {
|
|
4005
|
-
const { next_protocol } = yield this.rpc.getBlockMetadata();
|
|
4006
|
-
return protocol.includes(next_protocol);
|
|
4007
|
-
}
|
|
4008
|
-
});
|
|
4009
|
-
}
|
|
4010
|
-
getConfirmationPollingInterval() {
|
|
4011
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4012
|
-
// Granada will generally halve the time between blocks, from 60 seconds to 30 seconds (mainnet).
|
|
4013
|
-
// We reduce the default value in the same proportion, from 10 to 5.
|
|
4014
|
-
const defaultInterval = 5;
|
|
4015
|
-
try {
|
|
4016
|
-
const constants = yield this.rpc.getConstants();
|
|
4017
|
-
let blockTime = constants.time_between_blocks[0];
|
|
4018
|
-
if (constants.minimal_block_delay !== undefined) {
|
|
4019
|
-
blockTime = constants.minimal_block_delay;
|
|
4020
|
-
}
|
|
4021
|
-
let confirmationPollingInterval = BigNumber.sum(blockTime,
|
|
4022
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
4023
|
-
new BigNumber(constants.delay_per_missing_endorsement).multipliedBy(
|
|
4024
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
4025
|
-
Math.max(0, constants.initial_endorsers - constants.endorsers_per_block)));
|
|
4026
|
-
// Divide the polling interval by a constant 3
|
|
4027
|
-
// to improvise for polling time to work in prod,
|
|
4028
|
-
// testnet and sandbox enviornment.
|
|
4029
|
-
confirmationPollingInterval = confirmationPollingInterval.dividedBy(3);
|
|
4030
|
-
this.config.confirmationPollingIntervalSecond =
|
|
4031
|
-
confirmationPollingInterval.toNumber() === 0 ? 0.1 : confirmationPollingInterval.toNumber();
|
|
4032
|
-
return this.config.confirmationPollingIntervalSecond;
|
|
4033
|
-
}
|
|
4034
|
-
catch (exception) {
|
|
4035
|
-
// Return default value if there is
|
|
4036
|
-
// an issue returning from constants
|
|
4037
|
-
// file.
|
|
4038
|
-
return defaultInterval;
|
|
4039
|
-
}
|
|
4040
|
-
});
|
|
4041
|
-
}
|
|
4042
|
-
/**
|
|
4043
|
-
* @description Create a copy of the current context. Useful when you have long running operation and you do not want a context change to affect the operation
|
|
4044
|
-
*/
|
|
4045
|
-
clone() {
|
|
4046
|
-
return new Context(this.rpc, this.signer, this.proto, this._config, this.forger, this._injector, this.packer);
|
|
3755
|
+
/**
|
|
3756
|
+
* @description Return all the information about a block
|
|
3757
|
+
* @param block from which we want to retrieve the information
|
|
3758
|
+
*/
|
|
3759
|
+
getBlock(block) {
|
|
3760
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3761
|
+
return this.context.rpc.getBlock({ block: String(block) });
|
|
3762
|
+
});
|
|
4047
3763
|
}
|
|
4048
3764
|
/**
|
|
4049
|
-
* @description
|
|
3765
|
+
* @description Return a list of the ancestors of the given block which, if referred to as the branch in an operation header, are recent enough for that operation to be included in the current block.
|
|
3766
|
+
* @param block from which we want to retrieve the information
|
|
4050
3767
|
*/
|
|
4051
|
-
|
|
4052
|
-
this.
|
|
3768
|
+
getLiveBlocks(block) {
|
|
3769
|
+
return this.context.rpc.getLiveBlocks({ block: String(block) });
|
|
4053
3770
|
}
|
|
4054
3771
|
}
|
|
4055
3772
|
|
|
@@ -4198,11 +3915,15 @@ class ObservableSubscription {
|
|
|
4198
3915
|
}
|
|
4199
3916
|
}
|
|
4200
3917
|
|
|
3918
|
+
const defaultConfigStreamer = {
|
|
3919
|
+
shouldObservableSubscriptionRetry: false,
|
|
3920
|
+
observableSubscriptionRetryFunction: retry(),
|
|
3921
|
+
};
|
|
4201
3922
|
const getLastBlock = (context) => {
|
|
4202
3923
|
return from(context.rpc.getBlock()).pipe(first());
|
|
4203
3924
|
};
|
|
4204
|
-
const applyFilter = (filter) => concatMap(block => {
|
|
4205
|
-
return new Observable(sub => {
|
|
3925
|
+
const applyFilter = (filter) => concatMap((block) => {
|
|
3926
|
+
return new Observable((sub) => {
|
|
4206
3927
|
for (const ops of block.operations) {
|
|
4207
3928
|
for (const op of ops) {
|
|
4208
3929
|
for (const content of op.contents) {
|
|
@@ -4216,24 +3937,237 @@ const applyFilter = (filter) => concatMap(block => {
|
|
|
4216
3937
|
});
|
|
4217
3938
|
});
|
|
4218
3939
|
class PollingSubscribeProvider {
|
|
4219
|
-
constructor(context) {
|
|
3940
|
+
constructor(context, config = {}) {
|
|
4220
3941
|
this.context = context;
|
|
4221
|
-
|
|
4222
|
-
this.timer$ = this.
|
|
4223
|
-
|
|
3942
|
+
this._config$ = new BehaviorSubject(Object.assign(Object.assign({}, defaultConfigStreamer), config));
|
|
3943
|
+
this.timer$ = this._config$.pipe(pluck('pollingIntervalMilliseconds'), switchMap((pollingIntervalMilliseconds) => {
|
|
3944
|
+
if (!pollingIntervalMilliseconds) {
|
|
3945
|
+
return from(this.getConfirmationPollingInterval()).pipe(switchMap((interval) => {
|
|
3946
|
+
return timer(0, interval);
|
|
3947
|
+
}));
|
|
3948
|
+
}
|
|
3949
|
+
else {
|
|
3950
|
+
return timer(0, pollingIntervalMilliseconds);
|
|
3951
|
+
}
|
|
3952
|
+
}));
|
|
3953
|
+
this.newBlock$ = this.timer$.pipe(switchMap(() => getLastBlock(this.context)), distinctUntilKeyChanged('hash'), publish(), refCount());
|
|
3954
|
+
}
|
|
3955
|
+
get config() {
|
|
3956
|
+
return this._config$.getValue();
|
|
3957
|
+
}
|
|
3958
|
+
getConfirmationPollingInterval() {
|
|
3959
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3960
|
+
if (!this.config.pollingIntervalMilliseconds) {
|
|
3961
|
+
const defaultIntervalTestnetsMainnet = 5000;
|
|
3962
|
+
const defaultIntervalSandbox = 1000;
|
|
3963
|
+
try {
|
|
3964
|
+
const constants = yield this.context.readProvider.getProtocolConstants('head');
|
|
3965
|
+
const blockTime = constants.minimal_block_delay
|
|
3966
|
+
? constants.minimal_block_delay.multipliedBy(1000)
|
|
3967
|
+
: constants.time_between_blocks
|
|
3968
|
+
? constants.time_between_blocks[0].multipliedBy(1000)
|
|
3969
|
+
: new BigNumber(defaultIntervalTestnetsMainnet);
|
|
3970
|
+
const confirmationPollingInterval = blockTime.dividedBy(3);
|
|
3971
|
+
this.config.pollingIntervalMilliseconds =
|
|
3972
|
+
confirmationPollingInterval.toNumber() === 0
|
|
3973
|
+
? defaultIntervalSandbox
|
|
3974
|
+
: confirmationPollingInterval.toNumber();
|
|
3975
|
+
}
|
|
3976
|
+
catch (exception) {
|
|
3977
|
+
return defaultIntervalTestnetsMainnet;
|
|
3978
|
+
}
|
|
3979
|
+
}
|
|
3980
|
+
return this.config.pollingIntervalMilliseconds;
|
|
3981
|
+
});
|
|
3982
|
+
}
|
|
3983
|
+
subscribeBlock(_filter) {
|
|
3984
|
+
return new ObservableSubscription(this.newBlock$, this.config.shouldObservableSubscriptionRetry, this.config.observableSubscriptionRetryFunction);
|
|
4224
3985
|
}
|
|
4225
3986
|
subscribe(_filter) {
|
|
4226
|
-
return new ObservableSubscription(this.newBlock$.pipe(pluck('hash')), this.
|
|
3987
|
+
return new ObservableSubscription(this.newBlock$.pipe(pluck('hash')), this.config.shouldObservableSubscriptionRetry, this.config.observableSubscriptionRetryFunction);
|
|
4227
3988
|
}
|
|
4228
3989
|
subscribeOperation(filter) {
|
|
4229
|
-
return new ObservableSubscription(this.newBlock$.pipe(applyFilter(filter)), this.
|
|
3990
|
+
return new ObservableSubscription(this.newBlock$.pipe(applyFilter(filter)), this.config.shouldObservableSubscriptionRetry, this.config.observableSubscriptionRetryFunction);
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
class TaquitoLocalForger {
|
|
3995
|
+
constructor(context) {
|
|
3996
|
+
this.context = context;
|
|
3997
|
+
}
|
|
3998
|
+
getNextProto() {
|
|
3999
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4000
|
+
if (!this.context.proto) {
|
|
4001
|
+
const nextProto = yield this.context.readProvider.getNextProtocol('head');
|
|
4002
|
+
this.context.proto = nextProto;
|
|
4003
|
+
}
|
|
4004
|
+
return this.context.proto;
|
|
4005
|
+
});
|
|
4006
|
+
}
|
|
4007
|
+
forge({ branch, contents }) {
|
|
4008
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4009
|
+
const forger = new LocalForger(yield this.getNextProto());
|
|
4010
|
+
return forger.forge({ branch, contents });
|
|
4011
|
+
});
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
|
|
4015
|
+
const defaultConfigConfirmation = {
|
|
4016
|
+
defaultConfirmationCount: 1,
|
|
4017
|
+
confirmationPollingTimeoutSecond: 180,
|
|
4018
|
+
};
|
|
4019
|
+
/**
|
|
4020
|
+
* @description Encapsulate common service used throughout different part of the library
|
|
4021
|
+
*/
|
|
4022
|
+
class Context {
|
|
4023
|
+
constructor(_rpc, _signer = new NoopSigner(), _proto, _config = new BehaviorSubject(Object.assign({}, defaultConfigConfirmation)), forger, injector, packer, wallet, parser, globalConstantsProvider, readProvider, stream) {
|
|
4024
|
+
this._rpc = _rpc;
|
|
4025
|
+
this._signer = _signer;
|
|
4026
|
+
this._proto = _proto;
|
|
4027
|
+
this._config = _config;
|
|
4028
|
+
this.providerDecorator = [];
|
|
4029
|
+
this.tz = new RpcTzProvider(this);
|
|
4030
|
+
this.estimate = new RPCEstimateProvider(this);
|
|
4031
|
+
this.contract = new RpcContractProvider(this, this.estimate);
|
|
4032
|
+
this.batch = new RPCBatchProvider(this, this.estimate);
|
|
4033
|
+
this.wallet = new Wallet(this);
|
|
4034
|
+
/**
|
|
4035
|
+
* @description Applies the decorators on a cloned instance of the context and returned this cloned instance.
|
|
4036
|
+
* The decorators are functions that inject logic into the context.
|
|
4037
|
+
* They are provided by the extensions set on the TezosToolkit by calling the registerProviderDecorator method.
|
|
4038
|
+
*/
|
|
4039
|
+
this.withExtensions = () => {
|
|
4040
|
+
let clonedContext = this.clone();
|
|
4041
|
+
this.providerDecorator.forEach((decorator) => {
|
|
4042
|
+
clonedContext = decorator(clonedContext);
|
|
4043
|
+
});
|
|
4044
|
+
return clonedContext;
|
|
4045
|
+
};
|
|
4046
|
+
if (typeof this._rpc === 'string') {
|
|
4047
|
+
this._rpcClient = new RpcClient(this._rpc);
|
|
4048
|
+
}
|
|
4049
|
+
else {
|
|
4050
|
+
this._rpcClient = this._rpc;
|
|
4051
|
+
}
|
|
4052
|
+
this._forger = forger ? forger : new TaquitoLocalForger(this);
|
|
4053
|
+
this._injector = injector ? injector : new RpcInjector(this);
|
|
4054
|
+
this.operationFactory = new OperationFactory(this);
|
|
4055
|
+
this._walletProvider = wallet ? wallet : new LegacyWalletProvider(this);
|
|
4056
|
+
this._parser = parser ? parser : new MichelCodecParser(this);
|
|
4057
|
+
this._packer = packer ? packer : new RpcPacker(this);
|
|
4058
|
+
this._globalConstantsProvider = globalConstantsProvider
|
|
4059
|
+
? globalConstantsProvider
|
|
4060
|
+
: new NoopGlobalConstantsProvider();
|
|
4061
|
+
this._readProvider = readProvider ? readProvider : new RpcReadAdapter(this);
|
|
4062
|
+
this._stream = stream ? stream : new PollingSubscribeProvider(this);
|
|
4063
|
+
}
|
|
4064
|
+
get config() {
|
|
4065
|
+
return this._config.getValue();
|
|
4066
|
+
}
|
|
4067
|
+
set config(value) {
|
|
4068
|
+
this._config.next(Object.assign({}, value));
|
|
4069
|
+
}
|
|
4070
|
+
setPartialConfig(value) {
|
|
4071
|
+
this._config.next(Object.assign(Object.assign({}, this._config.getValue()), value));
|
|
4072
|
+
}
|
|
4073
|
+
get rpc() {
|
|
4074
|
+
return this._rpcClient;
|
|
4075
|
+
}
|
|
4076
|
+
set rpc(value) {
|
|
4077
|
+
this._rpcClient = value;
|
|
4078
|
+
}
|
|
4079
|
+
get injector() {
|
|
4080
|
+
return this._injector;
|
|
4081
|
+
}
|
|
4082
|
+
set injector(value) {
|
|
4083
|
+
this._injector = value;
|
|
4084
|
+
}
|
|
4085
|
+
get forger() {
|
|
4086
|
+
return this._forger;
|
|
4087
|
+
}
|
|
4088
|
+
set forger(value) {
|
|
4089
|
+
this._forger = value;
|
|
4090
|
+
}
|
|
4091
|
+
get signer() {
|
|
4092
|
+
return this._signer;
|
|
4093
|
+
}
|
|
4094
|
+
set signer(value) {
|
|
4095
|
+
this._signer = value;
|
|
4096
|
+
}
|
|
4097
|
+
get walletProvider() {
|
|
4098
|
+
return this._walletProvider;
|
|
4099
|
+
}
|
|
4100
|
+
set walletProvider(value) {
|
|
4101
|
+
this._walletProvider = value;
|
|
4102
|
+
}
|
|
4103
|
+
set proto(value) {
|
|
4104
|
+
this._proto = value;
|
|
4105
|
+
}
|
|
4106
|
+
get proto() {
|
|
4107
|
+
return this._proto;
|
|
4108
|
+
}
|
|
4109
|
+
get parser() {
|
|
4110
|
+
return this._parser;
|
|
4111
|
+
}
|
|
4112
|
+
set parser(value) {
|
|
4113
|
+
this._parser = value;
|
|
4114
|
+
}
|
|
4115
|
+
get packer() {
|
|
4116
|
+
return this._packer;
|
|
4117
|
+
}
|
|
4118
|
+
set packer(value) {
|
|
4119
|
+
this._packer = value;
|
|
4120
|
+
}
|
|
4121
|
+
get globalConstantsProvider() {
|
|
4122
|
+
return this._globalConstantsProvider;
|
|
4123
|
+
}
|
|
4124
|
+
set globalConstantsProvider(value) {
|
|
4125
|
+
this._globalConstantsProvider = value;
|
|
4126
|
+
}
|
|
4127
|
+
get readProvider() {
|
|
4128
|
+
return this._readProvider;
|
|
4129
|
+
}
|
|
4130
|
+
set readProvider(value) {
|
|
4131
|
+
this._readProvider = value;
|
|
4132
|
+
}
|
|
4133
|
+
get stream() {
|
|
4134
|
+
return this._stream;
|
|
4135
|
+
}
|
|
4136
|
+
set stream(value) {
|
|
4137
|
+
this._stream = value;
|
|
4138
|
+
}
|
|
4139
|
+
isAnyProtocolActive(protocol = []) {
|
|
4140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4141
|
+
if (this._proto) {
|
|
4142
|
+
return protocol.includes(this._proto);
|
|
4143
|
+
}
|
|
4144
|
+
else {
|
|
4145
|
+
const next_protocol = yield this.readProvider.getNextProtocol('head');
|
|
4146
|
+
return protocol.includes(next_protocol);
|
|
4147
|
+
}
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4150
|
+
isAnySignerConfigured() {
|
|
4151
|
+
return !(this.signer instanceof NoopSigner);
|
|
4152
|
+
}
|
|
4153
|
+
/**
|
|
4154
|
+
* @description Create a copy of the current context. Useful when you have long running operation and you do not want a context change to affect the operation
|
|
4155
|
+
*/
|
|
4156
|
+
clone() {
|
|
4157
|
+
return new Context(this.rpc, this.signer, this.proto, this._config, this.forger, this._injector, this.packer, this._walletProvider, this._parser, this._globalConstantsProvider, this._readProvider, this._stream);
|
|
4158
|
+
}
|
|
4159
|
+
/**
|
|
4160
|
+
* @description Allows extensions set on the TezosToolkit to inject logic into the context
|
|
4161
|
+
*/
|
|
4162
|
+
registerProviderDecorator(fx) {
|
|
4163
|
+
this.providerDecorator.push(fx);
|
|
4230
4164
|
}
|
|
4231
4165
|
}
|
|
4232
4166
|
|
|
4233
4167
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
4234
4168
|
const VERSION = {
|
|
4235
|
-
"commitHash": "
|
|
4236
|
-
"version": "
|
|
4169
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
4170
|
+
"version": "12.0.0-beta-RC.0"
|
|
4237
4171
|
};
|
|
4238
4172
|
|
|
4239
4173
|
class ForgingMismatchError extends Error {
|
|
@@ -4273,6 +4207,15 @@ class CompositeForger {
|
|
|
4273
4207
|
}
|
|
4274
4208
|
}
|
|
4275
4209
|
|
|
4210
|
+
class RpcForger {
|
|
4211
|
+
constructor(context) {
|
|
4212
|
+
this.context = context;
|
|
4213
|
+
}
|
|
4214
|
+
forge({ branch, contents }) {
|
|
4215
|
+
return this.context.rpc.forgeOperations({ branch, contents });
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4276
4219
|
class NoopParser {
|
|
4277
4220
|
prepareCodeOrigination(params) {
|
|
4278
4221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -4323,6 +4266,110 @@ class DefaultGlobalConstantsProvider {
|
|
|
4323
4266
|
}
|
|
4324
4267
|
}
|
|
4325
4268
|
|
|
4269
|
+
/**
|
|
4270
|
+
* @description Naïve implementation of an estimate provider. Will work for basic transaction but your operation risk to fail if they are more complex (smart contract interaction)
|
|
4271
|
+
*
|
|
4272
|
+
* @deprecated Deprecated in favor of RPCEstimateProvider
|
|
4273
|
+
*/
|
|
4274
|
+
class NaiveEstimateProvider {
|
|
4275
|
+
constructor(protocol) {
|
|
4276
|
+
this.protocol = protocol;
|
|
4277
|
+
this._costPerByte = 250;
|
|
4278
|
+
}
|
|
4279
|
+
registerGlobalConstant(params) {
|
|
4280
|
+
throw new Error(`Unsupported operation kind: ${params.kind}`);
|
|
4281
|
+
}
|
|
4282
|
+
/**
|
|
4283
|
+
*
|
|
4284
|
+
* @description Estimate gasLimit, storageLimit and fees for an origination operation
|
|
4285
|
+
*
|
|
4286
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
4287
|
+
*
|
|
4288
|
+
* @param OriginationOperation Originate operation parameter
|
|
4289
|
+
*/
|
|
4290
|
+
originate({ fee = DEFAULT_FEE.ORIGINATION, storageLimit = DEFAULT_STORAGE_LIMIT.ORIGINATION, gasLimit = DEFAULT_GAS_LIMIT.ORIGINATION * 1000, }) {
|
|
4291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4292
|
+
return new Estimate(gasLimit, storageLimit, 185, this._costPerByte, fee);
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
/**
|
|
4296
|
+
*
|
|
4297
|
+
* @description Estimate gasLimit, storageLimit and fees for an transfer operation
|
|
4298
|
+
*
|
|
4299
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
4300
|
+
*
|
|
4301
|
+
* @param TransferOperation Originate operation parameter
|
|
4302
|
+
*/
|
|
4303
|
+
transfer({ fee = DEFAULT_FEE.TRANSFER, storageLimit = DEFAULT_STORAGE_LIMIT.TRANSFER, gasLimit = DEFAULT_GAS_LIMIT.TRANSFER * 1000, }) {
|
|
4304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4305
|
+
return new Estimate(gasLimit, storageLimit, 162, this._costPerByte, fee);
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
/**
|
|
4309
|
+
*
|
|
4310
|
+
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
|
|
4311
|
+
*
|
|
4312
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
4313
|
+
*
|
|
4314
|
+
* @param Estimate
|
|
4315
|
+
*/
|
|
4316
|
+
setDelegate({ fee = DEFAULT_FEE.DELEGATION, gasLimit = DEFAULT_GAS_LIMIT.DELEGATION * 1000, }) {
|
|
4317
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4318
|
+
return new Estimate(gasLimit, 0, 157, this._costPerByte, fee);
|
|
4319
|
+
});
|
|
4320
|
+
}
|
|
4321
|
+
/**
|
|
4322
|
+
*
|
|
4323
|
+
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
|
|
4324
|
+
*
|
|
4325
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
4326
|
+
*
|
|
4327
|
+
* @param Estimate
|
|
4328
|
+
*/
|
|
4329
|
+
registerDelegate({ fee = DEFAULT_FEE.DELEGATION, gasLimit = DEFAULT_GAS_LIMIT.DELEGATION * 1000, }) {
|
|
4330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4331
|
+
return new Estimate(gasLimit, 0, 157, this._costPerByte, fee);
|
|
4332
|
+
});
|
|
4333
|
+
}
|
|
4334
|
+
/**
|
|
4335
|
+
*
|
|
4336
|
+
* @description Estimate gasLimit, storageLimit and fees for a reveal operation
|
|
4337
|
+
*
|
|
4338
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
4339
|
+
*
|
|
4340
|
+
* @param Estimate
|
|
4341
|
+
*/
|
|
4342
|
+
reveal() {
|
|
4343
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4344
|
+
return new Estimate(DEFAULT_GAS_LIMIT.REVEAL * 1000, DEFAULT_STORAGE_LIMIT.REVEAL, 64, this._costPerByte, DEFAULT_FEE.REVEAL);
|
|
4345
|
+
});
|
|
4346
|
+
}
|
|
4347
|
+
batch(params) {
|
|
4348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4349
|
+
const estimates = [];
|
|
4350
|
+
for (const param of params) {
|
|
4351
|
+
switch (param.kind) {
|
|
4352
|
+
case 'transaction':
|
|
4353
|
+
estimates.push(yield this.transfer(param));
|
|
4354
|
+
break;
|
|
4355
|
+
case 'origination':
|
|
4356
|
+
estimates.push(yield this.originate(param));
|
|
4357
|
+
break;
|
|
4358
|
+
case 'delegation':
|
|
4359
|
+
estimates.push(yield this.setDelegate(param));
|
|
4360
|
+
break;
|
|
4361
|
+
case 'activate_account':
|
|
4362
|
+
estimates.push(new Estimate(0, 0, 0, this._costPerByte, 0));
|
|
4363
|
+
break;
|
|
4364
|
+
default:
|
|
4365
|
+
throw new Error(`Unsupported operation kind: ${param.kind}`);
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4368
|
+
return estimates;
|
|
4369
|
+
});
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4326
4373
|
/**
|
|
4327
4374
|
* @packageDocumentation
|
|
4328
4375
|
* @module @taquito/taquito
|
|
@@ -4357,7 +4404,7 @@ class TezosToolkit {
|
|
|
4357
4404
|
* @example Tezos.setProvider({ config: { confirmationPollingTimeoutSecond: 300 }})
|
|
4358
4405
|
*
|
|
4359
4406
|
*/
|
|
4360
|
-
setProvider({ rpc, stream, signer, protocol, config, forger, wallet, packer, globalConstantsProvider, }) {
|
|
4407
|
+
setProvider({ rpc, stream, signer, protocol, config, forger, wallet, packer, globalConstantsProvider, readProvider, }) {
|
|
4361
4408
|
this.setRpcProvider(rpc);
|
|
4362
4409
|
this.setStreamProvider(stream);
|
|
4363
4410
|
this.setSignerProvider(signer);
|
|
@@ -4365,6 +4412,7 @@ class TezosToolkit {
|
|
|
4365
4412
|
this.setWalletProvider(wallet);
|
|
4366
4413
|
this.setPackerProvider(packer);
|
|
4367
4414
|
this.setGlobalConstantsProvider(globalConstantsProvider);
|
|
4415
|
+
this.setReadProvider(readProvider);
|
|
4368
4416
|
this._context.proto = protocol;
|
|
4369
4417
|
if (config) {
|
|
4370
4418
|
this._context.setPartialConfig(config);
|
|
@@ -4409,16 +4457,23 @@ class TezosToolkit {
|
|
|
4409
4457
|
}
|
|
4410
4458
|
/**
|
|
4411
4459
|
* @description Sets forger provider on the Tezos Taquito instance
|
|
4460
|
+
* The `LocalForger` from `@taquito/local-forging` is set by default.
|
|
4412
4461
|
*
|
|
4413
4462
|
* @param options forger to use to interact with the Tezos network
|
|
4414
4463
|
*
|
|
4415
|
-
* @example Tezos.setForgerProvider(
|
|
4464
|
+
* @example Tezos.setForgerProvider(this.getFactory(RpcForger)())
|
|
4416
4465
|
*
|
|
4417
4466
|
*/
|
|
4418
4467
|
setForgerProvider(forger) {
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4468
|
+
if (typeof forger !== 'undefined') {
|
|
4469
|
+
this._options.forger = forger;
|
|
4470
|
+
this._context.forger = forger;
|
|
4471
|
+
}
|
|
4472
|
+
else if (this._options.forger === undefined) {
|
|
4473
|
+
const f = this.getFactory(TaquitoLocalForger)();
|
|
4474
|
+
this._options.forger = f;
|
|
4475
|
+
this._context.forger = f;
|
|
4476
|
+
}
|
|
4422
4477
|
}
|
|
4423
4478
|
/**
|
|
4424
4479
|
* @description Sets stream provider on the Tezos Taquito instance
|
|
@@ -4430,15 +4485,19 @@ class TezosToolkit {
|
|
|
4430
4485
|
*/
|
|
4431
4486
|
setStreamProvider(stream) {
|
|
4432
4487
|
if (typeof stream === 'string') {
|
|
4433
|
-
|
|
4488
|
+
const s = new PollingSubscribeProvider(new Context(new RpcClient(stream)));
|
|
4489
|
+
this._options.stream = s;
|
|
4490
|
+
this._context.stream = s;
|
|
4434
4491
|
}
|
|
4435
4492
|
else if (typeof stream !== 'undefined') {
|
|
4436
|
-
this.
|
|
4493
|
+
this._options.stream = stream;
|
|
4494
|
+
this._context.stream = stream;
|
|
4437
4495
|
}
|
|
4438
4496
|
else if (this._options.stream === undefined) {
|
|
4439
|
-
|
|
4497
|
+
const s = this.getFactory(PollingSubscribeProvider)();
|
|
4498
|
+
this._options.stream = s;
|
|
4499
|
+
this._context.stream = s;
|
|
4440
4500
|
}
|
|
4441
|
-
this._options.stream = stream;
|
|
4442
4501
|
}
|
|
4443
4502
|
/**
|
|
4444
4503
|
* @description Sets wallet provider on the Tezos Taquito instance
|
|
@@ -4468,9 +4527,15 @@ class TezosToolkit {
|
|
|
4468
4527
|
*
|
|
4469
4528
|
*/
|
|
4470
4529
|
setPackerProvider(packer) {
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4530
|
+
if (!this._options.packer && typeof packer === 'undefined') {
|
|
4531
|
+
const p = this.getFactory(RpcPacker)();
|
|
4532
|
+
this._context.packer = p;
|
|
4533
|
+
this._options.packer = p;
|
|
4534
|
+
}
|
|
4535
|
+
else if (typeof packer !== 'undefined') {
|
|
4536
|
+
this._context.packer = packer;
|
|
4537
|
+
this._options.packer = packer;
|
|
4538
|
+
}
|
|
4474
4539
|
}
|
|
4475
4540
|
/**
|
|
4476
4541
|
* @description Sets global constants provider on the Tezos Taquito instance
|
|
@@ -4489,11 +4554,27 @@ class TezosToolkit {
|
|
|
4489
4554
|
*
|
|
4490
4555
|
*/
|
|
4491
4556
|
setGlobalConstantsProvider(globalConstantsProvider) {
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4557
|
+
if (!this._options.globalConstantsProvider && typeof globalConstantsProvider === 'undefined') {
|
|
4558
|
+
const g = new NoopGlobalConstantsProvider();
|
|
4559
|
+
this._context.globalConstantsProvider = g;
|
|
4560
|
+
this._options.globalConstantsProvider = g;
|
|
4561
|
+
}
|
|
4562
|
+
else if (typeof globalConstantsProvider !== 'undefined') {
|
|
4563
|
+
this._context.globalConstantsProvider = globalConstantsProvider;
|
|
4564
|
+
this._options.globalConstantsProvider = globalConstantsProvider;
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
/**
|
|
4568
|
+
* @description Sets read provider on the Tezos Taquito instance
|
|
4569
|
+
* By default reads are done from the RPC usign the RpcReadAdapter class, this can be overridden to read from an indexer that implements the TzReadProvider interface
|
|
4570
|
+
*
|
|
4571
|
+
* @param options TzReadProvider to use to interact with the Tezos network
|
|
4572
|
+
*
|
|
4573
|
+
*/
|
|
4574
|
+
setReadProvider(readProvider) {
|
|
4575
|
+
const readP = typeof readProvider === 'undefined' ? this.getFactory(RpcReadAdapter)() : readProvider;
|
|
4576
|
+
this._options.readProvider = readP;
|
|
4577
|
+
this._context.readProvider = readP;
|
|
4497
4578
|
}
|
|
4498
4579
|
/**
|
|
4499
4580
|
* @description Provide access to tezos account management
|
|
@@ -4523,7 +4604,7 @@ class TezosToolkit {
|
|
|
4523
4604
|
* @description Provide access to streaming utilities backed by an streamer implementation
|
|
4524
4605
|
*/
|
|
4525
4606
|
get stream() {
|
|
4526
|
-
return this.
|
|
4607
|
+
return this._context.stream;
|
|
4527
4608
|
}
|
|
4528
4609
|
/**
|
|
4529
4610
|
* @description Provide access to the currently used rpc client
|
|
@@ -4571,5 +4652,5 @@ class TezosToolkit {
|
|
|
4571
4652
|
}
|
|
4572
4653
|
}
|
|
4573
4654
|
|
|
4574
|
-
export { BatchOperation, BigMapAbstraction, ChainIds, CompositeForger, Context, ContractAbstraction, ContractMethod, ContractMethodObject, ContractView, DEFAULT_FEE, DEFAULT_GAS_LIMIT, DEFAULT_SMART_CONTRACT_METHOD_NAME, DEFAULT_STORAGE_LIMIT, DefaultGlobalConstantsProvider,
|
|
4655
|
+
export { BatchOperation, BigMapAbstraction, ChainIds, CompositeForger, Context, ContractAbstraction, ContractMethod, ContractMethodObject, ContractView, DEFAULT_FEE, DEFAULT_GAS_LIMIT, DEFAULT_SMART_CONTRACT_METHOD_NAME, DEFAULT_STORAGE_LIMIT, DefaultGlobalConstantsProvider, DelegateOperation, DelegationWalletOperation, Estimate, GlobalConstantNotFound, InvalidCodeParameter, InvalidDelegationSource, InvalidInitParameter, InvalidParameterError, InvalidViewParameterError, InvalidViewSimulationContext, LegacyWalletProvider, MANAGER_LAMBDA, MichelCodecPacker, MichelCodecParser, MissedBlockDuringConfirmationError, NaiveEstimateProvider, NoopParser, ObservableSubscription, Operation, OperationBatch, OriginationOperation, OriginationWalletOperation, PollingSubscribeProvider, Protocols, RPCEstimateProvider, RevealEstimateError, RpcForger, RpcPacker, RpcReadAdapter, TezosOperationError, TezosPreapplyFailureError, TezosToolkit, TransactionOperation, TransactionWalletOperation, UnconfiguredGlobalConstantsProviderError, UndefinedLambdaContractError, VIEW_LAMBDA, ViewSimulationError, Wallet, WalletOperation, WalletOperationBatch, compose, createOriginationOperation, createRegisterDelegateOperation, createRegisterGlobalConstantOperation, createRevealOperation, createSetDelegateOperation, createTransferOperation, defaultConfigConfirmation, protocols, validateAndExtractFailwith };
|
|
4575
4656
|
//# sourceMappingURL=taquito.es6.js.map
|