@taquito/taquito 24.2.0 → 24.3.0-beta.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 +1 -1
- package/dist/lib/batch/rpc-batch-provider.js +91 -83
- package/dist/lib/context.js +22 -26
- package/dist/lib/contract/big-map.js +16 -29
- package/dist/lib/contract/contract-methods/contract-method-object-param.js +7 -7
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +31 -44
- package/dist/lib/contract/contract.js +21 -32
- package/dist/lib/contract/errors.js +9 -9
- package/dist/lib/contract/prepare.js +36 -45
- package/dist/lib/contract/rpc-contract-provider.js +426 -475
- package/dist/lib/contract/sapling-state-abstraction.js +3 -14
- package/dist/lib/contract/semantic.js +2 -2
- package/dist/lib/errors.js +3 -3
- package/dist/lib/estimate/errors.js +1 -1
- package/dist/lib/estimate/estimate.js +66 -20
- package/dist/lib/estimate/rpc-estimate-provider.js +427 -460
- package/dist/lib/forger/composite-forger.js +16 -27
- package/dist/lib/forger/errors.js +2 -2
- package/dist/lib/forger/taquito-local-forger.js +9 -22
- package/dist/lib/global-constants/default-global-constants-provider.js +8 -19
- package/dist/lib/global-constants/errors.js +2 -2
- package/dist/lib/global-constants/noop-global-constants-provider.js +2 -13
- package/dist/lib/import-key.js +23 -34
- package/dist/lib/injector/rpc-injector.js +13 -24
- package/dist/lib/operations/ballot-operation.js +2 -3
- package/dist/lib/operations/delegate-operation.js +5 -8
- package/dist/lib/operations/drain-delegate-operation.js +1 -1
- package/dist/lib/operations/errors.js +9 -6
- package/dist/lib/operations/increase-paid-storage-operation.js +4 -7
- package/dist/lib/operations/operations.js +100 -30
- package/dist/lib/operations/origination-operation.js +16 -27
- package/dist/lib/operations/proposals-operation.js +2 -3
- package/dist/lib/operations/register-global-constant-operation.js +4 -7
- package/dist/lib/operations/reveal-operation.js +1 -1
- package/dist/lib/operations/smart-rollup-add-messages-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-originate-operation.js +4 -7
- package/dist/lib/operations/transaction-operation.js +2 -2
- package/dist/lib/operations/transfer-ticket-operation.js +4 -6
- package/dist/lib/operations/types.js +17 -19
- package/dist/lib/operations/update-companion-key-operation.js +4 -7
- package/dist/lib/operations/update-consensus-key-operation.js +4 -7
- package/dist/lib/packer/michel-codec-packer.js +3 -14
- package/dist/lib/packer/rpc-packer.js +2 -13
- package/dist/lib/parser/michel-codec-parser.js +82 -107
- package/dist/lib/parser/noop-parser.js +2 -13
- package/dist/lib/prepare/prepare-provider.js +780 -744
- package/dist/lib/provider.js +322 -128
- package/dist/lib/read-provider/rpc-read-adapter.js +76 -121
- package/dist/lib/signer/errors.js +1 -1
- package/dist/lib/signer/noop.js +9 -26
- package/dist/lib/subscribe/errors.js +2 -2
- package/dist/lib/subscribe/polling-subcribe-provider.js +35 -38
- package/dist/lib/taquito.js +33 -33
- package/dist/lib/tz/rpc-tz-provider.js +27 -44
- package/dist/lib/version.js +2 -2
- package/dist/lib/wallet/batch-operation.js +32 -45
- package/dist/lib/wallet/delegation-operation.js +25 -40
- package/dist/lib/wallet/errors.js +15 -3
- package/dist/lib/wallet/increase-paid-storage-operation.js +25 -40
- package/dist/lib/wallet/legacy.js +28 -63
- package/dist/lib/wallet/operation-factory.js +27 -56
- package/dist/lib/wallet/operation.js +123 -59
- package/dist/lib/wallet/origination-operation.js +34 -46
- package/dist/lib/wallet/register-global-constant-operation.js +26 -43
- package/dist/lib/wallet/transaction-operation.js +21 -36
- package/dist/lib/wallet/transfer-ticket-operation.js +21 -36
- package/dist/lib/wallet/wallet.js +187 -184
- package/dist/taquito.es6.js +3424 -3197
- package/dist/taquito.es6.js.map +1 -1
- package/dist/taquito.min.js +1 -1
- package/dist/taquito.umd.js +7930 -7701
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/batch/rpc-batch-provider.d.ts +18 -18
- package/dist/types/context.d.ts +4 -4
- package/dist/types/contract/big-map.d.ts +3 -3
- package/dist/types/contract/contract-methods/contract-method-interface.d.ts +4 -4
- package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +6 -6
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +3 -3
- package/dist/types/contract/contract.d.ts +6 -6
- package/dist/types/contract/errors.d.ts +11 -11
- package/dist/types/contract/interface.d.ts +42 -42
- package/dist/types/contract/rpc-contract-provider.d.ts +44 -43
- package/dist/types/contract/sapling-state-abstraction.d.ts +1 -1
- package/dist/types/contract/semantic.d.ts +2 -2
- package/dist/types/errors.d.ts +5 -5
- package/dist/types/estimate/errors.d.ts +1 -1
- package/dist/types/estimate/estimate-provider-interface.d.ts +81 -84
- package/dist/types/estimate/estimate.d.ts +28 -11
- package/dist/types/estimate/rpc-estimate-provider.d.ts +34 -30
- package/dist/types/forger/errors.d.ts +2 -2
- package/dist/types/global-constants/default-global-constants-provider.d.ts +2 -2
- package/dist/types/global-constants/errors.d.ts +2 -2
- package/dist/types/global-constants/interface-global-constants-provider.d.ts +1 -1
- package/dist/types/import-key.d.ts +2 -2
- package/dist/types/operations/ballot-operation.d.ts +1 -1
- package/dist/types/operations/delegate-operation.d.ts +2 -2
- package/dist/types/operations/drain-delegate-operation.d.ts +1 -1
- package/dist/types/operations/errors.d.ts +5 -5
- package/dist/types/operations/failing-noop-operation.d.ts +1 -1
- package/dist/types/operations/increase-paid-storage-operation.d.ts +1 -1
- package/dist/types/operations/operations.d.ts +2 -2
- package/dist/types/operations/origination-operation.d.ts +5 -5
- package/dist/types/operations/proposals-operation.d.ts +1 -1
- package/dist/types/operations/register-global-constant-operation.d.ts +2 -2
- package/dist/types/operations/reveal-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-originate-operation.d.ts +1 -1
- package/dist/types/operations/transaction-operation.d.ts +2 -2
- package/dist/types/operations/transfer-ticket-operation.d.ts +2 -2
- package/dist/types/operations/types.d.ts +387 -25
- package/dist/types/operations/update-companion-key-operation.d.ts +1 -1
- package/dist/types/operations/update-consensus-key-operation.d.ts +1 -1
- package/dist/types/prepare/interface.d.ts +32 -33
- package/dist/types/prepare/prepare-provider.d.ts +34 -60
- package/dist/types/provider.d.ts +7 -1
- package/dist/types/read-provider/interface.d.ts +21 -21
- package/dist/types/read-provider/rpc-read-adapter.d.ts +22 -22
- package/dist/types/signer/errors.d.ts +1 -1
- package/dist/types/signer/noop.d.ts +1 -1
- package/dist/types/subscribe/errors.d.ts +2 -2
- package/dist/types/taquito.d.ts +33 -33
- package/dist/types/wallet/errors.d.ts +10 -2
- package/dist/types/wallet/interface.d.ts +13 -13
- package/dist/types/wallet/operation.d.ts +4 -3
- package/dist/types/wallet/wallet.d.ts +36 -35
- package/package.json +27 -15
- package/LICENSE +0 -202
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RpcContractProvider = void 0;
|
|
13
4
|
const http_utils_1 = require("@taquito/http-utils");
|
|
@@ -45,36 +36,34 @@ class RpcContractProvider extends provider_1.Provider {
|
|
|
45
36
|
}
|
|
46
37
|
/**
|
|
47
38
|
*
|
|
48
|
-
*
|
|
39
|
+
* Return a well formatted json object of the contract storage
|
|
49
40
|
*
|
|
50
41
|
* @param contract contract address you want to get the storage from
|
|
51
42
|
* @param schema optional schema can either be the contract script rpc response or a michelson-encoder schema
|
|
52
43
|
* @throws {@link InvalidContractAddressError}
|
|
53
44
|
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
|
|
54
45
|
*/
|
|
55
|
-
getStorage(contract, schema) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return contractSchema.Execute(script.storage, (0, semantic_1.smartContractAbstractionSemantic)(this)); // Cast into T because only the caller can know the true type of the storage
|
|
73
|
-
});
|
|
46
|
+
async getStorage(contract, schema) {
|
|
47
|
+
const contractValidation = (0, utils_1.validateContractAddress)(contract);
|
|
48
|
+
if (contractValidation !== utils_1.ValidationResult.VALID) {
|
|
49
|
+
throw new core_1.InvalidContractAddressError(contract, contractValidation);
|
|
50
|
+
}
|
|
51
|
+
const script = await this.context.readProvider.getScript(contract, 'head');
|
|
52
|
+
if (!schema) {
|
|
53
|
+
schema = script;
|
|
54
|
+
}
|
|
55
|
+
let contractSchema;
|
|
56
|
+
if (michelson_encoder_1.Schema.isSchema(schema)) {
|
|
57
|
+
contractSchema = schema;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
contractSchema = michelson_encoder_1.Schema.fromRPCResponse({ script: schema });
|
|
61
|
+
}
|
|
62
|
+
return contractSchema.Execute(script.storage, (0, semantic_1.smartContractAbstractionSemantic)(this)); // Cast into T because only the caller can know the true type of the storage
|
|
74
63
|
}
|
|
75
64
|
/**
|
|
76
65
|
*
|
|
77
|
-
*
|
|
66
|
+
* Return a well formatted json object of a big map value
|
|
78
67
|
*
|
|
79
68
|
* @param id Big Map ID
|
|
80
69
|
* @param keyToEncode key to query (will be encoded properly according to the schema)
|
|
@@ -83,20 +72,18 @@ class RpcContractProvider extends provider_1.Provider {
|
|
|
83
72
|
*
|
|
84
73
|
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr
|
|
85
74
|
*/
|
|
86
|
-
getBigMapKeyByID(id, keyToEncode, schema, block) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return schema.ExecuteOnBigMapValue(bigMapValue, (0, semantic_1.smartContractAbstractionSemantic)(this));
|
|
95
|
-
});
|
|
75
|
+
async getBigMapKeyByID(id, keyToEncode, schema, block) {
|
|
76
|
+
const { key, type } = schema.EncodeBigMapKey(keyToEncode);
|
|
77
|
+
const { packed } = await this.context.packer.packData({ data: key, type });
|
|
78
|
+
const encodedExpr = (0, utils_1.encodeExpr)(packed);
|
|
79
|
+
const bigMapValue = block
|
|
80
|
+
? await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, block)
|
|
81
|
+
: await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, 'head');
|
|
82
|
+
return schema.ExecuteOnBigMapValue(bigMapValue, (0, semantic_1.smartContractAbstractionSemantic)(this));
|
|
96
83
|
}
|
|
97
84
|
/**
|
|
98
85
|
*
|
|
99
|
-
*
|
|
86
|
+
* Fetch multiple values in a big map
|
|
100
87
|
* 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.
|
|
101
88
|
* 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.
|
|
102
89
|
* If one of the keys does not exist in the big map, its value will be set to undefined.
|
|
@@ -109,605 +96,569 @@ class RpcContractProvider extends provider_1.Provider {
|
|
|
109
96
|
* @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
|
|
110
97
|
*
|
|
111
98
|
*/
|
|
112
|
-
getBigMapKeysByID(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return bigMapValues;
|
|
129
|
-
});
|
|
99
|
+
async getBigMapKeysByID(id, keys, schema, block, batchSize = 5) {
|
|
100
|
+
const level = await this.getBlockForRequest(keys, block);
|
|
101
|
+
const bigMapValues = new michelson_encoder_1.MichelsonMap();
|
|
102
|
+
// Execute batch of promises in series
|
|
103
|
+
let position = 0;
|
|
104
|
+
let results = [];
|
|
105
|
+
while (position < keys.length) {
|
|
106
|
+
const keysBatch = keys.slice(position, position + batchSize);
|
|
107
|
+
const batch = keysBatch.map((keyToEncode) => this.getBigMapValueOrUndefined(keyToEncode, id, schema, level));
|
|
108
|
+
results = [...results, ...(await Promise.all(batch))];
|
|
109
|
+
position += batchSize;
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0; i < results.length; i++) {
|
|
112
|
+
bigMapValues.set(keys[i], results[i]);
|
|
113
|
+
}
|
|
114
|
+
return bigMapValues;
|
|
130
115
|
}
|
|
131
|
-
getBlockForRequest(keys, block) {
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
: yield this.context.readProvider.getBlockLevel('head');
|
|
136
|
-
});
|
|
116
|
+
async getBlockForRequest(keys, block) {
|
|
117
|
+
return keys.length === 1 || typeof block !== 'undefined'
|
|
118
|
+
? block
|
|
119
|
+
: await this.context.readProvider.getBlockLevel('head');
|
|
137
120
|
}
|
|
138
|
-
getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
async getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
|
|
122
|
+
try {
|
|
123
|
+
return await this.getBigMapKeyByID(id, keyToEncode, schema, level);
|
|
124
|
+
}
|
|
125
|
+
catch (ex) {
|
|
126
|
+
if (ex instanceof http_utils_1.HttpResponseError && ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
|
|
127
|
+
return;
|
|
142
128
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
throw ex;
|
|
149
|
-
}
|
|
129
|
+
else {
|
|
130
|
+
throw ex;
|
|
150
131
|
}
|
|
151
|
-
}
|
|
132
|
+
}
|
|
152
133
|
}
|
|
153
134
|
/**
|
|
154
135
|
*
|
|
155
|
-
*
|
|
136
|
+
* Return a well formatted json object of a sapling state
|
|
156
137
|
*
|
|
157
138
|
* @param id Sapling state ID
|
|
158
139
|
* @param block optional block level to fetch the value from
|
|
159
140
|
*
|
|
160
141
|
*/
|
|
161
|
-
getSaplingDiffByID(id, block) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return saplingState;
|
|
167
|
-
});
|
|
142
|
+
async getSaplingDiffByID(id, block) {
|
|
143
|
+
const saplingState = block
|
|
144
|
+
? await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
|
|
145
|
+
: await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
|
|
146
|
+
return saplingState;
|
|
168
147
|
}
|
|
169
148
|
/**
|
|
170
149
|
*
|
|
171
|
-
*
|
|
150
|
+
* Originate a new contract according to the script in parameters. Will sign and inject an operation using the current context
|
|
172
151
|
*
|
|
173
152
|
* @returns An operation handle with the result from the rpc node
|
|
174
153
|
*
|
|
175
154
|
* @warn You cannot specify storage and init at the same time (use init to pass the raw michelson representation of storage)
|
|
176
155
|
*
|
|
177
|
-
* @param
|
|
156
|
+
* @param params Originate operation parameter
|
|
178
157
|
*/
|
|
179
|
-
originate(params) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return new origination_operation_1.OriginationOperation(hash, content, forgedBytes, opResponse, context, this);
|
|
187
|
-
});
|
|
158
|
+
async originate(params) {
|
|
159
|
+
const estimate = await this.estimate(params, this.estimator.originate.bind(this.estimator));
|
|
160
|
+
const preparedOrigination = await this.prepare.originate({ ...params, ...estimate });
|
|
161
|
+
const content = preparedOrigination.opOb.contents.find((op) => op.kind === rpc_1.OpKind.ORIGINATION);
|
|
162
|
+
const forgedOrigination = await this.forge(preparedOrigination);
|
|
163
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(forgedOrigination);
|
|
164
|
+
return new origination_operation_1.OriginationOperation(hash, content, forgedBytes, opResponse, context, this);
|
|
188
165
|
}
|
|
189
166
|
/**
|
|
190
167
|
*
|
|
191
|
-
*
|
|
168
|
+
* Set the delegate for a contract. Will sign and inject an operation using the current context
|
|
192
169
|
*
|
|
193
170
|
* @returns An operation handle with the result from the rpc node
|
|
194
171
|
*
|
|
195
|
-
* @param SetDelegate operation parameter
|
|
172
|
+
* @param params SetDelegate operation parameter
|
|
196
173
|
*/
|
|
197
|
-
setDelegate(params) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
219
|
-
return new delegate_operation_1.DelegateOperation(hash, content, sourceOrDefault, forgedBytes, opResponse, context);
|
|
220
|
-
});
|
|
174
|
+
async setDelegate(params) {
|
|
175
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
176
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
177
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
178
|
+
}
|
|
179
|
+
const delegateValidation = (0, utils_1.validateAddress)(params.delegate ?? '');
|
|
180
|
+
if (params.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
|
|
181
|
+
throw new core_1.InvalidAddressError(params.delegate, delegateValidation);
|
|
182
|
+
}
|
|
183
|
+
// Since babylon delegation source cannot smart contract
|
|
184
|
+
if (/^kt1/i.test(params.source ?? '')) {
|
|
185
|
+
throw new errors_1.InvalidDelegationSource(params.source ?? '');
|
|
186
|
+
}
|
|
187
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
188
|
+
const sourceOrDefault = params.source || publicKeyHash;
|
|
189
|
+
const estimate = await this.estimate(params, this.estimator.setDelegate.bind(this.estimator));
|
|
190
|
+
const preparedDelegation = await this.prepare.delegation({ ...params, ...estimate });
|
|
191
|
+
const content = preparedDelegation.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
|
|
192
|
+
const opBytes = await this.forge(preparedDelegation);
|
|
193
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
194
|
+
return new delegate_operation_1.DelegateOperation(hash, content, sourceOrDefault, forgedBytes, opResponse, context);
|
|
221
195
|
}
|
|
222
196
|
/**
|
|
223
197
|
*
|
|
224
|
-
*
|
|
198
|
+
* Register the current address as delegate. Will sign and inject an operation using the current context
|
|
225
199
|
*
|
|
226
200
|
* @returns An operation handle with the result from the rpc node
|
|
227
201
|
*
|
|
228
|
-
* @param RegisterDelegate operation parameter
|
|
202
|
+
* @param params RegisterDelegate operation parameter
|
|
229
203
|
*/
|
|
230
|
-
registerDelegate(params) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return new delegate_operation_1.DelegateOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
239
|
-
});
|
|
204
|
+
async registerDelegate(params) {
|
|
205
|
+
const estimate = await this.estimate(params, this.estimator.registerDelegate.bind(this.estimator));
|
|
206
|
+
const source = await this.signer.publicKeyHash();
|
|
207
|
+
const prepared = await this.prepare.registerDelegate({ ...params, ...estimate });
|
|
208
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
|
|
209
|
+
const opBytes = await this.forge(prepared);
|
|
210
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
211
|
+
return new delegate_operation_1.DelegateOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
240
212
|
}
|
|
241
213
|
/**
|
|
242
214
|
*
|
|
243
|
-
*
|
|
215
|
+
* Transfer tz from current address to a specific address. Will sign and inject an operation using the current context
|
|
244
216
|
*
|
|
245
217
|
* @returns An operation handle with the result from the rpc node
|
|
246
218
|
*
|
|
247
|
-
* @param Transfer operation parameter
|
|
219
|
+
* @param params Transfer operation parameter
|
|
248
220
|
*/
|
|
249
|
-
transfer(params) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
270
|
-
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
271
|
-
});
|
|
221
|
+
async transfer(params) {
|
|
222
|
+
const toValidation = (0, utils_1.validateAddress)(params.to);
|
|
223
|
+
if (toValidation !== utils_1.ValidationResult.VALID) {
|
|
224
|
+
throw new core_1.InvalidAddressError(params.to, toValidation);
|
|
225
|
+
}
|
|
226
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
227
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
228
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
229
|
+
}
|
|
230
|
+
if (params.amount < 0) {
|
|
231
|
+
throw new core_1.InvalidAmountError(params.amount.toString());
|
|
232
|
+
}
|
|
233
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
234
|
+
const estimate = await this.estimate(params, this.estimator.transfer.bind(this.estimator));
|
|
235
|
+
const source = params.source || publicKeyHash;
|
|
236
|
+
const prepared = await this.prepare.transaction({ ...params, ...estimate });
|
|
237
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
|
|
238
|
+
const opBytes = await this.forge(prepared);
|
|
239
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
240
|
+
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
272
241
|
}
|
|
273
242
|
/**
|
|
274
243
|
*
|
|
275
|
-
*
|
|
244
|
+
* Stake a given amount for the source address
|
|
276
245
|
*
|
|
277
246
|
* @returns An operation handle with the result from the rpc node
|
|
278
247
|
*
|
|
279
|
-
* @param Stake pseudo-operation parameter
|
|
248
|
+
* @param params Stake pseudo-operation parameter
|
|
280
249
|
*/
|
|
281
|
-
stake(params) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
304
|
-
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
305
|
-
});
|
|
250
|
+
async stake(params) {
|
|
251
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
252
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
253
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
254
|
+
}
|
|
255
|
+
if (!params.to) {
|
|
256
|
+
params.to = params.source;
|
|
257
|
+
}
|
|
258
|
+
if (params.to && params.to !== params.source) {
|
|
259
|
+
throw new core_1.InvalidStakingAddressError(params.to);
|
|
260
|
+
}
|
|
261
|
+
if (params.amount < 0) {
|
|
262
|
+
throw new core_1.InvalidAmountError(params.amount.toString());
|
|
263
|
+
}
|
|
264
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
265
|
+
const estimate = await this.estimate(params, this.estimator.stake.bind(this.estimator));
|
|
266
|
+
const source = params.source || publicKeyHash;
|
|
267
|
+
const prepared = await this.prepare.stake({ ...params, ...estimate });
|
|
268
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
|
|
269
|
+
const opBytes = await this.forge(prepared);
|
|
270
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
271
|
+
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
306
272
|
}
|
|
307
273
|
/**
|
|
308
274
|
*
|
|
309
|
-
*
|
|
275
|
+
* Unstake the given amount. If "everything" is given as amount, unstakes everything from the staking balance.
|
|
310
276
|
* Unstaked tez remains frozen for a set amount of cycles (the slashing period) after the operation. Once this period is over,
|
|
311
277
|
* the operation "finalize unstake" must be called for the funds to appear in the liquid balance.
|
|
312
278
|
*
|
|
313
279
|
* @returns An operation handle with the result from the rpc node
|
|
314
280
|
*
|
|
315
|
-
* @param Unstake pseudo-operation parameter
|
|
281
|
+
* @param params Unstake pseudo-operation parameter
|
|
316
282
|
*/
|
|
317
|
-
unstake(params) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
340
|
-
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
341
|
-
});
|
|
283
|
+
async unstake(params) {
|
|
284
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
285
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
286
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
287
|
+
}
|
|
288
|
+
if (!params.to) {
|
|
289
|
+
params.to = params.source;
|
|
290
|
+
}
|
|
291
|
+
if (params.to && params.to !== params.source) {
|
|
292
|
+
throw new core_1.InvalidStakingAddressError(params.to);
|
|
293
|
+
}
|
|
294
|
+
if (params.amount < 0) {
|
|
295
|
+
throw new core_1.InvalidAmountError(params.amount.toString());
|
|
296
|
+
}
|
|
297
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
298
|
+
const estimate = await this.estimate(params, this.estimator.unstake.bind(this.estimator));
|
|
299
|
+
const source = params.source || publicKeyHash;
|
|
300
|
+
const prepared = await this.prepare.unstake({ ...params, ...estimate });
|
|
301
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
|
|
302
|
+
const opBytes = await this.forge(prepared);
|
|
303
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
304
|
+
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
342
305
|
}
|
|
343
306
|
/**
|
|
344
307
|
*
|
|
345
|
-
*
|
|
308
|
+
* Transfer all the finalizable unstaked funds of the source to their liquid balance
|
|
346
309
|
* @returns An operation handle with the result from the rpc node
|
|
347
310
|
*
|
|
348
|
-
* @param Finalize_unstake pseudo-operation parameter
|
|
311
|
+
* @param params Finalize_unstake pseudo-operation parameter
|
|
349
312
|
*/
|
|
350
|
-
finalizeUnstake(params) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
373
|
-
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
374
|
-
});
|
|
313
|
+
async finalizeUnstake(params) {
|
|
314
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
315
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
316
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
317
|
+
}
|
|
318
|
+
if (!params.to) {
|
|
319
|
+
params.to = params.source;
|
|
320
|
+
}
|
|
321
|
+
if (!params.amount) {
|
|
322
|
+
params.amount = 0;
|
|
323
|
+
}
|
|
324
|
+
if (params.amount !== undefined && params.amount > 0) {
|
|
325
|
+
throw new core_1.InvalidFinalizeUnstakeAmountError('Amount must be 0 to finalize unstake.');
|
|
326
|
+
}
|
|
327
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
328
|
+
const estimate = await this.estimate(params, this.estimator.finalizeUnstake.bind(this.estimator));
|
|
329
|
+
const source = params.source || publicKeyHash;
|
|
330
|
+
const prepared = await this.prepare.finalizeUnstake({ ...params, ...estimate });
|
|
331
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
|
|
332
|
+
const opBytes = await this.forge(prepared);
|
|
333
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
334
|
+
return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
375
335
|
}
|
|
376
336
|
/**
|
|
377
337
|
*
|
|
378
|
-
*
|
|
338
|
+
* Transfer Tickets to a smart contract address
|
|
379
339
|
*
|
|
380
340
|
* @returns An operation handle with the result from the rpc node
|
|
381
341
|
*
|
|
382
|
-
* @param
|
|
342
|
+
* @param params TransferTicket operation parameter
|
|
383
343
|
*/
|
|
384
|
-
transferTicket(params) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
402
|
-
return new transfer_ticket_operation_1.TransferTicketOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
403
|
-
});
|
|
344
|
+
async transferTicket(params) {
|
|
345
|
+
const destinationValidation = (0, utils_1.validateAddress)(params.destination);
|
|
346
|
+
if (destinationValidation !== utils_1.ValidationResult.VALID) {
|
|
347
|
+
throw new core_1.InvalidAddressError(params.destination, destinationValidation);
|
|
348
|
+
}
|
|
349
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
350
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
351
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
352
|
+
}
|
|
353
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
354
|
+
const source = params.source ?? publicKeyHash;
|
|
355
|
+
const estimate = await this.estimate(params, this.estimator.transferTicket.bind(this.estimator));
|
|
356
|
+
const prepared = await this.prepare.transferTicket({ ...params, ...estimate });
|
|
357
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSFER_TICKET);
|
|
358
|
+
const opBytes = await this.forge(prepared);
|
|
359
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
360
|
+
return new transfer_ticket_operation_1.TransferTicketOperation(hash, content, source, forgedBytes, opResponse, context);
|
|
404
361
|
}
|
|
405
362
|
/**
|
|
406
363
|
*
|
|
407
|
-
*
|
|
364
|
+
* Reveal the public key of the current address. Will throw an error if the address is already revealed.
|
|
408
365
|
* @returns An operation handle with the result from the rpc node
|
|
409
366
|
*
|
|
410
|
-
* @param
|
|
367
|
+
* @param params Reveal operation parameter
|
|
411
368
|
*/
|
|
412
|
-
reveal(params) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
|
|
418
|
-
(0, utils_1.b58DecodeAndCheckPrefix)(params.proof, [utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
const { prefixSig } = yield this.signer.provePossession();
|
|
422
|
-
params.proof = prefixSig;
|
|
423
|
-
}
|
|
369
|
+
async reveal(params) {
|
|
370
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
371
|
+
const [, pkhPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(publicKeyHash, utils_1.publicKeyHashPrefixes);
|
|
372
|
+
if (pkhPrefix === utils_1.PrefixV2.BLS12_381PublicKeyHash) {
|
|
373
|
+
if (params.proof) {
|
|
374
|
+
(0, utils_1.b58DecodeAndCheckPrefix)(params.proof, [utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
|
|
424
375
|
}
|
|
425
376
|
else {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const estimateReveal = yield this.estimator.reveal(params);
|
|
431
|
-
if (estimateReveal) {
|
|
432
|
-
const estimated = yield this.estimate(params, () => __awaiter(this, void 0, void 0, function* () { return estimateReveal; }));
|
|
433
|
-
const prepared = yield this.prepare.reveal(Object.assign(Object.assign({}, params), estimated));
|
|
434
|
-
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REVEAL);
|
|
435
|
-
const opBytes = yield this.forge(prepared);
|
|
436
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
437
|
-
return new reveal_operation_1.RevealOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
377
|
+
const { prefixSig } = await this.signer.provePossession();
|
|
378
|
+
params.proof = prefixSig;
|
|
438
379
|
}
|
|
439
|
-
|
|
440
|
-
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (params.proof) {
|
|
383
|
+
throw new core_1.ProhibitedActionError('Proof field is only allowed to reveal a bls account ');
|
|
441
384
|
}
|
|
442
|
-
}
|
|
385
|
+
}
|
|
386
|
+
const estimateReveal = await this.estimator.reveal(params);
|
|
387
|
+
if (estimateReveal) {
|
|
388
|
+
const estimated = await this.estimate(params, async () => estimateReveal);
|
|
389
|
+
const prepared = await this.prepare.reveal({ ...params, ...estimated });
|
|
390
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REVEAL);
|
|
391
|
+
const opBytes = await this.forge(prepared);
|
|
392
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
393
|
+
return new reveal_operation_1.RevealOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
throw new errors_1.RevealOperationError(`The publicKeyHash '${publicKeyHash}' has already been revealed.`);
|
|
397
|
+
}
|
|
443
398
|
}
|
|
444
399
|
/**
|
|
445
400
|
*
|
|
446
|
-
*
|
|
401
|
+
* Register a Micheline expression in a global table of constants. Will sign and inject an operation using the current context
|
|
447
402
|
*
|
|
448
403
|
* @returns An operation handle with the result from the rpc node
|
|
449
404
|
*
|
|
450
405
|
* @param params registerGlobalConstant operation parameter
|
|
451
406
|
*/
|
|
452
|
-
registerGlobalConstant(params) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
461
|
-
});
|
|
407
|
+
async registerGlobalConstant(params) {
|
|
408
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
409
|
+
const estimate = await this.estimate(params, this.estimator.registerGlobalConstant.bind(this.estimator));
|
|
410
|
+
const prepared = await this.prepare.registerGlobalConstant({ ...params, ...estimate });
|
|
411
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REGISTER_GLOBAL_CONSTANT);
|
|
412
|
+
const opBytes = await this.forge(prepared);
|
|
413
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
414
|
+
return new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
462
415
|
}
|
|
463
416
|
/**
|
|
464
417
|
*
|
|
465
|
-
*
|
|
418
|
+
* Increase the paid storage of a smart contract
|
|
466
419
|
*
|
|
467
420
|
* @returns An operation handle with the result from the rpc node
|
|
468
421
|
*
|
|
469
422
|
* @param params increasePaidStorage operation parameter
|
|
470
423
|
*/
|
|
471
|
-
increasePaidStorage(params) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
return new increase_paid_storage_operation_1.IncreasePaidStorageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
483
|
-
});
|
|
424
|
+
async increasePaidStorage(params) {
|
|
425
|
+
if (params.amount <= 0) {
|
|
426
|
+
throw new core_1.InvalidAmountError(params.amount.toString());
|
|
427
|
+
}
|
|
428
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
429
|
+
const estimate = await this.estimate(params, this.estimator.increasePaidStorage.bind(this.estimator));
|
|
430
|
+
const prepared = await this.prepare.increasePaidStorage({ ...params, ...estimate });
|
|
431
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.INCREASE_PAID_STORAGE);
|
|
432
|
+
const opBytes = await this.forge(prepared);
|
|
433
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
434
|
+
return new increase_paid_storage_operation_1.IncreasePaidStorageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
484
435
|
}
|
|
485
436
|
/**
|
|
486
437
|
*
|
|
487
|
-
*
|
|
438
|
+
* Transfers the spendable balance of the delegate to destination when consensus_key is the active consensus key of delegate
|
|
488
439
|
*
|
|
489
440
|
* @returns An operation handle with the result from the rpc node
|
|
490
441
|
*
|
|
491
442
|
* @param params drainDelegate operation parameter
|
|
492
443
|
*/
|
|
493
|
-
drainDelegate(params) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return new drain_delegate_operation_1.DrainDelegateOperation(hash, content, forgedBytes, opResponse, context);
|
|
500
|
-
});
|
|
444
|
+
async drainDelegate(params) {
|
|
445
|
+
const prepared = await this.prepare.drainDelegate(params);
|
|
446
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DRAIN_DELEGATE);
|
|
447
|
+
const opBytes = await this.forge(prepared);
|
|
448
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
449
|
+
return new drain_delegate_operation_1.DrainDelegateOperation(hash, content, forgedBytes, opResponse, context);
|
|
501
450
|
}
|
|
502
451
|
/**
|
|
503
452
|
*
|
|
504
|
-
*
|
|
453
|
+
* Submit a ballot vote to a specified proposal
|
|
505
454
|
*
|
|
506
455
|
* @returns An operation handle with the result from the rpc node
|
|
507
456
|
*
|
|
508
|
-
* @param
|
|
457
|
+
* @param params Ballot operation parameter
|
|
509
458
|
*/
|
|
510
|
-
ballot(params) {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
523
|
-
return new ballot_operation_1.BallotOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
524
|
-
});
|
|
459
|
+
async ballot(params) {
|
|
460
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
461
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
462
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
463
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
464
|
+
}
|
|
465
|
+
const source = params.source ?? publicKeyHash;
|
|
466
|
+
const prepared = await this.prepare.ballot({ ...params, source });
|
|
467
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.BALLOT);
|
|
468
|
+
const opBytes = await this.forge(prepared);
|
|
469
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
470
|
+
return new ballot_operation_1.BallotOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
525
471
|
}
|
|
526
472
|
/**
|
|
527
473
|
*
|
|
528
|
-
*
|
|
474
|
+
* Submit or upvote a proposal during the Proposal period
|
|
529
475
|
*
|
|
530
476
|
* @returns An operation handle with the result from the rpc node
|
|
531
477
|
*
|
|
532
|
-
* @param
|
|
478
|
+
* @param params Proposals operation parameter
|
|
533
479
|
*/
|
|
534
|
-
proposals(params) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
|
|
547
|
-
return new proposals_operation_1.ProposalsOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
548
|
-
});
|
|
480
|
+
async proposals(params) {
|
|
481
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
482
|
+
const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
|
|
483
|
+
if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
|
|
484
|
+
throw new core_1.InvalidAddressError(params.source, sourceValidation);
|
|
485
|
+
}
|
|
486
|
+
const source = params.source ?? publicKeyHash;
|
|
487
|
+
const prepared = await this.prepare.proposals({ ...params, source });
|
|
488
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.PROPOSALS);
|
|
489
|
+
const opBytes = await this.forge(prepared);
|
|
490
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
491
|
+
return new proposals_operation_1.ProposalsOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
549
492
|
}
|
|
550
493
|
/**
|
|
551
494
|
*
|
|
552
|
-
*
|
|
495
|
+
* Update the consensus key of a delegate starting from the current cycle plus CONSENSUS_RIGHTS_DELAY + 1
|
|
553
496
|
* @returns An operation handle with the result from the rpc node
|
|
554
497
|
*
|
|
555
|
-
* @param
|
|
498
|
+
* @param params UpdateConsensusKey operation parameter
|
|
556
499
|
*/
|
|
557
|
-
updateConsensusKey(params) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (
|
|
562
|
-
|
|
563
|
-
throw new core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
|
|
564
|
-
}
|
|
500
|
+
async updateConsensusKey(params) {
|
|
501
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
502
|
+
const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
|
|
503
|
+
if (pkPrefix === utils_1.PrefixV2.BLS12_381PublicKey) {
|
|
504
|
+
if (!params.proof) {
|
|
505
|
+
throw new core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
|
|
565
506
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
if (params.proof) {
|
|
510
|
+
throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as consensus key');
|
|
570
511
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
512
|
+
}
|
|
513
|
+
const estimate = await this.estimate(params, this.estimator.updateConsensusKey.bind(this.estimator));
|
|
514
|
+
const prepared = await this.prepare.updateConsensusKey({ ...params, ...estimate });
|
|
515
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_CONSENSUS_KEY);
|
|
516
|
+
const opBytes = await this.forge(prepared);
|
|
517
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
518
|
+
return new update_consensus_key_operation_1.UpdateConsensusKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
578
519
|
}
|
|
579
520
|
/**
|
|
580
521
|
*
|
|
581
|
-
*
|
|
522
|
+
* Updates the companion key of the delegate starting from the current cycle plus CONSENSUS_KEY_ACTIVATION_DELAY + 1
|
|
582
523
|
* @returns An operation handle with the result from the rpc node
|
|
583
524
|
*
|
|
584
|
-
* @param
|
|
525
|
+
* @param params UpdateCompanionKey operation parameter
|
|
585
526
|
*/
|
|
586
|
-
updateCompanionKey(params) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
return new update_companion_key_operation_1.UpdateCompanionKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
602
|
-
});
|
|
527
|
+
async updateCompanionKey(params) {
|
|
528
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
529
|
+
const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
|
|
530
|
+
if (pkPrefix !== utils_1.PrefixV2.BLS12_381PublicKey) {
|
|
531
|
+
throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as companion key');
|
|
532
|
+
}
|
|
533
|
+
if (!params.proof) {
|
|
534
|
+
throw new core_1.InvalidProofError('Proof is required to set a bls account as companion key ');
|
|
535
|
+
}
|
|
536
|
+
const estimate = await this.estimate(params, this.estimator.updateCompanionKey.bind(this.estimator));
|
|
537
|
+
const prepared = await this.prepare.updateCompanionKey({ ...params, ...estimate });
|
|
538
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_COMPANION_KEY);
|
|
539
|
+
const opBytes = await this.forge(prepared);
|
|
540
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
541
|
+
return new update_companion_key_operation_1.UpdateCompanionKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
603
542
|
}
|
|
604
543
|
/**
|
|
605
|
-
*
|
|
606
|
-
* @param
|
|
544
|
+
* Adds messages to the rollup inbox that can be executed/claimed after it gets cemented
|
|
545
|
+
* @param params SmartRollupAddMessages operation parameter
|
|
607
546
|
* @returns An operation handle with results from the RPC node
|
|
608
547
|
*/
|
|
609
|
-
smartRollupAddMessages(params) {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
return new smart_rollup_add_messages_operation_1.SmartRollupAddMessagesOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
618
|
-
});
|
|
548
|
+
async smartRollupAddMessages(params) {
|
|
549
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
550
|
+
const estimate = await this.estimate(params, this.estimator.smartRollupAddMessages.bind(this.estimator));
|
|
551
|
+
const prepared = await this.prepare.smartRollupAddMessages({ ...params, ...estimate });
|
|
552
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ADD_MESSAGES);
|
|
553
|
+
const opBytes = await this.forge(prepared);
|
|
554
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
555
|
+
return new smart_rollup_add_messages_operation_1.SmartRollupAddMessagesOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
619
556
|
}
|
|
620
557
|
/**
|
|
621
|
-
*
|
|
622
|
-
* @param
|
|
558
|
+
* Creates a smart rollup originate operation
|
|
559
|
+
* @param params SmartRollupOriginate operation parameter
|
|
623
560
|
* @returns An operation handle with results from the RPC node
|
|
624
561
|
*/
|
|
625
|
-
smartRollupOriginate(params) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
return new smart_rollup_originate_operation_1.SmartRollupOriginateOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
634
|
-
});
|
|
562
|
+
async smartRollupOriginate(params) {
|
|
563
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
564
|
+
const estimate = await this.estimate(params, this.estimator.smartRollupOriginate.bind(this.estimator));
|
|
565
|
+
const prepared = await this.prepare.smartRollupOriginate({ ...params, ...estimate });
|
|
566
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ORIGINATE);
|
|
567
|
+
const opBytes = await this.forge(prepared);
|
|
568
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
569
|
+
return new smart_rollup_originate_operation_1.SmartRollupOriginateOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
635
570
|
}
|
|
636
571
|
/**
|
|
637
|
-
*
|
|
638
|
-
* @param
|
|
572
|
+
* Execute a message from a smart rollup's outbox of a cemented commitment
|
|
573
|
+
* @param params SmartRollupExecuteOutboxMessage operation parameter
|
|
639
574
|
* @returns An operation handle with results from the RPC node
|
|
640
575
|
*/
|
|
641
|
-
smartRollupExecuteOutboxMessage(params) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
return new smart_rollup_execute_outbox_message_operation_1.SmartRollupExecuteOutboxMessageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
650
|
-
});
|
|
576
|
+
async smartRollupExecuteOutboxMessage(params) {
|
|
577
|
+
const publicKeyHash = await this.signer.publicKeyHash();
|
|
578
|
+
const estimate = await this.estimate(params, this.estimator.smartRollupExecuteOutboxMessage.bind(this.estimator));
|
|
579
|
+
const prepared = await this.prepare.smartRollupExecuteOutboxMessage({ ...params, ...estimate });
|
|
580
|
+
const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE);
|
|
581
|
+
const opBytes = await this.forge(prepared);
|
|
582
|
+
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
|
|
583
|
+
return new smart_rollup_execute_outbox_message_operation_1.SmartRollupExecuteOutboxMessageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
|
|
651
584
|
}
|
|
652
585
|
/**
|
|
653
586
|
*
|
|
654
|
-
*
|
|
587
|
+
* A failing_noop operation that is guaranteed to fail.
|
|
655
588
|
*
|
|
656
589
|
* @returns A FailingNoopOperation object representing the signed failing_noop operation
|
|
657
590
|
*
|
|
658
591
|
* @param params failingNoop operation parameter
|
|
659
592
|
*/
|
|
660
|
-
failingNoop(params) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
contents: [op],
|
|
670
|
-
});
|
|
671
|
-
const { prefixSig } = yield this.signer.sign(forged, new Uint8Array([3]));
|
|
672
|
-
return {
|
|
673
|
-
signature: prefixSig,
|
|
674
|
-
bytes: forged,
|
|
675
|
-
signedContent: {
|
|
676
|
-
branch: hash,
|
|
677
|
-
contents: [
|
|
678
|
-
{
|
|
679
|
-
kind: rpc_1.OpKind.FAILING_NOOP,
|
|
680
|
-
arbitrary: params.arbitrary,
|
|
681
|
-
},
|
|
682
|
-
],
|
|
683
|
-
},
|
|
684
|
-
};
|
|
593
|
+
async failingNoop(params) {
|
|
594
|
+
const op = {
|
|
595
|
+
kind: rpc_1.OpKind.FAILING_NOOP,
|
|
596
|
+
arbitrary: params.arbitrary,
|
|
597
|
+
};
|
|
598
|
+
const hash = await this.context.readProvider.getBlockHash(params.basedOnBlock);
|
|
599
|
+
const forged = await this.context.forger.forge({
|
|
600
|
+
branch: hash,
|
|
601
|
+
contents: [op],
|
|
685
602
|
});
|
|
603
|
+
const { prefixSig } = await this.signer.sign(forged, new Uint8Array([3]));
|
|
604
|
+
return {
|
|
605
|
+
signature: prefixSig,
|
|
606
|
+
bytes: forged,
|
|
607
|
+
signedContent: {
|
|
608
|
+
branch: hash,
|
|
609
|
+
contents: [
|
|
610
|
+
{
|
|
611
|
+
kind: rpc_1.OpKind.FAILING_NOOP,
|
|
612
|
+
arbitrary: params.arbitrary,
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
},
|
|
616
|
+
};
|
|
686
617
|
}
|
|
687
618
|
/**
|
|
688
619
|
*
|
|
689
|
-
*
|
|
620
|
+
* Create an smart contract abstraction for the address specified.
|
|
690
621
|
*
|
|
691
622
|
* @param address Smart contract address
|
|
692
623
|
* @throws {@link InvalidContractAddressError}
|
|
693
624
|
*/
|
|
694
|
-
at(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
625
|
+
async at(address, contractAbstractionComposer = (x) => x, block = 'head') {
|
|
626
|
+
const addressValidation = (0, utils_1.validateContractAddress)(address);
|
|
627
|
+
if (addressValidation !== utils_1.ValidationResult.VALID) {
|
|
628
|
+
throw new core_1.InvalidContractAddressError(address, addressValidation);
|
|
629
|
+
}
|
|
630
|
+
const rpc = this.context.withExtensions().rpc;
|
|
631
|
+
const readProvider = this.context.withExtensions().readProvider;
|
|
632
|
+
const loadContractState = async (requestedBlock) => {
|
|
633
|
+
const script = await readProvider.getScript(address, requestedBlock);
|
|
634
|
+
const entrypoints = requestedBlock === 'head'
|
|
635
|
+
? await readProvider.getEntrypoints(address)
|
|
636
|
+
: await rpc.getEntrypoints(address, { block: String(requestedBlock) });
|
|
637
|
+
return { script, entrypoints };
|
|
638
|
+
};
|
|
639
|
+
let contractState;
|
|
640
|
+
try {
|
|
641
|
+
contractState = await loadContractState(block);
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
// Shadownet's rolling nodes occasionally 404 a just-originated contract at the exact
|
|
645
|
+
// inclusion level even after confirmation. Retry at head so the contract abstraction still
|
|
646
|
+
// resolves once the node's contract index catches up.
|
|
647
|
+
if (block !== 'head' &&
|
|
648
|
+
error instanceof http_utils_1.HttpResponseError &&
|
|
649
|
+
error.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
|
|
650
|
+
contractState = await loadContractState('head');
|
|
699
651
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
});
|
|
652
|
+
else {
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const abs = new contract_1.ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider);
|
|
657
|
+
return contractAbstractionComposer(abs, this.context);
|
|
707
658
|
}
|
|
708
659
|
/**
|
|
709
660
|
*
|
|
710
|
-
*
|
|
661
|
+
* Batch a group of operation together. Operations will be applied in the order in which they are added to the batch
|
|
711
662
|
*
|
|
712
663
|
* @returns A batch object from which we can add more operation or send a command to execute the batch
|
|
713
664
|
*
|