Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to manually specify fee payer nonce #497

Merged
merged 5 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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.
- 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 }, () => {})`
Trivo25 marked this conversation as resolved.
Show resolved Hide resolved

### Changed

Expand Down
19 changes: 16 additions & 3 deletions src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ let currentTransaction = Context.create<CurrentTransaction>();

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) {
Expand All @@ -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(),
Expand Down Expand Up @@ -154,11 +160,18 @@ function createTransaction(
if (feePayerKey !== undefined) {
// if senderKey is provided, fetch account to get nonce and mark to be signed
let senderAddress = feePayerKey.toPublicKey();
let senderAccount = getAccount(senderAddress, TokenId.default);

let nonce_;
if (!nonce) {
Trivo25 marked this conversation as resolved.
Show resolved Hide resolved
let senderAccount = getAccount(senderAddress, TokenId.default);
nonce_ = senderAccount.nonce;
} else {
nonce_ = UInt32.fromNumber(nonce);
}
feePayerAccountUpdate = AccountUpdate.defaultFeePayer(
senderAddress,
feePayerKey,
senderAccount.nonce
nonce_
);
if (fee !== undefined) {
feePayerAccountUpdate.body.fee =
Expand Down