Skip to content

Commit

Permalink
Updated types for functions to support platformID (#26)
Browse files Browse the repository at this point in the history
* Added functionality to specify PlatformId as a parameter

* Updated Comments (PlatformID parameter)

* Updates Types with PlatformId Parameter

* Added functions for 'mintForAddress' and 'updateServiceData'

* added a function to cancel a service

---------

Co-authored-by: pranavsinghal <pranavsinghal96@gmail.com>
  • Loading branch information
pranav-dblocked and pranav-singhal authored Apr 19, 2024
1 parent 1e88a50 commit b6d6d13
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client/src/disputes/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransactionHash } from '../types';

export interface IDispute {
getArbitrationCost(): Promise<any>;
getArbitrationCost(platformId?: number): Promise<any>;
setPrice(value: number | string): Promise<TransactionHash>;
}
5 changes: 3 additions & 2 deletions packages/client/src/escrow/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export interface IEscrow {
serviceId: string,
proposalId: string,
metaEvidenceCid: string,
platformId?: number
): Promise<ClientTransactionResponse>;
release(serviceId: string, amount: bigint, userId: number): Promise<any>;
reimburse(serviceId: string, amount: bigint, userId: number): Promise<any>;
release(serviceId: string, amount: bigint, userId: number, platformId?: number): Promise<any>;
reimburse(serviceId: string, amount: bigint, userId: number, platformId?: number): Promise<any>;
getProtocolAndPlatformsFees(
originServicePlatformId: string,
originValidatedProposalPlatformId: string,
Expand Down
22 changes: 22 additions & 0 deletions packages/client/src/platform/__tests__/platform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,26 @@ describe('Platform', () => {

})
})

describe('mintForAddress', () => {
it('should mint a platform Id for a address', async () => {
// Arrange
const platformName = 'racoon';
const address = testAddress;
const mintFee = BigInt("1000000000000000000");


// Act
const result = await platform.mintForAddress(platformName, address, mintFee);

// Assert
expect(mockViemClient.writeContract).toHaveBeenCalledWith('talentLayerPlatformId',
'mintForAddress',
[platformName, address],
mintFee);
expect(result).toEqual(testAddress);
})
})


});
18 changes: 18 additions & 0 deletions packages/client/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ export class Platform {
return tx;
}

/**
* Mints a platform Id for a address.
*
* @param {string} platformName - The name of the platform.
* @param {string} address - The address of the user.
* @param {string} mintFee - The Fee for the minting of platform Id.
* @returns {Promise<Hash>} A promise that resolves to the transaction hash of the create operation.
*/
public async mintForAddress(platformName: string, address: string, mintFee: any): Promise<Hash> {
const tx = await this.wallet.writeContract(
'talentLayerPlatformId',
'mintForAddress',
[platformName, address],
mintFee as bigint
);
return tx;
}

/**
* Sets the fee timeout for the platform.
*
Expand Down
15 changes: 8 additions & 7 deletions packages/client/src/platform/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export type Arbitrator = {

export interface IPlatform {
getOne(id: string): Promise<any>;
update(data: PlatformDetails): Promise<ClientTransactionResponse>;
updateOriginServiceFeeRate(value: number): Promise<TransactionHash>;
updateOriginValidatedProposalFeeRate(value: number): Promise<TransactionHash>;
updateServicePostingFee(value: number): Promise<TransactionHash>;
updateProposalPostingFee(value: number): Promise<TransactionHash>;
update(data: PlatformDetails, platformId?: number): Promise<ClientTransactionResponse>;
updateOriginServiceFeeRate(value: number, platformId?: number): Promise<TransactionHash>;
updateOriginValidatedProposalFeeRate(value: number, platformId?: number): Promise<TransactionHash>;
updateServicePostingFee(value: number, platformId?: number): Promise<TransactionHash>;
updateProposalPostingFee(value: number, PlatformId?: number): Promise<TransactionHash>;
getByOwner(address: `0x${string}`): Promise<any>;
mint(platformName: string): Promise<TransactionHash>;
setFeeTimeout(timeout: number): Promise<TransactionHash>;
mintForAddress(platformName: string, address: string, mintFee: any): Promise<TransactionHash>;
setFeeTimeout(timeout: number, platformId?: number): Promise<TransactionHash>;
getArbitrators(chainId: NetworkEnum): Arbitrator[];
updateArbitrator(address: `0x${string}`): Promise<TransactionHash>;
updateArbitrator(address: `0x${string}`, platformId?: number): Promise<TransactionHash>;
}
12 changes: 12 additions & 0 deletions packages/client/src/profile/__tests__/profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ describe('Profile', () => {
})
})


describe('createForAddress', () => {
it('should create a new profile for a address and return a response', async () => {
const handle = testName;
const userAddress = testAddress;
const platformId = testPlatformId;
const handlePrice = "1000000000000000000";
const result = await profile.createForAddress(handle, userAddress, platformId, handlePrice);
expect(mockViemClient.writeContract).toHaveBeenCalledWith('talentLayerId', 'mintForAddress', [userAddress, platformId,handle], BigInt(handlePrice))
})
})

describe('getByAddress', () => {
it('getByAddress returns data for a given address', async () => {

Expand Down
19 changes: 19 additions & 0 deletions packages/client/src/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ export class Profile {
);
}


/**
* create - Creates a new user profile by minting it on the TalentLayerId contract for a particular address. This function is typically called when a new user registers and a profile needs to be created in the system for that user.
* @param {string} handle - The user handle or username for the new profile.
* @param {Hash} userAddress - The address of the user whose profile is created.
* @param {number} platformId - The platform ID where the profile is created.
* @param {string} handlePrice - The fee for minting the new profile.
* @returns {Promise<Hash>} - A promise that resolves to the transaction hash once the profile creation transaction is completed.
*/
public async createForAddress(handle: string, userAddress: Hash, platformId: number, handlePrice: string): Promise<Hash> {
const tx = await this.viemClient.writeContract(
'talentLayerId',
'mintForAddress',
[userAddress, platformId, handle],
BigInt(handlePrice),
);
return tx;
}

