Skip to content

Commit f03b5ea

Browse files
authored
chore: support AA addresses in /send-transaction (#548)
1 parent 4ef3b08 commit f03b5ea

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/server/routes/backend-wallet/sendTransaction.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
transactionWritesResponseSchema,
99
} from "../../schemas/sharedApiSchemas";
1010
import { txOverridesSchema } from "../../schemas/txOverrides";
11-
import { walletHeaderSchema } from "../../schemas/wallet";
11+
import { walletWithAAHeaderSchema } from "../../schemas/wallet";
1212
import { getChainIdFromChain } from "../../utils/chain";
1313

1414
const ParamsSchema = Type.Object({
@@ -57,7 +57,7 @@ export async function sendTransaction(fastify: FastifyInstance) {
5757
operationId: "sendTransaction",
5858
params: ParamsSchema,
5959
body: requestBodySchema,
60-
headers: walletHeaderSchema,
60+
headers: walletWithAAHeaderSchema,
6161
querystring: requestQuerystringSchema,
6262
response: {
6363
...standardResponseSchema,
@@ -71,19 +71,37 @@ export async function sendTransaction(fastify: FastifyInstance) {
7171
const {
7272
"x-backend-wallet-address": fromAddress,
7373
"x-idempotency-key": idempotencyKey,
74-
} = request.headers as Static<typeof walletHeaderSchema>;
74+
"x-account-address": accountAddress,
75+
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7576
const chainId = await getChainIdFromChain(chain);
7677

77-
const { id: queueId } = await queueTxRaw({
78-
chainId: chainId.toString(),
79-
fromAddress,
80-
toAddress,
81-
data,
82-
value,
83-
simulateTx,
84-
idempotencyKey,
85-
...txOverrides,
86-
});
78+
let queueId: string;
79+
if (accountAddress) {
80+
const { id } = await queueTxRaw({
81+
chainId: chainId.toString(),
82+
signerAddress: fromAddress,
83+
accountAddress,
84+
target: toAddress,
85+
data,
86+
value,
87+
simulateTx,
88+
idempotencyKey,
89+
...txOverrides,
90+
});
91+
queueId = id;
92+
} else {
93+
const { id } = await queueTxRaw({
94+
chainId: chainId.toString(),
95+
fromAddress,
96+
toAddress,
97+
data,
98+
value,
99+
simulateTx,
100+
idempotencyKey,
101+
...txOverrides,
102+
});
103+
queueId = id;
104+
}
87105

88106
reply.status(StatusCodes.OK).send({
89107
result: {

0 commit comments

Comments
 (0)