Skip to content

Commit

Permalink
fix: accountList.
Browse files Browse the repository at this point in the history
  • Loading branch information
web3max committed Jan 25, 2024
1 parent 099634f commit 5f10061
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 44 deletions.
42 changes: 13 additions & 29 deletions docs/api/dotbit.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ List all .bit accounts (including SubDID accounts) of a given blockchain owner a
- key: `string`. The address on a certain blockchain
- (Optional) coin_type: `string`. (60: ETH, 195: TRX, 714: BNB, 966: Matic). See [What is coin_type?](../../README.md#what-is-coin_type) in FAQ for more details.
### Return Value
Promise<BitAccount[]>
Promise<BitAccountListItem[]>
### Example
```javascript
// To get all BitAccount instances of Ethereum addresss '0x1d643fac9a463c9d544506006a6348c234da485f'
Expand All @@ -291,19 +291,11 @@ dotbit.accountsOfOwner({
// The printed result would be like:
[
...,
BitAccount {
account: 'cz-vs-sbf.bit',
bitIndexer: BitIndexer { rpc: [JSONRPC] },
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
},
BitSubAccount {
account: 'jeff.makeafriend.bit',
bitIndexer: BitIndexer { rpc: [JSONRPC] },
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
isSubAccount: true,
mainAccount: 'makeafriend.bit'
{
"account": "gaoyuanyuan.bit",
"display_name": "gaoyuanyuan.bit",
"registered_at": 1626962335,
"expired_at": 1721570335
}
]
```
Expand All @@ -315,7 +307,7 @@ List all .bit accounts (including SubDID accounts) of a given blockchain manager
- key: `string`. The address on a certain blockchain
- (Optional) coin_type: `string`. (60: ETH, 195: TRX, 714: BNB, 966: Matic). See [What is coin_type?](../../README.md#what-is-coin_type) in FAQ for more details.
### Return Value
Promise<BitAccount[]>
Promise<BitAccountListItem[]>
### Example
```javascript
// To get all BitAccount instances of Ethereum addresss '0x1d643fac9a463c9d544506006a6348c234da485f'
Expand All @@ -328,20 +320,12 @@ dotbit.accountsOfManager({
// The printed result would be like:
[
...,
BitAccount {
account: 'cz-vs-sbf.bit',
bitIndexer: BitIndexer { rpc: [JSONRPC] },
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
},
BitSubAccount {
account: 'jeff.makeafriend.bit',
bitIndexer: BitIndexer { rpc: [JSONRPC] },
bitBuilder: RemoteTxBuilder {},
signer: // Your signer instance
isSubAccount: true,
mainAccount: 'makeafriend.bit'
}
{
"account": "gaoyuanyuan.bit",
"display_name": "gaoyuanyuan.bit",
"registered_at": 1626962335,
"expired_at": 1721570335
}
]
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotbit",
"version": "0.4.27",
"version": "0.4.28",
"description": "A complete .bit SDK and utilities in TypeScript",
"author": "Jeff Jing <https://github.com/zgayjjf>",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions src/DotBit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BitSubAccount } from './BitSubAccount'
import { RemoteTxBuilder } from './builders/RemoteTxBuilder'
import { BitNetwork, DWebProtocol } from './const'
import { BitIndexer } from './fetchers/BitIndexer'
import { KeyInfo } from './fetchers/BitIndexer.type'
import { BitAccountListItem, KeyInfo } from './fetchers/BitIndexer.type'
import { BitSigner } from './signers/BitSigner'
import { isSubAccount } from './tools/account'
import { BitErrorCode, BitIndexerErrorCode, DotbitError } from './errors/DotbitError'
Expand Down Expand Up @@ -102,16 +102,16 @@ export class DotBit {
return this.reverse(keyInfo)
}

async accountsOfOwner (keyInfo: KeyInfo): Promise<BitAccount[]> {
async accountsOfOwner (keyInfo: KeyInfo): Promise<BitAccountListItem[]> {
const accounts = await this.bitIndexer.accountList(keyInfo)

return accounts.map(account => this.getAccount(account))
return accounts
}

async accountsOfManager (keyInfo: KeyInfo): Promise<BitAccount[]> {
async accountsOfManager (keyInfo: KeyInfo): Promise<BitAccountListItem[]> {
const accounts = await this.bitIndexer.accountList(keyInfo, 'manager')

return accounts.map(account => this.getAccount(account))
return accounts
}

account (account: string): BitAccount {
Expand Down
5 changes: 3 additions & 2 deletions src/fetchers/BitIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BatchAccountInfo,
BitAccountInfo,
BitAccountList,
BitAccountListItem,
BitAccountRecord,
BitKeyInfo,
DasAccountRecords,
Expand Down Expand Up @@ -66,13 +67,13 @@ export class BitIndexer {
* @param keyInfo
* @param role
*/
accountList (keyInfo: KeyInfo, role: 'manager' | 'owner' = 'owner'): Promise<string[]> {
accountList (keyInfo: KeyInfo, role: 'manager' | 'owner' = 'owner'): Promise<BitAccountListItem[]> {
return this.request<BitAccountList>('das_accountList', [{
type: 'blockchain',
key_info: keyInfo,
role,
}])
.then(result => result.account_list.map(item => item.account))
.then(result => result.account_list)
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/fetchers/BitIndexer.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ export interface BitKeyInfo {
key_info: KeyInfo,
}

export interface BitAccountListItem {
account: string,
display_name: string,
registered_at: number,
expired_at: number,
}

export interface BitAccountList {
account_list: Array<{
account: string,
}>,
account_list: BitAccountListItem[],
}

export interface BatchAccountInfo {
Expand Down
6 changes: 2 additions & 4 deletions tests/DotBit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ describe('accountsOfOwner', function () {
coin_type: CoinType.ETH,
})

expect(accounts[0]).toBeInstanceOf(BitAccount)
expect(accounts.length).toBeGreaterThan(10)
expect(accounts.length).toBeGreaterThan(5)
})
})

Expand All @@ -63,8 +62,7 @@ describe('accountsOfManager', function () {
coin_type: CoinType.ETH,
})

expect(accounts[0]).toBeInstanceOf(BitAccount)
expect(accounts.length).toBeGreaterThan(10)
expect(accounts.length).toBeGreaterThan(5)
})
})

Expand Down

0 comments on commit 5f10061

Please sign in to comment.