Skip to content

Commit

Permalink
Merge pull request #698 from threefoldtech/development_add_extra_fees
Browse files Browse the repository at this point in the history
Add set & get dedicated node extra fees in chain & client
  • Loading branch information
zaelgohary authored Jun 22, 2023
2 parents f2277a6 + c72b59b commit 09b0e28
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/grid_client/scripts/extraFees.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getClient } from "./client_loader";
import { log } from "./utils";

async function main() {
const grid3 = await getClient();

const node = { nodeId: 73 };

const extraFees = await grid3.contracts.setDedicatedNodeExtraFee({ ...node, extraFee: 5 });

console.log(extraFees);

grid3.contracts
.getDedicatedNodeExtraFee(node)
.then(res => {
log(res);
})
.catch(err => {
throw err;
})
.finally(() => {
grid3.disconnect();
});
}

main();
16 changes: 16 additions & 0 deletions packages/grid_client/src/modules/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ContractsByTwinId,
ContractState,
CreateServiceContractModel,
GetDedicatedNodePriceModel,
GetServiceContractModel,
NameContractCreateModel,
NameContractGetModel,
Expand All @@ -27,6 +28,7 @@ import {
ServiceContractApproveModel,
ServiceContractBillModel,
ServiceContractCancelModel,
SetDedicatedNodeExtraFeesModel,
SetServiceContractFeesModel,
SetServiceContractMetadataModel,
} from "./models";
Expand Down Expand Up @@ -93,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) {
Expand Down Expand Up @@ -181,6 +189,7 @@ class Contracts {
async setMetadataServiceContract(options: SetServiceContractMetadataModel) {
return (await this.client.contracts.setServiceMetadata(options)).apply();
}

@expose
@validateInput
async getServiceContract(options: GetServiceContractModel) {
Expand Down Expand Up @@ -212,6 +221,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.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -720,4 +729,6 @@ export {
GetServiceContractModel,
NetworkGetModel,
NodeGetModel,
SetDedicatedNodeExtraFeesModel,
GetDedicatedNodePriceModel,
};
20 changes: 20 additions & 0 deletions packages/tfchain_client/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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): Promise<number> {
const res = await this.client.api.query.smartContractModule.dedicatedNodesExtraFee(options.nodeId);
return res.toPrimitive() as number;
}
}

export interface CreateNodeOptions {
Expand Down Expand Up @@ -188,6 +194,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;
Expand Down Expand Up @@ -308,6 +322,12 @@ class Contracts extends QueryContracts {
return this.client.patchExtrinsic<ServiceContract>(extrinsic);
}

@checkConnection
async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions) {
const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee);
return this.client.patchExtrinsic(extrinsic);
}

@checkConnection
async setServiceMetadata(options: SetServiceMetadataOptions) {
const extrinsic = await this.client.api.tx.smartContractModule.serviceContractSetMetadata(
Expand Down

0 comments on commit 09b0e28

Please sign in to comment.