@taquito/contracts-library 17.3.2 → 17.4.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/dist/lib/errors.js +0 -1
- package/dist/lib/read-provider-wrapper.js +0 -1
- package/dist/lib/rpc-wrapper.js +4 -3
- package/dist/lib/taquito-contracts-library.js +2 -3
- package/dist/lib/version.js +2 -3
- package/dist/taquito-contracts-library.es6.js +158 -156
- package/dist/taquito-contracts-library.es6.js.map +1 -1
- package/dist/taquito-contracts-library.umd.js +158 -158
- package/dist/taquito-contracts-library.umd.js.map +1 -1
- package/dist/types/errors.d.ts +12 -12
- package/dist/types/read-provider-wrapper.d.ts +35 -35
- package/dist/types/rpc-wrapper.d.ts +65 -65
- package/dist/types/taquito-contracts-library.d.ts +56 -56
- package/dist/types/version.d.ts +4 -4
- package/package.json +29 -31
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/read-provider-wrapper.js.map +0 -1
- package/dist/lib/rpc-wrapper.js.map +0 -1
- package/dist/lib/taquito-contracts-library.js.map +0 -1
- package/dist/lib/version.js.map +0 -1
package/dist/lib/errors.js
CHANGED
package/dist/lib/rpc-wrapper.js
CHANGED
|
@@ -209,14 +209,16 @@ class RpcWrapperContractsLibrary {
|
|
|
209
209
|
return this.rpc.runCode(code, { block });
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
-
runScriptView(_a,
|
|
212
|
+
runScriptView(_a, _b) {
|
|
213
213
|
var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
|
|
214
|
+
var _c = _b === void 0 ? rpc_1.defaultRPCOptions : _b, block = _c.block;
|
|
214
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
216
|
return this.rpc.runScriptView(Object.assign({ unparsing_mode }, rest), { block });
|
|
216
217
|
});
|
|
217
218
|
}
|
|
218
|
-
runView(_a,
|
|
219
|
+
runView(_a, _b) {
|
|
219
220
|
var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
|
|
221
|
+
var _c = _b === void 0 ? rpc_1.defaultRPCOptions : _b, block = _c.block;
|
|
220
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
221
223
|
return this.rpc.runView(Object.assign({ unparsing_mode }, rest), { block });
|
|
222
224
|
});
|
|
@@ -296,4 +298,3 @@ class RpcWrapperContractsLibrary {
|
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
300
|
exports.RpcWrapperContractsLibrary = RpcWrapperContractsLibrary;
|
|
299
|
-
//# sourceMappingURL=rpc-wrapper.js.map
|
|
@@ -64,9 +64,9 @@ class ContractsLibrary {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
validateContractAddress(address) {
|
|
67
|
-
const addressValidation = utils_1.validateAddress(address);
|
|
67
|
+
const addressValidation = (0, utils_1.validateAddress)(address);
|
|
68
68
|
if (addressValidation !== utils_1.ValidationResult.VALID) {
|
|
69
|
-
throw new core_1.InvalidAddressError(address, utils_1.invalidDetail(addressValidation));
|
|
69
|
+
throw new core_1.InvalidAddressError(address, (0, utils_1.invalidDetail)(addressValidation));
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
validateContractScriptFormat(script, address) {
|
|
@@ -76,4 +76,3 @@ class ContractsLibrary {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
exports.ContractsLibrary = ContractsLibrary;
|
|
79
|
-
//# sourceMappingURL=taquito-contracts-library.js.map
|
package/dist/lib/version.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "17.
|
|
6
|
+
"commitHash": "a908ab176a8c52c025fd43e7acd452415396f54e",
|
|
7
|
+
"version": "17.4.0"
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=version.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { validateAddress, ValidationResult, invalidDetail } from '@taquito/utils';
|
|
2
2
|
import { ParameterValidationError, InvalidAddressError } from '@taquito/core';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @category Error
|
|
6
|
-
* @description Error that indicates invalid script format being useed or passed
|
|
7
|
-
*/
|
|
8
|
-
class InvalidScriptFormatError extends ParameterValidationError {
|
|
9
|
-
constructor(message, script, address) {
|
|
10
|
-
super();
|
|
11
|
-
this.message = message;
|
|
12
|
-
this.script = script;
|
|
13
|
-
this.address = address;
|
|
14
|
-
this.name = 'InvalidScriptFormatError';
|
|
15
|
-
}
|
|
4
|
+
/**
|
|
5
|
+
* @category Error
|
|
6
|
+
* @description Error that indicates invalid script format being useed or passed
|
|
7
|
+
*/
|
|
8
|
+
class InvalidScriptFormatError extends ParameterValidationError {
|
|
9
|
+
constructor(message, script, address) {
|
|
10
|
+
super();
|
|
11
|
+
this.message = message;
|
|
12
|
+
this.script = script;
|
|
13
|
+
this.address = address;
|
|
14
|
+
this.name = 'InvalidScriptFormatError';
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/******************************************************************************
|
|
@@ -29,6 +29,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
29
29
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
30
30
|
PERFORMANCE OF THIS SOFTWARE.
|
|
31
31
|
***************************************************************************** */
|
|
32
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
33
|
+
|
|
32
34
|
|
|
33
35
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -45,152 +47,152 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
45
47
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
class ReadWrapperContractsLibrary {
|
|
49
|
-
constructor(readProvider, contractslibrary) {
|
|
50
|
-
this.readProvider = readProvider;
|
|
51
|
-
this.contractslibrary = contractslibrary;
|
|
52
|
-
}
|
|
53
|
-
getScript(address, block) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const contractData = this.contractslibrary.getContract(address);
|
|
56
|
-
if (contractData) {
|
|
57
|
-
return contractData.script;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return this.readProvider.getScript(address, block);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
getEntrypoints(contract) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const contractData = this.contractslibrary.getContract(contract);
|
|
67
|
-
if (contractData) {
|
|
68
|
-
return contractData.entrypoints;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return this.readProvider.getEntrypoints(contract);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getBalance(address, block) {
|
|
76
|
-
return this.readProvider.getBalance(address, block);
|
|
77
|
-
}
|
|
78
|
-
getDelegate(address, block) {
|
|
79
|
-
return this.readProvider.getDelegate(address, block);
|
|
80
|
-
}
|
|
81
|
-
getNextProtocol(block) {
|
|
82
|
-
return this.readProvider.getNextProtocol(block);
|
|
83
|
-
}
|
|
84
|
-
getProtocolConstants(block) {
|
|
85
|
-
return this.readProvider.getProtocolConstants(block);
|
|
86
|
-
}
|
|
87
|
-
getStorage(contract, block) {
|
|
88
|
-
return this.readProvider.getStorage(contract, block);
|
|
89
|
-
}
|
|
90
|
-
getBlockHash(block) {
|
|
91
|
-
return this.readProvider.getBlockHash(block);
|
|
92
|
-
}
|
|
93
|
-
getBlockLevel(block) {
|
|
94
|
-
return this.readProvider.getBlockLevel(block);
|
|
95
|
-
}
|
|
96
|
-
getCounter(pkh, block) {
|
|
97
|
-
return this.readProvider.getCounter(pkh, block);
|
|
98
|
-
}
|
|
99
|
-
getBlockTimestamp(block) {
|
|
100
|
-
return this.readProvider.getBlockTimestamp(block);
|
|
101
|
-
}
|
|
102
|
-
getBigMapValue(bigMapQuery, block) {
|
|
103
|
-
return this.readProvider.getBigMapValue(bigMapQuery, block);
|
|
104
|
-
}
|
|
105
|
-
getSaplingDiffById(saplingStateQuery, block) {
|
|
106
|
-
return this.readProvider.getSaplingDiffById(saplingStateQuery, block);
|
|
107
|
-
}
|
|
108
|
-
getSaplingDiffByContract(contractAddress, block) {
|
|
109
|
-
return this.readProvider.getSaplingDiffByContract(contractAddress, block);
|
|
110
|
-
}
|
|
111
|
-
getChainId() {
|
|
112
|
-
return this.readProvider.getChainId();
|
|
113
|
-
}
|
|
114
|
-
isAccountRevealed(publicKeyHash, block) {
|
|
115
|
-
return this.readProvider.isAccountRevealed(publicKeyHash, block);
|
|
116
|
-
}
|
|
117
|
-
getBlock(block) {
|
|
118
|
-
return this.readProvider.getBlock(block);
|
|
119
|
-
}
|
|
120
|
-
getLiveBlocks(block) {
|
|
121
|
-
return this.readProvider.getLiveBlocks(block);
|
|
122
|
-
}
|
|
50
|
+
class ReadWrapperContractsLibrary {
|
|
51
|
+
constructor(readProvider, contractslibrary) {
|
|
52
|
+
this.readProvider = readProvider;
|
|
53
|
+
this.contractslibrary = contractslibrary;
|
|
54
|
+
}
|
|
55
|
+
getScript(address, block) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const contractData = this.contractslibrary.getContract(address);
|
|
58
|
+
if (contractData) {
|
|
59
|
+
return contractData.script;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return this.readProvider.getScript(address, block);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getEntrypoints(contract) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const contractData = this.contractslibrary.getContract(contract);
|
|
69
|
+
if (contractData) {
|
|
70
|
+
return contractData.entrypoints;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return this.readProvider.getEntrypoints(contract);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
getBalance(address, block) {
|
|
78
|
+
return this.readProvider.getBalance(address, block);
|
|
79
|
+
}
|
|
80
|
+
getDelegate(address, block) {
|
|
81
|
+
return this.readProvider.getDelegate(address, block);
|
|
82
|
+
}
|
|
83
|
+
getNextProtocol(block) {
|
|
84
|
+
return this.readProvider.getNextProtocol(block);
|
|
85
|
+
}
|
|
86
|
+
getProtocolConstants(block) {
|
|
87
|
+
return this.readProvider.getProtocolConstants(block);
|
|
88
|
+
}
|
|
89
|
+
getStorage(contract, block) {
|
|
90
|
+
return this.readProvider.getStorage(contract, block);
|
|
91
|
+
}
|
|
92
|
+
getBlockHash(block) {
|
|
93
|
+
return this.readProvider.getBlockHash(block);
|
|
94
|
+
}
|
|
95
|
+
getBlockLevel(block) {
|
|
96
|
+
return this.readProvider.getBlockLevel(block);
|
|
97
|
+
}
|
|
98
|
+
getCounter(pkh, block) {
|
|
99
|
+
return this.readProvider.getCounter(pkh, block);
|
|
100
|
+
}
|
|
101
|
+
getBlockTimestamp(block) {
|
|
102
|
+
return this.readProvider.getBlockTimestamp(block);
|
|
103
|
+
}
|
|
104
|
+
getBigMapValue(bigMapQuery, block) {
|
|
105
|
+
return this.readProvider.getBigMapValue(bigMapQuery, block);
|
|
106
|
+
}
|
|
107
|
+
getSaplingDiffById(saplingStateQuery, block) {
|
|
108
|
+
return this.readProvider.getSaplingDiffById(saplingStateQuery, block);
|
|
109
|
+
}
|
|
110
|
+
getSaplingDiffByContract(contractAddress, block) {
|
|
111
|
+
return this.readProvider.getSaplingDiffByContract(contractAddress, block);
|
|
112
|
+
}
|
|
113
|
+
getChainId() {
|
|
114
|
+
return this.readProvider.getChainId();
|
|
115
|
+
}
|
|
116
|
+
isAccountRevealed(publicKeyHash, block) {
|
|
117
|
+
return this.readProvider.isAccountRevealed(publicKeyHash, block);
|
|
118
|
+
}
|
|
119
|
+
getBlock(block) {
|
|
120
|
+
return this.readProvider.getBlock(block);
|
|
121
|
+
}
|
|
122
|
+
getLiveBlocks(block) {
|
|
123
|
+
return this.readProvider.getLiveBlocks(block);
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
/**
|
|
126
|
-
* @packageDocumentation
|
|
127
|
-
* @module @taquito/contracts-library
|
|
128
|
-
*/
|
|
129
|
-
/**
|
|
130
|
-
* @description Allows to specify static data related to contracts (i.e., script and entrypoints) avoiding Taquito to fetch them from the network.
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```
|
|
134
|
-
* import { ContractsLibrary } from '@taquito/contracts-library';
|
|
135
|
-
* import { TezosToolkit } from '@taquito/taquito';
|
|
136
|
-
*
|
|
137
|
-
* const Tezos = new TezosToolkit('rpcUrl');
|
|
138
|
-
* const contractsLibrary = new ContractsLibrary();
|
|
139
|
-
*
|
|
140
|
-
* contractsLibrary.addContract({
|
|
141
|
-
* ['contractAddress1']: {
|
|
142
|
-
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
143
|
-
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
144
|
-
* },
|
|
145
|
-
* // load more contracts
|
|
146
|
-
* });
|
|
147
|
-
*
|
|
148
|
-
* Tezos.addExtension(contractsLibrary);
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
class ContractsLibrary {
|
|
153
|
-
constructor() {
|
|
154
|
-
this._contractsLibrary = {};
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @description Saves one of several contract in the library
|
|
158
|
-
*
|
|
159
|
-
* @param contract is an object where the key is a contract address and the value is an object having a script and an entrypoints properties.
|
|
160
|
-
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
161
|
-
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
162
|
-
* @throws {@link InvalidAddressError} If the contract address is not valid
|
|
163
|
-
* @throws {@link InvalidScriptFormatError} If the script is not in the expected format
|
|
164
|
-
*/
|
|
165
|
-
addContract(contract) {
|
|
166
|
-
for (const contractAddress in contract) {
|
|
167
|
-
this.validateContractAddress(contractAddress);
|
|
168
|
-
this.validateContractScriptFormat(contract[contractAddress].script, contractAddress);
|
|
169
|
-
Object.assign(this._contractsLibrary, {
|
|
170
|
-
[contractAddress]: Object.assign({}, contract[contractAddress]),
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
getContract(contractAddress) {
|
|
175
|
-
return this._contractsLibrary[contractAddress];
|
|
176
|
-
}
|
|
177
|
-
configureContext(context) {
|
|
178
|
-
context.registerProviderDecorator((context) => {
|
|
179
|
-
context.readProvider = new ReadWrapperContractsLibrary(context.readProvider, this);
|
|
180
|
-
return context;
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
validateContractAddress(address) {
|
|
184
|
-
const addressValidation = validateAddress(address);
|
|
185
|
-
if (addressValidation !== ValidationResult.VALID) {
|
|
186
|
-
throw new InvalidAddressError(address, invalidDetail(addressValidation));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
validateContractScriptFormat(script, address) {
|
|
190
|
-
if (!script.code) {
|
|
191
|
-
throw new InvalidScriptFormatError(`Invalid script format of ${address} missing property "code". Valid script can be retrieved from "TezosToolkit.rpc.getNormalizedScript(${address})".`, script, address);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
127
|
+
/**
|
|
128
|
+
* @packageDocumentation
|
|
129
|
+
* @module @taquito/contracts-library
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* @description Allows to specify static data related to contracts (i.e., script and entrypoints) avoiding Taquito to fetch them from the network.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```
|
|
136
|
+
* import { ContractsLibrary } from '@taquito/contracts-library';
|
|
137
|
+
* import { TezosToolkit } from '@taquito/taquito';
|
|
138
|
+
*
|
|
139
|
+
* const Tezos = new TezosToolkit('rpcUrl');
|
|
140
|
+
* const contractsLibrary = new ContractsLibrary();
|
|
141
|
+
*
|
|
142
|
+
* contractsLibrary.addContract({
|
|
143
|
+
* ['contractAddress1']: {
|
|
144
|
+
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
145
|
+
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
146
|
+
* },
|
|
147
|
+
* // load more contracts
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* Tezos.addExtension(contractsLibrary);
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
class ContractsLibrary {
|
|
155
|
+
constructor() {
|
|
156
|
+
this._contractsLibrary = {};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @description Saves one of several contract in the library
|
|
160
|
+
*
|
|
161
|
+
* @param contract is an object where the key is a contract address and the value is an object having a script and an entrypoints properties.
|
|
162
|
+
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
163
|
+
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
164
|
+
* @throws {@link InvalidAddressError} If the contract address is not valid
|
|
165
|
+
* @throws {@link InvalidScriptFormatError} If the script is not in the expected format
|
|
166
|
+
*/
|
|
167
|
+
addContract(contract) {
|
|
168
|
+
for (const contractAddress in contract) {
|
|
169
|
+
this.validateContractAddress(contractAddress);
|
|
170
|
+
this.validateContractScriptFormat(contract[contractAddress].script, contractAddress);
|
|
171
|
+
Object.assign(this._contractsLibrary, {
|
|
172
|
+
[contractAddress]: Object.assign({}, contract[contractAddress]),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
getContract(contractAddress) {
|
|
177
|
+
return this._contractsLibrary[contractAddress];
|
|
178
|
+
}
|
|
179
|
+
configureContext(context) {
|
|
180
|
+
context.registerProviderDecorator((context) => {
|
|
181
|
+
context.readProvider = new ReadWrapperContractsLibrary(context.readProvider, this);
|
|
182
|
+
return context;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
validateContractAddress(address) {
|
|
186
|
+
const addressValidation = validateAddress(address);
|
|
187
|
+
if (addressValidation !== ValidationResult.VALID) {
|
|
188
|
+
throw new InvalidAddressError(address, invalidDetail(addressValidation));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
validateContractScriptFormat(script, address) {
|
|
192
|
+
if (!script.code) {
|
|
193
|
+
throw new InvalidScriptFormatError(`Invalid script format of ${address} missing property "code". Valid script can be retrieved from "TezosToolkit.rpc.getNormalizedScript(${address})".`, script, address);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
export { ContractsLibrary };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-contracts-library.es6.js","sources":["../src/errors.ts","../src/read-provider-wrapper.ts","../src/taquito-contracts-library.ts"],"sourcesContent":["import { ParameterValidationError } from '@taquito/core';\nimport { ScriptedContracts } from '@taquito/rpc';\n/**\n * @category Error\n * @description Error that indicates invalid script format being useed or passed\n */\nexport class InvalidScriptFormatError extends ParameterValidationError {\n constructor(\n public readonly message: string,\n public readonly script: ScriptedContracts,\n public readonly address: string\n ) {\n super();\n this.name = 'InvalidScriptFormatError';\n }\n}\n","import { BigNumber } from 'bignumber.js';\nimport {\n BlockResponse,\n EntrypointsResponse,\n MichelsonV1Expression,\n SaplingDiffResponse,\n ScriptedContracts,\n} from '@taquito/rpc';\nimport { ContractsLibrary } from './taquito-contracts-library';\nimport { BigMapQuery, BlockIdentifier, SaplingStateQuery, TzReadProvider } from '@taquito/taquito';\n\nexport class ReadWrapperContractsLibrary implements TzReadProvider {\n constructor(private readProvider: TzReadProvider, private contractslibrary: ContractsLibrary) {}\n\n async getScript(address: string, block: BlockIdentifier): Promise<ScriptedContracts> {\n const contractData = this.contractslibrary.getContract(address);\n if (contractData) {\n return contractData.script;\n } else {\n return this.readProvider.getScript(address, block);\n }\n }\n\n async getEntrypoints(contract: string): Promise<EntrypointsResponse> {\n const contractData = this.contractslibrary.getContract(contract);\n if (contractData) {\n return contractData.entrypoints;\n } else {\n return this.readProvider.getEntrypoints(contract);\n }\n }\n\n getBalance(address: string, block: BlockIdentifier): Promise<BigNumber> {\n return this.readProvider.getBalance(address, block);\n }\n getDelegate(address: string, block: BlockIdentifier): Promise<string | null> {\n return this.readProvider.getDelegate(address, block);\n }\n getNextProtocol(block: BlockIdentifier): Promise<string> {\n return this.readProvider.getNextProtocol(block);\n }\n getProtocolConstants(block: BlockIdentifier): Promise<{\n time_between_blocks?: BigNumber[] | undefined;\n minimal_block_delay?: BigNumber | undefined;\n hard_gas_limit_per_operation: BigNumber;\n hard_gas_limit_per_block: BigNumber;\n hard_storage_limit_per_operation: BigNumber;\n cost_per_byte: BigNumber;\n smart_rollup_origination_size: number;\n }> {\n return this.readProvider.getProtocolConstants(block);\n }\n getStorage(contract: string, block: BlockIdentifier): Promise<MichelsonV1Expression> {\n return this.readProvider.getStorage(contract, block);\n }\n getBlockHash(block: BlockIdentifier): Promise<string> {\n return this.readProvider.getBlockHash(block);\n }\n getBlockLevel(block: BlockIdentifier): Promise<number> {\n return this.readProvider.getBlockLevel(block);\n }\n getCounter(pkh: string, block: BlockIdentifier): Promise<string> {\n return this.readProvider.getCounter(pkh, block);\n }\n getBlockTimestamp(block: BlockIdentifier): Promise<string> {\n return this.readProvider.getBlockTimestamp(block);\n }\n getBigMapValue(bigMapQuery: BigMapQuery, block: BlockIdentifier): Promise<MichelsonV1Expression> {\n return this.readProvider.getBigMapValue(bigMapQuery, block);\n }\n getSaplingDiffById(\n saplingStateQuery: SaplingStateQuery,\n block: BlockIdentifier\n ): Promise<SaplingDiffResponse> {\n return this.readProvider.getSaplingDiffById(saplingStateQuery, block);\n }\n getSaplingDiffByContract(\n contractAddress: string,\n block: BlockIdentifier\n ): Promise<SaplingDiffResponse> {\n return this.readProvider.getSaplingDiffByContract(contractAddress, block);\n }\n getChainId(): Promise<string> {\n return this.readProvider.getChainId();\n }\n isAccountRevealed(publicKeyHash: string, block: BlockIdentifier): Promise<boolean> {\n return this.readProvider.isAccountRevealed(publicKeyHash, block);\n }\n getBlock(block: BlockIdentifier): Promise<BlockResponse> {\n return this.readProvider.getBlock(block);\n }\n getLiveBlocks(block: BlockIdentifier): Promise<string[]> {\n return this.readProvider.getLiveBlocks(block);\n }\n}\n","/**\n * @packageDocumentation\n * @module @taquito/contracts-library\n */\n\nimport { EntrypointsResponse, ScriptedContracts } from '@taquito/rpc';\nimport { Extension, Context } from '@taquito/taquito';\nimport { validateAddress, ValidationResult, invalidDetail } from '@taquito/utils';\nimport { InvalidScriptFormatError } from './errors';\nimport { ReadWrapperContractsLibrary } from './read-provider-wrapper';\nimport { InvalidAddressError } from '@taquito/core';\n\ninterface ContractsData {\n [contractAddress: string]: { script: ScriptedContracts; entrypoints: EntrypointsResponse };\n}\n\n/**\n * @description Allows to specify static data related to contracts (i.e., script and entrypoints) avoiding Taquito to fetch them from the network.\n *\n * @example\n * ```\n * import { ContractsLibrary } from '@taquito/contracts-library';\n * import { TezosToolkit } from '@taquito/taquito';\n *\n * const Tezos = new TezosToolkit('rpcUrl');\n * const contractsLibrary = new ContractsLibrary();\n *\n * contractsLibrary.addContract({\n * ['contractAddress1']: {\n * script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script\n * entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')\n * },\n * // load more contracts\n * });\n *\n * Tezos.addExtension(contractsLibrary);\n * ```\n *\n */\nexport class ContractsLibrary implements Extension {\n private _contractsLibrary: ContractsData = {};\n\n /**\n * @description Saves one of several contract in the library\n *\n * @param contract is an object where the key is a contract address and the value is an object having a script and an entrypoints properties.\n * Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by\n * `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`\n * @throws {@link InvalidAddressError} If the contract address is not valid\n * @throws {@link InvalidScriptFormatError} If the script is not in the expected format\n */\n addContract(contract: ContractsData) {\n for (const contractAddress in contract) {\n this.validateContractAddress(contractAddress);\n this.validateContractScriptFormat(contract[contractAddress].script, contractAddress);\n Object.assign(this._contractsLibrary, {\n [contractAddress]: { ...contract[contractAddress] },\n });\n }\n }\n\n getContract(contractAddress: string) {\n return this._contractsLibrary[contractAddress];\n }\n\n configureContext(context: Context) {\n context.registerProviderDecorator((context: Context) => {\n context.readProvider = new ReadWrapperContractsLibrary(context.readProvider, this);\n return context;\n });\n }\n\n private validateContractAddress(address: string) {\n const addressValidation = validateAddress(address);\n if (addressValidation !== ValidationResult.VALID) {\n throw new InvalidAddressError(address, invalidDetail(addressValidation));\n }\n }\n\n private validateContractScriptFormat(script: ScriptedContracts, address: string) {\n if (!script.code) {\n throw new InvalidScriptFormatError(\n `Invalid script format of ${address} missing property \"code\". Valid script can be retrieved from \"TezosToolkit.rpc.getNormalizedScript(${address})\".`,\n script,\n address\n );\n }\n }\n}\n"],"names":[],"mappings":";;;AAEA;;;AAGG;AACG,MAAO,wBAAyB,SAAQ,wBAAwB,CAAA;AACpE,IAAA,WAAA,CACkB,OAAe,EACf,MAAyB,EACzB,OAAe,EAAA;AAE/B,QAAA,KAAK,EAAE,CAAC;QAJQ,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;QACf,IAAM,CAAA,MAAA,GAAN,MAAM,CAAmB;QACzB,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;AAG/B,QAAA,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;KACxC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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