@tezos-x/octez.js 0.9.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.
Files changed (208) hide show
  1. package/README.md +154 -0
  2. package/dist/lib/batch/constants.js +16 -0
  3. package/dist/lib/batch/rpc-batch-provider.js +319 -0
  4. package/dist/lib/constants.js +133 -0
  5. package/dist/lib/context.js +182 -0
  6. package/dist/lib/contract/big-map.js +70 -0
  7. package/dist/lib/contract/compose.js +6 -0
  8. package/dist/lib/contract/constants.js +4 -0
  9. package/dist/lib/contract/contract-methods/contract-method-factory.js +18 -0
  10. package/dist/lib/contract/contract-methods/contract-method-interface.js +2 -0
  11. package/dist/lib/contract/contract-methods/contract-method-object-param.js +72 -0
  12. package/dist/lib/contract/contract-methods/contract-on-chain-view.js +124 -0
  13. package/dist/lib/contract/contract.js +169 -0
  14. package/dist/lib/contract/errors.js +140 -0
  15. package/dist/lib/contract/index.js +30 -0
  16. package/dist/lib/contract/interface.js +2 -0
  17. package/dist/lib/contract/manager-lambda.js +71 -0
  18. package/dist/lib/contract/prepare.js +240 -0
  19. package/dist/lib/contract/rpc-contract-provider.js +724 -0
  20. package/dist/lib/contract/sapling-state-abstraction.js +35 -0
  21. package/dist/lib/contract/semantic.js +40 -0
  22. package/dist/lib/contract/view_lambda.js +27 -0
  23. package/dist/lib/errors.js +42 -0
  24. package/dist/lib/estimate/errors.js +16 -0
  25. package/dist/lib/estimate/estimate-provider-interface.js +2 -0
  26. package/dist/lib/estimate/estimate.js +130 -0
  27. package/dist/lib/estimate/index.js +20 -0
  28. package/dist/lib/estimate/rpc-estimate-provider.js +673 -0
  29. package/dist/lib/extension/extension.js +2 -0
  30. package/dist/lib/forger/composite-forger.js +43 -0
  31. package/dist/lib/forger/errors.js +30 -0
  32. package/dist/lib/forger/octez.js-local-forger.js +34 -0
  33. package/dist/lib/forger/rpc-forger.js +12 -0
  34. package/dist/lib/global-constants/default-global-constants-provider.js +46 -0
  35. package/dist/lib/global-constants/errors.js +30 -0
  36. package/dist/lib/global-constants/interface-global-constants-provider.js +2 -0
  37. package/dist/lib/global-constants/noop-global-constants-provider.js +21 -0
  38. package/dist/lib/import-key.js +51 -0
  39. package/dist/lib/injector/helper.js +18 -0
  40. package/dist/lib/injector/interface.js +2 -0
  41. package/dist/lib/injector/rpc-injector.js +38 -0
  42. package/dist/lib/octez.js +404 -0
  43. package/dist/lib/operations/ballot-operation.js +33 -0
  44. package/dist/lib/operations/batch-operation.js +66 -0
  45. package/dist/lib/operations/delegate-operation.js +57 -0
  46. package/dist/lib/operations/drain-delegate-operation.js +31 -0
  47. package/dist/lib/operations/errors.js +130 -0
  48. package/dist/lib/operations/failing-noop-operation.js +2 -0
  49. package/dist/lib/operations/increase-paid-storage-operation.js +52 -0
  50. package/dist/lib/operations/index.js +54 -0
  51. package/dist/lib/operations/operations.js +123 -0
  52. package/dist/lib/operations/origination-operation.js +89 -0
  53. package/dist/lib/operations/proposals-operation.js +30 -0
  54. package/dist/lib/operations/register-global-constant-operation.js +55 -0
  55. package/dist/lib/operations/reveal-operation.js +74 -0
  56. package/dist/lib/operations/smart-rollup-add-messages-operation.js +47 -0
  57. package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +56 -0
  58. package/dist/lib/operations/smart-rollup-originate-operation.js +53 -0
  59. package/dist/lib/operations/transaction-operation.js +70 -0
  60. package/dist/lib/operations/transfer-ticket-operation.js +49 -0
  61. package/dist/lib/operations/types.js +90 -0
  62. package/dist/lib/operations/update-companion-key-operation.js +58 -0
  63. package/dist/lib/operations/update-consensus-key-operation.js +58 -0
  64. package/dist/lib/packer/interface.js +2 -0
  65. package/dist/lib/packer/michel-codec-packer.js +22 -0
  66. package/dist/lib/packer/rpc-packer.js +23 -0
  67. package/dist/lib/parser/interface.js +2 -0
  68. package/dist/lib/parser/michel-codec-parser.js +135 -0
  69. package/dist/lib/parser/noop-parser.js +20 -0
  70. package/dist/lib/prepare/index.js +18 -0
  71. package/dist/lib/prepare/interface.js +2 -0
  72. package/dist/lib/prepare/prepare-provider.js +1010 -0
  73. package/dist/lib/provider.js +169 -0
  74. package/dist/lib/read-provider/interface.js +2 -0
  75. package/dist/lib/read-provider/rpc-read-adapter.js +228 -0
  76. package/dist/lib/signer/errors.js +17 -0
  77. package/dist/lib/signer/noop.js +40 -0
  78. package/dist/lib/subscribe/create-observable-from-subscription.js +20 -0
  79. package/dist/lib/subscribe/errors.js +30 -0
  80. package/dist/lib/subscribe/filters.js +96 -0
  81. package/dist/lib/subscribe/interface.js +2 -0
  82. package/dist/lib/subscribe/observable-subscription.js +79 -0
  83. package/dist/lib/subscribe/polling-subcribe-provider.js +118 -0
  84. package/dist/lib/tz/interface.js +2 -0
  85. package/dist/lib/tz/rpc-tz-provider.js +63 -0
  86. package/dist/lib/version.js +8 -0
  87. package/dist/lib/wallet/batch-operation.js +84 -0
  88. package/dist/lib/wallet/delegation-operation.js +57 -0
  89. package/dist/lib/wallet/errors.js +28 -0
  90. package/dist/lib/wallet/increase-paid-storage-operation.js +57 -0
  91. package/dist/lib/wallet/index.js +25 -0
  92. package/dist/lib/wallet/interface.js +2 -0
  93. package/dist/lib/wallet/legacy.js +86 -0
  94. package/dist/lib/wallet/operation-factory.js +117 -0
  95. package/dist/lib/wallet/operation.js +157 -0
  96. package/dist/lib/wallet/origination-operation.js +65 -0
  97. package/dist/lib/wallet/receipt.js +43 -0
  98. package/dist/lib/wallet/register-global-constant-operation.js +62 -0
  99. package/dist/lib/wallet/transaction-operation.js +53 -0
  100. package/dist/lib/wallet/transfer-ticket-operation.js +53 -0
  101. package/dist/lib/wallet/wallet.js +442 -0
  102. package/dist/octez.es6.js +7673 -0
  103. package/dist/octez.es6.js.map +1 -0
  104. package/dist/octez.umd.js +7787 -0
  105. package/dist/octez.umd.js.map +1 -0
  106. package/dist/types/batch/constants.d.ts +3 -0
  107. package/dist/types/batch/rpc-batch-provider.d.ts +139 -0
  108. package/dist/types/constants.d.ts +81 -0
  109. package/dist/types/context.d.ts +100 -0
  110. package/dist/types/contract/big-map.d.ts +35 -0
  111. package/dist/types/contract/compose.d.ts +5 -0
  112. package/dist/types/contract/constants.d.ts +1 -0
  113. package/dist/types/contract/contract-methods/contract-method-factory.d.ts +14 -0
  114. package/dist/types/contract/contract-methods/contract-method-interface.d.ts +28 -0
  115. package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +39 -0
  116. package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +43 -0
  117. package/dist/types/contract/contract.d.ts +75 -0
  118. package/dist/types/contract/errors.d.ts +83 -0
  119. package/dist/types/contract/index.d.ts +11 -0
  120. package/dist/types/contract/interface.d.ts +254 -0
  121. package/dist/types/contract/manager-lambda.d.ts +73 -0
  122. package/dist/types/contract/prepare.d.ts +18 -0
  123. package/dist/types/contract/rpc-contract-provider.d.ts +269 -0
  124. package/dist/types/contract/sapling-state-abstraction.d.ts +17 -0
  125. package/dist/types/contract/semantic.d.ts +7 -0
  126. package/dist/types/contract/view_lambda.d.ts +34 -0
  127. package/dist/types/errors.d.ts +26 -0
  128. package/dist/types/estimate/errors.d.ts +8 -0
  129. package/dist/types/estimate/estimate-provider-interface.d.ts +156 -0
  130. package/dist/types/estimate/estimate.d.ts +94 -0
  131. package/dist/types/estimate/index.d.ts +4 -0
  132. package/dist/types/estimate/rpc-estimate-provider.d.ts +170 -0
  133. package/dist/types/extension/extension.d.ts +4 -0
  134. package/dist/types/forger/composite-forger.d.ts +6 -0
  135. package/dist/types/forger/errors.d.ts +16 -0
  136. package/dist/types/forger/octez.js-local-forger.d.ts +8 -0
  137. package/dist/types/forger/rpc-forger.d.ts +7 -0
  138. package/dist/types/global-constants/default-global-constants-provider.d.ts +18 -0
  139. package/dist/types/global-constants/errors.d.ts +16 -0
  140. package/dist/types/global-constants/interface-global-constants-provider.d.ts +11 -0
  141. package/dist/types/global-constants/noop-global-constants-provider.d.ts +5 -0
  142. package/dist/types/import-key.d.ts +13 -0
  143. package/dist/types/injector/helper.d.ts +2 -0
  144. package/dist/types/injector/interface.d.ts +5 -0
  145. package/dist/types/injector/rpc-injector.d.ts +7 -0
  146. package/dist/types/octez.d.ts +248 -0
  147. package/dist/types/operations/ballot-operation.d.ts +18 -0
  148. package/dist/types/operations/batch-operation.d.ts +19 -0
  149. package/dist/types/operations/delegate-operation.d.ts +24 -0
  150. package/dist/types/operations/drain-delegate-operation.d.ts +17 -0
  151. package/dist/types/operations/errors.d.ts +50 -0
  152. package/dist/types/operations/failing-noop-operation.d.ts +17 -0
  153. package/dist/types/operations/increase-paid-storage-operation.d.ts +23 -0
  154. package/dist/types/operations/index.d.ts +18 -0
  155. package/dist/types/operations/operations.d.ts +35 -0
  156. package/dist/types/operations/origination-operation.d.ts +35 -0
  157. package/dist/types/operations/proposals-operation.d.ts +17 -0
  158. package/dist/types/operations/register-global-constant-operation.d.ts +25 -0
  159. package/dist/types/operations/reveal-operation.d.ts +25 -0
  160. package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +20 -0
  161. package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +24 -0
  162. package/dist/types/operations/smart-rollup-originate-operation.d.ts +23 -0
  163. package/dist/types/operations/transaction-operation.d.ts +28 -0
  164. package/dist/types/operations/transfer-ticket-operation.d.ts +22 -0
  165. package/dist/types/operations/types.d.ts +461 -0
  166. package/dist/types/operations/update-companion-key-operation.d.ts +23 -0
  167. package/dist/types/operations/update-consensus-key-operation.d.ts +23 -0
  168. package/dist/types/packer/interface.d.ts +4 -0
  169. package/dist/types/packer/michel-codec-packer.d.ts +5 -0
  170. package/dist/types/packer/rpc-packer.d.ts +8 -0
  171. package/dist/types/parser/interface.d.ts +4 -0
  172. package/dist/types/parser/michel-codec-parser.d.ts +16 -0
  173. package/dist/types/parser/noop-parser.d.ts +5 -0
  174. package/dist/types/prepare/index.d.ts +2 -0
  175. package/dist/types/prepare/interface.d.ts +153 -0
  176. package/dist/types/prepare/prepare-provider.d.ts +213 -0
  177. package/dist/types/provider.d.ts +44 -0
  178. package/dist/types/read-provider/interface.d.ts +132 -0
  179. package/dist/types/read-provider/rpc-read-adapter.d.ts +130 -0
  180. package/dist/types/signer/errors.d.ts +8 -0
  181. package/dist/types/signer/noop.d.ts +11 -0
  182. package/dist/types/subscribe/create-observable-from-subscription.d.ts +4 -0
  183. package/dist/types/subscribe/errors.d.ts +18 -0
  184. package/dist/types/subscribe/filters.d.ts +6 -0
  185. package/dist/types/subscribe/interface.d.ts +48 -0
  186. package/dist/types/subscribe/observable-subscription.d.ts +21 -0
  187. package/dist/types/subscribe/polling-subcribe-provider.d.ts +23 -0
  188. package/dist/types/tz/interface.d.ts +20 -0
  189. package/dist/types/tz/rpc-tz-provider.d.ts +13 -0
  190. package/dist/types/version.d.ts +4 -0
  191. package/dist/types/wallet/batch-operation.d.ts +13 -0
  192. package/dist/types/wallet/delegation-operation.d.ts +12 -0
  193. package/dist/types/wallet/errors.d.ts +16 -0
  194. package/dist/types/wallet/increase-paid-storage-operation.d.ts +12 -0
  195. package/dist/types/wallet/index.d.ts +9 -0
  196. package/dist/types/wallet/interface.d.ts +66 -0
  197. package/dist/types/wallet/legacy.d.ts +21 -0
  198. package/dist/types/wallet/operation-factory.d.ts +32 -0
  199. package/dist/types/wallet/operation.d.ts +54 -0
  200. package/dist/types/wallet/origination-operation.d.ts +14 -0
  201. package/dist/types/wallet/receipt.d.ts +16 -0
  202. package/dist/types/wallet/register-global-constant-operation.d.ts +13 -0
  203. package/dist/types/wallet/transaction-operation.d.ts +12 -0
  204. package/dist/types/wallet/transfer-ticket-operation.d.ts +12 -0
  205. package/dist/types/wallet/wallet.d.ts +195 -0
  206. package/package.json +131 -0
  207. package/patch.js +20 -0
  208. package/signature.json +866 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Context = exports.defaultConfigConfirmation = void 0;
