Skip to content

Commit

Permalink
Move send transaction from /wallet to /backend-wallet (#218)
Browse files Browse the repository at this point in the history
* Add endpoint to send raw transactions

* Move send transaction from /transaction to /backend-wallet

* Remove extra send transaction endpoint
  • Loading branch information
adam-maj authored Oct 12, 2023
1 parent ba29679 commit b0270be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import {
standardResponseSchema,
transactionWritesResponseSchema,
} from "../../helpers/sharedApiSchemas";
import { walletAuthSchema } from "../../schemas/wallet";
import { getChainIdFromChain } from "../../utilities/chain";

const ParamsSchema = Type.Object({
chain: Type.String(),
});

const requestBodySchema = Type.Object({
fromAddress: Type.String({
examples: ["0x..."],
}),
toAddress: Type.Optional(
Type.String({
examples: ["0x..."],
Expand All @@ -31,36 +29,37 @@ const requestBodySchema = Type.Object({

requestBodySchema.examples = [
{
fromAddress: "0x43CAe0d7fe86C713530E679Ce02574743b2Ee9FC",
toAddress: "0x7a0ce8524bea337f0bee853b68fabde145dac0a0",
data: "0x449a52f800000000000000000000000043cae0d7fe86c713530e679ce02574743b2ee9fc0000000000000000000000000000000000000000000000000de0b6b3a7640000",
value: "0x00",
},
];

export async function sendRawTransaction(fastify: FastifyInstance) {
export async function sendTransaction(fastify: FastifyInstance) {
fastify.route<{
Params: Static<typeof ParamsSchema>;
Body: Static<typeof requestBodySchema>;
Reply: Static<typeof transactionWritesResponseSchema>;
}>({
method: "POST",
url: "/transaction/:chain/send-raw",
url: "/wallet/:chain/send-transaction",
schema: {
summary: "Send a raw transaction",
description: "Send a raw transaction with transaction parameters",
tags: ["Transaction"],
operationId: "txSendRaw",
tags: ["Backend Wallet"],
operationId: "walletSendTransaction",
params: ParamsSchema,
body: requestBodySchema,
headers: Type.Omit(walletAuthSchema, ["x-account-address"]),
response: {
...standardResponseSchema,
[StatusCodes.OK]: transactionWritesResponseSchema,
},
},
handler: async (request, reply) => {
const { chain } = request.params;
const { fromAddress, toAddress, data, value } = request.body;
const { toAddress, data, value } = request.body;
const fromAddress = request.headers["x-backend-wallet-address"] as string;
const chainId = getChainIdFromChain(chain);

// TODO: At some point we should simulate this first
Expand Down
4 changes: 2 additions & 2 deletions server/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import { createWallet } from "./backend-wallet/create";
import { getAll } from "./backend-wallet/getAll";
import { getBalance } from "./backend-wallet/getBalance";
import { importWallet } from "./backend-wallet/import";
import { sendTransaction } from "./backend-wallet/send";
import { transfer } from "./backend-wallet/transfer";
import { accountRoutes } from "./contract/extensions/account";
import { accountFactoryRoutes } from "./contract/extensions/accountFactory";
import { sendRawTransaction } from "./transaction/send";

export const apiRoutes = async (fastify: FastifyInstance) => {
// Wallet
Expand All @@ -59,6 +59,7 @@ export const apiRoutes = async (fastify: FastifyInstance) => {
await fastify.register(getBalance);
await fastify.register(getAll);
await fastify.register(transfer);
await fastify.register(sendTransaction);

// Chains
await fastify.register(getChainData);
Expand Down Expand Up @@ -97,7 +98,6 @@ export const apiRoutes = async (fastify: FastifyInstance) => {
await fastify.register(checkTxStatus);
await fastify.register(getAllTx);
await fastify.register(getAllDeployedContracts);
await fastify.register(sendRawTransaction);
await fastify.register(retryTransaction);
await fastify.register(cancelTransaction);

Expand Down

0 comments on commit b0270be

Please sign in to comment.