Skip to content

Commit

Permalink
WIP: Adds following module
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-toth committed Nov 17, 2023
1 parent 61ac193 commit fda0a9a
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/client/authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { AuthenticatedArtByCityCurations } from '../curations'
import { AuthenticatedArFSClient } from '../arfs'
import { AuthenticatedArtByCityPublications } from '../publications'
import BaseArtByCityClient from './base'
import { AuthenticatedArtByCityFollowing } from '../following'

export default class AuthenticatedArtByCityClient extends BaseArtByCityClient {
declare public readonly curations: AuthenticatedArtByCityCurations
declare public readonly arfs: AuthenticatedArFSClient
declare public readonly publications: AuthenticatedArtByCityPublications
declare public readonly following: AuthenticatedArtByCityFollowing
declare public readonly signer: ArweaveSigner | InjectedArweaveSigner

constructor(
Expand Down Expand Up @@ -56,5 +58,10 @@ export default class AuthenticatedArtByCityClient extends BaseArtByCityClient {
this.config,
this.signer
)
this.following = new AuthenticatedArtByCityFollowing(
this.config,
this.warp,
this.signer
)
}
}
3 changes: 3 additions & 0 deletions src/client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ArtByCityUsernames } from '../usernames'
import { ArFSClient } from '../arfs'
import TransactionsModule from '../common/transactions'
import { ArtByCityPublications } from '../publications'
import { ArtByCityFollowing } from '../following'