13
+ const octez_js_rpc_1 = require("@tezos-x/octez.js-rpc");
14
+ const rpc_injector_1 = require("./injector/rpc-injector");
15
+ const noop_1 = require("./signer/noop");
16
+ const operation_factory_1 = require("./wallet/operation-factory");
17
+ const rpc_tz_provider_1 = require("./tz/rpc-tz-provider");
18
+ const rpc_estimate_provider_1 = require("./estimate/rpc-estimate-provider");
19
+ const rpc_contract_provider_1 = require("./contract/rpc-contract-provider");
20
+ const rpc_batch_provider_1 = require("./batch/rpc-batch-provider");
21
+ const wallet_1 = require("./wallet");
22
+ const michel_codec_parser_1 = require("./parser/michel-codec-parser");
23
+ const rpc_packer_1 = require("./packer/rpc-packer");
24
+ const rxjs_1 = require("rxjs");
25
+ const noop_global_constants_provider_1 = require("./global-constants/noop-global-constants-provider");
26
+ const rpc_read_adapter_1 = require("./read-provider/rpc-read-adapter");
27
+ const polling_subcribe_provider_1 = require("./subscribe/polling-subcribe-provider");
28
+ const octez_js_local_forger_1 = require("./forger/octez.js-local-forger");
29
+ const prepare_provider_1 = require("./prepare/prepare-provider");
30
+ exports.defaultConfigConfirmation = {
31
+ defaultConfirmationCount: 1,
32
+ confirmationPollingTimeoutSecond: 180,
33
+ };
34
+ /**
35
+ * @description Encapsulate common service used throughout different part of the library
36
+ */
37
+ class Context {
38
+ constructor(_rpc, _signer = new noop_1.NoopSigner(), _proto, _config = new rxjs_1.BehaviorSubject(Object.assign({}, exports.defaultConfigConfirmation)), forger, injector, packer, wallet, parser, globalConstantsProvider, readProvider, stream) {
39
+ this._rpc = _rpc;
40
+ this._signer = _signer;
41
+ this._proto = _proto;
42
+ this._config = _config;
43
+ this.providerDecorator = [];
44
+ this.tz = new rpc_tz_provider_1.RpcTzProvider(this);
45
+ this.estimate = new rpc_estimate_provider_1.RPCEstimateProvider(this);
46
+ this.contract = new rpc_contract_provider_1.RpcContractProvider(this, this.estimate);
47
+ this.prepare = new prepare_provider_1.PrepareProvider(this);
48
+ this.batch = new rpc_batch_provider_1.RPCBatchProvider(this, this.estimate);
49
+ this.wallet = new wallet_1.Wallet(this);
50
+ /**
51
+ * @description Applies the decorators on a cloned instance of the context and returned this cloned instance.
52
+ * The decorators are functions that inject logic into the context.
53
+ * They are provided by the extensions set on the TezosToolkit by calling the registerProviderDecorator method.
54
+ */
55
+ this.withExtensions = () => {
56
+ let clonedContext = this.clone();
57
+ this.providerDecorator.forEach((decorator) => {
58
+ clonedContext = decorator(clonedContext);
59
+ });
60
+ return clonedContext;
61
+ };
62
+ if (typeof this._rpc === 'string') {
63
+ this._rpcClient = new octez_js_rpc_1.RpcClient(this._rpc);
64
+ }
65
+ else {
66
+ this._rpcClient = this._rpc;
67
+ }
68
+ this._forger = forger ? forger : new octez_js_local_forger_1.TaquitoLocalForger(this);
69
+ this._injector = injector ? injector : new rpc_injector_1.RpcInjector(this);
70
+ this.operationFactory = new operation_factory_1.OperationFactory(this);
71
+ this._walletProvider = wallet ? wallet : new wallet_1.LegacyWalletProvider(this);
72
+ this._parser = parser ? parser : new michel_codec_parser_1.MichelCodecParser(this);
73
+ this._packer = packer ? packer : new rpc_packer_1.RpcPacker(this);
74
+ this._globalConstantsProvider = globalConstantsProvider
75
+ ? globalConstantsProvider
76
+ : new noop_global_constants_provider_1.NoopGlobalConstantsProvider();
77
+ this._readProvider = readProvider ? readProvider : new rpc_read_adapter_1.RpcReadAdapter(this._rpcClient);
78
+ this._stream = stream ? stream : new polling_subcribe_provider_1.PollingSubscribeProvider(this);
79
+ }
80
+ get config() {
81
+ return this._config.getValue();
82
+ }
83
+ set config(value) {
84
+ this._config.next(Object.assign({}, value));
85
+ }
86
+ setPartialConfig(value) {
87
+ this._config.next(Object.assign(Object.assign({}, this._config.getValue()), value));
88
+ }
89
+ get rpc() {
90
+ return this._rpcClient;
91
+ }
92
+ set rpc(value) {
93
+ this._rpcClient = value;
94
+ }
95
+ get injector() {
96
+ return this._injector;
97
+ }
98
+ set injector(value) {
99
+ this._injector = value;
100
+ }
101
+ get forger() {
102
+ return this._forger;
103
+ }
104
+ set forger(value) {
105
+ this._forger = value;
106
+ }
107
+ get signer() {
108
+ return this._signer;
109
+ }
110
+ set signer(value) {
111
+ this._signer = value;
112
+ }
113
+ get walletProvider() {
114
+ return this._walletProvider;
115
+ }
116
+ set walletProvider(value) {
117
+ this._walletProvider = value;
118
+ }
119
+ set proto(value) {
120
+ this._proto = value;
121
+ }
122
+ get proto() {
123
+ return this._proto;
124
+ }
125
+ get parser() {
126
+ return this._parser;
127
+ }
128
+ set parser(value) {
129
+ this._parser = value;
130
+ }
131
+ get packer() {
132
+ return this._packer;
133
+ }
134
+ set packer(value) {
135
+ this._packer = value;
136
+ }
137
+ get globalConstantsProvider() {
138
+ return this._globalConstantsProvider;
139
+ }
140
+ set globalConstantsProvider(value) {
141
+ this._globalConstantsProvider = value;
142
+ }
143
+ get readProvider() {
144
+ return this._readProvider;
145
+ }
146
+ set readProvider(value) {
147
+ this._readProvider = value;
148
+ }
149
+ get stream() {
150
+ return this._stream;
151
+ }
152
+ set stream(value) {
153
+ this._stream = value;
154
+ }
155
+ isAnyProtocolActive() {
156
+ return __awaiter(this, arguments, void 0, function* (protocol = []) {
157
+ if (this._proto) {
158
+ return protocol.includes(this._proto);
159
+ }
160
+ else {
161
+ const next_protocol = yield this.readProvider.getNextProtocol('head');
162
+ return protocol.includes(next_protocol);
163
+ }
164
+ });
165
+ }
166
+ isAnySignerConfigured() {
167
+ return !(this.signer instanceof noop_1.NoopSigner);
168
+ }
169
+ /**
170
+ * @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
171
+ */
172
+ clone() {
173
+ 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);
174
+ }
175
+ /**
176
+ * @description Allows extensions set on the TezosToolkit to inject logic into the context
177
+ */
178
+ registerProviderDecorator(fx) {
179
+ this.providerDecorator.push(fx);
180
+ }
181
+ }
182
+ exports.Context = Context;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BigMapAbstraction = void 0;
13
+ const octez_js_http_utils_1 = require("@tezos-x/octez.js-http-utils");
14
+ class BigMapAbstraction {
15
+ constructor(id, schema, provider) {
16
+ this.id = id;
17
+ this.schema = schema;
18
+ this.provider = provider;
19
+ }
20
+ /**
21
+ *
22
+ * @description Fetch one value in a big map
23
+ *
24
+ * @param keysToEncode Key to query (will be encoded properly according to the schema)
25
+ * @param block optional block level to fetch the values from (head will be use by default)
26
+ * @returns Return a well formatted json object of a big map value or undefined if the key is not found in the big map
27
+ *
28
+ */
29
+ get(keyToEncode, block) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ try {
32
+ const id = yield this.provider.getBigMapKeyByID(this.id.toString(), keyToEncode, this.schema, block);
33
+ return id;
34
+ }
35
+ catch (e) {
36
+ if (e instanceof octez_js_http_utils_1.HttpResponseError && e.status === octez_js_http_utils_1.STATUS_CODE.NOT_FOUND) {
37
+ return undefined;
38
+ }
39
+ else {
40
+ throw e;
41
+ }
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ *
47
+ * @description Fetch multiple values in a big map
48
+ * All values will be fetched on the same block level. If a block is specified in the request, the values will be fetched at it.
49
+ * Otherwise, a first request will be done to the node to fetch the level of the head and all values will be fetched at this level.
50
+ * If one of the keys does not exist in the big map, its value will be set to undefined.
51
+ *
52
+ * @param keysToEncode Array of keys to query (will be encoded properly according to the schema)
53
+ * @param block optional block level to fetch the values from
54
+ * @param batchSize optional batch size representing the number of requests to execute in parallel
55
+ * @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
56
+ *
57
+ */
58
+ getMultipleValues(keysToEncode_1, block_1) {
59
+ return __awaiter(this, arguments, void 0, function* (keysToEncode, block, batchSize = 5) {
60
+ return this.provider.getBigMapKeysByID(this.id.toString(), keysToEncode, this.schema, block, batchSize);
61
+ });
62
+ }
63
+ toJSON() {
64
+ return this.id.toString();
65
+ }
66
+ toString() {
67
+ return this.id.toString();
68
+ }
69
+ }
70
+ exports.BigMapAbstraction = BigMapAbstraction;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compose = compose;
4
+ function compose(functioncomposer1, functioncomposer2) {
5
+ return (contractAbstraction, context) => functioncomposer2(functioncomposer1(contractAbstraction, context), context);
6
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SMART_CONTRACT_METHOD_NAME = void 0;
4
+ exports.DEFAULT_SMART_CONTRACT_METHOD_NAME = 'default';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContractMethodFactory = void 0;
4
+ const contract_method_object_param_1 = require("./contract-method-object-param");
5
+ const contract_on_chain_view_1 = require("./contract-on-chain-view");
6
+ class ContractMethodFactory {
7
+ constructor(provider, contractAddress) {
8
+ this.provider = provider;
9
+ this.contractAddress = contractAddress;
10
+ }
11
+ createContractMethodObjectParam(smartContractMethodSchema, smartContractMethodName, args, isMultipleEntrypoint = true, isAnonymous = false) {
12
+ return new contract_method_object_param_1.ContractMethodObject(this.provider, this.contractAddress, smartContractMethodSchema, smartContractMethodName, args, isMultipleEntrypoint, isAnonymous);
13
+ }
14
+ createContractViewObjectParam(rpc, readProvider, smartContractViewSchema, contractStorageType, viewArgs) {
15
+ return new contract_on_chain_view_1.OnChainView(rpc, readProvider, this.contractAddress, smartContractViewSchema, contractStorageType, viewArgs);
16
+ }
17
+ }
18
+ exports.ContractMethodFactory = ContractMethodFactory;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContractMethodObject = void 0;
4
+ const constants_1 = require("../constants");
5
+ /**
6
+ * @description Utility class to send smart contract operation
7
+ * The format for the arguments is the object representation
8
+ */
9
+ class ContractMethodObject {
10
+ constructor(provider, address, parameterSchema, name, args = 'unit', isMultipleEntrypoint = true, isAnonymous = false) {
11
+ this.provider = provider;
12
+ this.address = address;
13
+ this.parameterSchema = parameterSchema;
14
+ this.name = name;
15
+ this.args = args;
16
+ this.isMultipleEntrypoint = isMultipleEntrypoint;
17
+ this.isAnonymous = isAnonymous;
18
+ }
19
+ /**
20
+ * @description Get the signature of the smart contract method
21
+ */
22
+ getSignature() {
23
+ const generatedSchema = this.parameterSchema.generateSchema();
24
+ if (this.isAnonymous) {
25
+ const schemaObj = generatedSchema.schema;
26
+ return schemaObj === null || schemaObj === void 0 ? void 0 : schemaObj[this.name];
27
+ }
28
+ return generatedSchema;
29
+ }
30
+ /**
31
+ *
32
+ * @description Send the smart contract operation
33
+ *
34
+ * @param Options generic operation parameter
35
+ */
36
+ send(params = {}) {
37
+ // provider is either ContractProvider | Wallet but pkh method is unique to Wallet
38
+ if (this.provider && 'pkh' in this.provider) {
39
+ return this.provider
40
+ .transfer(this.toTransferParams(params))
41
+ .send();
42
+ }
43
+ else {
44
+ return this.provider.transfer(this.toTransferParams(params));
45
+ }
46
+ }
47
+ /**
48
+ *
49
+ * @description Create transfer params to be used with TezosToolkit.contract.transfer methods
50
+ *
51
+ * @param Options generic transfer operation parameters
52
+ */
53
+ toTransferParams({ fee, gasLimit, storageLimit, source, amount = 0, mutez = false, } = {}) {
54
+ const fullTransferParams = {
55
+ to: this.address,
56
+ amount,
57
+ fee,
58
+ mutez,
59
+ source,
60
+ gasLimit,
61
+ storageLimit,
62
+ parameter: {
63
+ entrypoint: this.isMultipleEntrypoint ? this.name : constants_1.DEFAULT_SMART_CONTRACT_METHOD_NAME,
64
+ value: this.isAnonymous
65
+ ? this.parameterSchema.EncodeObject({ [this.name]: this.args })
66
+ : this.parameterSchema.EncodeObject(this.args),
67
+ },
68
+ };
69
+ return fullTransferParams;
70
+ }
71
+ }
72
+ exports.ContractMethodObject = ContractMethodObject;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OnChainView = void 0;
13
+ const octez_js_utils_1 = require("@tezos-x/octez.js-utils");
14
+ const errors_1 = require("../errors");
15
+ const octez_js_core_1 = require("@tezos-x/octez.js-core");
16
+ class OnChainView {
17
+ constructor(_rpc, _readProvider, _contractAddress, _smartContractViewSchema, _contractStorageType, _args = 'Unit') {
18
+ this._rpc = _rpc;
19
+ this._readProvider = _readProvider;
20
+ this._contractAddress = _contractAddress;
21
+ this._smartContractViewSchema = _smartContractViewSchema;
22
+ this._contractStorageType = _contractStorageType;
23
+ this._args = _args;
24
+ }
25
+ /**
26
+ * @description Get the signature of the smart contract view
27
+ */
28
+ getSignature() {
29
+ return {
30
+ parameter: this._smartContractViewSchema.extractArgsSchema(),
31
+ result: this._smartContractViewSchema.extractResultSchema(),
32
+ };
33
+ }
34
+ /**
35
+ * @description Get the result of the view simulation
36
+ * @param executionContext.source the public key hash of the account who initialized this view execution.
37
+ * @param executionContext.viewCaller the contract address which is the caller of view.
38
+ */
39
+ executeView(executionContext) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ this.verifyContextExecution(executionContext);
42
+ const chainId = yield this._readProvider.getChainId();
43
+ const viewArgs = this.transformArgsToMichelson();
44
+ const scriptView = {
45
+ contract: this._contractAddress,
46
+ view: this._smartContractViewSchema.viewName,
47
+ input: viewArgs,
48
+ chain_id: chainId,
49
+ source: executionContext.viewCaller,
50
+ };
51
+ if (executionContext.source) {
52
+ scriptView.payer = executionContext.source;
53
+ }
54
+ return this.executeViewAndDecodeResult(scriptView);
55
+ });
56
+ }
57
+ verifyContextExecution(executionContext) {
58
+ if (executionContext.source &&
59
+ (0, octez_js_utils_1.validateAddress)(executionContext.source) !== octez_js_utils_1.ValidationResult.VALID) {
60
+ throw new errors_1.InvalidViewSimulationContext(`The source account who initialized the view execution is invalid: ${executionContext.source}.`);
61
+ }
62
+ if (!executionContext.viewCaller ||
63
+ (0, octez_js_utils_1.validateAddress)(executionContext.viewCaller) !== octez_js_utils_1.ValidationResult.VALID) {
64
+ throw new errors_1.InvalidViewSimulationContext(`The contract which is the caller of view is invalid: ${executionContext.viewCaller}.`);
65
+ }
66
+ }
67
+ transformArgsToMichelson() {
68
+ try {
69
+ return this._smartContractViewSchema.encodeViewArgs(this._args);
70
+ }
71
+ catch (error) {
72
+ throw new octez_js_core_1.InvalidViewParameterError(this._smartContractViewSchema.viewName, this.getSignature(), this._args, error);
73
+ }
74
+ }
75
+ /**
76
+ * @description Loops through the view's instructions and replace BALANCE, SENDER, SELF_ADDRESS and AMOUNT with Michelson expressions that match the current context, if applicable.
77
+ *
78
+ * Certain specific instructions have different semantics in view:
79
+ * BALANCE represents the current amount of mutez held by the contract where view is;
80
+ * SENDER represents the contract which is the caller of view;
81
+ * SELF_ADDRESS represents the contract where view is;
82
+ * AMOUNT is always 0 mutez.
83
+ *
84
+ */
85
+ adaptViewCodeToContext(instructions, viewCaller, contractBalance) {
86
+ const instructionsToReplace = {
87
+ BALANCE: [{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: contractBalance }] }],
88
+ SENDER: [{ prim: 'PUSH', args: [{ prim: 'address' }, { string: viewCaller }] }],
89
+ SELF_ADDRESS: [
90
+ { prim: 'PUSH', args: [{ prim: 'address' }, { string: this._contractAddress }] },
91
+ ],
92
+ AMOUNT: [{ prim: 'PUSH', args: [{ prim: 'mutez' }, { int: '0' }] }],
93
+ };
94
+ instructions.forEach((inst, i) => {
95
+ if (inst.prim in instructionsToReplace) {
96
+ instructions[i] = Object(instructionsToReplace)[inst.prim];
97
+ }
98
+ if (inst.args && inst.args.length !== 0) {
99
+ this.adaptViewCodeToContext(inst.args, viewCaller, contractBalance);
100
+ }
101
+ else if (Array.isArray(inst)) {
102
+ this.adaptViewCodeToContext(inst, viewCaller, contractBalance);
103
+ }
104
+ });
105
+ return instructions;
106
+ }
107
+ executeViewAndDecodeResult(viewScript) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ let storage;
110
+ try {
111
+ storage = (yield this._rpc.runScriptView(viewScript))
112
+ .data;
113
+ }
114
+ catch (error) {
115
+ const failWith = (0, errors_1.validateAndExtractFailwith)(error);
116
+ throw failWith
117
+ ? new errors_1.ViewSimulationError(`The simulation of the on-chain view named ${this._smartContractViewSchema.viewName} failed with: ${JSON.stringify(failWith)}`, this._smartContractViewSchema.viewName, failWith, error)
118
+ : error;
119
+ }
120
+ return this._smartContractViewSchema.decodeViewResult(storage);
121
+ });
122
+ }
123
+ }
124
+ exports.OnChainView = OnChainView;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ContractAbstraction = exports.ContractView = exports.DEFAULT_SMART_CONTRACT_METHOD_NAME = void 0;
13
+ const octez_js_michelson_encoder_1 = require("@tezos-x/octez.js-michelson-encoder");
14
+ const octez_js_utils_1 = require("@tezos-x/octez.js-utils");
15
+ const contract_method_factory_1 = require("./contract-methods/contract-method-factory");
16
+ const errors_1 = require("./errors");
17
+ const octez_js_core_1 = require("@tezos-x/octez.js-core");
18
+ const constants_1 = require("./constants");
19
+ Object.defineProperty(exports, "DEFAULT_SMART_CONTRACT_METHOD_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_SMART_CONTRACT_METHOD_NAME; } });
20
+ /**
21
+ * @description Utility class to retrieve data from a smart contract's storage without incurring fees via a contract's view method
22
+ */
23
+ class ContractView {
24
+ constructor(currentContract, name, callbackParametersSchema, parameterSchema, args, rpc, readProvider) {
25
+ this.currentContract = currentContract;
26
+ this.name = name;
27
+ this.callbackParametersSchema = callbackParametersSchema;
28
+ this.parameterSchema = parameterSchema;
29
+ this.args = args;
30
+ this.rpc = rpc;
31
+ this.readProvider = readProvider;
32
+ }
33
+ read(chainId) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const chainIdValidation = (0, octez_js_utils_1.validateChain)(chainId !== null && chainId !== void 0 ? chainId : '');
36
+ if ((0, octez_js_utils_1.validateContractAddress)(chainId !== null && chainId !== void 0 ? chainId : '') == octez_js_utils_1.ValidationResult.VALID) {
37
+ throw new octez_js_core_1.DeprecationError(`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.`);
38
+ }
39
+ else if (chainId && chainIdValidation !== octez_js_utils_1.ValidationResult.VALID) {
40
+ throw new octez_js_core_1.InvalidChainIdError(chainId, chainIdValidation);
41
+ }
42
+ const arg = this.parameterSchema.Encode(...this.args);
43
+ const result = yield this.rpc.runView({
44
+ contract: this.currentContract.address,
45
+ entrypoint: this.name,
46
+ input: arg,
47
+ chain_id: chainId ? chainId : yield this.readProvider.getChainId(),
48
+ });
49
+ return this.callbackParametersSchema.Execute(result.data);
50
+ });
51
+ }
52
+ }
53
+ exports.ContractView = ContractView;
54
+ const validateArgs = (args, schema, name) => {
55
+ const sigs = schema.ExtractSignatures();
56
+ if (!sigs.find((x) => x.length === args.length)) {
57
+ throw new errors_1.InvalidParameterError(name, sigs, args);
58
+ }
59
+ };
60
+ // lambda view tzip4
61
+ const isView = (entrypoint) => {
62
+ let isView = false;
63
+ if ('prim' in entrypoint && entrypoint.prim === 'pair' && entrypoint.args) {
64
+ const lastElement = entrypoint.args[entrypoint.args.length - 1];
65
+ if ('prim' in lastElement && lastElement.prim === 'contract') {
66
+ isView = true;
67
+ }
68
+ }
69
+ return isView;
70
+ };
71
+ /**
72
+ * @description Smart contract abstraction
73
+ */
74
+ class ContractAbstraction {
75
+ constructor(address, script, provider, storageProvider, entrypoints, rpc, readProvider) {
76
+ this.address = address;
77
+ this.script = script;
78
+ this.storageProvider = storageProvider;
79
+ this.entrypoints = entrypoints;
80
+ this.rpc = rpc;
81
+ this.readProvider = readProvider;
82
+ /**
83
+ * @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.
84
+ * `methodsObject` serves the exact same purpose as the `methods` member. The difference is that it allows passing the parameter in an object format when calling the smart contract method (instead of the flattened representation)
85
+ * NB: if the contract contains annotation it will include named properties; if not it will be indexed by a number.
86
+ *
87
+ */
88
+ this.methodsObject = {};
89
+ /**
90
+ * @description Contains lamda views (tzip4) that are implemented by the target Tezos Smart Contract, and offers the user to call the lambda views as if they were native TS/JS methods.
91
+ * NB: These are the view defined in the tzip4 standard, not the views introduced by the Hangzhou protocol.
92
+ */
93
+ this.views = {};
94
+ /**
95
+ * @description Contains on-chain views that are defined by the target Tezos Smart Contract, and offers the user to simulate the views execution as if they were native TS/JS methods.
96
+ * NB: the expected format for the parameter when calling a smart contract view is the object format (same format as for the storage) and not the flattened representation.
97
+ *
98
+ */
99
+ this.contractViews = {};
100
+ this.contractMethodFactory = new contract_method_factory_1.ContractMethodFactory(provider, address);
101
+ this.schema = octez_js_michelson_encoder_1.Schema.fromRPCResponse({ script: this.script });
102
+ this.parameterSchema = octez_js_michelson_encoder_1.ParameterSchema.fromRPCResponse({ script: this.script });
103
+ this.viewSchema = octez_js_michelson_encoder_1.ViewSchema.fromRPCResponse({ script: this.script });
104
+ if (this.viewSchema.length !== 0) {
105
+ this._initializeOnChainViews(this, rpc, this.readProvider, this.viewSchema);
106
+ }
107
+ this.eventSchema = octez_js_michelson_encoder_1.EventSchema.fromRPCResponse({ script: this.script });
108
+ this._initializeMethods(this, this.entrypoints.entrypoints, this.rpc, this.readProvider);
109
+ }
110
+ _initializeMethods(currentContract, entrypoints, rpc, readProvider) {
111
+ const parameterSchema = this.parameterSchema;
112
+ const keys = Object.keys(entrypoints);
113
+ if (parameterSchema.isMultipleEntryPoint) {
114
+ keys.forEach((smartContractMethodName) => {
115
+ const smartContractMethodSchema = new octez_js_michelson_encoder_1.ParameterSchema(entrypoints[smartContractMethodName]);
116
+ this.methodsObject[smartContractMethodName] = function (args) {
117
+ return currentContract.contractMethodFactory.createContractMethodObjectParam(smartContractMethodSchema, smartContractMethodName, args);
118
+ };
119
+ if (isView(entrypoints[smartContractMethodName])) {
120
+ const view = function (...args) {
121
+ const entrypointParamWithoutCallback = entrypoints[smartContractMethodName]
122
+ .args[0];
123
+ const smartContractMethodSchemaWithoutCallback = new octez_js_michelson_encoder_1.ParameterSchema(entrypointParamWithoutCallback);
124
+ const parametersCallback = entrypoints[smartContractMethodName].args[1]
125
+ .args[0];
126
+ const smartContractMethodCallbackSchema = new octez_js_michelson_encoder_1.ParameterSchema(parametersCallback);
127
+ validateArgs(args, smartContractMethodSchemaWithoutCallback, smartContractMethodName);
128
+ return new ContractView(currentContract, smartContractMethodName, smartContractMethodCallbackSchema, smartContractMethodSchemaWithoutCallback, args, rpc, readProvider);
129
+ };
130
+ this.views[smartContractMethodName] = view;
131
+ }
132
+ });
133
+ // Deal with methods with no annotations which were not discovered by the RPC endpoint
134
+ // Methods with no annotations are discovered using parameter schema
135
+ const generatedSchema = parameterSchema.generateSchema();
136
+ const schemaKeys = generatedSchema.schema && typeof generatedSchema.schema === 'object'
137
+ ? Object.keys(generatedSchema.schema)
138
+ : [];
139
+ const anonymousMethods = schemaKeys.filter((key) => Object.keys(entrypoints).indexOf(key) === -1);
140
+ anonymousMethods.forEach((smartContractMethodName) => {
141
+ this.methodsObject[smartContractMethodName] = function (args) {
142
+ return currentContract.contractMethodFactory.createContractMethodObjectParam(parameterSchema, smartContractMethodName, args, false, true);
143
+ };
144
+ });
145
+ }
146
+ else {
147
+ const smartContractMethodSchema = this.parameterSchema;
148
+ this.methodsObject[constants_1.DEFAULT_SMART_CONTRACT_METHOD_NAME] =
149
+ function (args) {
150
+ return currentContract.contractMethodFactory.createContractMethodObjectParam(smartContractMethodSchema, constants_1.DEFAULT_SMART_CONTRACT_METHOD_NAME, args, false);
151
+ };
152
+ }
153
+ }
154
+ _initializeOnChainViews(currentContract, rpc, readProvider, allContractViews) {
155
+ const storageType = this.schema.val;
156
+ allContractViews.forEach((viewSchema) => {
157
+ this.contractViews[viewSchema.viewName] = function (args) {
158
+ return currentContract.contractMethodFactory.createContractViewObjectParam(rpc, readProvider, viewSchema, storageType, args);
159
+ };
160
+ });
161
+ }
162
+ /**
163
+ * @description Return a friendly representation of the smart contract storage
164
+ */
165
+ storage() {
166
+ return this.storageProvider.getStorage(this.address, this.schema);
167
+ }
168
+ }
169
+ exports.ContractAbstraction = ContractAbstraction;