Skip to content

Commit

Permalink
Use the chain client instance create on the grid client while connect…
Browse files Browse the repository at this point in the history
…ing for all modules instead of creating a new one
  • Loading branch information
AhmedHanafy725 committed Sep 27, 2023
1 parent 01d7dee commit 6e4b731
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/grid_client/src/high_level/farmerbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FarmerBot {
client: TFClient;

constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
this.rmb = new RMB(config.rmbClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TwinDeploymentHandler {
nodes: Nodes;

constructor(public config: GridClientConfig) {
this.tfclient = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.tfclient = config.tfclient;
this.deploymentFactory = new DeploymentFactory(this.config);
this.rmb = new RMB(config.rmbClient);
this.nodes = new Nodes(this.config.graphqlURL, this.config.proxyURL, this.config.rmbClient);
Expand Down
7 changes: 1 addition & 6 deletions packages/grid_client/src/modules/algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ class Algorand implements blockchainInterface {
config.backendStorage,
config.seed,
);
this.tfClient = new TFClient(
this.config.substrateURL,
this.config.mnemonic,
this.config.storeSecret,
this.config.keypairType,
);
this.tfClient = config.tfclient;
}

private async saveIfKVStoreBackend(extrinsics) {
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkBalance } from "./utils";
class Balance {
client: TFClient;
constructor(config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}
@expose
@validateInput
Expand Down
7 changes: 1 addition & 6 deletions packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ class BaseModule {
config.backendStorage,
config.seed,
);
this.tfClient = new TFClient(
this.config.substrateURL,
this.config.mnemonic,
this.config.storeSecret,
this.config.keypairType,
);
this.tfClient = config.tfclient;
}

getDeploymentPath(name: string): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Calculator {
client: TFClient;

constructor(config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}
@expose
@validateInput
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Contracts {
client: TFClient;
nodes: Nodes;
constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
this.nodes = new Nodes(config.graphqlURL, config.proxyURL, config.rmbClient);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/farmerbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Farmerbot {
rmb: RMB;

constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
this.farmerBot = new FarmerBot(this.config);
this.rmb = new RMB(config.rmbClient);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Farms {
client: TFClient;

constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}

@expose
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkBalance } from "./utils";
class KVStore {
client: TFClient;
constructor(config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}
@expose
@validateInput
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { checkBalance } from "./utils";
class Nodes {
client: TFClient;
constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}

@expose
Expand Down
7 changes: 1 addition & 6 deletions packages/grid_client/src/modules/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ class Stellar implements blockchainInterface {
config.backendStorage,
config.seed,
);
this.tfClient = new TFClient(
this.config.substrateURL,
this.config.mnemonic,
this.config.storeSecret,
this.config.keypairType,
);
this.tfClient = config.tfclient;
}

private async saveIfKVStoreBackend(extrinsics) {
Expand Down
7 changes: 1 addition & 6 deletions packages/grid_client/src/modules/tfchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ class TFChain implements blockchainInterface {
this.storeSecret = config.storeSecret as string;
this.keypairType = config.keypairType;
this.network = config.network;
this.tfClient = new TFClient(
this.config.substrateURL,
this.config.mnemonic,
this.config.storeSecret,
this.config.keypairType,
);
this.tfClient = config.tfclient;
}

getPath() {
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/twins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkBalance } from "./utils";
class Twins {
client: TFClient;
constructor(config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}

@expose
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Utility {
client: TFClient;

constructor(public config: GridClientConfig) {
this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType);
this.client = config.tfclient;
}

@expose
Expand Down
4 changes: 1 addition & 3 deletions packages/grid_client/src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { TFClient } from "../clients/tf-grid/client";
function checkBalance(target, propertyKey: string, descriptor: PropertyDescriptor) {
const method = descriptor.value;
descriptor.value = async function (...args) {
const { substrateURL, mnemonic, storeSecret, keypairType } = this.config;
const tfclient = new TFClient(substrateURL, mnemonic, storeSecret, keypairType);
const balances = await tfclient.balances.getMyBalance();
const balances = await this.config.tfclient.balances.getMyBalance();
if (balances["free"] < 0.001) {
throw Error("Balance is not enough to apply an extrinsic");
}
Expand Down
7 changes: 1 addition & 6 deletions packages/grid_client/src/primitives/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ class Network {
);
this.rmb = new RMB(config.rmbClient);
this.capacity = new Nodes(this.config.graphqlURL, this.config.proxyURL, this.config.rmbClient);
this.tfClient = new TFClient(
this.config.substrateURL,
this.config.mnemonic,
this.config.storeSecret,
this.config.keypairType,
);
this.tfClient = config.tfclient;
}

private async saveIfKVStoreBackend(extrinsics) {
Expand Down

0 comments on commit 6e4b731

Please sign in to comment.