-
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.
- Loading branch information
Showing
14 changed files
with
249 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { Query, Resolver } from '@nestjs/graphql'; | ||
import { BitcoinChainInfo } from './bitcoin.model'; | ||
import { Query, ResolveField, Resolver } from '@nestjs/graphql'; | ||
import { BitcoinBaseChainInfo, BitcoinChainInfo, BitcoinFees } from './bitcoin.model'; | ||
import { BitcoinApiService } from 'src/core/bitcoin-api/bitcoin-api.service'; | ||
|
||
@Resolver(() => BitcoinChainInfo) | ||
export class BitcoinResolver { | ||
constructor(private bitcoinApiService: BitcoinApiService) {} | ||
|
||
@Query(() => BitcoinChainInfo) | ||
public async getBitcoinChainInfo(): Promise<BitcoinChainInfo> { | ||
@Query(() => BitcoinChainInfo, { name: 'btcChainInfo' }) | ||
public async chainInfo(): Promise<BitcoinBaseChainInfo> { | ||
const info = await this.bitcoinApiService.getBlockchainInfo(); | ||
return BitcoinChainInfo.from(info); | ||
} | ||
|
||
@ResolveField(() => BitcoinFees) | ||
public async fees(): Promise<BitcoinFees> { | ||
const fees = await this.bitcoinApiService.getFeesRecommended(); | ||
return BitcoinFees.from(fees); | ||
} | ||
} |
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,72 @@ | ||
import { Field, Float, Int, ObjectType } from "@nestjs/graphql"; | ||
import { CkbScript } from "src/modules/ckb/script/script.model"; | ||
import * as CkbExplorer from 'src/core/ckb-explorer/ckb-explorer.interface'; | ||
import { toNumber } from "lodash"; | ||
|
||
@ObjectType({ description: 'RGB++ Coin' }) | ||
export class RgbppCoin { | ||
@Field(() => String) | ||
name: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
description: string; | ||
|
||
@Field(() => String) | ||
symbol: string; | ||
|
||
@Field(() => Float) | ||
decimal: number; | ||
|
||
@Field(() => String, { nullable: true }) | ||
icon: string; | ||
|
||
@Field(() => String) | ||
typeHash: string; | ||
|
||
@Field(() => CkbScript) | ||
typeScript: CkbScript; | ||
|
||
@Field(() => Int) | ||
holdersCount: number; | ||
|
||
@Field(() => Int) | ||
h24CkbTransactionsCount: number; | ||
|
||
@Field(() => Float) | ||
totalAmount: number; | ||
|
||
@Field(() => String) | ||
issuer: string; | ||
|
||
@Field(() => Date) | ||
deployedAt: Date; | ||
|
||
public static from(xudt: CkbExplorer.XUDT): RgbppCoin { | ||
return { | ||
name: xudt.full_name, | ||
description: xudt.description, | ||
symbol: xudt.symbol, | ||
decimal: toNumber(xudt.decimal), | ||
icon: xudt.icon_file, | ||
typeHash: xudt.type_hash, | ||
typeScript: CkbScript.from(xudt.type_script), | ||
holdersCount: toNumber(xudt.addresses_count), | ||
h24CkbTransactionsCount: toNumber(xudt.h24_ckb_transactions_count), | ||
totalAmount: toNumber(xudt.total_amount), | ||
issuer: xudt.issuer_address, | ||
deployedAt: new Date(xudt.created_at), | ||
}; | ||
} | ||
} | ||
|
||
@ObjectType({ description: 'RGB++ Coin List' }) | ||
export class RgbppCoinList { | ||
@Field(() => [RgbppCoin]) | ||
coins: RgbppCoin[]; | ||
|
||
@Field(() => Int) | ||
total: number; | ||
|
||
@Field(() => Int) | ||
page: number; | ||
} |
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 { RgbppCoinResolver } from './coin.resolver'; | ||
import { CkbExplorerModule } from 'src/core/ckb-explorer/ckb-explorer.module'; | ||
|
||
@Module({ | ||
imports: [CkbExplorerModule], | ||
providers: [RgbppCoinResolver], | ||
}) | ||
export class CoinModule {} |
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,35 @@ | ||
import { Args, Int, Query, Resolver } from '@nestjs/graphql'; | ||
import { RgbppCoin, RgbppCoinList } from './coin.model'; | ||
import { CkbExplorerService } from 'src/core/ckb-explorer/ckb-explorer.service'; | ||
import { XUDTTag } from 'src/core/ckb-explorer/ckb-explorer.interface'; | ||
|
||
@Resolver(() => RgbppCoin) | ||
export class RgbppCoinResolver { | ||
constructor(private ckbExplorerService: CkbExplorerService) { } | ||
|
||
@Query(() => RgbppCoinList, { name: 'rgbppCoinList' }) | ||
public async coins( | ||
@Args('page', { type: () => Int, nullable: true }) page: number = 1, | ||
@Args('pageSize', { type: () => Int, nullable: true }) pageSize: number = 10, | ||
): Promise<RgbppCoinList> { | ||
const response = await this.ckbExplorerService.getXUDTList({ | ||
page, | ||
pageSize, | ||
tags: [XUDTTag.RgbppCompatible], | ||
}); | ||
const coins = response.data.map((coin) => RgbppCoin.from(coin.attributes)); | ||
return { | ||
coins, | ||
total: response.meta.total, | ||
page: response.meta.page_size, | ||
}; | ||
} | ||
|
||
@Query(() => RgbppCoin, { name: 'rgbppCoin' }) | ||
public async coin( | ||
@Args('typeHash', { type: () => String }) typeHash: string, | ||
): Promise<RgbppCoin> { | ||
const response = await this.ckbExplorerService.getXUDT(typeHash); | ||
return RgbppCoin.from(response.data.attributes); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TransactionModule } from './transaction/transaction.module'; | ||
import { CoinModule } from './coin/coin.module'; | ||
|
||
@Module({ | ||
imports: [TransactionModule] | ||
imports: [TransactionModule, CoinModule] | ||
}) | ||
export class RgbppModule {} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RgbppTransactionResolver } from './transaction.resolver'; | ||
import { CkbExplorerModule } from 'src/core/ckb-explorer/ckb-explorer.module'; | ||
import { RgbppTransactionService } from './transaction.service'; | ||
import { CkbTransactionModule } from 'src/modules/ckb/transaction/transaction.module'; | ||
|
||
@Module({ | ||
imports: [CkbExplorerModule, CkbTransactionModule], | ||
providers: [RgbppTransactionResolver, RgbppTransactionService], | ||
providers: [RgbppTransactionResolver], | ||
}) | ||
export class TransactionModule {} |
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
15 changes: 0 additions & 15 deletions
15
backend/src/modules/rgbpp/transaction/transaction.service.ts
This file was deleted.
Oops, something went wrong.