-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters