-
Notifications
You must be signed in to change notification settings - Fork 202
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
1 parent
861ee85
commit 2e67999
Showing
15 changed files
with
93 additions
and
71 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
12 changes: 12 additions & 0 deletions
12
packages/sdk-ui-ts/src/services/bonfida/InjBonfidaNameService.spec.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,12 @@ | ||
import { InjBonfidaNameService } from './InjBonfidaNameService' | ||
|
||
describe('InjBonfidaNameService', () => { | ||
test('fetchInjAddress', () => { | ||
const service = new InjBonfidaNameService() | ||
const name = 'randomname.sol' | ||
const result = service.fetchInjAddress(name) | ||
|
||
expect(result).toBeDefined() | ||
expect(result).toEqual('inj1...') | ||
}) | ||
}) |
47 changes: 47 additions & 0 deletions
47
packages/sdk-ui-ts/src/services/bonfida/InjBonfidaNameService.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,47 @@ | ||
import { GeneralException } from '@injectivelabs/exceptions' | ||
import { | ||
Network, | ||
NetworkEndpoints, | ||
getNetworkEndpoints, | ||
} from '@injectivelabs/networks' | ||
import { | ||
toBase64, | ||
fromBase64, | ||
ChainGrpcWasmApi, | ||
binaryToBase64, | ||
} from '@injectivelabs/sdk-ts' | ||
import { getBonfidaContractAddress } from './utils' | ||
|
||
export class InjBonfidaNameService { | ||
protected client: ChainGrpcWasmApi | ||
|
||
private contractAddress: string | ||
|
||
constructor( | ||
network: Network = Network.Testnet, | ||
endpoints?: NetworkEndpoints, | ||
) { | ||
const networkEndpoints = endpoints || getNetworkEndpoints(network) | ||
|
||
this.client = new ChainGrpcWasmApi(networkEndpoints.grpc) | ||
this.contractAddress = getBonfidaContractAddress(network) | ||
} | ||
|
||
async fetchInjAddress(name: string) { | ||
const query = { | ||
resolve: { | ||
domain_name: name, | ||
}, | ||
} | ||
const response = await this.client.fetchSmartContractState( | ||
this.contractAddress, | ||
toBase64(query), | ||
) | ||
|
||
return fromBase64(binaryToBase64(response.data)) | ||
} | ||
|
||
async fetchInjName(_address: string) { | ||
throw new GeneralException(new Error(`Not suported for this name service`)) | ||
} | ||
} |
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 @@ | ||
export * from './InjBonfidaNameService' |
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 { Network, isTestnet } from '@injectivelabs/networks' | ||
|
||
export function getBonfidaContractAddress(network: Network): string { | ||
if (isTestnet(network)) { | ||
return 'inj1q79ujqyh72p43mhr2ldaly3x6d50rzp3354at3' | ||
} | ||
|
||
return 'inj1v7chmgm7vmuwldjt80utmw9c95jkrch979ps8z' | ||
} |
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,3 +1,4 @@ | ||
export * from './web3' | ||
export * from './gas' | ||
export * from './nameservice' | ||
export * from './bonfida' |
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,4 +1,3 @@ | ||
export * from './mapByAddress' | ||
export * from './mapByHash' | ||
export * from './mapByName' | ||
export * from './mapBySymbol' |
This file was deleted.
Oops, something went wrong.
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