diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdfb086c..f43a98f18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,11 +30,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Also replaces `Experimental.accountUpdateFromCallback()` - `Circuit.log()` to easily log Fields and other provable types inside a method, with the same API as `console.log()` - `AccountUpdate.attachToTransaction()` for explicitly adding an account update to the current transaction. This replaces some previous behaviour where an account update got attached implicitly. +- ### Changed - BREAKING CHANGE: `tx.send()` is now asynchronous: old: `send(): TransactionId` new: `send(): Promise` and `tx.send()` now directly waits for the network response, as opposed to `tx.send().wait()` - `Circuit.witness` can now be called outside circuits, where it will just directly return the callback result +- The `FeePayerSpec`, which is used to specify properties of the transaction via `Mina.transaction()`, now has another optional parameter to specify the nonce manually. `Mina.transaction({ feePayerKey: feePayer, nonce: 1 }, () => {})` - BREAKING CHANGE: Static methods of type `.fromString()`, `.fromNumber()` and `.fromBigInt()` on `Field`, `UInt64`, `UInt32` and `Int64` are not longer supported. ### Deprecated diff --git a/src/lib/mina.ts b/src/lib/mina.ts index 5351212bd..aaa74404b 100644 --- a/src/lib/mina.ts +++ b/src/lib/mina.ts @@ -78,7 +78,12 @@ let currentTransaction = Context.create(); type FeePayerSpec = | PrivateKey - | { feePayerKey: PrivateKey; fee?: number | string | UInt64; memo?: string } + | { + feePayerKey: PrivateKey; + fee?: number | string | UInt64; + memo?: string; + nonce?: number; + } | undefined; function reportGetAccountError(publicKey: string, tokenId: string) { @@ -105,6 +110,7 @@ function createTransaction( feePayer instanceof PrivateKey ? feePayer : feePayer?.feePayerKey; let fee = feePayer instanceof PrivateKey ? undefined : feePayer?.fee; let memo = feePayer instanceof PrivateKey ? '' : feePayer?.memo ?? ''; + let nonce = feePayer instanceof PrivateKey ? undefined : feePayer?.nonce; let transactionId = currentTransaction.enter({ sender: feePayerKey?.toPublicKey(), @@ -154,11 +160,29 @@ function createTransaction( if (feePayerKey !== undefined) { // if senderKey is provided, fetch account to get nonce and mark to be signed let senderAddress = feePayerKey.toPublicKey(); + + let nonce_; let senderAccount = getAccount(senderAddress, TokenId.default); + + if (nonce === undefined) { + nonce_ = senderAccount.nonce; + } else { + nonce_ = UInt32.fromNumber(nonce); + senderAccount.nonce = nonce_; + Fetch.addCachedAccount({ + nonce: senderAccount.nonce, + publicKey: senderAccount.publicKey, + tokenId: senderAccount.tokenId.toString(), + balance: senderAccount.balance, + zkapp: { + appState: senderAccount.appState ?? [], + }, + }); + } feePayerAccountUpdate = AccountUpdate.defaultFeePayer( senderAddress, feePayerKey, - senderAccount.nonce + nonce_ ); if (fee !== undefined) { feePayerAccountUpdate.body.fee =