Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update solowallet transaction #60

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/api/src/solowallet/solowallet.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DepositFundsRequestDto,
UpdateTxDto,
UserTxsRequestDto,
WithdrawFundsRequestDto,
} from '@bitsacco/common';
Expand Down Expand Up @@ -41,4 +42,13 @@ export class SolowalletController {
userTransactions(@Body() req: UserTxsRequestDto) {
return this.walletService.userTransactions(req);
}

@Post('update')
@ApiOperation({ summary: 'Update Solowallet transaction' })
@ApiBody({
type: UpdateTxDto,
})
updateShares(@Body() req: UpdateTxDto) {
return this.walletService.updateTransaction(req);
}
}
5 changes: 5 additions & 0 deletions apps/api/src/solowallet/solowallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SOLOWALLET_SERVICE_NAME,
SolowalletServiceClient,
WithdrawFundsRequestDto,
UpdateTxDto,
} from '@bitsacco/common';
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
import { type ClientGrpc } from '@nestjs/microservices';
Expand Down Expand Up @@ -33,4 +34,8 @@ export class SolowalletService implements OnModuleInit {
withdrawFunds(req: WithdrawFundsRequestDto) {
return this.client.withdrawFunds(req);
}

updateTransaction(req: UpdateTxDto) {
return this.client.updateTransaction(req);
}
}
6 changes: 6 additions & 0 deletions apps/solowallet/src/solowallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DepositFundsRequestDto,
UserTxsRequestDto,
WithdrawFundsRequestDto,
UpdateTxDto,
} from '@bitsacco/common';
import { SolowalletService } from './solowallet.service';

Expand All @@ -27,4 +28,9 @@ export class SolowalletController {
withdrawFunds(request: WithdrawFundsRequestDto) {
return this.solowalletService.withdrawFunds(request);
}

@GrpcMethod()
updateTransaction(request: UpdateTxDto) {
return this.solowalletService.updateTransaction(request);
}
}
28 changes: 28 additions & 0 deletions apps/solowallet/src/solowallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TransactionType,
WithdrawFundsRequestDto,
CreateOfframpSwapDto,
UpdateTxDto,
} from '@bitsacco/common';
import { type ClientGrpc } from '@nestjs/microservices';
import { catchError, firstValueFrom, map, of, tap } from 'rxjs';
Expand Down Expand Up @@ -482,6 +483,33 @@ export class SolowalletService {
};
}

async updateTransaction({ txId, updates }: UpdateTxDto) {
const originTx = await this.wallet.findOne({ _id: txId });
const { status, lightning, reference } = updates;

let { userId } = await this.wallet.findOneAndUpdate(
{ _id: txId },
{
status: status !== undefined ? status : originTx.status,
lightning: lightning !== undefined ? lightning : originTx.lightning,
reference: reference ?? originTx.reference,
},
);

const ledger = await this.getPaginatedUserTxLedger({
userId,
pagination: { page: 0, size: 10 },
});
const meta = await this.getWalletMeta(userId);

return {
txId: originTx._id,
ledger,
meta,
userId,
};
}

@OnEvent(fedimint_receive_success)
private async handleSuccessfulReceive({
context,
Expand Down
39 changes: 39 additions & 0 deletions libs/common/src/dto/solowallet.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Type } from 'class-transformer';
import {
IsEnum,
IsNotEmpty,
IsNotEmptyObject,
IsNumber,
IsOptional,
IsString,
Min,
ValidateNested,
Expand All @@ -16,6 +19,9 @@ import {
DepositFundsRequest,
WithdrawFundsRequest,
UserTxsRequest,
UpdateTxRequest,
SolowalletTxUpdates,
TransactionStatus,
} from '../types';
import { PaginatedRequestDto } from './lib.dto';

Expand Down Expand Up @@ -86,3 +92,36 @@ export class UserTxsRequestDto implements UserTxsRequest {
@ApiProperty({ type: PaginatedRequestDto })
pagination: PaginatedRequestDto;
}

class SolowalletTxUpdatesDto implements SolowalletTxUpdates {
@IsOptional()
@IsEnum(TransactionStatus)
@ApiProperty({ enum: TransactionStatus })
status?: TransactionStatus;

@IsOptional()
@ValidateNested()
@Type(() => Bolt11InvoiceDto)
@ApiProperty({ type: Bolt11InvoiceDto })
lightning?: Bolt11InvoiceDto;

@IsOptional()
@IsString()
@Type(() => String)
@ApiProperty()
reference: string;
}

export class UpdateTxDto implements UpdateTxRequest {
@IsNotEmpty()
@IsString()
@Type(() => String)
@ApiProperty({ example: '4a4b4c4d-cb98-40b1-9ed2-a13006a9f670' })
txId: string;

@IsNotEmptyObject()
@ValidateNested()
@Type(() => SolowalletTxUpdatesDto)
@ApiProperty({ type: SolowalletTxUpdatesDto })
updates: SolowalletTxUpdatesDto;
}
18 changes: 18 additions & 0 deletions libs/common/src/types/proto/solowallet.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions proto/solowallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ service SolowalletService {
rpc WithdrawFunds(WithdrawFundsRequest) returns (UserTxsResponse){}

rpc UserTransactions(UserTxsRequest) returns (UserTxsResponse){}

rpc UpdateTransaction(UpdateTxRequest) returns (UserTxsResponse) {}
}

message DepositFundsRequest {
Expand Down Expand Up @@ -97,3 +99,14 @@ message WalletMeta {
float total_withdrawals = 2;
int32 current_balance = 3;
}

message UpdateTxRequest {
string tx_id = 1;
SolowalletTxUpdates updates = 2;
}

message SolowalletTxUpdates {
optional lib.TransactionStatus status = 1;
optional lightning.Bolt11 lightning = 2;
optional string reference = 3;
}
Loading