@aztec/cli-wallet 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891
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/dest/bin/index.d.ts +2 -1
- package/dest/bin/index.js +20 -10
- package/dest/cmds/authorize_action.d.ts +2 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +5 -3
- package/dest/cmds/bridge_fee_juice.d.ts +2 -2
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +3 -2
- package/dest/cmds/check_tx.d.ts +1 -1
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +44 -15
- package/dest/cmds/create_account.d.ts +4 -3
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +32 -18
- package/dest/cmds/create_authwit.d.ts +1 -1
- package/dest/cmds/create_authwit.js +1 -1
- package/dest/cmds/deploy.d.ts +1 -1
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +50 -24
- package/dest/cmds/deploy_account.d.ts +1 -1
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +31 -17
- package/dest/cmds/import_test_accounts.d.ts +1 -1
- package/dest/cmds/index.d.ts +1 -1
- package/dest/cmds/index.js +3 -3
- package/dest/cmds/profile.d.ts +1 -1
- package/dest/cmds/profile.js +1 -1
- package/dest/cmds/register_contract.d.ts +1 -1
- package/dest/cmds/register_sender.d.ts +1 -1
- package/dest/cmds/send.d.ts +2 -2
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +33 -18
- package/dest/cmds/simulate.d.ts +1 -1
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +4 -4
- package/dest/storage/wallet_db.d.ts +5 -5
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +47 -32
- package/dest/utils/authorizations.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -1
- package/dest/utils/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +7 -0
- package/dest/utils/ecdsa.d.ts +1 -1
- package/dest/utils/options/fees.d.ts +3 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +5 -3
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/profiling.d.ts.map +1 -1
- package/dest/utils/profiling.js +9 -1
- package/dest/utils/wallet.d.ts +15 -10
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +68 -47
- package/package.json +17 -14
- package/src/bin/index.ts +18 -12
- package/src/cmds/authorize_action.ts +2 -2
- package/src/cmds/bridge_fee_juice.ts +3 -2
- package/src/cmds/check_tx.ts +50 -21
- package/src/cmds/create_account.ts +32 -20
- package/src/cmds/create_authwit.ts +1 -1
- package/src/cmds/deploy.ts +45 -23
- package/src/cmds/deploy_account.ts +29 -18
- package/src/cmds/index.ts +4 -4
- package/src/cmds/profile.ts +1 -1
- package/src/cmds/send.ts +27 -12
- package/src/cmds/simulate.ts +5 -8
- package/src/storage/wallet_db.ts +51 -38
- package/src/utils/cli_wallet_and_node_wrapper.ts +1 -1
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +11 -4
- package/src/utils/options/options.ts +1 -1
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +83 -62
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
4
|
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
|
-
import { Fr } from '@aztec/foundation/
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
8
|
+
import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
7
9
|
|
|
8
10
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
11
|
+
import type { AccountType } from '../utils/constants.js';
|
|
9
12
|
import { CLIFeeArgs } from '../utils/options/fees.js';
|
|
10
13
|
import { printProfileResult } from '../utils/profiling.js';
|
|
11
|
-
import {
|
|
14
|
+
import { CLIWallet } from '../utils/wallet.js';
|
|
12
15
|
|
|
13
16
|
export async function createAccount(
|
|
14
17
|
wallet: CLIWallet,
|
|
@@ -63,8 +66,8 @@ export async function createAccount(
|
|
|
63
66
|
log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
let
|
|
67
|
-
let txReceipt;
|
|
69
|
+
let txHash: TxHash | undefined;
|
|
70
|
+
let txReceipt: TxReceipt | undefined;
|
|
68
71
|
if (!registerOnly) {
|
|
69
72
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
70
73
|
|
|
@@ -80,10 +83,13 @@ export async function createAccount(
|
|
|
80
83
|
};
|
|
81
84
|
|
|
82
85
|
const deployMethod = await account.getDeployMethod();
|
|
83
|
-
const
|
|
86
|
+
const sim = await deployMethod.simulate({
|
|
84
87
|
...deployAccountOpts,
|
|
85
88
|
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
86
89
|
});
|
|
90
|
+
// estimateGas: true guarantees these fields are present
|
|
91
|
+
const estimatedGas = sim.estimatedGas!;
|
|
92
|
+
const stats = sim.stats!;
|
|
87
93
|
|
|
88
94
|
if (feeOpts.estimateOnly) {
|
|
89
95
|
if (json) {
|
|
@@ -99,7 +105,14 @@ export async function createAccount(
|
|
|
99
105
|
};
|
|
100
106
|
}
|
|
101
107
|
} else {
|
|
102
|
-
|
|
108
|
+
if (verbose) {
|
|
109
|
+
printProfileResult(stats, log);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!json) {
|
|
113
|
+
log(`\nWaiting for account contract deployment...`);
|
|
114
|
+
}
|
|
115
|
+
const sendOpts = {
|
|
103
116
|
...deployAccountOpts,
|
|
104
117
|
fee: deployAccountOpts.fee
|
|
105
118
|
? {
|
|
@@ -107,32 +120,31 @@ export async function createAccount(
|
|
|
107
120
|
gasSettings: estimatedGas,
|
|
108
121
|
}
|
|
109
122
|
: undefined,
|
|
110
|
-
}
|
|
111
|
-
if (verbose) {
|
|
112
|
-
printProfileResult(stats, log);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const txHash = await tx.getTxHash();
|
|
116
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
117
|
-
out.txHash = txHash;
|
|
123
|
+
};
|
|
118
124
|
if (wait) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
const { receipt } = await deployMethod.send({
|
|
126
|
+
...sendOpts,
|
|
127
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true },
|
|
128
|
+
});
|
|
129
|
+
txReceipt = receipt;
|
|
130
|
+
txHash = receipt.txHash;
|
|
123
131
|
out.txReceipt = {
|
|
124
132
|
status: txReceipt.status,
|
|
125
133
|
transactionFee: txReceipt.transactionFee,
|
|
126
134
|
};
|
|
135
|
+
} else {
|
|
136
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
127
137
|
}
|
|
138
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
139
|
+
out.txHash = txHash;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
if (json) {
|
|
132
144
|
log(prettyPrintJSON(out));
|
|
133
145
|
} else {
|
|
134
|
-
if (
|
|
135
|
-
log(`Deploy tx hash: ${
|
|
146
|
+
if (txHash) {
|
|
147
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
136
148
|
}
|
|
137
149
|
if (txReceipt) {
|
|
138
150
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
|
@@ -28,7 +28,7 @@ export async function createAuthwit(
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const contract =
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
32
32
|
const call = await contract.methods[functionName](...functionArgs).getFunctionCall();
|
|
33
33
|
|
|
34
34
|
const witness = await wallet.createAuthWit(from, { caller, call });
|
package/src/cmds/deploy.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import type { DeployOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
3
4
|
import { ContractDeployer } from '@aztec/aztec.js/deployment';
|
|
4
5
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
5
6
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
@@ -70,10 +71,13 @@ export async function deploy(
|
|
|
70
71
|
skipInstancePublication,
|
|
71
72
|
};
|
|
72
73
|
|
|
73
|
-
const
|
|
74
|
+
const sim = await deploy.simulate({
|
|
74
75
|
...deployOpts,
|
|
75
76
|
fee: { ...deployOpts.fee, estimateGas: true },
|
|
76
77
|
});
|
|
78
|
+
// estimateGas: true guarantees these fields are present
|
|
79
|
+
const estimatedGas = sim.estimatedGas!;
|
|
80
|
+
const stats = sim.stats!;
|
|
77
81
|
|
|
78
82
|
if (feeOpts.estimateOnly) {
|
|
79
83
|
if (json) {
|
|
@@ -89,37 +93,55 @@ export async function deploy(
|
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
95
|
} else {
|
|
92
|
-
const tx = deploy.send(deployOpts);
|
|
93
96
|
if (verbose) {
|
|
94
97
|
printProfileResult(stats, log);
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
const txHash = await tx.getTxHash();
|
|
98
|
-
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
99
|
-
out.hash = txHash;
|
|
100
100
|
const { address, partialAddress } = deploy;
|
|
101
101
|
const instance = await deploy.getInstance();
|
|
102
|
-
|
|
103
|
-
log(`Contract deployed at ${address?.toString()}`);
|
|
104
|
-
log(`Contract partial address ${(await partialAddress)?.toString()}`);
|
|
105
|
-
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
106
|
-
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
107
|
-
log(`Deployment salt: ${salt.toString()}`);
|
|
108
|
-
log(`Deployer: ${instance.deployer.toString()}`);
|
|
109
|
-
} else {
|
|
110
|
-
out.contract = {
|
|
111
|
-
address: address?.toString(),
|
|
112
|
-
partialAddress: (await partialAddress)?.toString(),
|
|
113
|
-
initializationHash: instance.initializationHash.toString(),
|
|
114
|
-
salt: salt.toString(),
|
|
115
|
-
};
|
|
116
|
-
}
|
|
102
|
+
|
|
117
103
|
if (wait) {
|
|
118
|
-
const
|
|
104
|
+
const { receipt } = await deploy.send({ ...deployOpts, wait: { timeout, returnReceipt: true } });
|
|
105
|
+
const txHash = receipt.txHash;
|
|
106
|
+
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
107
|
+
out.hash = txHash;
|
|
108
|
+
|
|
109
|
+
if (!json) {
|
|
110
|
+
log(`Contract deployed at ${address?.toString()}`);
|
|
111
|
+
log(`Contract partial address ${(await partialAddress)?.toString()}`);
|
|
112
|
+
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
113
|
+
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
114
|
+
log(`Deployment salt: ${salt.toString()}`);
|
|
115
|
+
log(`Deployer: ${instance.deployer.toString()}`);
|
|
116
|
+
log(`Transaction fee: ${receipt.transactionFee?.toString()}`);
|
|
117
|
+
} else {
|
|
118
|
+
out.contract = {
|
|
119
|
+
address: address?.toString(),
|
|
120
|
+
partialAddress: (await partialAddress)?.toString(),
|
|
121
|
+
initializationHash: instance.initializationHash.toString(),
|
|
122
|
+
salt: salt.toString(),
|
|
123
|
+
transactionFee: receipt.transactionFee?.toString(),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
|
|
128
|
+
debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
|
|
129
|
+
out.hash = txHash;
|
|
130
|
+
|
|
119
131
|
if (!json) {
|
|
120
|
-
log(`
|
|
132
|
+
log(`Contract deployed at ${address?.toString()}`);
|
|
133
|
+
log(`Contract partial address ${(await partialAddress)?.toString()}`);
|
|
134
|
+
log(`Contract init hash ${instance.initializationHash.toString()}`);
|
|
135
|
+
log(`Deployment tx hash: ${txHash.toString()}`);
|
|
136
|
+
log(`Deployment salt: ${salt.toString()}`);
|
|
137
|
+
log(`Deployer: ${instance.deployer.toString()}`);
|
|
121
138
|
} else {
|
|
122
|
-
out.contract
|
|
139
|
+
out.contract = {
|
|
140
|
+
address: address?.toString(),
|
|
141
|
+
partialAddress: (await partialAddress)?.toString(),
|
|
142
|
+
initializationHash: instance.initializationHash.toString(),
|
|
143
|
+
salt: salt.toString(),
|
|
144
|
+
};
|
|
123
145
|
}
|
|
124
146
|
}
|
|
125
147
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
4
|
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
6
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
7
|
+
import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
6
8
|
|
|
7
9
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
8
10
|
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
@@ -45,8 +47,8 @@ export async function deployAccount(
|
|
|
45
47
|
log(`Init hash: ${initializationHash.toString()}`);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
let
|
|
49
|
-
let txReceipt;
|
|
50
|
+
let txHash: TxHash | undefined;
|
|
51
|
+
let txReceipt: TxReceipt | undefined;
|
|
50
52
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
51
53
|
|
|
52
54
|
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
@@ -61,10 +63,13 @@ export async function deployAccount(
|
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
const deployMethod = await account.getDeployMethod();
|
|
64
|
-
const
|
|
66
|
+
const sim = await deployMethod.simulate({
|
|
65
67
|
...deployAccountOpts,
|
|
66
68
|
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
67
69
|
});
|
|
70
|
+
// estimateGas: true guarantees these fields are present
|
|
71
|
+
const estimatedGas = sim.estimatedGas!;
|
|
72
|
+
const stats = sim.stats!;
|
|
68
73
|
|
|
69
74
|
if (feeOpts.estimateOnly) {
|
|
70
75
|
if (json) {
|
|
@@ -80,7 +85,14 @@ export async function deployAccount(
|
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
} else {
|
|
83
|
-
|
|
88
|
+
if (verbose) {
|
|
89
|
+
printProfileResult(stats, log);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!json) {
|
|
93
|
+
log(`\nWaiting for account contract deployment...`);
|
|
94
|
+
}
|
|
95
|
+
const sendOpts = {
|
|
84
96
|
...deployAccountOpts,
|
|
85
97
|
fee: deployAccountOpts.fee
|
|
86
98
|
? {
|
|
@@ -88,31 +100,30 @@ export async function deployAccount(
|
|
|
88
100
|
gasSettings: estimatedGas,
|
|
89
101
|
}
|
|
90
102
|
: undefined,
|
|
91
|
-
}
|
|
92
|
-
if (verbose) {
|
|
93
|
-
printProfileResult(stats, log);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const txHash = await tx.getTxHash();
|
|
97
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
98
|
-
out.txHash = txHash;
|
|
103
|
+
};
|
|
99
104
|
if (wait) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
const { receipt } = await deployMethod.send({
|
|
106
|
+
...sendOpts,
|
|
107
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true },
|
|
108
|
+
});
|
|
109
|
+
txReceipt = receipt;
|
|
110
|
+
txHash = receipt.txHash;
|
|
104
111
|
out.txReceipt = {
|
|
105
112
|
status: txReceipt.status,
|
|
106
113
|
transactionFee: txReceipt.transactionFee,
|
|
107
114
|
};
|
|
115
|
+
} else {
|
|
116
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
108
117
|
}
|
|
118
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
119
|
+
out.txHash = txHash;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
if (json) {
|
|
112
123
|
log(prettyPrintJSON(out));
|
|
113
124
|
} else {
|
|
114
|
-
if (
|
|
115
|
-
log(`Deploy tx hash: ${
|
|
125
|
+
if (txHash) {
|
|
126
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
116
127
|
}
|
|
117
128
|
if (txReceipt) {
|
|
118
129
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
package/src/cmds/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
parseFieldFromHexString,
|
|
11
11
|
parsePublicKey,
|
|
12
12
|
} from '@aztec/cli/utils';
|
|
13
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
13
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
14
14
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
15
15
|
|
|
16
16
|
import { type Command, Option } from 'commander';
|
|
@@ -18,6 +18,7 @@ import inquirer from 'inquirer';
|
|
|
18
18
|
|
|
19
19
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
20
20
|
import type { CliWalletAndNodeWrapper } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
21
|
+
import type { AccountType } from '../utils/constants.js';
|
|
21
22
|
import {
|
|
22
23
|
ARTIFACT_DESCRIPTION,
|
|
23
24
|
CLIFeeArgs,
|
|
@@ -38,7 +39,6 @@ import {
|
|
|
38
39
|
createVerboseOption,
|
|
39
40
|
integerArgParser,
|
|
40
41
|
} from '../utils/options/index.js';
|
|
41
|
-
import type { AccountType } from '../utils/wallet.js';
|
|
42
42
|
|
|
43
43
|
// TODO: This function is only used in 1 place so we could just inline this
|
|
44
44
|
export function injectCommands(
|
|
@@ -63,7 +63,7 @@ export function injectCommands(
|
|
|
63
63
|
const createAccountCommand = program
|
|
64
64
|
.command('create-account')
|
|
65
65
|
.description(
|
|
66
|
-
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr
|
|
66
|
+
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr account which uses an immutable key for authentication.',
|
|
67
67
|
)
|
|
68
68
|
.summary('Creates an aztec account that can be used for sending transactions.')
|
|
69
69
|
.addOption(createAccountOption('Alias or address of the account performing the deployment', !db, db))
|
|
@@ -346,7 +346,7 @@ export function injectCommands(
|
|
|
346
346
|
log,
|
|
347
347
|
);
|
|
348
348
|
if (db && sentTx) {
|
|
349
|
-
const txAlias = alias ? alias : `${functionName}-${randomBytes(16).toString()}`;
|
|
349
|
+
const txAlias = alias ? alias : `${functionName}-${randomBytes(16).toString('hex')}`;
|
|
350
350
|
await db.storeTx(sentTx, log, txAlias);
|
|
351
351
|
}
|
|
352
352
|
});
|
package/src/cmds/profile.ts
CHANGED
|
@@ -28,7 +28,7 @@ export async function profile(
|
|
|
28
28
|
) {
|
|
29
29
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
30
30
|
|
|
31
|
-
const contract =
|
|
31
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
32
32
|
const call = contract.methods[functionName](...functionArgs);
|
|
33
33
|
|
|
34
34
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
package/src/cmds/send.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import { Contract, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
6
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
@@ -27,7 +27,7 @@ export async function send(
|
|
|
27
27
|
) {
|
|
28
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
29
29
|
|
|
30
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
31
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
32
32
|
|
|
33
33
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
@@ -37,40 +37,55 @@ export async function send(
|
|
|
37
37
|
authWitnesses,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const sim = await call.simulate({
|
|
41
41
|
...sendOptions,
|
|
42
42
|
fee: { ...sendOptions.fee, estimateGas: true },
|
|
43
43
|
});
|
|
44
|
+
// estimateGas: true guarantees these fields are present
|
|
45
|
+
const estimatedGas = sim.estimatedGas!;
|
|
46
|
+
const stats = sim.stats!;
|
|
44
47
|
|
|
45
48
|
if (feeOpts.estimateOnly) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
const tx = call.send({ ...sendOptions, fee: { ...sendOptions.fee, gasSettings: estimatedGas } });
|
|
50
52
|
if (verbose) {
|
|
51
53
|
printProfileResult(stats!, log);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
const txHash = await tx.getTxHash();
|
|
55
|
-
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
56
56
|
if (wait) {
|
|
57
57
|
try {
|
|
58
|
-
await
|
|
58
|
+
const { receipt } = await call.send({
|
|
59
|
+
...sendOptions,
|
|
60
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
61
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S },
|
|
62
|
+
});
|
|
59
63
|
|
|
64
|
+
const txHash = receipt.txHash;
|
|
65
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
60
66
|
log('Transaction has been mined');
|
|
61
|
-
|
|
62
|
-
const receipt = await tx.getReceipt();
|
|
63
67
|
log(` Tx fee: ${receipt.transactionFee}`);
|
|
64
68
|
log(` Status: ${receipt.status}`);
|
|
65
69
|
log(` Block number: ${receipt.blockNumber}`);
|
|
66
70
|
log(` Block hash: ${receipt.blockHash?.toString()}`);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
txHash,
|
|
74
|
+
};
|
|
67
75
|
} catch (err: any) {
|
|
68
76
|
log(`Transaction failed\n ${err.message}`);
|
|
77
|
+
throw err;
|
|
69
78
|
}
|
|
70
79
|
} else {
|
|
80
|
+
const { txHash } = await call.send({
|
|
81
|
+
...sendOptions,
|
|
82
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
83
|
+
wait: NO_WAIT,
|
|
84
|
+
});
|
|
85
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
71
86
|
log('Transaction pending. Check status with check-tx');
|
|
87
|
+
return {
|
|
88
|
+
txHash,
|
|
89
|
+
};
|
|
72
90
|
}
|
|
73
|
-
return {
|
|
74
|
-
txHash,
|
|
75
|
-
};
|
|
76
91
|
}
|
package/src/cmds/simulate.ts
CHANGED
|
@@ -27,7 +27,7 @@ export async function simulate(
|
|
|
27
27
|
) {
|
|
28
28
|
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
|
|
29
29
|
|
|
30
|
-
const contract =
|
|
30
|
+
const contract = Contract.at(contractAddress, contractArtifact, wallet);
|
|
31
31
|
const call = contract.methods[functionName](...functionArgs);
|
|
32
32
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
|
|
33
33
|
const simulationResult = await call.simulate({
|
|
@@ -38,17 +38,14 @@ export async function simulate(
|
|
|
38
38
|
});
|
|
39
39
|
if (verbose) {
|
|
40
40
|
await printAuthorizations(
|
|
41
|
-
simulationResult.offchainEffects
|
|
41
|
+
simulationResult.offchainEffects,
|
|
42
42
|
async (address: AztecAddress) => {
|
|
43
43
|
const metadata = await wallet.getContractMetadata(address);
|
|
44
|
-
if (!metadata.
|
|
44
|
+
if (!metadata.instance) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
true,
|
|
50
|
-
);
|
|
51
|
-
return classMetadata.artifact;
|
|
47
|
+
const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
|
|
48
|
+
return artifact;
|
|
52
49
|
},
|
|
53
50
|
log,
|
|
54
51
|
);
|
package/src/storage/wallet_db.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
4
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import type { TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
|
+
import type { AccountType } from '../utils/constants.js';
|
|
8
9
|
import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
|
|
9
|
-
import type { AccountType } from '../utils/wallet.js';
|
|
10
10
|
|
|
11
11
|
export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
|
|
12
12
|
export type AliasType = (typeof Aliases)[number];
|
|
13
13
|
|
|
14
14
|
export class WalletDB {
|
|
15
|
+
#store!: AztecAsyncKVStore;
|
|
15
16
|
#accounts!: AztecAsyncMap<string, Buffer>;
|
|
16
17
|
#aliases!: AztecAsyncMap<string, Buffer>;
|
|
17
18
|
#bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
|
|
@@ -29,6 +30,7 @@ export class WalletDB {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async init(store: AztecAsyncKVStore) {
|
|
33
|
+
this.#store = store;
|
|
32
34
|
this.#accounts = store.openMap('accounts');
|
|
33
35
|
this.#aliases = store.openMap('aliases');
|
|
34
36
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
@@ -41,14 +43,17 @@ export class WalletDB {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
await this.#store.transactionAsync(async () => {
|
|
47
|
+
let stackPointer =
|
|
48
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
49
|
+
stackPointer++;
|
|
50
|
+
await this.#bridgedFeeJuice.set(
|
|
51
|
+
`${recipient.toString()}:${stackPointer}`,
|
|
52
|
+
Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
|
|
53
|
+
);
|
|
54
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
|
|
55
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
@@ -76,19 +81,24 @@ export class WalletDB {
|
|
|
76
81
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
77
82
|
log: LogFn,
|
|
78
83
|
) {
|
|
79
|
-
|
|
80
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
81
|
-
}
|
|
82
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
83
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
84
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
84
|
+
let publicSigningKey: Buffer | undefined;
|
|
85
85
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
86
|
-
|
|
87
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
86
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
88
87
|
}
|
|
89
|
-
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
90
|
-
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
91
88
|
|
|
89
|
+
await this.#store.transactionAsync(async () => {
|
|
90
|
+
if (alias) {
|
|
91
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
92
|
+
}
|
|
93
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
94
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
95
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
96
|
+
if (publicSigningKey) {
|
|
97
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
98
|
+
}
|
|
99
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
100
|
+
});
|
|
101
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
92
102
|
await this.refreshAliasCache();
|
|
93
103
|
}
|
|
94
104
|
|
|
@@ -100,35 +110,38 @@ export class WalletDB {
|
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
await this.#store.transactionAsync(async () => {
|
|
114
|
+
if (alias) {
|
|
115
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
116
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
119
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
120
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
121
|
+
});
|
|
110
122
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
111
|
-
|
|
112
123
|
await this.refreshAliasCache();
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
130
|
+
}
|
|
131
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
132
|
+
});
|
|
120
133
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
121
|
-
|
|
122
134
|
await this.refreshAliasCache();
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
await this.#store.transactionAsync(async () => {
|
|
139
|
+
if (alias) {
|
|
140
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
141
|
+
}
|
|
142
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
143
|
+
});
|
|
130
144
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
131
|
-
|
|
132
145
|
await this.refreshAliasCache();
|
|
133
146
|
}
|
|
134
147
|
|