koilib 5.2.1 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/koinos.js CHANGED
@@ -10167,6 +10167,9 @@ class Contract {
10167
10167
  }),
10168
10168
  },
10169
10169
  };
10170
+ if (opts.onlyOperation) {
10171
+ return { operation };
10172
+ }
10170
10173
  let tx = await this.signer.prepareTransaction({
10171
10174
  header: {
10172
10175
  ...(opts.chainId && { chain_id: opts.chainId }),
@@ -10175,7 +10178,11 @@ class Contract {
10175
10178
  ...(opts.payer && { payer: opts.payer }),
10176
10179
  ...(opts.payee && { payee: opts.payee }),
10177
10180
  },
10178
- operations: [operation],
10181
+ operations: [
10182
+ ...(opts.previousOperations ? opts.previousOperations : []),
10183
+ operation,
10184
+ ...(opts.nextOperations ? opts.nextOperations : []),
10185
+ ],
10179
10186
  });
10180
10187
  const optsSend = {
10181
10188
  broadcast: opts.broadcast,
@@ -10388,8 +10395,8 @@ class Provider {
10388
10395
  }
10389
10396
  /**
10390
10397
  * Function to call "chain.get_account_nonce" to return the number of
10391
- * transactions for a particular account. This call is used
10392
- * when creating new transactions.
10398
+ * transactions for a particular account. If you are creating a new
10399
+ * transaction consider using [[Provider.getNextNonce]].
10393
10400
  * @param account - account address
10394
10401
  * @param deserialize - If set true it will deserialize the nonce
10395
10402
  * and return it as number (default). If set false it will return
@@ -10410,6 +10417,25 @@ class Provider {
10410
10417
  // todo: consider the case where nonce is greater than max safe integer
10411
10418
  return Number(object.uint64_value);
10412
10419
  }
10420
+ /**
10421
+ * Function to call "chain.get_account_nonce" (number of
10422
+ * transactions for a particular account) and return the next nonce.
10423
+ * This call is used when creating new transactions. The result is
10424
+ * encoded in base64url
10425
+ * @param account - account address
10426
+ * @returns Nonce
10427
+ */
10428
+ async getNextNonce(account) {
10429
+ const oldNonce = (await this.getNonce(account));
10430
+ const message = protocol_proto_js_1.koinos.chain.value_type.create({
10431
+ // todo: consider using bigint for big nonces
10432
+ uint64_value: String(oldNonce + 1),
10433
+ });
10434
+ const nonceEncoded = protocol_proto_js_1.koinos.chain.value_type
10435
+ .encode(message)
10436
+ .finish();
10437
+ return (0, utils_1.encodeBase64url)(nonceEncoded);
10438
+ }
10413
10439
  async getAccountRc(account) {
10414
10440
  const { rc } = await this.call("chain.get_account_rc", {
10415
10441
  account,
@@ -11390,15 +11416,7 @@ class Signer {
11390
11416
  if (tx.header.nonce === undefined) {
11391
11417
  if (!this.provider)
11392
11418
  throw new Error("Cannot get the nonce because provider is undefined. To skip this call set a nonce in the transaction header");
11393
- const oldNonce = (await this.provider.getNonce(payee || payer));
11394
- const message = protocol_proto_js_1.koinos.chain.value_type.create({
11395
- // todo: consider using bigint for big nonces
11396
- uint64_value: String(oldNonce + 1),
11397
- });
11398
- const nonceEncoded = protocol_proto_js_1.koinos.chain.value_type
11399
- .encode(message)
11400
- .finish();
11401
- nonce = (0, utils_1.encodeBase64url)(nonceEncoded);
11419
+ nonce = await this.provider.getNextNonce(payee || payer);
11402
11420
  }
11403
11421
  else {
11404
11422
  nonce = tx.header.nonce;