From 54cf0eba323b41840abcca7d9407e5d21b115a03 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 16:27:51 +0300 Subject: [PATCH 01/11] Add set & get dedicated node price in chain & client --- packages/grid_client/scripts/extraFees.ts | 26 ++++++++++ packages/grid_client/src/modules/contracts.ts | 19 +++++++- packages/grid_client/src/modules/models.ts | 11 +++++ packages/tfchain_client/src/contracts.ts | 48 ++++++++++++------- packages/tfchain_client/src/nodes.ts | 2 + 5 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 packages/grid_client/scripts/extraFees.ts diff --git a/packages/grid_client/scripts/extraFees.ts b/packages/grid_client/scripts/extraFees.ts new file mode 100644 index 0000000000..bc2059ca25 --- /dev/null +++ b/packages/grid_client/scripts/extraFees.ts @@ -0,0 +1,26 @@ +import { getClient } from "./client_loader"; +import { log } from "./utils"; + +async function main() { + const grid3 = await getClient(); + + const node = { nodeId: 5 }; + + const extraFees = await grid3.contracts.setExtraFees({ ...node, extraFee: 5 }); + + console.log(extraFees); + + grid3.contracts + .getDedicatedNodePrice(node) + .then(res => { + log(res); + }) + .catch(err => { + throw err; + }) + .finally(() => { + grid3.disconnect(); + }); +} + +main(); diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index aa7e000d1e..e1d153acb6 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -18,6 +18,7 @@ import { ContractsByTwinId, ContractState, CreateServiceContractModel, + GetDedicatedNodePriceModel, GetServiceContractModel, NameContractCreateModel, NameContractGetModel, @@ -27,6 +28,7 @@ import { ServiceContractApproveModel, ServiceContractBillModel, ServiceContractCancelModel, + SetDedicatedNodeExtraFeesModel, SetServiceContractFeesModel, SetServiceContractMetadataModel, } from "./models"; @@ -178,14 +180,27 @@ class Contracts { @expose @validateInput @checkBalance - async setMetadataServiceContract(options: SetServiceContractMetadataModel) { - return (await this.client.contracts.setServiceMetadata(options)).apply(); + async setExtraFees(options: SetDedicatedNodeExtraFeesModel) { + return (await this.client.contracts.setExtraFees(options)).apply(); } @expose @validateInput async getServiceContract(options: GetServiceContractModel) { return this.client.contracts.getService(options); } + + @expose + @validateInput + @checkBalance + async setMetadataServiceContract(options: SetServiceContractMetadataModel) { + return (await this.client.contracts.setServiceMetadata(options)).apply(); + } + + @expose + @validateInput + async getDedicatedNodePrice(options: GetDedicatedNodePriceModel) { + return this.client.contracts.getDedicatedNodePrice(options); + } /** * WARNING: Please be careful when executing this method, it will delete all your contracts. * @returns Promise diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index da35dead12..31fe7fe1b5 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -605,6 +605,15 @@ class NetworkGetModel { @Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string; } +class SetDedicatedNodeExtraFeesModel { + @Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number; + @Expose() @IsInt() @IsNotEmpty() @Min(1) extraFee: number; +} + +class GetDedicatedNodePriceModel { + @Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number; +} + export { AlgorandAccountCreateModel, AlgorandAccountInitModel, @@ -720,4 +729,6 @@ export { GetServiceContractModel, NetworkGetModel, NodeGetModel, + SetDedicatedNodeExtraFeesModel, + GetDedicatedNodePriceModel, }; diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index e7c16f721c..dbafe7be23 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -188,6 +188,14 @@ export interface SetServiceFeesOptions { baseFee: number; variableFee: number; } +export interface SetDedicatedNodeExtraFeesOptions { + nodeId: number; + extraFee: number; +} + +export interface GetDedicatedNodePriceOptions { + nodeId: number; +} export interface SetServiceMetadataOptions { serviceId: number; @@ -214,7 +222,7 @@ class Contracts extends QueryContracts { @checkConnection async createNode(options: CreateNodeOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.createNodeContract( + const extrinsic = this.client.api.tx.smartContractModule.createNodeContract( options.nodeId, options.hash, options.data, @@ -226,23 +234,19 @@ class Contracts extends QueryContracts { @checkConnection async updateNode(options: UpdateNodeOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.updateNodeContract( - options.id, - options.hash, - options.data, - ); + const extrinsic = this.client.api.tx.smartContractModule.updateNodeContract(options.id, options.hash, options.data); return this.client.patchExtrinsic(extrinsic); } @checkConnection async createName(options: CreateNameOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.createNameContract(options.name); + const extrinsic = this.client.api.tx.smartContractModule.createNameContract(options.name); return this.client.patchExtrinsic(extrinsic); } @checkConnection async createRent(options: CreateRentOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.createRentContract( + const extrinsic = this.client.api.tx.smartContractModule.createRentContract( options.nodeId, options.solutionProviderId, ); @@ -255,7 +259,7 @@ class Contracts extends QueryContracts { if (!contract) { return; } - const extrinsic = await this.client.api.tx.smartContractModule.cancelContract(options.id); + const extrinsic = this.client.api.tx.smartContractModule.cancelContract(options.id); return this.client.patchExtrinsic(extrinsic, { map: () => options.id, resultEvents: ["NodeContractCanceled", "NameContractCanceled", "RentContractCanceled", "ContractCanceled"], @@ -264,7 +268,7 @@ class Contracts extends QueryContracts { @checkConnection async createService(options: CreateServiceOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCreate( + const extrinsic = this.client.api.tx.smartContractModule.serviceContractCreate( options.serviceAccount, options.consumerAccount, ); @@ -275,16 +279,16 @@ class Contracts extends QueryContracts { async approveService(options: ApproveServiceOptions) { let extrinsic: any; if (options.approve) { - extrinsic = await this.client.api.tx.smartContractModule.serviceContractApprove(options.serviceId); + extrinsic = this.client.api.tx.smartContractModule.serviceContractApprove(options.serviceId); } else { - extrinsic = await this.client.api.tx.smartContractModule.serviceContractReject(options.serviceId); + extrinsic = this.client.api.tx.smartContractModule.serviceContractReject(options.serviceId); } return this.client.patchExtrinsic(extrinsic); } @checkConnection async billService(options: BillServiceOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.serviceContractBill( + const extrinsic = this.client.api.tx.smartContractModule.serviceContractBill( options.serviceId, options.variableAmount, options.metadata, @@ -294,13 +298,13 @@ class Contracts extends QueryContracts { @checkConnection async cancelService(options: CancelServiceOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId); + const extrinsic = this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId); return this.client.patchExtrinsic(extrinsic, { map: () => options.serviceId }); } @checkConnection async setServiceFees(options: SetServiceFeesOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetFees( + const extrinsic = this.client.api.tx.smartContractModule.serviceContractSetFees( options.serviceId, options.baseFee, options.variableFee, @@ -308,9 +312,21 @@ class Contracts extends QueryContracts { return this.client.patchExtrinsic(extrinsic); } + @checkConnection + async setExtraFees(options: SetDedicatedNodeExtraFeesOptions) { + const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); + return this.client.patchExtrinsic(extrinsic); + } + + @checkConnection + async getDedicatedNodePrice(options: GetDedicatedNodePriceOptions) { + const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId); + return res.toPrimitive() as number; + } + @checkConnection async setServiceMetadata(options: SetServiceMetadataOptions) { - const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetMetadata( + const extrinsic = this.client.api.tx.smartContractModule.serviceContractSetMetadata( options.serviceId, options.metadata, ); diff --git a/packages/tfchain_client/src/nodes.ts b/packages/tfchain_client/src/nodes.ts index f1b0a99bbf..26a3eaca5c 100644 --- a/packages/tfchain_client/src/nodes.ts +++ b/packages/tfchain_client/src/nodes.ts @@ -21,6 +21,7 @@ export interface Node { virtualized: boolean; serialNumber: string; connectionPrice: number; + hasGpu: number; } interface NetworkInterfaceType { @@ -44,6 +45,7 @@ interface NodeResources { sru: number; cru: number; mru: number; + gpu: number; } interface NodeLocation { From 31a0600c47434a6c8e4c789a774d4bd43aa2bab5 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 16:46:59 +0300 Subject: [PATCH 02/11] rename get & set functions --- packages/grid_client/scripts/extraFees.ts | 8 ++++---- packages/grid_client/src/modules/contracts.ts | 8 ++++---- packages/tfchain_client/src/contracts.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/grid_client/scripts/extraFees.ts b/packages/grid_client/scripts/extraFees.ts index bc2059ca25..8d70fa6089 100644 --- a/packages/grid_client/scripts/extraFees.ts +++ b/packages/grid_client/scripts/extraFees.ts @@ -4,14 +4,14 @@ import { log } from "./utils"; async function main() { const grid3 = await getClient(); - const node = { nodeId: 5 }; + const node = { nodeId: 11 }; - const extraFees = await grid3.contracts.setExtraFees({ ...node, extraFee: 5 }); + // const extraFees = await grid3.contracts.setDedicatedNodeExtraFee({ ...node, extraFee: 5 }); - console.log(extraFees); + // console.log(extraFees); grid3.contracts - .getDedicatedNodePrice(node) + .getDedicatedNodeExtraFee(node) .then(res => { log(res); }) diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index e1d153acb6..a859fb7393 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -180,8 +180,8 @@ class Contracts { @expose @validateInput @checkBalance - async setExtraFees(options: SetDedicatedNodeExtraFeesModel) { - return (await this.client.contracts.setExtraFees(options)).apply(); + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesModel) { + return (await this.client.contracts.setDedicatedNodeExtraFee(options)).apply(); } @expose @validateInput @@ -198,8 +198,8 @@ class Contracts { @expose @validateInput - async getDedicatedNodePrice(options: GetDedicatedNodePriceModel) { - return this.client.contracts.getDedicatedNodePrice(options); + async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceModel) { + return this.client.contracts.getDedicatedNodeExtraFee(options); } /** * WARNING: Please be careful when executing this method, it will delete all your contracts. diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index dbafe7be23..1c24e7e5ce 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -313,13 +313,13 @@ class Contracts extends QueryContracts { } @checkConnection - async setExtraFees(options: SetDedicatedNodeExtraFeesOptions) { + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions) { const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); return this.client.patchExtrinsic(extrinsic); } @checkConnection - async getDedicatedNodePrice(options: GetDedicatedNodePriceOptions) { + async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceOptions) { const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId); return res.toPrimitive() as number; } From 9914d914f159e1108ecb6ad07da2f272855435bd Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 17:06:23 +0300 Subject: [PATCH 03/11] revert nodes.ts changes, adjust getDedicatedNodeExtraFee location --- packages/grid_client/src/modules/contracts.ts | 11 ++++++----- packages/tfchain_client/src/nodes.ts | 2 -- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index a859fb7393..5ab837b383 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -95,6 +95,12 @@ class Contracts { return this.client.contracts.getContractIdByName(options); } + @expose + @validateInput + async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceModel) { + return this.client.contracts.getDedicatedNodeExtraFee(options); + } + @expose @validateInput async activeRentContractForNode(options: RentContractGetModel) { @@ -196,11 +202,6 @@ class Contracts { return (await this.client.contracts.setServiceMetadata(options)).apply(); } - @expose - @validateInput - async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceModel) { - return this.client.contracts.getDedicatedNodeExtraFee(options); - } /** * WARNING: Please be careful when executing this method, it will delete all your contracts. * @returns Promise diff --git a/packages/tfchain_client/src/nodes.ts b/packages/tfchain_client/src/nodes.ts index 26a3eaca5c..f1b0a99bbf 100644 --- a/packages/tfchain_client/src/nodes.ts +++ b/packages/tfchain_client/src/nodes.ts @@ -21,7 +21,6 @@ export interface Node { virtualized: boolean; serialNumber: string; connectionPrice: number; - hasGpu: number; } interface NetworkInterfaceType { @@ -45,7 +44,6 @@ interface NodeResources { sru: number; cru: number; mru: number; - gpu: number; } interface NodeLocation { From 07a8bb0fad51055eff245896e26af1e0b6b5a1de Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 17:18:47 +0300 Subject: [PATCH 04/11] revert awaits in tfchain, adjust setDedicatedNodeExtraFee location --- packages/grid_client/src/modules/contracts.ts | 13 +++++----- packages/tfchain_client/src/contracts.ts | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index 5ab837b383..34b68394d1 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -183,12 +183,6 @@ class Contracts { return (await this.client.contracts.setServiceFees(options)).apply(); } - @expose - @validateInput - @checkBalance - async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesModel) { - return (await this.client.contracts.setDedicatedNodeExtraFee(options)).apply(); - } @expose @validateInput async getServiceContract(options: GetServiceContractModel) { @@ -228,6 +222,13 @@ class Contracts { return contracts; } + @expose + @validateInput + @checkBalance + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesModel) { + return (await this.client.contracts.setDedicatedNodeExtraFee(options)).apply(); + } + /** * Get contract consumption per hour in TFT. * diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index 1c24e7e5ce..9fdd792bef 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -222,7 +222,7 @@ class Contracts extends QueryContracts { @checkConnection async createNode(options: CreateNodeOptions) { - const extrinsic = this.client.api.tx.smartContractModule.createNodeContract( + const extrinsic = await this.client.api.tx.smartContractModule.createNodeContract( options.nodeId, options.hash, options.data, @@ -234,7 +234,11 @@ class Contracts extends QueryContracts { @checkConnection async updateNode(options: UpdateNodeOptions) { - const extrinsic = this.client.api.tx.smartContractModule.updateNodeContract(options.id, options.hash, options.data); + const extrinsic = await this.client.api.tx.smartContractModule.updateNodeContract( + options.id, + options.hash, + options.data, + ); return this.client.patchExtrinsic(extrinsic); } @@ -246,7 +250,7 @@ class Contracts extends QueryContracts { @checkConnection async createRent(options: CreateRentOptions) { - const extrinsic = this.client.api.tx.smartContractModule.createRentContract( + const extrinsic = await this.client.api.tx.smartContractModule.createRentContract( options.nodeId, options.solutionProviderId, ); @@ -259,7 +263,7 @@ class Contracts extends QueryContracts { if (!contract) { return; } - const extrinsic = this.client.api.tx.smartContractModule.cancelContract(options.id); + const extrinsic = await this.client.api.tx.smartContractModule.cancelContract(options.id); return this.client.patchExtrinsic(extrinsic, { map: () => options.id, resultEvents: ["NodeContractCanceled", "NameContractCanceled", "RentContractCanceled", "ContractCanceled"], @@ -268,7 +272,7 @@ class Contracts extends QueryContracts { @checkConnection async createService(options: CreateServiceOptions) { - const extrinsic = this.client.api.tx.smartContractModule.serviceContractCreate( + const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCreate( options.serviceAccount, options.consumerAccount, ); @@ -279,16 +283,16 @@ class Contracts extends QueryContracts { async approveService(options: ApproveServiceOptions) { let extrinsic: any; if (options.approve) { - extrinsic = this.client.api.tx.smartContractModule.serviceContractApprove(options.serviceId); + extrinsic = await this.client.api.tx.smartContractModule.serviceContractApprove(options.serviceId); } else { - extrinsic = this.client.api.tx.smartContractModule.serviceContractReject(options.serviceId); + extrinsic = await this.client.api.tx.smartContractModule.serviceContractReject(options.serviceId); } return this.client.patchExtrinsic(extrinsic); } @checkConnection async billService(options: BillServiceOptions) { - const extrinsic = this.client.api.tx.smartContractModule.serviceContractBill( + const extrinsic = await this.client.api.tx.smartContractModule.serviceContractBill( options.serviceId, options.variableAmount, options.metadata, @@ -298,13 +302,13 @@ class Contracts extends QueryContracts { @checkConnection async cancelService(options: CancelServiceOptions) { - const extrinsic = this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId); + const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId); return this.client.patchExtrinsic(extrinsic, { map: () => options.serviceId }); } @checkConnection async setServiceFees(options: SetServiceFeesOptions) { - const extrinsic = this.client.api.tx.smartContractModule.serviceContractSetFees( + const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetFees( options.serviceId, options.baseFee, options.variableFee, @@ -326,7 +330,7 @@ class Contracts extends QueryContracts { @checkConnection async setServiceMetadata(options: SetServiceMetadataOptions) { - const extrinsic = this.client.api.tx.smartContractModule.serviceContractSetMetadata( + const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetMetadata( options.serviceId, options.metadata, ); From e699d244952364195986eccabed344c035f1a199 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 17:26:49 +0300 Subject: [PATCH 05/11] simple change --- packages/grid_client/src/modules/contracts.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index 34b68394d1..1c9cfa65f3 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -183,12 +183,6 @@ class Contracts { return (await this.client.contracts.setServiceFees(options)).apply(); } - @expose - @validateInput - async getServiceContract(options: GetServiceContractModel) { - return this.client.contracts.getService(options); - } - @expose @validateInput @checkBalance @@ -196,6 +190,11 @@ class Contracts { return (await this.client.contracts.setServiceMetadata(options)).apply(); } + @expose + @validateInput + async getServiceContract(options: GetServiceContractModel) { + return this.client.contracts.getService(options); + } /** * WARNING: Please be careful when executing this method, it will delete all your contracts. * @returns Promise From db3208b10d1310c937abd13cdc63e34b586a01f6 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 17:38:20 +0300 Subject: [PATCH 06/11] add createName await --- packages/tfchain_client/src/contracts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index 9fdd792bef..f18ff5f50b 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -244,7 +244,7 @@ class Contracts extends QueryContracts { @checkConnection async createName(options: CreateNameOptions) { - const extrinsic = this.client.api.tx.smartContractModule.createNameContract(options.name); + const extrinsic = await this.client.api.tx.smartContractModule.createNameContract(options.name); return this.client.patchExtrinsic(extrinsic); } From 3e18d9ba1c8c066eaf7442ab21106adb75bf1b3e Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 17:43:18 +0300 Subject: [PATCH 07/11] remove getDedicatedNodeExtraFee to be in QueryContracts --- packages/tfchain_client/src/contracts.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index f18ff5f50b..376b8d7e00 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -146,6 +146,12 @@ class QueryContracts { const res = await this.client.api.query.smartContractModule.serviceContracts(options.serviceId); return res.toPrimitive() as unknown as ServiceContract; } + + @checkConnection + async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceOptions) { + const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId); + return res.toPrimitive() as number; + } } export interface CreateNodeOptions { @@ -322,12 +328,6 @@ class Contracts extends QueryContracts { return this.client.patchExtrinsic(extrinsic); } - @checkConnection - async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceOptions) { - const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId); - return res.toPrimitive() as number; - } - @checkConnection async setServiceMetadata(options: SetServiceMetadataOptions) { const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetMetadata( From 2d12277ed646930db01cd656edd7d0648b96db8a Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 21 Jun 2023 18:04:41 +0300 Subject: [PATCH 08/11] Added return types to get & set extra fees --- packages/grid_client/scripts/extraFees.ts | 6 +++--- packages/tfchain_client/src/contracts.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/grid_client/scripts/extraFees.ts b/packages/grid_client/scripts/extraFees.ts index 8d70fa6089..87a12284d1 100644 --- a/packages/grid_client/scripts/extraFees.ts +++ b/packages/grid_client/scripts/extraFees.ts @@ -4,11 +4,11 @@ import { log } from "./utils"; async function main() { const grid3 = await getClient(); - const node = { nodeId: 11 }; + const node = { nodeId: 73 }; - // const extraFees = await grid3.contracts.setDedicatedNodeExtraFee({ ...node, extraFee: 5 }); + const extraFees = await grid3.contracts.setDedicatedNodeExtraFee({ ...node, extraFee: 5 }); - // console.log(extraFees); + console.log(extraFees); grid3.contracts .getDedicatedNodeExtraFee(node) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index 376b8d7e00..e4a3edd6f3 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -1,5 +1,5 @@ import { Client, QueryClient } from "./client"; -import { PublicIp } from "./types"; +import { ExtrinsicResult, PublicIp } from "./types"; import { checkConnection } from "./utils"; const TWO_WEEKS = 1209600000; @@ -148,7 +148,7 @@ class QueryContracts { } @checkConnection - async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceOptions) { + async getDedicatedNodeExtraFee(options: GetDedicatedNodePriceOptions): Promise { const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId); return res.toPrimitive() as number; } @@ -323,7 +323,7 @@ class Contracts extends QueryContracts { } @checkConnection - async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions) { + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise> { const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); return this.client.patchExtrinsic(extrinsic); } From cbcc410fb5cd1fead0efb2a1c27d1d83cf064dc7 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 22 Jun 2023 11:03:55 +0300 Subject: [PATCH 09/11] edit contract type in setExtraFees --- packages/tfchain_client/src/contracts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index e4a3edd6f3..fb06947e09 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -323,9 +323,9 @@ class Contracts extends QueryContracts { } @checkConnection - async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise> { + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise> { const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } @checkConnection From 407465856ef35d7db43e299a57939fd53a7c71cb Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 22 Jun 2023 11:24:53 +0300 Subject: [PATCH 10/11] Remove setExtraFees return type --- packages/tfchain_client/src/contracts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index fb06947e09..3e9f2e4d04 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -323,9 +323,9 @@ class Contracts extends QueryContracts { } @checkConnection - async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise> { + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions) { const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } @checkConnection From c72b59b35810de040f79f25ec5e8b8756f9df75a Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 22 Jun 2023 11:28:50 +0300 Subject: [PATCH 11/11] Remove useless import --- packages/tfchain_client/src/contracts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index 3e9f2e4d04..5f3188bac5 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -1,5 +1,5 @@ import { Client, QueryClient } from "./client"; -import { ExtrinsicResult, PublicIp } from "./types"; +import { PublicIp } from "./types"; import { checkConnection } from "./utils"; const TWO_WEEKS = 1209600000;