Skip to content

Commit

Permalink
fix(naming): change epoch to epochStartHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 13, 2024
1 parent 0208317 commit 908971c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
});
const epoch = await arIO.getCurrentEpoch();
const observations = await arIO.getObservations();
const observation = await arIO.getObservations({ epoch: 1350700 });
const observation = await arIO.getObservations({ epochStartHeight: 1350700 });
const distributions = await arIO.getDistributions();

console.dir(
Expand Down
2 changes: 1 addition & 1 deletion examples/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ARNS_TESTNET_REGISTRY_TX, ArIO } from '../../lib/esm/node/index.js';
});
const epoch = await arIO.getCurrentEpoch();
const observations = await arIO.getObservations();
const observation = await arIO.getObservations({ epoch: 1350700 });
const observation = await arIO.getObservations({ epochStartHeight: 1350700 });
const distributions = await arIO.getDistributions();

console.dir(
Expand Down
12 changes: 8 additions & 4 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ export interface ArIOContract {
evaluationOptions,
}: EvaluationParameters): Promise<EpochDistributionData>;
getObservations({
epoch,
epochStartHeight,
evaluationOptions,
}: EvaluationParameters<{ epoch?: number }>): Promise<Observations>;
}: EvaluationParameters<{
epochStartHeight?: number;
}>): Promise<Observations>;
getDistributions({
epoch,
epochStartHeight,
evaluationOptions,
}: EvaluationParameters<{ epoch?: number }>): Promise<EpochDistributionData>;
}: EvaluationParameters<{
epochStartHeight?: number;
}>): Promise<EpochDistributionData>;
}

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
43 changes: 24 additions & 19 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import { RemoteContract } from './contracts/remote-contract.js';
// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ContractConfiguration =
| {
contract?: SmartWeaveContract<unknown>;
}
contract?: SmartWeaveContract<unknown>;
}
| {
contractTxId: string;
};
contractTxId: string;
};

function isContractConfiguration<T>(
config: ContractConfiguration,
Expand Down Expand Up @@ -185,30 +185,35 @@ export class ArIO implements ArIOContract {
});
}
async getObservations({
epoch,
epochStartHeight,
evaluationOptions,
}: EvaluationParameters<{ epoch?: number }> = {}): Promise<Observations> {
}: EvaluationParameters<{
epochStartHeight?: number;
}> = {}): Promise<Observations> {
const { observations } = await this.contract.getContractState({
evaluationOptions,
});
return epoch !== undefined ? { [epoch]: observations[epoch] } : observations;
return epochStartHeight !== undefined
? { [epochStartHeight]: observations[epochStartHeight] }
: observations;
}
async getDistributions({
epoch,
epochStartHeight,
evaluationOptions,
}: EvaluationParameters<{
epoch?: number;
epochStartHeight?: number;
}> = {}): Promise<EpochDistributionData> {
const distributions = epoch !== undefined
? await this.getEpoch({
...evaluationOptions,
blockHeight: epoch,
})
: await this.contract
.getContractState({
evaluationOptions,
})
.then((state) => state.distributions);
const distributions =
epochStartHeight !== undefined
? await this.getEpoch({
...evaluationOptions,
blockHeight: epochStartHeight,
})
: await this.contract
.getContractState({
evaluationOptions,
})
.then((state) => state.distributions);
return distributions;
}
}
2 changes: 1 addition & 1 deletion tests/ar-io.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('ArIO Client', () => {
it('should return observation information', async () => {
const observations = await arIO.getObservations();
const observation = await arIO.getObservations({
epoch: parseInt(Object.keys(observations)[0]),
epochStartHeight: parseInt(Object.keys(observations)[0]),
});
expect(observations).toBeDefined();
expect(observation).toBeDefined();
Expand Down

0 comments on commit 908971c

Please sign in to comment.