Skip to content

Commit

Permalink
Revert "Remove to/from from txdao, replace with 'origin' (#1024)"
Browse files Browse the repository at this point in the history
This reverts commit 2611e7c.
  • Loading branch information
spalladino committed Jul 11, 2023
1 parent 2611e7c commit cd7d823
Show file tree
Hide file tree
Showing 28 changed files with 93 additions and 75 deletions.
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, TxRequest<NCT> con

template <typename NCT> std::ostream& operator<<(std::ostream& os, TxRequest<NCT> const& tx_request)
{
return os << "origin: " << tx_request.origin << "\n"
return os << "from: " << tx_request.origin << "\n"
<< "function_data: " << tx_request.function_data << "\n"
<< "args_hash: " << tx_request.args_hash << "\n"
<< "tx_context: " << tx_request.tx_context << "\n";
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function main() {
.argument('[functionArgs...]', 'Function arguments', [])
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', 'http://localhost:8080')
.action(async (contractFile, _contractAddress, functionName, _from, _functionArgs, options) => {
const { contractAddress, functionArgs, origin, contractAbi } = prepTx(
const { contractAddress, functionArgs, from, contractAbi } = prepTx(
contractFile,
_contractAddress,
functionName,
Expand All @@ -217,7 +217,7 @@ async function main() {
const client = createAztecRpcClient(options.rpcUrl);
const wallet = await createAccounts(client);
const contract = new Contract(contractAddress, contractAbi, wallet);
const tx = contract.methods[functionName](...functionArgs).send({ origin });
const tx = contract.methods[functionName](...functionArgs).send({ from });
await tx.isMined();
log('TX has been mined');
const receipt = await tx.getReceipt();
Expand All @@ -236,7 +236,7 @@ async function main() {
.argument('[functionArgs...]', 'Function arguments', [])
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', 'http://localhost:8080')
.action(async (contractFile, _contractAddress, functionName, _from, _functionArgs, options) => {
const { contractAddress, functionArgs, origin } = prepTx(
const { contractAddress, functionArgs, from } = prepTx(
contractFile,
_contractAddress,
functionName,
Expand All @@ -245,7 +245,7 @@ async function main() {
log,
);
const client = createAztecRpcClient(options.rpcUrl);
const result = await client.viewTx(functionName, functionArgs, contractAddress, origin);
const result = await client.viewTx(functionName, functionArgs, contractAddress, from);
log('View TX returned result: ', JsonStringify(result, true));
});

Expand Down
14 changes: 7 additions & 7 deletions yarn-project/aztec-cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function getContractAbi(fileDir: string, log: Logger) {
* @param contractFile - Directory of the compiled contract ABI.
* @param _contractAddress - Aztec Address of the contract.
* @param functionName - Name of the function to be called.
* @param _origin - The caller's address.
* @param _from - The caller's address.
* @param _functionArgs - Arguments to call the function with.
* @param log - Logger instance that will output to the CLI
* @returns Formatted contract address, function arguments and caller's aztec address.
Expand All @@ -56,7 +56,7 @@ export function prepTx(
contractFile: string,
_contractAddress: string,
functionName: string,
_origin: string,
_from: string,
_functionArgs: string[],
log: Logger,
) {
Expand All @@ -73,14 +73,14 @@ export function prepTx(
}

const functionArgs = encodeArgs(_functionArgs, functionAbi.parameters);
let origin;
if (_origin) {
let from;
if (_from) {
try {
origin = AztecAddress.fromString(_origin);
from = AztecAddress.fromString(_from);
} catch {
throw new Error(`Unable to parse caller address ${_origin}.`);
throw new Error(`Unable to parse caller address ${_from}.`);
}
}

return { contractAddress, functionArgs, origin, contractAbi };
return { contractAddress, functionArgs, from, contractAbi };
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('Account State', () => {
expect(txs).toEqual([
expect.objectContaining({
blockNumber: 1,
origin: ownerAddress,
from: ownerAddress,
}),
]);
expect(addNoteSpendingInfoBatchSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -125,15 +125,15 @@ describe('Account State', () => {
expect(txs).toEqual([
expect.objectContaining({
blockNumber: 2,
origin: ownerAddress,
from: ownerAddress,
}),
expect.objectContaining({
blockNumber: 5,
origin: ownerAddress,
from: ownerAddress,
}),
expect.objectContaining({
blockNumber: 5,
origin: ownerAddress,
from: ownerAddress,
}),
]);
expect(addNoteSpendingInfoBatchSpy).toHaveBeenCalledTimes(1);
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/aztec-rpc/src/account_state/account_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,15 @@ export class AccountState {
const { newContractData } = blockContext.block.getTx(txIndex);
const isContractDeployment = !newContractData[0].contractAddress.isZero();
const noteSpendingInfo = noteSpendingInfoDaos[j];
const contractAddress = isContractDeployment ? noteSpendingInfo.contractAddress : undefined;
const [to, contractAddress] = isContractDeployment
? [undefined, noteSpendingInfo.contractAddress]
: [noteSpendingInfo.contractAddress, undefined];
txDaos.push({
txHash,
blockHash: blockContext.getBlockHash(),
blockNumber: blockContext.block.number,
origin: this.address,
from: this.address,
to,
contractAddress,
error: '',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export class AztecRPCServer implements AztecRPC {
await this.db.addTx(
TxDao.from({
txHash: await tx.getTxHash(),
origin: account.getAddress(),
from: account.getAddress(),
to: account.getAddress(),
contractAddress: deployedContractAddress,
}),
);
Expand Down Expand Up @@ -221,7 +222,8 @@ export class AztecRPCServer implements AztecRPC {
txHash: txHash,
blockHash: localTx?.blockHash,
blockNumber: localTx?.blockNumber,
origin: localTx?.origin,
from: localTx?.from,
to: localTx?.to,
contractAddress: localTx?.contractAddress,
error: '',
};
Expand All @@ -244,7 +246,7 @@ export class AztecRPCServer implements AztecRPC {
// if the transaction mined it will be removed from the pending pool and there is a race condition here as the synchroniser will not have the tx as mined yet, so it will appear dropped
// until the synchroniser picks this up

const accountState = this.synchroniser.getAccount(localTx.origin);
const accountState = this.synchroniser.getAccount(localTx.from);
if (accountState && !(await accountState?.isSynchronised())) {
// there is a pending L2 block, which means the transaction will not be in the tx pool but may be awaiting mine on L1
return {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-rpc/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface GetOptions {
*/
export interface Database extends ContractDatabase {
getTx(txHash: TxHash): Promise<TxDao | undefined>;
getTxsByAddress(origin: AztecAddress): Promise<TxDao[]>;
getTxsByAddress(from: AztecAddress): Promise<TxDao[]>;
addTx(tx: TxDao): Promise<void>;
addTxs(txs: TxDao[]): Promise<void>;

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-rpc/src/database/memory_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
/**
* Retrieve all transactions associated with a given AztecAddress.
*
* @param origin - The sender's address.
* @param from - The sender's address.
* @returns A Promise resolving to an array of TxDao objects associated with the sender.
*/
public getTxsByAddress(origin: AztecAddress) {
return Promise.resolve(this.txTable.filter(tx => tx.origin.equals(origin)));
public getTxsByAddress(from: AztecAddress) {
return Promise.resolve(this.txTable.filter(tx => tx.from.equals(from)));
}

/**
Expand Down
13 changes: 10 additions & 3 deletions yarn-project/aztec-rpc/src/database/tx_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class TxDao {
/**
* The sender's Aztec address.
*/
public readonly origin: AztecAddress,
public readonly from: AztecAddress,
/**
* The contract address involved in the transaction. Undefined if the transaction is for deployinig a new contract.
*/
public readonly to: AztecAddress | undefined,
/**
* The address of the contract deployed by the transaction. Undefined if the transaction does not deploy a new contract.
*/
Expand Down Expand Up @@ -49,7 +53,9 @@ export class TxDao {
/** The block number in which the transaction was included. */
blockNumber?: number | undefined;
/** The sender's Aztec address. */
origin: AztecAddress;
from: AztecAddress;
/** The contract address involved in the transaction. Undefined if the transaction is for deployinig a new contract. */
to: AztecAddress | undefined;
/** The address of the contract deployed by the transaction. Undefined if the transaction does not deploy a new contract. */
contractAddress: AztecAddress | undefined;
/** Description of any error encountered during the transaction. */
Expand All @@ -61,7 +67,8 @@ export class TxDao {
args.txHash,
args.blockHash,
args.blockNumber,
args.origin,
args.from,
args.to,
args.contractAddress,
args.error,
args.contractBytecode,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ export class Synchroniser {
throw new Error(`Transaction ${txHash} not found in RPC database`);
}

const account = this.getAccount(tx.origin);
const account = this.getAccount(tx.from);
if (!account) {
throw new Error(`Unauthorised account: ${tx.origin}`);
throw new Error(`Unauthorised account: ${tx.from}`);
}

return tx;
Expand Down
9 changes: 7 additions & 2 deletions yarn-project/aztec-rpc/src/tx/tx_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum TxStatus {

/**
* Represents a transaction receipt in the Aztec network.
* Contains essential information about the transaction including its status, origin, and associated addresses.
* Contains essential information about the transaction including its status, sender, receiver, and associated addresses.
*/
export interface TxReceipt {
/**
Expand All @@ -29,8 +29,13 @@ export interface TxReceipt {
blockNumber?: number;
/**
* The sender's address.
* TODO: From and to are the same since we went full AA. We should unify these.
*/
origin?: AztecAddress;
from?: AztecAddress;
/**
* The contract address for the transaction.
*/
to?: AztecAddress;
/**
* The deployed contract's address.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const transferWethOnL2 = async (
pointToPublicKey(await aztecRpcClient.getAccountPublicKey(ownerAddress)),
pointToPublicKey(await aztecRpcClient.getAccountPublicKey(receiver)),
)
.send({ origin: ownerAddress });
.send({ from: ownerAddress });
await transferTx.isMined(0, 0.5);
const transferReceipt = await transferTx.getReceipt();
// expect(transferReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -242,7 +242,7 @@ async function main() {
// Call the mint tokens function on the noir contract
const consumptionTx = wethL2Contract.methods
.mint(wethAmountToBridge, ownerPub, owner, messageKey, secret, ethAccount.toField())
.send({ origin: owner });
.send({ from: owner });
await consumptionTx.isMined(0, 0.5);
const consumptionReceipt = await consumptionTx.getReceipt();
// expect(consumptionReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -277,7 +277,7 @@ async function main() {
uniswapPortalAddress,
ethAccount.toField(),
)
.send({ origin: owner });
.send({ from: owner });
await withdrawTx.isMined(0, 0.5);
const withdrawReceipt = await withdrawTx.getReceipt();
// expect(withdrawReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -328,7 +328,7 @@ async function main() {
// Call the mint tokens function on the noir contract
const daiMintTx = daiL2Contract.methods
.mint(daiAmountToBridge, ownerPub, owner, depositDaiMessageKey, secret, ethAccount.toField())
.send({ origin: owner });
.send({ from: owner });
await daiMintTx.isMined(0, 0.5);
const daiMintTxReceipt = await daiMintTx.getReceipt();
// expect(daiMintTxReceipt.status).toBe(TxStatus.MINED);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-sandbox/src/examples/zk_token_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function main() {

// Mint more tokens
logger(`Minting ${SECONDARY_AMOUNT} more coins`);
const mintTx = zkContract.methods.mint(SECONDARY_AMOUNT, ownerPubKeyPoint).send({ origin: ownerAddress });
const mintTx = zkContract.methods.mint(SECONDARY_AMOUNT, ownerPubKeyPoint).send({ from: ownerAddress });
await mintTx.isMined(0, 0.5);
const balanceAfterMint = await getBalance(zkContract, ownerPubKeyPoint, ownerAddress);
logger(`Owner's balance is now: ${balanceAfterMint}`);
Expand All @@ -81,7 +81,7 @@ async function main() {
logger(`Transferring ${SECONDARY_AMOUNT} tokens from owner to another account.`);
const transferTx = zkContract.methods
.transfer(SECONDARY_AMOUNT, ownerPubKeyPoint, address2PubKeyPoint)
.send({ origin: ownerAddress });
.send({ from: ownerAddress });
await transferTx.isMined(0, 0.5);
const balanceAfterTransfer = await getBalance(zkContract, ownerPubKeyPoint, ownerAddress);
const receiverBalance = await getBalance(zkContract, address2PubKeyPoint, address2);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Contract } from '@aztec/aztec.js';
const contract = new Contract(contractAddress, contractAbi, aztecRpcServer);
const tx = contract.methods
.transfer(amount, recipientAddress))
.send({ origin: senderAddress });
.send({ from: senderAddress });
await tx.isMined();
console.log(`Transferred ${amount} to ${recipientAddress}!`);
```
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Contract Class', () => {
const param0 = 12;
const param1 = 345n;
const sentTx = fooContract.methods.bar(param0, param1).send({
origin: account,
from: account,
});
const txHash = await sentTx.getTxHash();
const receipt = await sentTx.getReceipt();
Expand All @@ -128,7 +128,7 @@ describe('Contract Class', () => {
const fooContract = new Contract(contractAddress, defaultAbi, wallet);
expect(() =>
fooContract.methods.qux().send({
origin: account,
from: account,
}),
).toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SendMethodOptions {
/**
* Sender's address initiating the transaction.
*/
origin?: AztecAddress;
from?: AztecAddress;
/**
* The nonce representing the order of transactions sent by the address.
*/
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ContractFunctionInteraction {
throw new Error("Can't call `create` on an unconstrained function.");
}
if (!this.txRequest) {
const executionRequest = this.getExecutionRequest(this.contractAddress, options.origin);
const executionRequest = this.getExecutionRequest(this.contractAddress, options.from);
const nodeInfo = await this.wallet.getNodeInfo();
const txContext = TxContext.empty(new Fr(nodeInfo.chainId), new Fr(nodeInfo.version));
const txRequest = await this.wallet.createAuthenticatedTxRequest([executionRequest], txContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe.skip('Contract Deployer', () => {
const sentTx = deployer.deploy(args[0], args[1]).send({
portalContract,
contractAddressSalt,
origin: account,
from: account,
});
const txHash = await sentTx.getTxHash();
const receipt = await sentTx.getReceipt();
Expand Down
Loading

0 comments on commit cd7d823

Please sign in to comment.