/**
* getBy - Retrieves profiles based on specified search criteria. This function is useful for fetching multiple profiles, for instance, when implementing search functionality.
* @param {{ numberPerPage?: number; offset?: number; searchQuery?: string; }} params - The search parameters including pagination and search query.
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/profile/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export interface IProfile {
upload(profileData: TalentLayerProfile): Promise<string>;
getByAddress(address: `0x${string}`): Promise<any>;
getById(userId: string): Promise<any>;
create(handle: string): Promise<any>;
create(handle: string, platformId?: number): Promise<any>;
createForAddress(handle: string, userAddress: `0x${string}`, platformId: number, handlePrice: string): Promise<any>;
update(profileData: TalentLayerProfile, userId: string): Promise<ClientTransactionResponse>;
getBy(params: {
numberPerPage?: number;
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/proposals/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export interface IProposal {
serviceId: string,
rateToken: string,
rateAmount: string,
expirationDate: string
expirationDate: string,
platformId?: number
): Promise<ClientTransactionResponse>;

update(
Expand Down
43 changes: 43 additions & 0 deletions packages/client/src/services/__tests__/services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,49 @@ describe('Service', () => {
})
})


describe('update', () => {
it('should update an existing service', async () => {
// Arrange
const serviceDetails = testServiceDetails;
const userId = testUserId;
const existingServiceId = testServiceId;

// Act
const response = await service.update(serviceDetails, userId, parseInt(existingServiceId));

// Assert
expect(response.cid).toEqual(testIpfsHash);
expect(response.tx).toEqual(testAddress);
expect(mockViemClient.writeContract).toHaveBeenCalledWith(
'talentLayerService',
'updateServiceData',
[userId, parseInt(existingServiceId), testIpfsHash]
);
})
})

describe('cancel', () => {
it('should cancel an existing service', async () => {
// Arrange
const userId = testUserId;
const serviceId = parseInt(testServiceId);

// Act
const response = await service.cancel(userId, serviceId);

// Assert
expect(response).toEqual(testAddress);
expect(mockViemClient.writeContract).toHaveBeenCalledWith(
'talentLayerService',
'cancelService',
[userId, serviceId]
);


})
})

describe('search', () => {
it('should reaturn services based on criteria', async () => {
// Arranage
Expand Down
58 changes: 58 additions & 0 deletions packages/client/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Hash } from 'viem';
import GraphQLClient from '../graphql';
import IPFSClient from '../ipfs';
import { Logger } from '../logger';
Expand All @@ -19,9 +20,15 @@ export interface IService {
userId: string,
platformId: number,
): Promise<ClientTransactionResponse>;
update(
serviceDetails: ServiceDetails,
userId: string,
existingServiceId: number,
): Promise<ClientTransactionResponse>;
updloadServiceDataToIpfs(serviceData: ServiceDetails): Promise<string>;
getServices(params: IProps): Promise<any>;
search(params: IProps): Promise<any>;
cancel(userId: string, serviceId: number): Promise<Hash>;
}

/**
Expand Down Expand Up @@ -151,4 +158,55 @@ export class Service {

throw new Error('Unable to create service');
}

/**
* Asynchronously updates an existing service.
* @param {ServiceDetails} serviceDetails - The details of the service to update.
* @param {string} userId - The user ID updating the service.
* @param {number} existingServiceId - The existing Service ID which is getting updated.
* @returns {Promise<ClientTransactionResponse>} - A promise that resolves to the transaction response of the service update.
*/
public async update(
serviceDetails: ServiceDetails,
userId: string,
existingServiceId: number,
): Promise<ClientTransactionResponse> {

const cid = await this.updloadServiceDataToIpfs(serviceDetails);

const tx = await this.viemClient.writeContract(
'talentLayerService',
'updateServiceData',
[userId, existingServiceId, cid],
);

if (cid && tx) {
return { cid, tx };
}

throw new Error('Unable to update service');
}

/**
* Cancel an existing service.
* @param {string} userId - Id of the user cancelling the service
* @param {number} serviceId - Id of the service being updated
* @returns {Promise<Hash>} - A promise that resolves to the transaction hash for the cancelService function call
*/
public async cancel(
userId: string,
serviceId: number
): Promise<Hash> {
const tx = await this.viemClient.writeContract(
'talentLayerService',
'cancelService',
[userId, serviceId]
)

if (tx) {
return tx;
}

throw new Error('Unable to cancel service');
}
}

0 comments on commit b6d6d13

Please sign in to comment.