Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set & get dedicated node extra fees in chain & client #698

Merged
merged 11 commits into from
Jun 22, 2023
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