casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
48 stars 9 forks source link

Implement `xpCreateContract` procedure #509

Open KallynGowdy opened 1 month ago

KallynGowdy commented 1 month ago

Name: xpCreateContract HTTP: POST /api/v2/xp/contract Authentication: REQUIRED - sessionKey Input:

{
    holdingUserId: z.string(),
    rate: z.number().int().nonnegative(),
    amount: z.numer().int().nonnegative(),
    description: z.string(),
}

Operation: Create a contract with the given holdingUserId, rate, amount, and description with issuerUserId = sessionKey.userId. The returned information should be limited to the information specified below. Success Output:

{
    success: true,

    // Same contract output as xpGetUserIssuedContracts
    contract: {
        id: 'contract-id',
        issuerUserId: 'issuer-user-id',
        holdingUserId: 'holding-user-id',
        accountBalance: 123,
        accountCurrency: 'usd',
        accountEntries: [
            {
                id: 'entry-id',
                amount: 123,
                balance: 456,
                timeMs: 123,
                transactionId: 'transaction-id',
                note: 'string'
            }
        ],
        rate: 123,
        description: 'desc',
        status: 'open',
        accountId: 'account-id',
        createdAtMs: 123,
        updatedAtMs: 123
    }
}