Skip to content

Commit

Permalink
fix(names): update chosen names logic using contract source
Browse files Browse the repository at this point in the history
We were not passing the height around so the choseNames kept returning an empty array
  • Loading branch information
dtfiedler committed Jun 11, 2024
1 parent 7472a97 commit 4e03038
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/names/contract-names-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ export class ContractNamesSource implements ArnsNamesSource, ArnsNameList {
return names;
}

async getAllNames(): Promise<string[]> {
// we don't use height here, but it's required by the interface
async getAllNames(_height: number): Promise<string[]> {
const names = await this.contract.getArNSRecords();
const namesArray = Object.keys(names).sort();
return namesArray;
}

async getName(index: number): Promise<string> {
const names = await this.getAllNames();
async getName(height: number, index: number): Promise<string> {
const names = await this.getAllNames(height);
return names[index];
}

async getNamesCount(): Promise<number> {
return (await this.getAllNames()).length;
async getNamesCount(height: number): Promise<number> {
return (await this.getAllNames(height)).length;
}
}
16 changes: 8 additions & 8 deletions src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ const namesSource = new ContractNamesSource({
contract: networkContract,
});

const remoteCacheArnsNameList =
config.ARNS_NAMES.length > 0
? new StaticArnsNameList({
names: config.ARNS_NAMES,
})
: namesSource;

const chainEntropySource = new ChainEntropySource({
arweaveBaseUrl: config.ARWEAVE_URL,
});
Expand All @@ -150,8 +143,15 @@ const compositeEntropySource = new CompositeEntropySource({
sources: [cachedEntropySource, chainEntropySource],
});

const nameListSource =
config.ARNS_NAMES.length > 0
? new StaticArnsNameList({
names: config.ARNS_NAMES,
})
: namesSource; // use the contract source if nothing configured

const chosenNamesSource = new RandomArnsNamesSource({
nameList: remoteCacheArnsNameList,
nameList: nameListSource,
entropySource: compositeEntropySource,
numNamesToSource: config.NUM_ARNS_NAMES_TO_OBSERVE_PER_GROUP,
});
Expand Down

0 comments on commit 4e03038

Please sign in to comment.