-
Notifications
You must be signed in to change notification settings - Fork 7
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
cmd
committed
Mar 5, 2024
1 parent
bdb3d90
commit 409b34a
Showing
10 changed files
with
145 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DraftSession } from '@scrow/core' | ||
import { signer } from './config.js' | ||
|
||
import { address, secret_id } from '../terms.js' | ||
|
||
/** ========== [ Draft Session ] ========== **/ | ||
|
||
// Create a draft session | ||
const session = new DraftSession(signer, { | ||
debug : false, | ||
verbose : true | ||
}) | ||
|
||
session.on('error', console.log) | ||
session.on('reject', console.log) | ||
|
||
// When the session is ready: | ||
session.on('ready', () => { | ||
console.log('session ready') | ||
console.dir(session.data, { depth : null }) | ||
}) | ||
|
||
session.on('update', () => { | ||
console.log('session update') | ||
//console.dir(session.data, { depth : null }) | ||
}) | ||
|
||
session.on('join', (mship) => { | ||
console.log('member joined:', mship.pub) | ||
}) | ||
|
||
session.on('leave', (mship) => { | ||
console.log('member left:', mship.pub) | ||
}) | ||
|
||
await session.connect(address, secret_id) |
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,25 @@ | ||
import { DraftSession } from '@scrow/core' | ||
import { signer } from './config.js' | ||
|
||
import { address, secret_id } from '../terms.js' | ||
|
||
const session = new DraftSession(signer, { | ||
debug : false, | ||
verbose : false | ||
}) | ||
|
||
session.on('ready', () => { | ||
console.log('session ready') | ||
console.log('session:', session.data) | ||
if (session.is_member) { | ||
console.log('member leaving session:', session.mship.pub) | ||
session.leave() | ||
} | ||
}) | ||
|
||
session.on('leave', (mship) => { | ||
console.log('member left:', mship.pub) | ||
session.close() | ||
}) | ||
|
||
await session.connect(address, secret_id) |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { DraftSession } from '@scrow/core' | ||
import { signer } from './config.js' | ||
import { address } from '../terms.js' | ||
|
||
console.log(signer.pubkey) | ||
|
||
const addr = 'wss://relay.damus.io' | ||
const drafts = await DraftSession.list(addr, signer) | ||
const drafts = await DraftSession.list(address, signer) | ||
|
||
console.dir(drafts, { depth : null }) |
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,35 @@ | ||
import { DraftSession } from '@scrow/core' | ||
import { signer } from './config.js' | ||
|
||
import { address, secret_id } from '../terms.js' | ||
|
||
const role = 'buyer' | ||
|
||
const session = new DraftSession(signer, { | ||
debug : false, | ||
verbose : true | ||
}) | ||
|
||
session.on('error', console.log) | ||
session.on('reject', console.log) | ||
|
||
session.on('ready', () => { | ||
console.log('session ready') | ||
console.log('session:', session.data) | ||
if (!session.is_member) { | ||
if (session.has_role(role)) { | ||
console.log('joining session as:', role) | ||
const pol = session.get_role(role) | ||
session.join(pol.id) | ||
} | ||
} else { | ||
console.log('you are already a member') | ||
} | ||
}) | ||
|
||
session.on('join', (mship) => { | ||
console.log('member joined:', mship.pub) | ||
// session.close() | ||
}) | ||
|
||
await session.connect(address, secret_id) |
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,28 @@ | ||
import { DraftSession } from '@scrow/core' | ||
import { signer } from './config.js' | ||
|
||
import { address, secret_id } from '../terms.js' | ||
|
||
const session = new DraftSession(signer, { | ||
debug : false, | ||
verbose : true | ||
}) | ||
|
||
session.on('error', console.log) | ||
session.on('reject', console.log) | ||
|
||
session.on('ready', () => { | ||
console.log('session ready') | ||
if (session.is_member) { | ||
console.log('member leaving session:', session.mship.pub) | ||
session.leave() | ||
} else { | ||
console.log('you are not a member') | ||
} | ||
}) | ||
|
||
session.on('leave', (mship) => { | ||
console.log('member left:', mship.pub) | ||
}) | ||
|
||
await session.connect(address, secret_id) |
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