keep-starknet-strange / vault

Empower Your Assets, Redefine Control.
https://vlt.finance
MIT License
18 stars 16 forks source link

Implement /transaction_history Endpoint #31

Closed LucasLvy closed 2 months ago

LucasLvy commented 3 months ago

Description

We need to implement the /transaction_history endpoint in the Vault backend. This endpoint is responsible for retrieving transaction history for a specific account.

Details

Request Parameters:

Response:

{
  "page_count": 5,
  "transactions": [
    {
      "amount": "0x123456789012345678",
      "from": "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
      "hash": "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
      "name": "Other User 1"
    },
    {
      "amount": "0x987654321098765432",
      "to": "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
      "hash": "0xABCDEF0123456789abcdef0123456789abcdefABCDEF0123456789abcdef0123",
      "name": "Other User 2"
    }
  ]
}

Validation:

Notes:

Suggested Implementation (using TypeScript and Fastify):

// Import necessary modules
import fastify from 'fastify';

// Create Fastify instance
const app = fastify({ logger: true });

// Define the transaction_history endpoint
app.get('/transaction_history', async (request, reply) => {
    try {
        // Mocked transaction history data
        const transactionHistory = [
            {
                amount: "0x123456789012345678",
                from: "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
                hash: "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
                name: "Other User 1"
            },
            {
                amount: "0x987654321098765432",
                to: "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
                hash: "0xABCDEF0123456789abcdef0123456789abcdefABCDEF0123456789abcdef0123",
                name: "Other User 2"
            }
        ];

        // Return transaction history
        return transactionHistory;
    } catch (error) {
        // Handle errors
        console.error('Error retrieving transaction history:', error);
        return reply.status(500).send({ error: 'Internal Server Error' });
    }
});

// Start the server
app.listen(3000, '0.0.0.0', (err, address) => {
    if (err) throw err;
    console.log(`Server listening on ${address}`);
});

Tasks:

Xavek commented 2 months ago

Transaction history of USDC transfers for payload address? Can I work on it?

LucasLvy commented 2 months ago

yes please do