export default class ArtByCity {
public readonly arweave!: Arweave
Expand All @@ -24,6 +25,7 @@ export default class ArtByCity {
public readonly arfs!: ArFSClient
public readonly transactions!: TransactionsModule
public readonly publications!: ArtByCityPublications
public readonly following!: ArtByCityFollowing

constructor(arweave?: Arweave, config?: Partial<ArtByCityConfig>) {
const environment = config?.environment || 'production'
Expand Down Expand Up @@ -58,5 +60,6 @@ export default class ArtByCity {
this.arfs,
this.config
)
this.following = new ArtByCityFollowing(this.config, this.warp)
}
}
9 changes: 6 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type ArtByCityConfig = {
whitelist: string
collaborative: string
collaborativeWhitelist: string
}
},
following: string
}
cache: {
type: CacheStrategy
Expand All @@ -34,7 +35,8 @@ export const DEFAULT_ARTBYCITY_CONFIG: ArtByCityConfig = {
whitelist: 'wQyCsSM-gROX2iVUaezrfNJg-z9MJdy_FCJB5oEx8cY',
collaborative: 'O_SmOtUfUNYf8Z8BqFao1MzBM_9Ydh8djkcDAV2u7eM',
collaborativeWhitelist: '3M_dT7kclnFtiITTMDRKvrbfAZEWWZb05KWH6OojEWs'
}
},
following: 'uPPmKBhY4L4MKAaGi2pCDU30nnEo9VtMb9Sw-zSApFY'
},
cache: {
type: 'memcache'
Expand All @@ -51,7 +53,8 @@ export const ARTBYCITY_STAGING_CONFIG: ArtByCityConfig = {
whitelist: 'wQyCsSM-gROX2iVUaezrfNJg-z9MJdy_FCJB5oEx8cY',
collaborative: 'O_SmOtUfUNYf8Z8BqFao1MzBM_9Ydh8djkcDAV2u7eM',
collaborativeWhitelist: '3M_dT7kclnFtiITTMDRKvrbfAZEWWZb05KWH6OojEWs'
}
},
following: 'uPPmKBhY4L4MKAaGi2pCDU30nnEo9VtMb9Sw-zSApFY'
},
cache: {
type: 'memcache'
Expand Down
2 changes: 1 addition & 1 deletion src/curations/authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class AuthenticatedArtByCityCurations
{
constructor(
arweave: Arweave,
protected warp: Warp,
protected readonly warp: Warp,
config: ArtByCityConfig,
private readonly signer: ArweaveSigner | InjectedArweaveSigner
) {
Expand Down
65 changes: 65 additions & 0 deletions src/following/authenticated-following.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Tag, Warp } from 'warp-contracts'
import { ArweaveSigner } from 'warp-arbundles'
import { InjectedArweaveSigner, isSigner } from 'warp-contracts-plugin-deploy'

import { ArtByCityConfig } from '../config'
import { getAddressFromSigner } from '../util/crypto'
import { ArtByCityFollowing, FollowingCreationOptions } from './'

export default class AuthenticatedArtByCityFollowing
extends ArtByCityFollowing
{
constructor(
protected readonly config: ArtByCityConfig,
protected readonly warp: Warp,
private readonly signer: ArweaveSigner | InjectedArweaveSigner
) {
super(config, warp)
}

async getOrCreate() {
// TODO -> try to get

// TODO -> if null, create

// TODO -> return contract followingId
}

async create(opts?: FollowingCreationOptions) {
if (!opts) {
opts = {}
}

if (!opts.owner) {
opts.owner = await getAddressFromSigner(this.signer)
}

const initialState = {
owner: opts.owner,
following: opts.following || []
}

const tags = (opts.tags || []).map<Tag>(tag => new Tag(tag.name, tag.value))
tags.push(
new Tag('Protocol', 'ArtByCity'),
new Tag('Contract-Name', 'Following'),
new Tag('Contract-Version', '0.0.1'),
new Tag('Entity-Type', 'following')
)

const { contractTxId } = await this.warp.deployFromSourceTx({
/* @ts-expect-error warp types are spaghetti */
wallet: this.signer,
srcTxId: this.config.contracts.following,
initState: JSON.stringify(initialState),
tags
/* @ts-expect-error warp types are spaghetti */
}, !isSigner(this.signer))

return contractTxId
}

async follow(address: string) {}

async unfollow(address: string) {}
}
14 changes: 14 additions & 0 deletions src/following/following.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Warp } from 'warp-contracts'

import { ArtByCityConfig } from '../config'

export default class ArtByCityFollowing {
constructor(
protected readonly config: ArtByCityConfig,
protected readonly warp: Warp
) {}

async getContract(address: string) {}

async following(address: string) {}
}
11 changes: 11 additions & 0 deletions src/following/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { default as ArtByCityFollowing } from './following'
export {
default as AuthenticatedArtByCityFollowing
} from './authenticated-following'

export interface FollowingCreationOptions {
owner?: string
following?: string[]
tags?: { name: string, value: string }[]
slug?: boolean | string
}
68 changes: 68 additions & 0 deletions test/e2e/following.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable */
import('mocha') // NB: this style import makes both webpack and typescript happy
import { expect } from 'chai'
import Arweave from 'arweave'
import { JWKInterface } from 'warp-contracts'

import TestweaveJWK from '../testweave-keyfile.json'
import ArtByCity, { ArtByCityConfig } from '../../dist/web'

/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
const jwk: JWKInterface = TestweaveJWK

const arweave = Arweave.init({
protocol: 'http',
host: 'localhost',
port: 1984
})
const config: Partial<ArtByCityConfig> = {
environment: 'development',
contracts: {
usernames: '-0MjbNd0EwwmnNgHefa5axa0we64kNM3BOnXITcF7n0',
atomicLicense: '8i_mVmJ9RPvG9KnMEBJimgD_l_I2BEkYja67vRZBWNo',
curation: {
ownable: '18WFZLc9rAfNpwWKKUNDycKaLXoknfjCUq42O6IK07Q',
whitelist: 'N4JmgBHUu5ZHbcgaOUsKAydcVlQTSi5L7pwvq_NPZuA',
collaborative: 'KNrobEq1MzK7121Tzd-J61trXcxKZujqPQ_B3ojZeb8',
collaborativeWhitelist: '06Llbzymx4RI8Y0Ygen1grv4hM7MwjmmcCdCqeU9mAI'
},
following: 'ed6xnpsezIXbOg5XpO5DrsvQbxdXgUzWb-hzzMJ6zp0'
}
}

describe('Following Module', () => {
context('Authencitated', () => {
it('creates following contract for signer', async function () {
this.timeout(0)
const abc = new ArtByCity(arweave, config)

const followingId = await abc.connect(jwk).following.create()

console.log('followingId', followingId)

expect(followingId).to.be.a('string')
})
// it('gets or creates following contract for signer', async function () {
// this.timeout(0)
// const abc = new ArtByCity(arweave, config)

// const followingId = await abc.connect(jwk).following.getOrCreate()
// })

it('follows addresses')

it('unfollows addresses')
})

context('Unauthenticated', () => {
it.only('gets following contract by address', async function () {
this.timeout(0)
const abc = new ArtByCity(arweave, config)
const address = 'MlV6DeOtRmakDOf6vgOBlif795tcWimgyPsYYNQ8q1Y'

const followingContract = await abc.following.getContract(address)

expect(followingContract).to.exist
})
})
})
3 changes: 2 additions & 1 deletion test/e2e/publications.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const config: Partial<ArtByCityConfig> = {
whitelist: 'N4JmgBHUu5ZHbcgaOUsKAydcVlQTSi5L7pwvq_NPZuA',
collaborative: 'KNrobEq1MzK7121Tzd-J61trXcxKZujqPQ_B3ojZeb8',
collaborativeWhitelist: '06Llbzymx4RI8Y0Ygen1grv4hM7MwjmmcCdCqeU9mAI'
}
},
following: 'ed6xnpsezIXbOg5XpO5DrsvQbxdXgUzWb-hzzMJ6zp0'
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/usernames.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ describe('ArtByCity Usernames Module', () => {
whitelist: 'bad-contract-id',
collaborative: 'bad-contract-id',
collaborativeWhitelist: 'bad-contract-id'
}
},
following: 'bad-contract-id'
}
})

Expand Down
3 changes: 2 additions & 1 deletion test/spec/curations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const MOCK_ABC_CONFIG: ArtByCityConfig = {
collaborative: 'mock-collaborative-curation-contract-src-id',
collaborativeWhitelist:
'mock-collaborative-whitelist-curation-contract-src-id'
}
},
following: 'mock-following-contract-src-id'
},
cache: {
type: 'memcache'
Expand Down
3 changes: 2 additions & 1 deletion test/spec/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const MOCK_ABC_CONFIG: ArtByCityConfig = {
collaborative: 'mock-collaborative-curation-contract-src-id',
collaborativeWhitelist:
'mock-collaborative-whitelist-curation-contract-src-id'
}
},
following: 'mock-following-contract-src-id'
},
cache: {
type: 'memcache'
Expand Down
3 changes: 2 additions & 1 deletion test/spec/publications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const MOCK_ABC_CONFIG: ArtByCityConfig = {
collaborative: 'mock-collaborative-curation-contract-src-id',
collaborativeWhitelist:
'mock-collaborative-whitelist-curation-contract-src-id'
}
},
following: 'mock-following-contract-src-id'
},
cache: {
type: 'memcache'
Expand Down

0 comments on commit fda0a9a

Please sign in to comment.