Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Mar 4, 2024
1 parent 436646b commit 4acb3bb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
32 changes: 32 additions & 0 deletions demo/draft/alice/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DraftSession } from '@scrow/core'
import { alias, role, signer } from './config.js'
import { agent_draft, secret_id } from '../terms.js'

/** ========== [ Draft Session ] ========== **/

// Create a draft session
const session = new DraftSession(secret_id, signer, {
debug : true,
verbose : true
})

session.on('error', console.log)
session.on('reject', console.log)

// When the session is ready:
session.on('ready', () => {
console.log('alice ready')
// If we are not a member:
if (!session.is_member) {
// Grab the buyer policy from the roles list.
console.log(`fetching role "${role}"...`)
const policy = session.get_role(role)
// Join the session as the buyer.
console.log('joining the session...')
session.join(policy.id)
// Print to console.
console.log(`${alias} joined the draft as role ${policy.title}`)
}
})

await session.init('wss://relay.damus.io', agent_draft)
10 changes: 3 additions & 7 deletions demo/draft/alice/list.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { DraftSession } from '@scrow/core'

import { signer } from './config.js'

/** ========== [ Draft Session ] ========== **/

// Create a draft session
import { signer } from './config.js'

console.log(signer.pubkey)

const drafts = await DraftSession.list('wss://relay.damus.io', signer, { verbose : true })
const addr = 'wss://relay.damus.io'
const drafts = await DraftSession.list(addr, signer)

console.dir(drafts, { depth : null })
File renamed without changes.
30 changes: 14 additions & 16 deletions src/client/class/draft.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { verify_proposal } from '@/validators/proposal.js'
import { EventEmitter } from './emitter.js'
import { EscrowSigner } from './signer.js'
import { EscrowContract } from './contract.js'
import { EscrowClient } from './client.js'
import { DraftItem } from '../types.js'
import { EscrowClient } from '@/client/class/client.js'
import { EscrowContract } from '@/client/class/contract.js'
import { EventEmitter } from '@/client/class/emitter.js'
import { EscrowSigner } from '@/client/class/signer.js'
import { DraftItem } from '@/client/types.js'
import { is_hash } from '@/lib/util.js'

import {
EventMessage,
Expand All @@ -24,11 +25,6 @@ import {
tabulate_enrollment
} from '@/lib/policy.js'

import {
is_hash,
now
} from '@/lib/util.js'

import {
find_program,
get_proposal_id
Expand Down Expand Up @@ -111,7 +107,7 @@ export class DraftSession extends EventEmitter <{

this._room.on('fetch', () => { void this.emit('fetch', this) })

this._room.on('ready', () => {
this._room.once('ready', () => {
this._init = true
this.emit('ready', this)
})
Expand Down Expand Up @@ -413,12 +409,10 @@ export class DraftSession extends EventEmitter <{
this.emit('terms', terms)
}

// TODO: Fix the use of a timestamp here.

async _update (data : DraftData, _cat = now()) {
async _update (data : DraftData, cat ?: number) {
validate_draft(data)
verify_draft(data)
await this._room.update(data)
this._room.update(data, [], cat)
if (this.is_full && !this._full) {
this.emit('full', this)
}
Expand Down Expand Up @@ -451,7 +445,7 @@ export class DraftSession extends EventEmitter <{
}
return true
}

async connect (address : string) {
await this._room.connect(address)
return this
Expand Down Expand Up @@ -563,6 +557,10 @@ export class DraftSession extends EventEmitter <{
return contract
}

refresh () {
return this._room.refresh()
}

update_terms (terms : Partial<ProposalData>) {
if (!this.check_terms(terms)) {
throw new Error('invalid terms: ' + terms.toString())
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"@cmdcode/buff" "^2.2.5"
"@cmdcode/crypto-tools" "^2.7.6"

"@cmdcode/nostr-sdk@^0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@cmdcode/nostr-sdk/-/nostr-sdk-0.0.6.tgz#6a70b76a769fbc1f9827f5321f281ea60753cc9d"
integrity sha512-bF5SHMBxALd4akGB+a+QXJXzSh+6yHQJnkdNCi4GynwehapVfgT9Gj4rcOypYOOMQW/o0mOCjTUpUkw22emPWQ==
"@cmdcode/nostr-sdk@^0.0.11":
version "0.0.11"
resolved "https://registry.yarnpkg.com/@cmdcode/nostr-sdk/-/nostr-sdk-0.0.11.tgz#ef9fa2321ca55c933c02a05315ef5cf49638e21e"
integrity sha512-foimrnYq4+P5qw8M32ujja9INkNAlwnQqvH+NdPlFuMwhn5DfSNIW7lSIS6fSVkGOCvGUhwCgE+XATuJ6GqxVA==
dependencies:
"@cmdcode/buff" "2.2.5"
"@cmdcode/crypto-tools" "2.7.6"
Expand Down

0 comments on commit 4acb3bb

Please sign in to comment.