-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ckb-cell/refactor/update-graphql-model
refactor: update graphql model
- Loading branch information
Showing
21 changed files
with
9,365 additions
and
6,986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Field, Float, ObjectType } from '@nestjs/graphql'; | ||
|
||
export type RgbppBaseAddress = Pick<RgbppAddress, 'address'>; | ||
|
||
@ObjectType({ description: 'Rgbpp Address' }) | ||
export class RgbppAddress { | ||
@Field(() => String) | ||
address: string; | ||
|
||
@Field(() => Float) | ||
utxosCount: number; | ||
|
||
@Field(() => Float) | ||
cellsCount: number; | ||
|
||
public static from(address: string): RgbppBaseAddress { | ||
return { | ||
address, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RgbppAddressResolver } from './address.resolver'; | ||
import { CkbExplorerModule } from 'src/core/ckb-explorer/ckb-explorer.module'; | ||
|
||
@Module({ | ||
imports: [CkbExplorerModule], | ||
providers: [RgbppAddressResolver], | ||
}) | ||
export class RgbppAddressModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Args, Float, Parent, Query, ResolveField, Resolver } from '@nestjs/graphql'; | ||
import { CkbExplorerService } from 'src/core/ckb-explorer/ckb-explorer.service'; | ||
import { RgbppAddress, RgbppBaseAddress } from './address.model'; | ||
|
||
@Resolver(() => RgbppAddress) | ||
export class RgbppAddressResolver { | ||
constructor(private ckbExplorerService: CkbExplorerService) {} | ||
|
||
@Query(() => RgbppAddress, { name: 'rgbppAddress', nullable: true }) | ||
public async getBtcAddress(@Args('address') address: string): Promise<RgbppBaseAddress> { | ||
return RgbppAddress.from(address); | ||
} | ||
|
||
@ResolveField(() => Float) | ||
public async utxosCount(@Parent() address: RgbppBaseAddress): Promise<number> { | ||
const cells = await this.ckbExplorerService.getAddressRgbppCells({ | ||
address: address.address, | ||
}); | ||
return cells.meta.total; | ||
} | ||
|
||
@ResolveField(() => Float) | ||
public async cellsCount(@Parent() address: RgbppBaseAddress): Promise<number> { | ||
// TODO: implement this resolver | ||
// XXX: how to relate ckb address with rgbpp cells? (except the address is rgbpp-lock/btc-time-lock) | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/src/modules/rgbpp/transaction/transaction.dataloader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import DataLoader from 'dataloader'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { NestDataLoader } from '@applifting-io/nestjs-dataloader'; | ||
import { DataLoaderResponse } from 'src/common/type/dataloader'; | ||
import { RgbppTransactionService } from './transaction.service'; | ||
import { RgbppBaseTransaction } from './transaction.model'; | ||
|
||
@Injectable() | ||
export class RgbppTransactionLoader | ||
implements NestDataLoader<string, RgbppBaseTransaction | null> { | ||
private logger = new Logger(RgbppTransactionLoader.name); | ||
|
||
constructor(private transactionService: RgbppTransactionService) { } | ||
|
||
public getBatchFunction() { | ||
return async (ids: string[]) => { | ||
this.logger.debug(`Loading rgbpp transactions: ${ids.join(', ')}`); | ||
const results = await Promise.allSettled( | ||
ids.map((txidOrTxHash) => this.transactionService.getTransaction(txidOrTxHash)), | ||
); | ||
return results.map((result) => { | ||
if (result.status === 'fulfilled') { | ||
return result.value; | ||
} | ||
return null; | ||
}); | ||
}; | ||
} | ||
} | ||
export type RgbppTransactionLoaderType = DataLoader<string, RgbppBaseTransaction | null>; | ||
export type RgbppTransactionLoaderResponse = DataLoaderResponse<RgbppTransactionLoader>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.