Skip to content

Commit

Permalink
fix(types): remove any types
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 18, 2024
1 parent 014a262 commit d8d910b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/common/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class ANT implements ANTContract {
evaluationOptions,
}: {
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined;
}): Promise<any[]> {
}): Promise<string[]> {
const state = await this.contract.getContractState({ evaluationOptions });
return state.controllers;
}
Expand All @@ -87,7 +87,7 @@ export class ANT implements ANTContract {
evaluationOptions,
}: {
evaluationOptions?: EvaluationOptions | Record<string, never> | undefined;
}): Promise<any> {
}): Promise<string> {
const state = await this.contract.getContractState({ evaluationOptions });
return state.name;
}
Expand Down
46 changes: 34 additions & 12 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ARNS_TESTNET_REGISTRY_TX } from '../constants.js';
import { ArconnectSigner, ArweaveSigner } from 'arbundles';

import {
ArIOContract,
ArIOState,
ArNSAuctionData,
ArNSNameData,
ContractConfiguration,
EpochDistributionData,
EvaluationOptions,
EvaluationParameters,
Expand All @@ -29,28 +29,50 @@ import {
RegistrationType,
SmartWeaveContract,
WeightedObserver,
isContractConfiguration,
isContractTxIdConfiguration,
} from '../types.js';
import { RemoteContract } from './contracts/remote-contract.js';

// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ArIOSigner = ArweaveSigner | ArconnectSigner;
export type ContractConfiguration = {
signer?: ArIOSigner; // TODO: optionally allow JWK in place of signer
} & (
| {

Check failure on line 40 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Delete `··`

Check failure on line 40 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Delete `··`
contract?: SmartWeaveContract<unknown>;
}
| {

Check failure on line 43 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Delete `··`

Check failure on line 43 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Delete `··`
contractTxId: string;
}
);

Check failure on line 46 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Delete `··`

Check failure on line 46 in src/common/ar-io.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Delete `··`

function isContractConfiguration<T>(
config: ContractConfiguration,
): config is { contract: SmartWeaveContract<T> } {
return 'contract' in config;
}

function isContractTxIdConfiguration(
config: ContractConfiguration,
): config is { contractTxId: string } {
return 'contractTxId' in config;
}

export class ArIO implements ArIOContract {
private contract: SmartWeaveContract<ArIOState>;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private signer: ArIOSigner | undefined;

constructor(
config: ContractConfiguration = {
// default to a contract that uses the arns service to do the evaluation
contract: new RemoteContract<ArIOState>({
contractTxId: ARNS_TESTNET_REGISTRY_TX,
}),
},
) {
constructor({ signer, ...config }: ContractConfiguration) {
this.signer = signer;
if (isContractConfiguration<ArIOState>(config)) {
this.contract = config.contract;
} else if (isContractTxIdConfiguration(config)) {
this.contract = new RemoteContract<ArIOState>({
contractTxId: config.contractTxId,
});
} else {
throw new Error('Invalid configuration.');
}
}

Expand Down

0 comments on commit d8d910b

Please sign in to comment.