-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stub out/correct broken GP parameters (#377)
- Loading branch information
Showing
22 changed files
with
262 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Address, DefaultSchemePermissions, SchemePermissions } from "./commonTypes"; | ||
import { ContractWrapperBase } from "./contractWrapperBase"; | ||
import { ControllerService } from "./controllerService"; | ||
import { ISchemeWrapper } from "./iContractWrapperBase"; | ||
|
||
/** | ||
* Abstract base class for all Arc scheme contract wrapper classes. A scheme is defined as an Arc | ||
* contract that can be registered with and can thus interact with a DAO controller. | ||
*/ | ||
export abstract class SchemeWrapperBase extends ContractWrapperBase implements ISchemeWrapper { | ||
/** | ||
* Minimum permissions required by the scheme | ||
*/ | ||
public getDefaultPermissions(): SchemePermissions { | ||
return DefaultSchemePermissions.MinimumPermissions as number; | ||
} | ||
|
||
/** | ||
* Returns the scheme permissions. | ||
* @param avatarAddress | ||
*/ | ||
public getSchemePermissions(avatarAddress: Address): Promise<SchemePermissions> { | ||
return Promise.resolve(this.getDefaultPermissions()); | ||
} | ||
|
||
/** | ||
* Returns this scheme's permissions. | ||
* @param avatarAddress | ||
*/ | ||
protected async _getSchemePermissions(avatarAddress: Address): Promise<SchemePermissions> { | ||
const controllerService = new ControllerService(avatarAddress); | ||
const controller = await controllerService.getController(); | ||
const permissions = await controller.getSchemePermissions(this.address, avatarAddress) as string; | ||
|
||
return SchemePermissions.fromString(permissions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Address, Hash } from "./commonTypes"; | ||
import { ControllerService } from "./controllerService"; | ||
import { | ||
ArcTransactionDataResult, | ||
IUniversalSchemeWrapper, | ||
StandardSchemeParams, | ||
} from "./iContractWrapperBase"; | ||
import { SchemeWrapperBase } from "./schemeWrapperBase"; | ||
import { TxEventContext } from "./transactionService"; | ||
|
||
/** | ||
* Abstract base class for all Arc universal scheme contract wrapper classes. A universal scheme | ||
* is defined as an Arc scheme (see `SchemeWrapperBase`) that follows the pattern of registering | ||
* operating parameters with the DAO's controller, thus enabling the contract to be reused across DAOs. | ||
*/ | ||
export abstract class USchemeWrapperBase extends SchemeWrapperBase { | ||
|
||
/** | ||
* Given a hash, returns the associated parameters as an object. | ||
* @param paramsHash | ||
*/ | ||
public abstract getParameters(paramsHash: Hash): Promise<any>; | ||
|
||
public abstract getParametersHash(params: any): Promise<Hash>; | ||
|
||
public abstract setParameters(params: any): Promise<ArcTransactionDataResult<Hash>>; | ||
|
||
public abstract getSchemeParameters(avatarAddress: Address): Promise<any>; | ||
|
||
/** | ||
* Given an avatar address, returns the schemes parameters hash | ||
* @param avatarAddress | ||
*/ | ||
public async getSchemeParametersHash(avatarAddress: Address): Promise<Hash> { | ||
const controllerService = new ControllerService(avatarAddress); | ||
const controller = await controllerService.getController(); | ||
return controller.getSchemeParameters(this.address, avatarAddress); | ||
} | ||
|
||
/** | ||
* Given a hash, returns the associated parameters as an array, ordered by the order | ||
* in which the parameters appear in the contract's Parameters struct. | ||
* @param paramsHash | ||
*/ | ||
public getParametersArray(paramsHash: Hash): Promise<Array<any>> { | ||
return this.contract.parameters(paramsHash); | ||
} | ||
protected async _setParameters( | ||
functionName: string, | ||
txEventContext: TxEventContext, | ||
...params: Array<any>): Promise<ArcTransactionDataResult<Hash>> { | ||
|
||
const parametersHash: Hash = await this.contract.getParametersHash(...params); | ||
|
||
const txResult = await this.wrapTransactionInvocation(functionName, | ||
// typically this is supposed to be an object, but here it is an array | ||
Object.assign(params, { txEventContext }), | ||
this.contract.setParameters, | ||
params); | ||
|
||
return new ArcTransactionDataResult<Hash>(txResult.tx, this.contract, parametersHash); | ||
} | ||
|
||
protected async _getSchemeParameters(avatarAddress: Address): Promise<any> { | ||
const paramsHash = await this.getSchemeParametersHash(avatarAddress); | ||
return this.getParameters(paramsHash); | ||
} | ||
|
||
protected _getParametersHash(...params: Array<any>): Promise<Hash> { | ||
return this.contract.getParametersHash(...params); | ||
} | ||
|
||
protected validateStandardSchemeParams(params: StandardSchemeParams): void { | ||
if (!params.voteParametersHash) { | ||
throw new Error(`voteParametersHash is not defined`); | ||
} | ||
if (!params.votingMachineAddress) { | ||
throw new Error(`votingMachineAddress is not defined`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.