Skip to content

Commit

Permalink
Merge pull request #50 from art-by-city/49-query-curations-by-creator
Browse files Browse the repository at this point in the history
Adds query curations by creator
  • Loading branch information
jim-toth authored Oct 10, 2023
2 parents 948d763 + d206bcf commit 70bd059
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/curation/authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ export default class AuthenticatedArtByCityCurations
super(arweave, warp, config)
}

private determineSourceTxId(type: CurationType): string {
private determineCurationType(
type: CurationType
): { srcTxId: string, contractName: string } {
switch (type) {
case 'ownable':
return this.config.contracts.curation.ownable
return {
srcTxId: this.config.contracts.curation.ownable,
contractName: 'Ownable-Curation-Contract'
}
case 'whitelist':
return this.config.contracts.curation.whitelist
return {
srcTxId: this.config.contracts.curation.whitelist,
contractName: 'Whitelist-Curation-Contract'
}
case 'collaborative':
return this.config.contracts.curation.collaborative
return {
srcTxId: this.config.contracts.curation.collaborative,
contractName: 'Collaborative-Curation-Contract'
}
case 'collaborative-whitelist':
return this.config.contracts.curation.collaborativeWhitelist
return {
srcTxId: this.config.contracts.curation.collaborativeWhitelist,
contractName: 'Collaborative-Whitelist-Curation-Contract'
}
default:
throw new UnknownCurationTypeError()
}
Expand Down Expand Up @@ -72,9 +86,11 @@ export default class AuthenticatedArtByCityCurations
}

async create(type: CurationType, opts: CurationCreationOptions) {
const srcTxId = this.determineSourceTxId(type)
const { srcTxId, contractName } = this.determineCurationType(type)
const initialState = this.createInitialState(type, opts)
const tags: Tag[] = [
new Tag('Contract-Name', contractName),

// ArtByCity / ArFS Entity-Type
new Tag('Entity-Type', 'curation'),

Expand Down
26 changes: 25 additions & 1 deletion src/curation/curation.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import ArDB from 'ardb'
import Arweave from 'arweave'
import { Contract, Warp } from 'warp-contracts'

import { ArtByCityConfig } from '../config'
import { CurationContractStates } from './'
import ArdbTransaction from 'ardb/lib/models/transaction'

export default class ArtByCityCurations {
protected readonly ardb!: ArDB

constructor(
protected readonly arweave: Arweave,
protected readonly warp: Warp,
protected readonly config: ArtByCityConfig
) {}
) {
this.ardb = new ArDB(this.arweave)
}

get<State extends CurationContractStates>(
curationId: string
): Contract<State> {
return this.warp.contract<State>(curationId)
}

async createdBy(creator: string, cursor?: string) {
let query = this.ardb
.search('transactions')
.from(creator)
.tag('Type', 'curation')

if (cursor) {
query = query.cursor(cursor)
}

const transactions = await query.findAll({
sort: 'HEIGHT_DESC'
}) as ArdbTransaction[]
const nextCursor = query.getCursor()

return { cursor: nextCursor, curations: transactions }
}
}
10 changes: 10 additions & 0 deletions test/e2e/curation.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,21 @@ describe('ArtByCity Curation Module', () => {
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)

console.log('latest', ownableCurationContractId)
const curation = abc.curations.get(ownableCurationContractId)
const { cachedValue: { state } } = await curation.readState()

expect(state).to.be.an('object').with.property('owner')
expect(state.owner).to.be.a('string').that.equals(address)
})

it('queries curations by creator', async () => {
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)

const { curations } = await abc.curations.createdBy(address)

expect(curations).to.be.an('array').that.is.not.empty
})
})
})

0 comments on commit 70bd059

Please sign in to comment.