@taquito/contracts-library 12.0.2 → 12.1.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 +8 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/rpc-wrapper.js +6 -5
- package/dist/lib/rpc-wrapper.js.map +1 -1
- package/dist/lib/taquito-contracts-library.js +2 -2
- package/dist/lib/version.js +2 -2
- package/dist/taquito-contracts-library.es6.js +10 -2
- package/dist/taquito-contracts-library.es6.js.map +1 -1
- package/dist/taquito-contracts-library.umd.js +10 -2
- package/dist/taquito-contracts-library.umd.js.map +1 -1
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/rpc-wrapper.d.ts +2 -2
- package/dist/types/taquito-contracts-library.d.ts +2 -2
- package/package.json +5 -5
package/dist/lib/errors.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidScriptFormatError = exports.InvalidAddressError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category Error
|
|
6
|
+
* @description Error that indicates an invalid address being used or passed
|
|
7
|
+
*/
|
|
4
8
|
class InvalidAddressError extends Error {
|
|
5
9
|
constructor(message) {
|
|
6
10
|
super(message);
|
|
7
11
|
}
|
|
8
12
|
}
|
|
9
13
|
exports.InvalidAddressError = InvalidAddressError;
|
|
14
|
+
/**
|
|
15
|
+
* @category Error
|
|
16
|
+
* @description Error that indicates invalid script format being useed or passed
|
|
17
|
+
*/
|
|
10
18
|
class InvalidScriptFormatError extends Error {
|
|
11
19
|
constructor(message) {
|
|
12
20
|
super(message);
|
package/dist/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,4DAIC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,kDAIC;AAED;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,4DAIC"}
|
package/dist/lib/rpc-wrapper.js
CHANGED
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.RpcWrapperContractsLibrary = void 0;
|
|
24
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
24
25
|
const rpc_1 = require("@taquito/rpc");
|
|
25
26
|
/**
|
|
26
27
|
* @deprecated RpcWrapperContractsLibrary has been deprecated in favor of ReadWrapperContractsLibrary
|
|
@@ -31,14 +32,14 @@ class RpcWrapperContractsLibrary {
|
|
|
31
32
|
this.rpc = rpc;
|
|
32
33
|
this.contractslibrary = contractslibrary;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
getContract(address, { block } = rpc_1.defaultRPCOptions) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
const contractData = this.contractslibrary.getContract(address);
|
|
37
38
|
if (contractData) {
|
|
38
|
-
return contractData.script;
|
|
39
|
+
return { script: contractData.script, balance: new bignumber_js_1.BigNumber(NaN) };
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
41
|
-
return this.rpc.
|
|
42
|
+
return this.rpc.getContract(address, { block });
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -78,9 +79,9 @@ class RpcWrapperContractsLibrary {
|
|
|
78
79
|
return this.rpc.getScript(address, { block });
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
getNormalizedScript(address, unparsingMode = { unparsing_mode: 'Readable' }, { block } = rpc_1.defaultRPCOptions) {
|
|
82
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
return this.rpc.
|
|
84
|
+
return this.rpc.getNormalizedScript(address, unparsingMode, { block });
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
getManagerKey(address, { block } = rpc_1.defaultRPCOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-wrapper.js","sourceRoot":"","sources":["../../src/rpc-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"rpc-wrapper.js","sourceRoot":"","sources":["../../src/rpc-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,sCAyCsB;AAGtB;;;GAGG;AACH,MAAa,0BAA0B;IACrC,YAAoB,GAAuB,EAAU,gBAAkC;QAAnE,QAAG,GAAH,GAAG,CAAoB;QAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAErF,WAAW,CACf,OAAe,EACf,EAAE,KAAK,KAAiB,uBAAiB;;YAEzC,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAChE,IAAI,YAAY,EAAE;gBAChB,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,wBAAS,CAAC,GAAG,CAAC,EAAE,CAAC;aACrE;iBAAM;gBACL,OAAO,IAAI,CAAC,GA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AO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1C,CAAC;KAAA;CACF;AApND,gEAoNC"}
|
|
@@ -21,7 +21,7 @@ const read_provider_wrapper_1 = require("./read-provider-wrapper");
|
|
|
21
21
|
*
|
|
22
22
|
* contractsLibrary.addContract({
|
|
23
23
|
* ['contractAddress1']: {
|
|
24
|
-
* script: script1, // obtained from Tezos.rpc.
|
|
24
|
+
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
25
25
|
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
26
26
|
* },
|
|
27
27
|
* // load more contracts
|
|
@@ -40,7 +40,7 @@ class ContractsLibrary {
|
|
|
40
40
|
*
|
|
41
41
|
* @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.
|
|
42
42
|
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
43
|
-
* `TezosToolkit.rpc.
|
|
43
|
+
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
46
|
addContract(contract) {
|
package/dist/lib/version.js
CHANGED
|
@@ -3,7 +3,7 @@ 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": "12.0
|
|
6
|
+
"commitHash": "cbdd0af87e400489076259d065e2d328feb8e1b4",
|
|
7
|
+
"version": "12.1.0"
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { validateAddress, ValidationResult } from '@taquito/utils';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @category Error
|
|
5
|
+
* @description Error that indicates an invalid address being used or passed
|
|
6
|
+
*/
|
|
3
7
|
class InvalidAddressError extends Error {
|
|
4
8
|
constructor(message) {
|
|
5
9
|
super(message);
|
|
6
10
|
}
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* @category Error
|
|
14
|
+
* @description Error that indicates invalid script format being useed or passed
|
|
15
|
+
*/
|
|
8
16
|
class InvalidScriptFormatError extends Error {
|
|
9
17
|
constructor(message) {
|
|
10
18
|
super(message);
|
|
@@ -127,7 +135,7 @@ class ReadWrapperContractsLibrary {
|
|
|
127
135
|
*
|
|
128
136
|
* contractsLibrary.addContract({
|
|
129
137
|
* ['contractAddress1']: {
|
|
130
|
-
* script: script1, // obtained from Tezos.rpc.
|
|
138
|
+
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
131
139
|
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
132
140
|
* },
|
|
133
141
|
* // load more contracts
|
|
@@ -146,7 +154,7 @@ class ContractsLibrary {
|
|
|
146
154
|
*
|
|
147
155
|
* @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.
|
|
148
156
|
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
149
|
-
* `TezosToolkit.rpc.
|
|
157
|
+
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
150
158
|
*
|
|
151
159
|
*/
|
|
152
160
|
addContract(contract) {
|
|
@@ -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":["export class InvalidAddressError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class InvalidScriptFormatError extends Error {\n constructor(message: string) {\n super(message);\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 }> {\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 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 } from '@taquito/utils';\nimport { InvalidAddressError, InvalidScriptFormatError } from './errors';\nimport { ReadWrapperContractsLibrary } from './read-provider-wrapper';\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.getNormalizedScript('contractAddress1')\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.getNormalizedScript` and `TezosToolkit.rpc.getEntrypoints`\n *\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 if (validateAddress(address) !== ValidationResult.VALID) {\n throw new InvalidAddressError(`Address is invalid: ${address}`);\n }\n }\n\n private validateContractScriptFormat(script: ScriptedContracts, address: string) {\n if (!script.code) {\n throw new InvalidScriptFormatError(\n `An invalid script property has been provided for ${address}. The script property can be retrieved from TezosToolkit.rpc.getNormalizedScript(${address}). Invalid script: ${script}`\n );\n }\n }\n}\n"],"names":[],"mappings":";;MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;KAChB;CACF;MAEY,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;KAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCEU,2BAA2B;IACtC,YAAoB,YAA4B,EAAU,gBAAkC;QAAxE,iBAAY,GAAZ,YAAY,CAAgB;QAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;KAAI;IAE1F,SAAS,CAAC,OAAe,EAAE,KAAsB;;YACrD,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAChE,IAAI,YAAY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AAQ,QAAQ,CAAC,eAAe,CAAC,CAAE;aACpD,CAAC,CAAC;SACJ;KACF;IAED,WAAW,CAAC,eAAuB;QACjC,OAAO,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;KAChD;IAED,gBAAgB,CAAC,OAAgB;QAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC,OAAgB;YACjD,OAAO,CAAC,YAAY,GAAG,IAAI,2BAA2B,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACnF,OAAO,OAAO,CAAC;SAChB,CAAC,CAAC;KACJ;IAEO,uBAAuB,CAAC,OAAe;QAC7C,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,gBAAgB,CAAC,KAAK,EAAE;YACvD,MAAM,IAAI,mBAAmB,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;SACjE;KACF;IAEO,4BAA4B,CAAC,MAAyB,EAAE,OAAe;QAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAChB,MAAM,IAAI,wBAAwB,CAChC,oDAAoD,OAAO,oFAAoF,OAAO,sBAAsB,MAAM,EAAE,CACrL,CAAC;SACH;KACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"taquito-contracts-library.es6.js","sources":["../src/errors.ts","../src/read-provider-wrapper.ts","../src/taquito-contracts-library.ts"],"sourcesContent":["/**\n * @category Error\n * @description Error that indicates an invalid address being used or passed\n */\nexport class InvalidAddressError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates invalid script format being useed or passed\n */\nexport class InvalidScriptFormatError extends Error {\n constructor(message: string) {\n super(message);\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 }> {\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 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 } from '@taquito/utils';\nimport { InvalidAddressError, InvalidScriptFormatError } from './errors';\nimport { ReadWrapperContractsLibrary } from './read-provider-wrapper';\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 *\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 if (validateAddress(address) !== ValidationResult.VALID) {\n throw new InvalidAddressError(`Address is invalid: ${address}`);\n }\n }\n\n private validateContractScriptFormat(script: ScriptedContracts, address: string) {\n if (!script.code) {\n throw new InvalidScriptFormatError(\n `An invalid script property has been provided for ${address}. The script property can be retrieved from TezosToolkit.rpc.getNormalizedScript(${address}). Invalid script: ${script}`\n );\n }\n }\n}\n"],"names":[],"mappings":";;AAAA;;;;MAIa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;KAChB;CACF;AAED;;;;MAIa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;KAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCNU,2BAA2B;IACtC,YAAoB,YAA4B,EAAU,gBAAkC;QAAxE,iBAAY,GAAZ,YAAY,CAAgB;QAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;KAAI;IAE1F,SAAS,CAAC,OAAe,EAAE,KAAsB;;YACrD,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAChE,IAAI,YAAY,EAAE;gBAChB,OAAO,YAAY,CAAC,MAAM,CAAC;aAC5B;iBAAM;gBACL,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,C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C,eAAe,CAAC,CAAC;KAChD;IAED,gBAAgB,CAAC,OAAgB;QAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC,OAAgB;YACjD,OAAO,CAAC,YAAY,GAAG,IAAI,2BAA2B,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACnF,OAAO,OAAO,CAAC;SAChB,CAAC,CAAC;KACJ;IAEO,uBAAuB,CAAC,OAAe;QAC7C,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,gBAAgB,CAAC,KAAK,EAAE;YACvD,MAAM,IAAI,mBAAmB,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;SACjE;KACF;IAEO,4BAA4B,CAAC,MAAyB,EAAE,OAAe;QAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAChB,MAAM,IAAI,wBAAwB,CAChC,oDAAoD,OAAO,oFAAoF,OAAO,sBAAsB,MAAM,EAAE,CACrL,CAAC;SACH;KACF;;;;;"}
|
|
@@ -4,11 +4,19 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoContractsLibrary = {}, global.utils));
|
|
5
5
|
})(this, (function (exports, utils) { 'use strict';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @category Error
|
|
9
|
+
* @description Error that indicates an invalid address being used or passed
|
|
10
|
+
*/
|
|
7
11
|
class InvalidAddressError extends Error {
|
|
8
12
|
constructor(message) {
|
|
9
13
|
super(message);
|
|
10
14
|
}
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @category Error
|
|
18
|
+
* @description Error that indicates invalid script format being useed or passed
|
|
19
|
+
*/
|
|
12
20
|
class InvalidScriptFormatError extends Error {
|
|
13
21
|
constructor(message) {
|
|
14
22
|
super(message);
|
|
@@ -131,7 +139,7 @@
|
|
|
131
139
|
*
|
|
132
140
|
* contractsLibrary.addContract({
|
|
133
141
|
* ['contractAddress1']: {
|
|
134
|
-
* script: script1, // obtained from Tezos.rpc.
|
|
142
|
+
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
135
143
|
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
136
144
|
* },
|
|
137
145
|
* // load more contracts
|
|
@@ -150,7 +158,7 @@
|
|
|
150
158
|
*
|
|
151
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.
|
|
152
160
|
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
153
|
-
* `TezosToolkit.rpc.
|
|
161
|
+
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
154
162
|
*
|
|
155
163
|
*/
|
|
156
164
|
addContract(contract) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-contracts-library.umd.js","sources":["../src/errors.ts","../src/read-provider-wrapper.ts","../src/taquito-contracts-library.ts"],"sourcesContent":["export class InvalidAddressError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class InvalidScriptFormatError extends Error {\n constructor(message: string) {\n super(message);\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 }> {\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 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 } from '@taquito/utils';\nimport { InvalidAddressError, InvalidScriptFormatError } from './errors';\nimport { ReadWrapperContractsLibrary } from './read-provider-wrapper';\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.getNormalizedScript('contractAddress1')\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.getNormalizedScript` and `TezosToolkit.rpc.getEntrypoints`\n *\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 if (validateAddress(address) !== ValidationResult.VALID) {\n throw new InvalidAddressError(`Address is invalid: ${address}`);\n }\n }\n\n private validateContractScriptFormat(script: ScriptedContracts, address: string) {\n if (!script.code) {\n throw new InvalidScriptFormatError(\n `An invalid script property has been provided for ${address}. The script property can be retrieved from TezosToolkit.rpc.getNormalizedScript(${address}). Invalid script: ${script}`\n );\n }\n }\n}\n"],"names":["validateAddress","ValidationResult"],"mappings":";;;;;;QAAa,mBAAoB,SAAQ,KAAK;MAC5C,YAAY,OAAe;UACzB,KAAK,CAAC,OAAO,CAAC,CAAC;OAChB;GACF;QAEY,wBAAyB,SAAQ,KAAK;MACjD,YAAY,OAAe;UACzB,KAAK,CAAC,OAAO,CAAC,CAAC;OAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;QCEU,2BAA2B;MACtC,YAAoB,YAA4B,EAAU,gBAAkC;UAAxE,iBAAY,GAAZ,YAAY,CAAgB;UAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;OAAI;MAE1F,SAAS,CAAC,OAAe,EAAE,KAAsB;;cACrD,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;cAChE,IAAI,YAAY,EAAE;kBAChB,OAAO,YAAY,CAAC,MAAM,CAAC;eAC5B;mBAAM;kBACL,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;eACpD;WACF;OAAA;MAEK,cAAc,CAAC,QAAgB;;cACnC,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;cACjE,IAAI,YAAY,EAAE;kBAChB,OAAO,YAAY,CAAC,WAAW,CAAC;eACjC;mBAAM;kBACL,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;eACnD;WACF;OAAA;MAED,UAAU,CAAC,OAAe,EAAE,KAA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,KAAK,EAAE;cACvD,MAAM,IAAI,mBAAmB,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;WACjE;OACF;MAEO,4BAA4B,CAAC,MAAyB,EAAE,OAAe;UAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;cAChB,MAAM,IAAI,wBAAwB,CAChC,oDAAoD,OAAO,oFAAoF,OAAO,sBAAsB,MAAM,EAAE,CACrL,CAAC;WACH;OACF;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"taquito-contracts-library.umd.js","sources":["../src/errors.ts","../src/read-provider-wrapper.ts","../src/taquito-contracts-library.ts"],"sourcesContent":["/**\n * @category Error\n * @description Error that indicates an invalid address being used or passed\n */\nexport class InvalidAddressError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\n/**\n * @category Error\n * @description Error that indicates invalid script format being useed or passed\n */\nexport class InvalidScriptFormatError extends Error {\n constructor(message: string) {\n super(message);\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 }> {\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 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 } from '@taquito/utils';\nimport { InvalidAddressError, InvalidScriptFormatError } from './errors';\nimport { ReadWrapperContractsLibrary } from './read-provider-wrapper';\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 *\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 if (validateAddress(address) !== ValidationResult.VALID) {\n throw new InvalidAddressError(`Address is invalid: ${address}`);\n }\n }\n\n private validateContractScriptFormat(script: ScriptedContracts, address: string) {\n if (!script.code) {\n throw new InvalidScriptFormatError(\n `An invalid script property has been provided for ${address}. The script property can be retrieved from TezosToolkit.rpc.getNormalizedScript(${address}). Invalid script: ${script}`\n );\n }\n }\n}\n"],"names":["validateAddress","ValidationResult"],"mappings":";;;;;;EAAA;;;;QAIa,mBAAoB,SAAQ,KAAK;MAC5C,YAAY,OAAe;UACzB,KAAK,CAAC,OAAO,CAAC,CAAC;OAChB;GACF;EAED;;;;QAIa,wBAAyB,SAAQ,KAAK;MACjD,YAAY,OAAe;UACzB,KAAK,CAAC,OAAO,CAAC,CAAC;OAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;QCNU,2BAA2B;MACtC,YAAoB,YAA4B,EAAU,gBAAkC;UAAxE,iBAAY,GAAZ,YAAY,CAAgB;UAAU,qBAAgB,GAAhB,gBAAgB,CAAkB;OAAI;MAE1F,SAAS,CAAC,OAAe,EAAE,KAAsB;;cACrD,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;cAChE,IAAI,YAAY,EAAE;kBAChB,OAAO,YAAY,CAAC,MAAM,CAAC;eAC5B;mBAAM;kBACL,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;eACpD;WACF;OAAA;MAEK,cAAc,CAAC,QAAgB;;cACnC,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;cACjE,IAAI,YAAY,EAAE;kBAChB,OAAO,YAAY,CAAC,WAAW,CAAC;eACjC;mBAAM;kBACL,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;eACnD;WACF;OAAA;MAED,UAAU,CAAC,OAAe,EAAE,KAAsB;UAChD,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;OACrD;MACD,WA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4BAA4B,CAAC,MAAyB,EAAE,OAAe;UAC7E,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;cAChB,MAAM,IAAI,wBAAwB,CAChC,oDAAoD,OAAO,oFAAoF,OAAO,sBAAsB,MAAM,EAAE,CACrL,CAAC;WACH;OACF;;;;;;;;;;;"}
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category Error
|
|
3
|
+
* @description Error that indicates an invalid address being used or passed
|
|
4
|
+
*/
|
|
1
5
|
export declare class InvalidAddressError extends Error {
|
|
2
6
|
constructor(message: string);
|
|
3
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @category Error
|
|
10
|
+
* @description Error that indicates invalid script format being useed or passed
|
|
11
|
+
*/
|
|
4
12
|
export declare class InvalidScriptFormatError extends Error {
|
|
5
13
|
constructor(message: string);
|
|
6
14
|
}
|
|
@@ -9,14 +9,14 @@ export declare class RpcWrapperContractsLibrary implements RpcClientInterface {
|
|
|
9
9
|
private rpc;
|
|
10
10
|
private contractslibrary;
|
|
11
11
|
constructor(rpc: RpcClientInterface, contractslibrary: ContractsLibrary);
|
|
12
|
-
|
|
12
|
+
getContract(address: string, { block }?: RPCOptions): Promise<ContractResponse>;
|
|
13
13
|
getEntrypoints(contract: string, { block }?: RPCOptions): Promise<EntrypointsResponse>;
|
|
14
14
|
getBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>;
|
|
15
15
|
getBlockHash({ block }?: RPCOptions): Promise<string>;
|
|
16
16
|
getLiveBlocks({ block }?: RPCOptions): Promise<string[]>;
|
|
17
17
|
getStorage(address: string, { block }?: RPCOptions): Promise<MichelsonV1Expression>;
|
|
18
18
|
getScript(address: string, { block }?: RPCOptions): Promise<ScriptResponse>;
|
|
19
|
-
|
|
19
|
+
getNormalizedScript(address: string, unparsingMode?: UnparsingMode, { block }?: RPCOptions): Promise<ScriptResponse>;
|
|
20
20
|
getManagerKey(address: string, { block }?: RPCOptions): Promise<ManagerKeyResponse>;
|
|
21
21
|
getDelegate(address: string, { block }?: RPCOptions): Promise<DelegateResponse>;
|
|
22
22
|
getBigMapKey(address: string, key: BigMapKey, { block }?: RPCOptions): Promise<MichelsonV1Expression>;
|
|
@@ -23,7 +23,7 @@ interface ContractsData {
|
|
|
23
23
|
*
|
|
24
24
|
* contractsLibrary.addContract({
|
|
25
25
|
* ['contractAddress1']: {
|
|
26
|
-
* script: script1, // obtained from Tezos.rpc.
|
|
26
|
+
* script: script1, // obtained from Tezos.rpc.getContract('contractAddress1').script
|
|
27
27
|
* entrypoints: entrypoints1 // obtained from Tezos.rpc.getEntrypoints('contractAddress1')
|
|
28
28
|
* },
|
|
29
29
|
* // load more contracts
|
|
@@ -40,7 +40,7 @@ export declare class ContractsLibrary implements Extension {
|
|
|
40
40
|
*
|
|
41
41
|
* @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.
|
|
42
42
|
* Note: the expected format for the script and entrypoints properties are the same as the one respectivlely returned by
|
|
43
|
-
* `TezosToolkit.rpc.
|
|
43
|
+
* `TezosToolkit.rpc.getContract('contractAddress').script` and `TezosToolkit.rpc.getEntrypoints`
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
46
|
addContract(contract: ContractsData): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taquito/contracts-library",
|
|
3
|
-
"version": "12.0
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Can be used as an extension on the TezosToolkit to provide contracts data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tezos"
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
]
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@taquito/rpc": "^12.0
|
|
72
|
-
"@taquito/taquito": "^12.0
|
|
73
|
-
"@taquito/utils": "^12.0
|
|
71
|
+
"@taquito/rpc": "^12.1.0",
|
|
72
|
+
"@taquito/taquito": "^12.1.0",
|
|
73
|
+
"@taquito/utils": "^12.1.0",
|
|
74
74
|
"bignumber.js": "^9.0.2"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"ts-toolbelt": "^9.6.0",
|
|
103
103
|
"typescript": "~4.1.5"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "8e044472d87e92bfa748e8193ba84a7ee57d659f"
|
|
106
106
|
}
|