Skip to content

Commit

Permalink
refactor: Update generate_rgbpp_transfer_all_txs response
Browse files Browse the repository at this point in the history
  • Loading branch information
duanyytop committed Aug 16, 2024
1 parent 1c11426 commit 4801db9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
27 changes: 11 additions & 16 deletions apps/service/src/rgbpp/rgbpp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from 'rgbpp';
import { RpcHandler, RpcMethodHandler } from '../json-rpc/json-rpc.decorators.js';
import { toSnakeCase, toCamelCase, SnakeCased } from '../utils/case.js';
import { ensureSafeJson } from '../utils/json.js';
import {
RgbppTransferReq,
RgbppCkbBtcTransaction,
Expand All @@ -20,7 +19,7 @@ import {
RgbppCkbTxHashReq,
BtcTxSendReq,
RgbppTransferAllReq,
RgbppTransferAllRes,
RgbppTransferAllResp,
} from './types.js';

@RpcHandler()
Expand Down Expand Up @@ -63,9 +62,11 @@ export class RgbppService {
}

@RpcMethodHandler({ name: 'generate_rgbpp_transfer_all_txs' })
public async generateRgbppTransferAllTxs(request: [RgbppTransferAllReq]): Promise<SnakeCased<RgbppTransferAllRes>> {
public async generateRgbppTransferAllTxs(
request: [RgbppTransferAllReq],
): Promise<SnakeCased<RgbppTransferAllResp>[]> {
const params = toCamelCase(request[0]);
const result = await buildRgbppTransferAllTxs({
const { transactions } = await buildRgbppTransferAllTxs({
ckb: {
collector: this.ckbCollector,
xudtTypeArgs: params.ckb.xudtTypeArgs,
Expand All @@ -84,18 +85,12 @@ export class RgbppService {
isMainnet: this.isMainnet,
});

return ensureSafeJson<SnakeCased<RgbppTransferAllRes>>(
toSnakeCase<RgbppTransferAllRes>({
...result,
transactions: result.transactions.map((group) => {
return {
...group,
ckb: {
...group.ckb,
virtualTxResult: JSON.stringify(group.ckb.virtualTxResult),
},
};
}),
return transactions.map(({ ckb, btc }) =>
toSnakeCase<RgbppTransferAllResp>({
ckbVirtualTxResult: JSON.stringify(ckb.virtualTxResult),
psbtHex: btc.psbtHex,
btcFeeRate: btc.feeRate,
btcFee: btc.fee,
}),
);
}
Expand Down
14 changes: 5 additions & 9 deletions apps/service/src/rgbpp/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RgbppTransferAllTxGroup, RgbppTransferAllTxsResult } from 'rgbpp';
import { AddressToPubkeyMap } from 'rgbpp/btc';
import { Hex } from 'rgbpp/ckb';

Expand Down Expand Up @@ -72,12 +71,9 @@ export interface RgbppTransferAllReq {
};
}

export interface RgbppTransferAllRes extends Omit<RgbppTransferAllTxsResult, 'transactions'> {
transactions: RgbppTransferAllGroupWithStringCkbVtx[];
}

export interface RgbppTransferAllGroupWithStringCkbVtx extends Omit<RgbppTransferAllTxGroup, 'ckb'> {
ckb: Omit<RgbppTransferAllTxGroup['ckb'], 'virtualTxResult'> & {
virtualTxResult: string;
};
export interface RgbppTransferAllResp {
ckbVirtualTxResult: string;
psbtHex: string;
btcFeeRate: number;
btcFee: number;
}

0 comments on commit 4801db9

Please sign in to comment.