Skip to content

Commit

Permalink
provide a mechanism to set the gas price on the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed May 4, 2023
1 parent 247603f commit 2870e75
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 496 deletions.
89 changes: 16 additions & 73 deletions community/communitybuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ import { CBuilder as Builder } from '../community/cbuilder';
class CommunityBuilder extends ContractAbi implements Builder {
static ABI_NAME = 'CommunityBuilder.json';

private readonly wallet: Wallet;
private readonly gas: number;

constructor(abiPath: string, contractAddress: string, web3: Web3, wallet: Wallet, gas: number) {
super(abiPath, CommunityBuilder.ABI_NAME, contractAddress, web3);
this.wallet = wallet;
this.gas = gas;
}

/**
* get the contract name
* @returns string - contract anme
Expand All @@ -78,10 +69,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async aCommunity(): Promise<Builder> {
this.logger.info('Community Builder Started');
const tx = await this.contract.methods.aCommunity().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.aCommunity().send();
this.logger.info(tx);
return this;
}
Expand All @@ -93,10 +81,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asOpenCommunity(): Promise<Builder> {
this.logger.info('asOpenCommunity');
const tx = await this.contract.methods.asOpenCommunity().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asOpenCommunity().send();
this.logger.info(tx);
return this;
}
Expand All @@ -108,10 +93,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asPoolCommunity(): Promise<Builder> {
this.logger.info('asPoolCommunity');
const tx = await this.contract.methods.asPoolCommunity().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asPoolCommunity().send();
this.logger.info(tx);
return this;
}
Expand All @@ -125,10 +107,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asErc721Community(project: string): Promise<Builder> {
this.logger.info('asErc721Community');
const tx = await this.contract.methods.asErc721Community(project).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asErc721Community(project).send();
this.logger.info(tx);
return this;
}
Expand All @@ -143,10 +122,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asClosedErc721Community(project: string, tokenThreshold: number): Promise<Builder> {
this.logger.info('asClosedErc721Community');
const tx = await this.contract.methods.asClosedErc721Community(project, tokenThreshold).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asClosedErc721Community(project, tokenThreshold).send();
this.logger.info(tx);
return this;
}
Expand All @@ -160,10 +136,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asErc20Community(project: string): Promise<Builder> {
this.logger.info('asErc20Community');
const tx = await this.contract.methods.asErc20Community(project).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asErc20Community(project).send();
this.logger.info(tx);
return this;
}
Expand All @@ -178,10 +151,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async asClosedErc20Community(project: string, tokenThreshold: number): Promise<Builder> {
this.logger.info('asClosedErc20Community');
const tx = await this.contract.methods.asClosedErc20Community(project, tokenThreshold).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.asClosedErc20Community(project, tokenThreshold).send();
this.logger.info(tx);
return this;
}
Expand All @@ -195,10 +165,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withVoter(voter: string): Promise<Builder> {
this.logger.info(`withVoter ${voter}`);
const tx = await this.contract.methods.withVoter(voter).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withVoter(voter).send();
this.logger.info(tx);
return this;
}
Expand All @@ -212,10 +179,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withCommunitySupervisor(supervisor: string): Promise<Builder> {
this.logger.info(`withCommunitySupervisor ${supervisor}`);
const tx = await this.contract.methods.withCommunitySupervisor(supervisor).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withCommunitySupervisor(supervisor).send();
this.logger.info(tx);
return this;
}
Expand All @@ -229,10 +193,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withWeight(weight: number): Promise<Builder> {
this.logger.info(`withWeight ${weight}`);
const tx = await this.contract.methods.withWeight(weight).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withWeight(weight).send();
this.logger.info(tx);
return this;
}
Expand All @@ -246,10 +207,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withQuorum(quorum: number): Promise<Builder> {
this.logger.info(`withQuorum ${quorum}`);
const tx = await this.contract.methods.withQuorum(quorum).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withQuorum(quorum).send();
this.logger.info(tx);
return this;
}
Expand All @@ -263,10 +221,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withMinimumVoteDelay(delay: number): Promise<Builder> {
this.logger.info(`withMinimumVoteDelay ${delay}`);
const tx = await this.contract.methods.withMinimumVoteDelay(delay).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withMinimumVoteDelay(delay).send();
this.logger.info(tx);
return this;
}
Expand All @@ -280,10 +235,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withMaximumVoteDelay(delay: number): Promise<Builder> {
this.logger.info(`withMaximumVoteDelay ${delay}`);
const tx = await this.contract.methods.withMaximumVoteDelay(delay).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withMaximumVoteDelay(delay).send();
this.logger.info(tx);
return this;
}
Expand All @@ -297,10 +249,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withMinimumVoteDuration(duration: number): Promise<Builder> {
this.logger.info(`withMinimumVoteDuration ${duration}`);
const tx = await this.contract.methods.withMinimumVoteDuration(duration).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withMinimumVoteDuration(duration).send();
this.logger.info(tx);
return this;
}
Expand All @@ -314,10 +263,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async withMaximumVoteDuration(duration: number): Promise<Builder> {
this.logger.info(`withMaximumVoteDuration ${duration}`);
const tx = await this.contract.methods.withMaximumVoteDuration(duration).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withMaximumVoteDuration(duration).send();
this.logger.info(tx);
return this;
}
Expand All @@ -329,10 +275,7 @@ class CommunityBuilder extends ContractAbi implements Builder {
*/
async build(): Promise<string> {
this.logger.info('Building Community Class');
const buildTx = await this.contract.methods.build().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const buildTx = await this.contract.methods.build().send();
this.logger.info(buildTx);

const event: EventData = buildTx.events['CommunityClassCreated'];
Expand Down
8 changes: 0 additions & 8 deletions governance/collectivestorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ import { parseIntOrThrow } from '../system/version';
export class CollectiveStorage extends ContractAbi implements Storage {
static ABI_NAME = 'Storage.json';

/**
* get the contract name
* @returns string - contract anme
*/
constructor(abiPath: string, contractAddress: string, web3: Web3) {
super(abiPath, CollectiveStorage.ABI_NAME, contractAddress, web3);
}

/**
* get the contract name
* @returns string - contract anme
Expand Down
44 changes: 7 additions & 37 deletions governance/governancebuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ import { parseIntOrThrow } from '../system/version';
export class GovernanceBuilder extends ContractAbi implements Builder {
static ABI_NAME = 'GovernanceBuilder.json';

private readonly wallet: Wallet;
private readonly gas: number;

constructor(abiPath: string, contractAddress: string, web3: Web3, wallet: Wallet, gas: number) {
super(abiPath, GovernanceBuilder.ABI_NAME, contractAddress, web3);
this.wallet = wallet;
this.gas = gas;
}

/**
* get the contract name
* @returns string - contract anme
Expand All @@ -77,10 +68,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async aGovernance(): Promise<Builder> {
this.logger.info('Governance Builder Started');
const tx = await this.contract.methods.aGovernance().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.aGovernance().send();
this.logger.info(tx);
return this;
}
Expand All @@ -94,10 +82,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
async withName(name: string): Promise<Builder> {
this.logger.info(`withName ${name}`);
const encodedName = this.web3.utils.asciiToHex(name);
const tx = await this.contract.methods.withName(encodedName).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withName(encodedName).send();
this.logger.info(tx);
return this;
}
Expand All @@ -110,10 +95,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async withUrl(url: string): Promise<Builder> {
this.logger.info(`withUrl ${url}`);
const tx = await this.contract.methods.withUrl(url).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withUrl(url).send();
this.logger.info(tx);
return this;
}
Expand All @@ -126,10 +108,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async withDescription(desc: string): Promise<Builder> {
this.logger.info(`withDescription ${desc}`);
const tx = await this.contract.methods.withDescription(desc).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withDescription(desc).send();
this.logger.info(tx);
return this;
}
Expand All @@ -143,10 +122,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async withSupervisor(supervisor: string): Promise<Builder> {
this.logger.info(`withSupervisor ${supervisor}`);
const tx = await this.contract.methods.withSupervisor(supervisor).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withSupervisor(supervisor).send();
this.logger.info(tx);
return this;
}
Expand All @@ -159,10 +135,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async withCommunityClassAddress(voterClass: string): Promise<Builder> {
this.logger.info(`withCommunityClassAddress ${voterClass}`);
const tx = await this.contract.methods.withCommunityClassAddress(voterClass).send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const tx = await this.contract.methods.withCommunityClassAddress(voterClass).send();
this.logger.info(tx);
return this;
}
Expand All @@ -174,10 +147,7 @@ export class GovernanceBuilder extends ContractAbi implements Builder {
*/
async build(): Promise<string> {
this.logger.info('Building Governance');
const buildTx = await this.contract.methods.build().send({
from: this.wallet.getAddress(),
gas: this.gas,
});
const buildTx = await this.contract.methods.build().send();
this.logger.info(buildTx);

const event: EventData = buildTx.events['GovernanceContractCreated'];
Expand Down
4 changes: 0 additions & 4 deletions governance/metastorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ import { parseIntOrThrow } from '../system/version';
export class MetaStorage extends ContractAbi implements Meta {
static ABI_NAME = 'MetaStorage.json';

constructor(abiPath: string, contractAddress: string, web3: Web3) {
super(abiPath, MetaStorage.ABI_NAME, contractAddress, web3);
}

/**
* get the contract name
* @returns string - contract anme
Expand Down
Loading

0 comments on commit 2870e75

Please sign in to comment.