-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dedicated pathfinderV2 class connecting to the circlesRpc
- Loading branch information
Showing
19 changed files
with
194 additions
and
216 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,5 @@ | |
}, | ||
"name": "@cirlces-sdk/root", | ||
"license": "MIT", | ||
"version": "0.13.4" | ||
"version": "0.14.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
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 |
---|---|---|
@@ -1,71 +1,72 @@ | ||
export interface Profile { | ||
name: string; | ||
description?: string; | ||
previewImageUrl?: string; | ||
imageUrl?: string; | ||
name: string; | ||
description?: string; | ||
previewImageUrl?: string; | ||
imageUrl?: string; | ||
extensions?: Record<string, any>; | ||
} | ||
|
||
export interface GroupProfile extends Profile { | ||
symbol: string; | ||
symbol: string; | ||
} | ||
|
||
export class Profiles { | ||
constructor(private readonly profileServiceUrl: string) { | ||
} | ||
|
||
private getProfileServiceUrl(): string { | ||
return this.profileServiceUrl.endsWith('/') ? this.profileServiceUrl : `${this.profileServiceUrl}/`; | ||
} | ||
constructor(private readonly profileServiceUrl: string) { | ||
} | ||
|
||
async create(profile: Profile): Promise<string> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}pin`, { | ||
method: 'POST', | ||
headers: {'Content-Type': 'application/json'}, | ||
body: JSON.stringify(profile) | ||
}); | ||
private getProfileServiceUrl(): string { | ||
return this.profileServiceUrl.endsWith('/') ? this.profileServiceUrl : `${this.profileServiceUrl}/`; | ||
} | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to create profile. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
} | ||
async create(profile: Profile): Promise<string> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}pin`, { | ||
method: 'POST', | ||
headers: {'Content-Type': 'application/json'}, | ||
body: JSON.stringify(profile) | ||
}); | ||
|
||
const data = await response.json(); | ||
return data.cid; | ||
if (!response.ok) { | ||
throw new Error(`Failed to create profile. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
} | ||
|
||
/** | ||
* Retrieves a profile by its CID. If the profile is not found, an error is thrown. | ||
* @param cid The CID of the profile to retrieve. | ||
*/ | ||
async get(cid: string): Promise<Profile|undefined> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}get?cid=${cid}`); | ||
if (!response.ok) { | ||
console.warn(`Failed to retrieve profile ${cid}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
return undefined; | ||
} | ||
const data = await response.json(); | ||
return data.cid; | ||
} | ||
|
||
return await response.json(); | ||
/** | ||
* Retrieves a profile by its CID. If the profile is not found, an error is thrown. | ||
* @param cid The CID of the profile to retrieve. | ||
*/ | ||
async get(cid: string): Promise<Profile | undefined> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}get?cid=${cid}`); | ||
if (!response.ok) { | ||
console.warn(`Failed to retrieve profile ${cid}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Retrieves multiple profiles by their CIDs. If a profile is not found, it will not be included in the result. | ||
* @param cids The CIDs of the profiles to retrieve. | ||
* @returns A map of CIDs to profiles. If a profile is not found, it will not be included in the map. | ||
*/ | ||
async getMany(cids: string[]): Promise<Record<string, Profile>> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}getBatch?cids=${cids.join(',')}`); | ||
if (!response.ok) { | ||
throw new Error(`Failed to retrieve profiles ${cids.join(',')}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
} | ||
return await response.json(); | ||
} | ||
|
||
const profilesArray = await response.json(); | ||
const profiles: Record<string, Profile> = {}; | ||
/** | ||
* Retrieves multiple profiles by their CIDs. If a profile is not found, it will not be included in the result. | ||
* @param cids The CIDs of the profiles to retrieve. | ||
* @returns A map of CIDs to profiles. If a profile is not found, it will not be included in the map. | ||
*/ | ||
async getMany(cids: string[]): Promise<Record<string, Profile>> { | ||
const response = await fetch(`${this.getProfileServiceUrl()}getBatch?cids=${cids.join(',')}`); | ||
if (!response.ok) { | ||
throw new Error(`Failed to retrieve profiles ${cids.join(',')}. Status: ${response.status} ${response.statusText}. Body: ${await response.text()}`); | ||
} | ||
|
||
for (let i = 0; i < cids.length; i++) { | ||
if (profilesArray[i]) { | ||
profiles[cids[i]] = profilesArray[i]; | ||
} | ||
} | ||
const profilesArray = await response.json(); | ||
const profiles: Record<string, Profile> = {}; | ||
|
||
return profiles; | ||
for (let i = 0; i < cids.length; i++) { | ||
if (profilesArray[i]) { | ||
profiles[cids[i]] = profilesArray[i]; | ||
} | ||
} | ||
|
||
return profiles; | ||
} | ||
} |
Oops, something went wrong.