@taquito/taquito 11.0.2 → 11.2.0-beta-RC.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/batch/rpc-batch-provider.js +115 -249
- package/dist/lib/batch/rpc-batch-provider.js.map +1 -1
- package/dist/lib/constants.js +10 -4
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context.js +143 -223
- package/dist/lib/context.js.map +1 -1
- package/dist/lib/contract/big-map.js +26 -66
- package/dist/lib/contract/big-map.js.map +1 -1
- package/dist/lib/contract/compose.js +1 -3
- package/dist/lib/contract/compose.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-method-factory.js +17 -16
- package/dist/lib/contract/contract-methods/contract-method-factory.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-method-flat-param.js +39 -68
- package/dist/lib/contract/contract-methods/contract-method-flat-param.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-method-object-param.js +21 -28
- package/dist/lib/contract/contract-methods/contract-method-object-param.js.map +1 -1
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +142 -0
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js.map +1 -0
- package/dist/lib/contract/contract.js +114 -162
- package/dist/lib/contract/contract.js.map +1 -1
- package/dist/lib/contract/errors.js +68 -24
- package/dist/lib/contract/errors.js.map +1 -1
- package/dist/lib/contract/estimate.js +74 -112
- package/dist/lib/contract/estimate.js.map +1 -1
- package/dist/lib/contract/lambda-view.js +39 -95
- package/dist/lib/contract/lambda-view.js.map +1 -1
- package/dist/lib/contract/manager-lambda.js +10 -10
- package/dist/lib/contract/manager-lambda.js.map +1 -1
- package/dist/lib/contract/naive-estimate-provider.js +49 -143
- package/dist/lib/contract/naive-estimate-provider.js.map +1 -1
- package/dist/lib/contract/prepare.js +96 -160
- package/dist/lib/contract/prepare.js.map +1 -1
- package/dist/lib/contract/rpc-contract-provider.js +237 -523
- package/dist/lib/contract/rpc-contract-provider.js.map +1 -1
- package/dist/lib/contract/rpc-estimate-provider.js +209 -532
- package/dist/lib/contract/rpc-estimate-provider.js.map +1 -1
- package/dist/lib/contract/sapling-state-abstraction.js +9 -39
- package/dist/lib/contract/sapling-state-abstraction.js.map +1 -1
- package/dist/lib/contract/semantic.js +9 -9
- package/dist/lib/contract/semantic.js.map +1 -1
- package/dist/lib/contract/view_lambda.js +4 -4
- package/dist/lib/contract/view_lambda.js.map +1 -1
- package/dist/lib/forger/composite-forger.js +26 -61
- package/dist/lib/forger/composite-forger.js.map +1 -1
- package/dist/lib/forger/rpc-forger.js +6 -8
- package/dist/lib/forger/rpc-forger.js.map +1 -1
- package/dist/lib/format.js +5 -7
- package/dist/lib/format.js.map +1 -1
- package/dist/lib/global-constants/default-global-constants-provider.js +47 -0
- package/dist/lib/global-constants/default-global-constants-provider.js.map +1 -0
- package/dist/lib/global-constants/error.js +19 -0
- package/dist/lib/global-constants/error.js.map +1 -0
- package/dist/lib/global-constants/interface-global-constants-provider.js +3 -0
- package/dist/lib/global-constants/interface-global-constants-provider.js.map +1 -0
- package/dist/lib/global-constants/noop-global-constants-provider.js +22 -0
- package/dist/lib/global-constants/noop-global-constants-provider.js.map +1 -0
- package/dist/lib/injector/rpc-injector.js +5 -6
- package/dist/lib/injector/rpc-injector.js.map +1 -1
- package/dist/lib/operations/batch-operation.js +43 -87
- package/dist/lib/operations/batch-operation.js.map +1 -1
- package/dist/lib/operations/delegate-operation.js +44 -96
- package/dist/lib/operations/delegate-operation.js.map +1 -1
- package/dist/lib/operations/operation-emitter.js +184 -340
- package/dist/lib/operations/operation-emitter.js.map +1 -1
- package/dist/lib/operations/operation-errors.js +29 -64
- package/dist/lib/operations/operation-errors.js.map +1 -1
- package/dist/lib/operations/operations.js +80 -148
- package/dist/lib/operations/operations.js.map +1 -1
- package/dist/lib/operations/origination-operation.js +59 -145
- package/dist/lib/operations/origination-operation.js.map +1 -1
- package/dist/lib/operations/register-global-constant-operation.js +38 -82
- package/dist/lib/operations/register-global-constant-operation.js.map +1 -1
- package/dist/lib/operations/reveal-operation.js +50 -106
- package/dist/lib/operations/reveal-operation.js.map +1 -1
- package/dist/lib/operations/transaction-operation.js +54 -114
- package/dist/lib/operations/transaction-operation.js.map +1 -1
- package/dist/lib/operations/types.js +11 -22
- package/dist/lib/operations/types.js.map +1 -1
- package/dist/lib/packer/michel-codec-packer.js +8 -41
- package/dist/lib/packer/michel-codec-packer.js.map +1 -1
- package/dist/lib/packer/rpc-packer.js +7 -37
- package/dist/lib/packer/rpc-packer.js.map +1 -1
- package/dist/lib/parser/michel-codec-parser.js +103 -159
- package/dist/lib/parser/michel-codec-parser.js.map +1 -1
- package/dist/lib/parser/noop-parser.js +6 -38
- package/dist/lib/parser/noop-parser.js.map +1 -1
- package/dist/lib/signer/noop.js +22 -61
- package/dist/lib/signer/noop.js.map +1 -1
- package/dist/lib/subscribe/filters.js +13 -33
- package/dist/lib/subscribe/filters.js.map +1 -1
- package/dist/lib/subscribe/observable-subscription.js +32 -56
- package/dist/lib/subscribe/observable-subscription.js.map +1 -1
- package/dist/lib/subscribe/polling-provider.js +24 -81
- package/dist/lib/subscribe/polling-provider.js.map +1 -1
- package/dist/lib/taquito.js +117 -142
- package/dist/lib/taquito.js.map +1 -1
- package/dist/lib/tz/rpc-tz-provider.js +37 -97
- package/dist/lib/tz/rpc-tz-provider.js.map +1 -1
- package/dist/lib/version.js +2 -4
- package/dist/lib/version.js.map +1 -1
- package/dist/lib/wallet/batch-operation.js +31 -89
- package/dist/lib/wallet/batch-operation.js.map +1 -1
- package/dist/lib/wallet/delegation-operation.js +29 -94
- package/dist/lib/wallet/delegation-operation.js.map +1 -1
- package/dist/lib/wallet/legacy.js +25 -86
- package/dist/lib/wallet/legacy.js.map +1 -1
- package/dist/lib/wallet/operation-factory.js +61 -191
- package/dist/lib/wallet/operation-factory.js.map +1 -1
- package/dist/lib/wallet/operation.js +79 -185
- package/dist/lib/wallet/operation.js.map +1 -1
- package/dist/lib/wallet/origination-operation.js +36 -108
- package/dist/lib/wallet/origination-operation.js.map +1 -1
- package/dist/lib/wallet/receipt.js +20 -21
- package/dist/lib/wallet/receipt.js.map +1 -1
- package/dist/lib/wallet/transaction-operation.js +29 -94
- package/dist/lib/wallet/transaction-operation.js.map +1 -1
- package/dist/lib/wallet/wallet.js +133 -311
- package/dist/lib/wallet/wallet.js.map +1 -1
- package/dist/taquito.es6.js +4573 -0
- package/dist/taquito.es6.js.map +1 -0
- package/dist/taquito.min.js +1 -1
- package/dist/taquito.umd.js +2741 -4196
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/batch/rpc-batch-provider.d.ts +2 -1
- package/dist/types/constants.d.ts +9 -3
- package/dist/types/context.d.ts +7 -4
- package/dist/types/contract/contract-methods/contract-method-factory.d.ts +9 -3
- package/dist/types/contract/contract-methods/contract-method-flat-param.d.ts +1 -1
- package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +2 -2
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +42 -0
- package/dist/types/contract/contract.d.ts +32 -15
- package/dist/types/contract/errors.d.ts +28 -8
- package/dist/types/contract/interface.d.ts +2 -2
- package/dist/types/contract/lambda-view.d.ts +1 -1
- package/dist/types/contract/prepare.d.ts +1 -1
- package/dist/types/contract/rpc-contract-provider.d.ts +3 -3
- package/dist/types/forger/composite-forger.d.ts +1 -2
- package/dist/types/global-constants/default-global-constants-provider.d.ts +18 -0
- package/dist/types/global-constants/error.d.ts +9 -0
- package/dist/types/global-constants/interface-global-constants-provider.d.ts +11 -0
- package/dist/types/global-constants/noop-global-constants-provider.d.ts +5 -0
- package/dist/types/operations/operation-emitter.d.ts +3 -3
- package/dist/types/operations/operation-errors.d.ts +2 -4
- package/dist/types/operations/origination-operation.d.ts +3 -2
- package/dist/types/operations/types.d.ts +2 -2
- package/dist/types/parser/michel-codec-parser.d.ts +1 -0
- package/dist/types/signer/interface.d.ts +1 -1
- package/dist/types/signer/noop.d.ts +2 -2
- package/dist/types/taquito.d.ts +28 -1
- package/dist/types/wallet/interface.d.ts +1 -1
- package/dist/types/wallet/legacy.d.ts +1 -1
- package/dist/types/wallet/operation.d.ts +2 -2
- package/dist/types/wallet/origination-operation.d.ts +3 -2
- package/dist/types/wallet/wallet.d.ts +5 -4
- package/package.json +30 -31
- package/dist/taquito.es5.js +0 -6036
- package/dist/taquito.es5.js.map +0 -1
|
@@ -1,28 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __assign = (this && this.__assign) || function () {
|
|
16
|
-
__assign = Object.assign || function(t) {
|
|
17
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
-
s = arguments[i];
|
|
19
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
-
t[p] = s[p];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
return __assign.apply(this, arguments);
|
|
25
|
-
};
|
|
26
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -32,78 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
9
|
});
|
|
34
10
|
};
|
|
35
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
37
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
38
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
-
function step(op) {
|
|
40
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
-
while (_) try {
|
|
42
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
43
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
-
switch (op[0]) {
|
|
45
|
-
case 0: case 1: t = op; break;
|
|
46
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
-
default:
|
|
50
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
-
if (t[2]) _.ops.pop();
|
|
55
|
-
_.trys.pop(); continue;
|
|
56
|
-
}
|
|
57
|
-
op = body.call(thisArg, _);
|
|
58
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
63
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
64
|
-
if (!m) return o;
|
|
65
|
-
var i = m.call(o), r, ar = [], e;
|
|
66
|
-
try {
|
|
67
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
68
|
-
}
|
|
69
|
-
catch (error) { e = { error: error }; }
|
|
70
|
-
finally {
|
|
71
|
-
try {
|
|
72
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
73
|
-
}
|
|
74
|
-
finally { if (e) throw e.error; }
|
|
75
|
-
}
|
|
76
|
-
return ar;
|
|
77
|
-
};
|
|
78
|
-
var __spread = (this && this.__spread) || function () {
|
|
79
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
80
|
-
return ar;
|
|
81
|
-
};
|
|
82
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
12
|
exports.RpcContractProvider = void 0;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return _this;
|
|
13
|
+
const http_utils_1 = require("@taquito/http-utils");
|
|
14
|
+
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
15
|
+
const rpc_1 = require("@taquito/rpc");
|
|
16
|
+
const utils_1 = require("@taquito/utils");
|
|
17
|
+
const rpc_batch_provider_1 = require("../batch/rpc-batch-provider");
|
|
18
|
+
const delegate_operation_1 = require("../operations/delegate-operation");
|
|
19
|
+
const operation_emitter_1 = require("../operations/operation-emitter");
|
|
20
|
+
const origination_operation_1 = require("../operations/origination-operation");
|
|
21
|
+
const register_global_constant_operation_1 = require("../operations/register-global-constant-operation");
|
|
22
|
+
const reveal_operation_1 = require("../operations/reveal-operation");
|
|
23
|
+
const transaction_operation_1 = require("../operations/transaction-operation");
|
|
24
|
+
const types_1 = require("../operations/types");
|
|
25
|
+
const contract_1 = require("./contract");
|
|
26
|
+
const errors_1 = require("./errors");
|
|
27
|
+
const prepare_1 = require("./prepare");
|
|
28
|
+
const semantic_1 = require("./semantic");
|
|
29
|
+
const utils_2 = require("@taquito/utils");
|
|
30
|
+
class RpcContractProvider extends operation_emitter_1.OperationEmitter {
|
|
31
|
+
constructor(context, estimator) {
|
|
32
|
+
super(context);
|
|
33
|
+
this.estimator = estimator;
|
|
34
|
+
this.contractProviderTypeSymbol = Symbol.for('taquito--provider-type-symbol');
|
|
107
35
|
}
|
|
108
36
|
/**
|
|
109
37
|
*
|
|
@@ -114,32 +42,25 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
114
42
|
*
|
|
115
43
|
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
|
|
116
44
|
*/
|
|
117
|
-
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
return [4 /*yield*/, this.rpc.getStorage(contract)];
|
|
136
|
-
case 3:
|
|
137
|
-
storage = _a.sent();
|
|
138
|
-
return [2 /*return*/, contractSchema.Execute(storage, semantic_1.smartContractAbstractionSemantic(this))]; // Cast into T because only the caller can know the true type of the storage
|
|
139
|
-
}
|
|
140
|
-
});
|
|
45
|
+
getStorage(contract, schema) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (utils_2.validateContractAddress(contract) !== utils_2.ValidationResult.VALID) {
|
|
48
|
+
throw new utils_2.InvalidContractAddressError(`Invalid contract address: ${contract}`);
|
|
49
|
+
}
|
|
50
|
+
if (!schema) {
|
|
51
|
+
schema = yield this.rpc.getNormalizedScript(contract);
|
|
52
|
+
}
|
|
53
|
+
let contractSchema;
|
|
54
|
+
if (michelson_encoder_1.Schema.isSchema(schema)) {
|
|
55
|
+
contractSchema = schema;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
contractSchema = michelson_encoder_1.Schema.fromRPCResponse({ script: schema });
|
|
59
|
+
}
|
|
60
|
+
const storage = yield this.rpc.getStorage(contract);
|
|
61
|
+
return contractSchema.Execute(storage, semantic_1.smartContractAbstractionSemantic(this)); // Cast into T because only the caller can know the true type of the storage
|
|
141
62
|
});
|
|
142
|
-
}
|
|
63
|
+
}
|
|
143
64
|
/**
|
|
144
65
|
*
|
|
145
66
|
* @description Return a well formatted json object of the contract big map storage
|
|
@@ -152,33 +73,26 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
152
73
|
*
|
|
153
74
|
* @see https://tezos.gitlab.io/api/rpc.html#post-block-id-context-contracts-contract-id-big-map-get
|
|
154
75
|
*/
|
|
155
|
-
|
|
156
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
encodedKey = contractSchema.EncodeBigMapKey(key);
|
|
174
|
-
return [4 /*yield*/, this.rpc.getBigMapKey(contract, encodedKey)];
|
|
175
|
-
case 3:
|
|
176
|
-
val = _a.sent();
|
|
177
|
-
return [2 /*return*/, contractSchema.ExecuteOnBigMapValue(val)]; // Cast into T because only the caller can know the true type of the storage
|
|
178
|
-
}
|
|
179
|
-
});
|
|
76
|
+
getBigMapKey(contract, key, schema) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
if (utils_2.validateContractAddress(contract) !== utils_2.ValidationResult.VALID) {
|
|
79
|
+
throw new utils_2.InvalidContractAddressError(`Invalid contract address: ${contract}`);
|
|
80
|
+
}
|
|
81
|
+
if (!schema) {
|
|
82
|
+
schema = yield this.rpc.getNormalizedScript(contract);
|
|
83
|
+
}
|
|
84
|
+
let contractSchema;
|
|
85
|
+
if (michelson_encoder_1.Schema.isSchema(schema)) {
|
|
86
|
+
contractSchema = schema;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
contractSchema = michelson_encoder_1.Schema.fromRPCResponse({ script: schema });
|
|
90
|
+
}
|
|
91
|
+
const encodedKey = contractSchema.EncodeBigMapKey(key);
|
|
92
|
+
const val = yield this.rpc.getBigMapKey(contract, encodedKey);
|
|
93
|
+
return contractSchema.ExecuteOnBigMapValue(val); // Cast into T because only the caller can know the true type of the storage
|
|
180
94
|
});
|
|
181
|
-
}
|
|
95
|
+
}
|
|
182
96
|
/**
|
|
183
97
|
*
|
|
184
98
|
* @description Return a well formatted json object of a big map value
|
|
@@ -190,33 +104,17 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
190
104
|
*
|
|
191
105
|
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr
|
|
192
106
|
*/
|
|
193
|
-
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
packed = (_c.sent()).packed;
|
|
203
|
-
encodedExpr = utils_1.encodeExpr(packed);
|
|
204
|
-
if (!block) return [3 /*break*/, 3];
|
|
205
|
-
return [4 /*yield*/, this.context.rpc.getBigMapExpr(id.toString(), encodedExpr, { block: String(block) })];
|
|
206
|
-
case 2:
|
|
207
|
-
_b = _c.sent();
|
|
208
|
-
return [3 /*break*/, 5];
|
|
209
|
-
case 3: return [4 /*yield*/, this.context.rpc.getBigMapExpr(id.toString(), encodedExpr)];
|
|
210
|
-
case 4:
|
|
211
|
-
_b = _c.sent();
|
|
212
|
-
_c.label = 5;
|
|
213
|
-
case 5:
|
|
214
|
-
bigMapValue = _b;
|
|
215
|
-
return [2 /*return*/, schema.ExecuteOnBigMapValue(bigMapValue, semantic_1.smartContractAbstractionSemantic(this))];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
107
|
+
getBigMapKeyByID(id, keyToEncode, schema, block) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const { key, type } = schema.EncodeBigMapKey(keyToEncode);
|
|
110
|
+
const { packed } = yield this.context.packer.packData({ data: key, type });
|
|
111
|
+
const encodedExpr = utils_1.encodeExpr(packed);
|
|
112
|
+
const bigMapValue = block
|
|
113
|
+
? yield this.context.rpc.getBigMapExpr(id.toString(), encodedExpr, { block: String(block) })
|
|
114
|
+
: yield this.context.rpc.getBigMapExpr(id.toString(), encodedExpr);
|
|
115
|
+
return schema.ExecuteOnBigMapValue(bigMapValue, semantic_1.smartContractAbstractionSemantic(this));
|
|
218
116
|
});
|
|
219
|
-
}
|
|
117
|
+
}
|
|
220
118
|
/**
|
|
221
119
|
*
|
|
222
120
|
* @description Fetch multiple values in a big map
|
|
@@ -232,83 +130,48 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
232
130
|
* @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
|
|
233
131
|
*
|
|
234
132
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
batch = keysBatch.map(function (keyToEncode) {
|
|
253
|
-
return _this.getBigMapValueOrUndefined(keyToEncode, id, schema, level);
|
|
254
|
-
});
|
|
255
|
-
_a = [results];
|
|
256
|
-
return [4 /*yield*/, Promise.all(batch)];
|
|
257
|
-
case 3:
|
|
258
|
-
results = __spread.apply(void 0, _a.concat([(_b.sent())]));
|
|
259
|
-
position += batchSize;
|
|
260
|
-
return [3 /*break*/, 2];
|
|
261
|
-
case 4:
|
|
262
|
-
for (i = 0; i < results.length; i++) {
|
|
263
|
-
bigMapValues.set(keys[i], results[i]);
|
|
264
|
-
}
|
|
265
|
-
return [2 /*return*/, bigMapValues];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
133
|
+
getBigMapKeysByID(id, keys, schema, block, batchSize = 5) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const level = yield this.getBlockForRequest(keys, block);
|
|
136
|
+
const bigMapValues = new michelson_encoder_1.MichelsonMap();
|
|
137
|
+
// Execute batch of promises in series
|
|
138
|
+
let position = 0;
|
|
139
|
+
let results = [];
|
|
140
|
+
while (position < keys.length) {
|
|
141
|
+
const keysBatch = keys.slice(position, position + batchSize);
|
|
142
|
+
const batch = keysBatch.map((keyToEncode) => this.getBigMapValueOrUndefined(keyToEncode, id, schema, level));
|
|
143
|
+
results = [...results, ...(yield Promise.all(batch))];
|
|
144
|
+
position += batchSize;
|
|
145
|
+
}
|
|
146
|
+
for (let i = 0; i < results.length; i++) {
|
|
147
|
+
bigMapValues.set(keys[i], results[i]);
|
|
148
|
+
}
|
|
149
|
+
return bigMapValues;
|
|
268
150
|
});
|
|
269
|
-
}
|
|
270
|
-
|
|
151
|
+
}
|
|
152
|
+
getBlockForRequest(keys, block) {
|
|
271
153
|
var _a;
|
|
272
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
case 0:
|
|
277
|
-
if (!(keys.length === 1 || typeof block !== 'undefined')) return [3 /*break*/, 1];
|
|
278
|
-
_b = block;
|
|
279
|
-
return [3 /*break*/, 3];
|
|
280
|
-
case 1: return [4 /*yield*/, this.rpc.getBlock()];
|
|
281
|
-
case 2:
|
|
282
|
-
_b = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.header.level;
|
|
283
|
-
_c.label = 3;
|
|
284
|
-
case 3: return [2 /*return*/, _b];
|
|
285
|
-
}
|
|
286
|
-
});
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
return keys.length === 1 || typeof block !== 'undefined'
|
|
156
|
+
? block
|
|
157
|
+
: (_a = (yield this.rpc.getBlock())) === null || _a === void 0 ? void 0 : _a.header.level;
|
|
287
158
|
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
298
|
-
case 2:
|
|
299
|
-
ex_1 = _a.sent();
|
|
300
|
-
if (ex_1 instanceof http_utils_1.HttpResponseError && ex_1.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
|
|
301
|
-
return [2 /*return*/];
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
throw ex_1;
|
|
305
|
-
}
|
|
306
|
-
return [3 /*break*/, 3];
|
|
307
|
-
case 3: return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
try {
|
|
163
|
+
return yield this.getBigMapKeyByID(id, keyToEncode, schema, level);
|
|
164
|
+
}
|
|
165
|
+
catch (ex) {
|
|
166
|
+
if (ex instanceof http_utils_1.HttpResponseError && ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
|
|
167
|
+
return;
|
|
308
168
|
}
|
|
309
|
-
|
|
169
|
+
else {
|
|
170
|
+
throw ex;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
310
173
|
});
|
|
311
|
-
}
|
|
174
|
+
}
|
|
312
175
|
/**
|
|
313
176
|
*
|
|
314
177
|
* @description Return a well formatted json object of a sapling state
|
|
@@ -317,60 +180,30 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
317
180
|
* @param block optional block level to fetch the value from
|
|
318
181
|
*
|
|
319
182
|
*/
|
|
320
|
-
|
|
321
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (!block) return [3 /*break*/, 2];
|
|
327
|
-
return [4 /*yield*/, this.context.rpc.getSaplingDiffById(id.toString(), { block: String(block) })];
|
|
328
|
-
case 1:
|
|
329
|
-
_a = _b.sent();
|
|
330
|
-
return [3 /*break*/, 4];
|
|
331
|
-
case 2: return [4 /*yield*/, this.context.rpc.getSaplingDiffById(id.toString())];
|
|
332
|
-
case 3:
|
|
333
|
-
_a = _b.sent();
|
|
334
|
-
_b.label = 4;
|
|
335
|
-
case 4:
|
|
336
|
-
saplingState = _a;
|
|
337
|
-
return [2 /*return*/, saplingState];
|
|
338
|
-
}
|
|
339
|
-
});
|
|
183
|
+
getSaplingDiffByID(id, block) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const saplingState = block
|
|
186
|
+
? yield this.context.rpc.getSaplingDiffById(id.toString(), { block: String(block) })
|
|
187
|
+
: yield this.context.rpc.getSaplingDiffById(id.toString());
|
|
188
|
+
return saplingState;
|
|
340
189
|
});
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
publicKey = _c.sent();
|
|
354
|
-
return [4 /*yield*/, this.estimator.reveal()];
|
|
355
|
-
case 2:
|
|
356
|
-
estimateReveal_1 = _c.sent();
|
|
357
|
-
if (!estimateReveal_1) return [3 /*break*/, 5];
|
|
358
|
-
reveal = { kind: rpc_1.OpKind.REVEAL };
|
|
359
|
-
return [4 /*yield*/, this.estimate(reveal, function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
360
|
-
return [2 /*return*/, estimateReveal_1];
|
|
361
|
-
}); }); })];
|
|
362
|
-
case 3:
|
|
363
|
-
estimatedReveal = _c.sent();
|
|
364
|
-
_b = (_a = ops).unshift;
|
|
365
|
-
return [4 /*yield*/, prepare_1.createRevealOperation(__assign({}, estimatedReveal), publicKeyHash, publicKey)];
|
|
366
|
-
case 4:
|
|
367
|
-
_b.apply(_a, [_c.sent()]);
|
|
368
|
-
return [2 /*return*/, ops];
|
|
369
|
-
case 5: return [2 /*return*/, operation];
|
|
190
|
+
}
|
|
191
|
+
addRevealOperationIfNeeded(operation, publicKeyHash) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
if (types_1.isOpRequireReveal(operation)) {
|
|
194
|
+
const ops = [operation];
|
|
195
|
+
const publicKey = yield this.signer.publicKey();
|
|
196
|
+
const estimateReveal = yield this.estimator.reveal();
|
|
197
|
+
if (estimateReveal) {
|
|
198
|
+
const reveal = { kind: rpc_1.OpKind.REVEAL };
|
|
199
|
+
const estimatedReveal = yield this.estimate(reveal, () => __awaiter(this, void 0, void 0, function* () { return estimateReveal; }));
|
|
200
|
+
ops.unshift(yield prepare_1.createRevealOperation(Object.assign({}, estimatedReveal), publicKeyHash, publicKey));
|
|
201
|
+
return ops;
|
|
370
202
|
}
|
|
371
|
-
}
|
|
203
|
+
}
|
|
204
|
+
return operation;
|
|
372
205
|
});
|
|
373
|
-
}
|
|
206
|
+
}
|
|
374
207
|
/**
|
|
375
208
|
*
|
|
376
209
|
* @description Originate a new contract according to the script in parameters. Will sign and inject an operation using the current context
|
|
@@ -381,42 +214,21 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
381
214
|
*
|
|
382
215
|
* @param OriginationOperation Originate operation parameter
|
|
383
216
|
*/
|
|
384
|
-
|
|
385
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
case 2:
|
|
394
|
-
publicKeyHash = _c.sent();
|
|
395
|
-
_a = prepare_1.createOriginationOperation;
|
|
396
|
-
return [4 /*yield*/, this.context.parser.prepareCodeOrigination(__assign(__assign({}, params), estimate))];
|
|
397
|
-
case 3: return [4 /*yield*/, _a.apply(void 0, [_c.sent()])];
|
|
398
|
-
case 4:
|
|
399
|
-
operation = _c.sent();
|
|
400
|
-
return [4 /*yield*/, this.addRevealOperationIfNeeded(operation, publicKeyHash)];
|
|
401
|
-
case 5:
|
|
402
|
-
ops = _c.sent();
|
|
403
|
-
return [4 /*yield*/, this.prepareOperation({
|
|
404
|
-
operation: ops,
|
|
405
|
-
source: publicKeyHash,
|
|
406
|
-
})];
|
|
407
|
-
case 6:
|
|
408
|
-
preparedOrigination = _c.sent();
|
|
409
|
-
return [4 /*yield*/, this.forge(preparedOrigination)];
|
|
410
|
-
case 7:
|
|
411
|
-
forgedOrigination = _c.sent();
|
|
412
|
-
return [4 /*yield*/, this.signAndInject(forgedOrigination)];
|
|
413
|
-
case 8:
|
|
414
|
-
_b = _c.sent(), hash = _b.hash, context = _b.context, forgedBytes = _b.forgedBytes, opResponse = _b.opResponse;
|
|
415
|
-
return [2 /*return*/, new origination_operation_1.OriginationOperation(hash, operation, forgedBytes, opResponse, context, this)];
|
|
416
|
-
}
|
|
217
|
+
originate(params) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
const estimate = yield this.estimate(params, this.estimator.originate.bind(this.estimator));
|
|
220
|
+
const publicKeyHash = yield this.signer.publicKeyHash();
|
|
221
|
+
const operation = yield prepare_1.createOriginationOperation(yield this.context.parser.prepareCodeOrigination(Object.assign(Object.assign({}, params), estimate)));
|
|
222
|
+
const ops = yield this.addRevealOperationIfNeeded(operation, publicKeyHash);
|
|
223
|
+
const preparedOrigination = yield this.prepareOperation({
|
|
224
|
+
operation: ops,
|
|
225
|
+
source: publicKeyHash,
|
|
417
226
|
});
|
|
227
|
+
const forgedOrigination = yield this.forge(preparedOrigination);
|
|
228
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(forgedOrigination);
|
|
229
|
+
return new origination_operation_1.OriginationOperation(hash, operation, forgedBytes, opResponse, context, this);
|
|
418
230
|
});
|
|
419
|
-
}
|
|
231
|
+
}
|
|
420
232
|
/**
|
|
421
233
|
*
|
|
422
234
|
* @description Set the delegate for a contract. Will sign and inject an operation using the current context
|
|
@@ -425,46 +237,32 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
425
237
|
*
|
|
426
238
|
* @param SetDelegate operation parameter
|
|
427
239
|
*/
|
|
428
|
-
|
|
429
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
return [4 /*yield*/, this.addRevealOperationIfNeeded(operation, publicKeyHash)];
|
|
449
|
-
case 4:
|
|
450
|
-
ops = _b.sent();
|
|
451
|
-
return [4 /*yield*/, this.prepareOperation({
|
|
452
|
-
operation: ops,
|
|
453
|
-
source: sourceOrDefault,
|
|
454
|
-
})];
|
|
455
|
-
case 5:
|
|
456
|
-
prepared = _b.sent();
|
|
457
|
-
return [4 /*yield*/, this.forge(prepared)];
|
|
458
|
-
case 6:
|
|
459
|
-
opBytes = _b.sent();
|
|
460
|
-
return [4 /*yield*/, this.signAndInject(opBytes)];
|
|
461
|
-
case 7:
|
|
462
|
-
_a = _b.sent(), hash = _a.hash, context = _a.context, forgedBytes = _a.forgedBytes, opResponse = _a.opResponse;
|
|
463
|
-
return [2 /*return*/, new delegate_operation_1.DelegateOperation(hash, operation, sourceOrDefault, forgedBytes, opResponse, context)];
|
|
464
|
-
}
|
|
240
|
+
setDelegate(params) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
if (params.source && utils_2.validateAddress(params.source) !== utils_2.ValidationResult.VALID) {
|
|
243
|
+
throw new utils_2.InvalidAddressError(`Invalid source Address: ${params.source}`);
|
|
244
|
+
}
|
|
245
|
+
if (params.delegate && utils_2.validateAddress(params.delegate) !== utils_2.ValidationResult.VALID) {
|
|
246
|
+
throw new utils_2.InvalidAddressError(`Invalid delegate Address: ${params.delegate}`);
|
|
247
|
+
}
|
|
248
|
+
// Since babylon delegation source cannot smart contract
|
|
249
|
+
if (/kt1/i.test(params.source)) {
|
|
250
|
+
throw new errors_1.InvalidDelegationSource(params.source);
|
|
251
|
+
}
|
|
252
|
+
const estimate = yield this.estimate(params, this.estimator.setDelegate.bind(this.estimator));
|
|
253
|
+
const publicKeyHash = yield this.signer.publicKeyHash();
|
|
254
|
+
const operation = yield prepare_1.createSetDelegateOperation(Object.assign(Object.assign({}, params), estimate));
|
|
255
|
+
const sourceOrDefault = params.source || publicKeyHash;
|
|
256
|
+
const ops = yield this.addRevealOperationIfNeeded(operation, publicKeyHash);
|
|
257
|
+
const prepared = yield this.prepareOperation({
|
|
258
|
+
operation: ops,
|
|
259
|
+
source: sourceOrDefault,
|
|
465
260
|
});
|
|
261
|
+
const opBytes = yield this.forge(prepared);
|
|
262
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
263
|
+
return new delegate_operation_1.DelegateOperation(hash, operation, sourceOrDefault, forgedBytes, opResponse, context);
|
|
466
264
|
});
|
|
467
|
-
}
|
|
265
|
+
}
|
|
468
266
|
/**
|
|
469
267
|
*
|
|
470
268
|
* @description Register the current address as delegate. Will sign and inject an operation using the current context
|
|
@@ -473,37 +271,18 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
473
271
|
*
|
|
474
272
|
* @param RegisterDelegate operation parameter
|
|
475
273
|
*/
|
|
476
|
-
|
|
477
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
source = _b.sent();
|
|
487
|
-
return [4 /*yield*/, prepare_1.createRegisterDelegateOperation(__assign(__assign({}, params), estimate), source)];
|
|
488
|
-
case 3:
|
|
489
|
-
operation = _b.sent();
|
|
490
|
-
return [4 /*yield*/, this.addRevealOperationIfNeeded(operation, source)];
|
|
491
|
-
case 4:
|
|
492
|
-
ops = _b.sent();
|
|
493
|
-
return [4 /*yield*/, this.prepareOperation({ operation: ops })];
|
|
494
|
-
case 5:
|
|
495
|
-
prepared = _b.sent();
|
|
496
|
-
return [4 /*yield*/, this.forge(prepared)];
|
|
497
|
-
case 6:
|
|
498
|
-
opBytes = _b.sent();
|
|
499
|
-
return [4 /*yield*/, this.signAndInject(opBytes)];
|
|
500
|
-
case 7:
|
|
501
|
-
_a = _b.sent(), hash = _a.hash, context = _a.context, forgedBytes = _a.forgedBytes, opResponse = _a.opResponse;
|
|
502
|
-
return [2 /*return*/, new delegate_operation_1.DelegateOperation(hash, operation, source, forgedBytes, opResponse, context)];
|
|
503
|
-
}
|
|
504
|
-
});
|
|
274
|
+
registerDelegate(params) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
const estimate = yield this.estimate(params, this.estimator.registerDelegate.bind(this.estimator));
|
|
277
|
+
const source = yield this.signer.publicKeyHash();
|
|
278
|
+
const operation = yield prepare_1.createRegisterDelegateOperation(Object.assign(Object.assign({}, params), estimate), source);
|
|
279
|
+
const ops = yield this.addRevealOperationIfNeeded(operation, source);
|
|
280
|
+
const prepared = yield this.prepareOperation({ operation: ops });
|
|
281
|
+
const opBytes = yield this.forge(prepared);
|
|
282
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
283
|
+
return new delegate_operation_1.DelegateOperation(hash, operation, source, forgedBytes, opResponse, context);
|
|
505
284
|
});
|
|
506
|
-
}
|
|
285
|
+
}
|
|
507
286
|
/**
|
|
508
287
|
*
|
|
509
288
|
* @description Transfer tz from current address to a specific address. Will sign and inject an operation using the current context
|
|
@@ -512,38 +291,25 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
512
291
|
*
|
|
513
292
|
* @param Transfer operation parameter
|
|
514
293
|
*/
|
|
515
|
-
|
|
516
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
ops = _b.sent();
|
|
533
|
-
return [4 /*yield*/, this.prepareOperation({ operation: ops, source: params.source })];
|
|
534
|
-
case 5:
|
|
535
|
-
prepared = _b.sent();
|
|
536
|
-
return [4 /*yield*/, this.forge(prepared)];
|
|
537
|
-
case 6:
|
|
538
|
-
opBytes = _b.sent();
|
|
539
|
-
return [4 /*yield*/, this.signAndInject(opBytes)];
|
|
540
|
-
case 7:
|
|
541
|
-
_a = _b.sent(), hash = _a.hash, context = _a.context, forgedBytes = _a.forgedBytes, opResponse = _a.opResponse;
|
|
542
|
-
return [2 /*return*/, new transaction_operation_1.TransactionOperation(hash, operation, source, forgedBytes, opResponse, context)];
|
|
543
|
-
}
|
|
544
|
-
});
|
|
294
|
+
transfer(params) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
if (utils_2.validateAddress(params.to) !== utils_2.ValidationResult.VALID) {
|
|
297
|
+
throw new utils_2.InvalidAddressError(`Invalid address passed in 'to' parameter: ${params.to}`);
|
|
298
|
+
}
|
|
299
|
+
if (params.source && utils_2.validateAddress(params.source) !== utils_2.ValidationResult.VALID) {
|
|
300
|
+
throw new utils_2.InvalidAddressError(`Invalid address passed in 'source' parameter: ${params.source}`);
|
|
301
|
+
}
|
|
302
|
+
const publickKeyHash = yield this.signer.publicKeyHash();
|
|
303
|
+
const estimate = yield this.estimate(params, this.estimator.transfer.bind(this.estimator));
|
|
304
|
+
const operation = yield prepare_1.createTransferOperation(Object.assign(Object.assign({}, params), estimate));
|
|
305
|
+
const source = params.source || publickKeyHash;
|
|
306
|
+
const ops = yield this.addRevealOperationIfNeeded(operation, publickKeyHash);
|
|
307
|
+
const prepared = yield this.prepareOperation({ operation: ops, source: params.source });
|
|
308
|
+
const opBytes = yield this.forge(prepared);
|
|
309
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
310
|
+
return new transaction_operation_1.TransactionOperation(hash, operation, source, forgedBytes, opResponse, context);
|
|
545
311
|
});
|
|
546
|
-
}
|
|
312
|
+
}
|
|
547
313
|
/**
|
|
548
314
|
*
|
|
549
315
|
* @description Reveal the current address. Will throw an error if the address is already revealed.
|
|
@@ -552,45 +318,23 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
552
318
|
*
|
|
553
319
|
* @param RevealParams operation parameter
|
|
554
320
|
*/
|
|
555
|
-
|
|
556
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}); }); })];
|
|
571
|
-
case 3:
|
|
572
|
-
estimated = _d.sent();
|
|
573
|
-
_a = prepare_1.createRevealOperation;
|
|
574
|
-
_b = [__assign({}, estimated), publicKeyHash];
|
|
575
|
-
return [4 /*yield*/, this.signer.publicKey()];
|
|
576
|
-
case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_d.sent()]))];
|
|
577
|
-
case 5:
|
|
578
|
-
operation = _d.sent();
|
|
579
|
-
return [4 /*yield*/, this.prepareOperation({ operation: operation, source: publicKeyHash })];
|
|
580
|
-
case 6:
|
|
581
|
-
prepared = _d.sent();
|
|
582
|
-
return [4 /*yield*/, this.forge(prepared)];
|
|
583
|
-
case 7:
|
|
584
|
-
opBytes = _d.sent();
|
|
585
|
-
return [4 /*yield*/, this.signAndInject(opBytes)];
|
|
586
|
-
case 8:
|
|
587
|
-
_c = _d.sent(), hash = _c.hash, context = _c.context, forgedBytes = _c.forgedBytes, opResponse = _c.opResponse;
|
|
588
|
-
return [2 /*return*/, new reveal_operation_1.RevealOperation(hash, operation, publicKeyHash, forgedBytes, opResponse, context)];
|
|
589
|
-
case 9: throw new Error('The current address is already revealed.');
|
|
590
|
-
}
|
|
591
|
-
});
|
|
321
|
+
reveal(params) {
|
|
322
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
323
|
+
const publicKeyHash = yield this.signer.publicKeyHash();
|
|
324
|
+
const estimateReveal = yield this.estimator.reveal(params);
|
|
325
|
+
if (estimateReveal) {
|
|
326
|
+
const estimated = yield this.estimate(params, () => __awaiter(this, void 0, void 0, function* () { return estimateReveal; }));
|
|
327
|
+
const operation = yield prepare_1.createRevealOperation(Object.assign({}, estimated), publicKeyHash, yield this.signer.publicKey());
|
|
328
|
+
const prepared = yield this.prepareOperation({ operation, source: publicKeyHash });
|
|
329
|
+
const opBytes = yield this.forge(prepared);
|
|
330
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
331
|
+
return new reveal_operation_1.RevealOperation(hash, operation, publicKeyHash, forgedBytes, opResponse, context);
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
throw new Error('The current address is already revealed.');
|
|
335
|
+
}
|
|
592
336
|
});
|
|
593
|
-
}
|
|
337
|
+
}
|
|
594
338
|
/**
|
|
595
339
|
*
|
|
596
340
|
* @description Register a Micheline expression in a global table of constants. Will sign and inject an operation using the current context
|
|
@@ -599,61 +343,32 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
599
343
|
*
|
|
600
344
|
* @param params registerGlobalConstant operation parameter
|
|
601
345
|
*/
|
|
602
|
-
|
|
603
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
estimate = _b.sent();
|
|
613
|
-
return [4 /*yield*/, prepare_1.createRegisterGlobalConstantOperation(__assign(__assign({}, params), estimate))];
|
|
614
|
-
case 3:
|
|
615
|
-
operation = _b.sent();
|
|
616
|
-
return [4 /*yield*/, this.addRevealOperationIfNeeded(operation, publickKeyHash)];
|
|
617
|
-
case 4:
|
|
618
|
-
ops = _b.sent();
|
|
619
|
-
return [4 /*yield*/, this.prepareOperation({ operation: ops, source: publickKeyHash })];
|
|
620
|
-
case 5:
|
|
621
|
-
prepared = _b.sent();
|
|
622
|
-
return [4 /*yield*/, this.forge(prepared)];
|
|
623
|
-
case 6:
|
|
624
|
-
opBytes = _b.sent();
|
|
625
|
-
return [4 /*yield*/, this.signAndInject(opBytes)];
|
|
626
|
-
case 7:
|
|
627
|
-
_a = _b.sent(), hash = _a.hash, context = _a.context, forgedBytes = _a.forgedBytes, opResponse = _a.opResponse;
|
|
628
|
-
return [2 /*return*/, new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, operation, publickKeyHash, forgedBytes, opResponse, context)];
|
|
629
|
-
}
|
|
630
|
-
});
|
|
346
|
+
registerGlobalConstant(params) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
const publickKeyHash = yield this.signer.publicKeyHash();
|
|
349
|
+
const estimate = yield this.estimate(params, this.estimator.registerGlobalConstant.bind(this.estimator));
|
|
350
|
+
const operation = yield prepare_1.createRegisterGlobalConstantOperation(Object.assign(Object.assign({}, params), estimate));
|
|
351
|
+
const ops = yield this.addRevealOperationIfNeeded(operation, publickKeyHash);
|
|
352
|
+
const prepared = yield this.prepareOperation({ operation: ops, source: publickKeyHash });
|
|
353
|
+
const opBytes = yield this.forge(prepared);
|
|
354
|
+
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
355
|
+
return new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, operation, publickKeyHash, forgedBytes, opResponse, context);
|
|
631
356
|
});
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
case 2:
|
|
646
|
-
entrypoints = _a.sent();
|
|
647
|
-
return [4 /*yield*/, this.rpc.getBlockHeader()];
|
|
648
|
-
case 3:
|
|
649
|
-
blockHeader = _a.sent();
|
|
650
|
-
chainId = blockHeader.chain_id;
|
|
651
|
-
abs = new contract_1.ContractAbstraction(address, script, this, this, entrypoints, chainId);
|
|
652
|
-
return [2 /*return*/, contractAbstractionComposer(abs, this.context)];
|
|
653
|
-
}
|
|
654
|
-
});
|
|
357
|
+
}
|
|
358
|
+
at(address, contractAbstractionComposer = (x) => x) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
if (utils_2.validateContractAddress(address) !== utils_2.ValidationResult.VALID) {
|
|
361
|
+
throw new utils_2.InvalidContractAddressError(`Invalid contract address: ${address}`);
|
|
362
|
+
}
|
|
363
|
+
const rpc = this.context.withExtensions().rpc;
|
|
364
|
+
const script = yield rpc.getNormalizedScript(address);
|
|
365
|
+
const entrypoints = yield rpc.getEntrypoints(address);
|
|
366
|
+
const blockHeader = yield this.rpc.getBlockHeader();
|
|
367
|
+
const chainId = blockHeader.chain_id;
|
|
368
|
+
const abs = new contract_1.ContractAbstraction(address, script, this, this, entrypoints, chainId, rpc);
|
|
369
|
+
return contractAbstractionComposer(abs, this.context);
|
|
655
370
|
});
|
|
656
|
-
}
|
|
371
|
+
}
|
|
657
372
|
/**
|
|
658
373
|
*
|
|
659
374
|
* @description Batch a group of operation together. Operations will be applied in the order in which they are added to the batch
|
|
@@ -662,14 +377,13 @@ var RpcContractProvider = /** @class */ (function (_super) {
|
|
|
662
377
|
*
|
|
663
378
|
* @param params List of operation to batch together
|
|
664
379
|
*/
|
|
665
|
-
|
|
666
|
-
|
|
380
|
+
batch(params) {
|
|
381
|
+
const batch = new rpc_batch_provider_1.OperationBatch(this.context, this.estimator);
|
|
667
382
|
if (Array.isArray(params)) {
|
|
668
383
|
batch.with(params);
|
|
669
384
|
}
|
|
670
385
|
return batch;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
}(operation_emitter_1.OperationEmitter));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
674
388
|
exports.RpcContractProvider = RpcContractProvider;
|
|
675
389
|
//# sourceMappingURL=rpc-contract-provider.js.map
|