Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Feb 23, 2024
1 parent 79be324 commit f878780
Show file tree
Hide file tree
Showing 73 changed files with 2,007 additions and 281 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions demo/04_roles_and_endorse.ts → demo/04_finish_draft.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print_banner } from '@scrow/test'
import { create_draft } from '@/lib/proposal.js'
import { signers } from './02_create_signer.js'
import { proposal, role } from './03_build_proposal.js'
import { proposal, role } from './03_create_draft.js'

const DEMO_MODE = process.env.DEMO_MODE === 'true'

Expand All @@ -26,7 +26,7 @@ signers.map(mbr => {
/**
* Define our final proposal and endorsements.
*/
export { session }
export const draft = session

if (DEMO_MODE) {
print_banner('final draft')
Expand Down
4 changes: 2 additions & 2 deletions demo/05_create_contract.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { print_banner } from '@scrow/test'
import { client } from './01_create_client.js'
import { session } from './04_roles_and_endorse.js'
import { draft } from './04_finish_draft.js'

const DEMO_MODE = process.env.DEMO_MODE === 'true'

// Deliver proposal and endorsements to server.
const res = await client.contract.create(session)
const res = await client.contract.create(draft)
// Check if response is valid.
if (!res.ok) throw new Error(res.error)

Expand Down
16 changes: 8 additions & 8 deletions demo/api/contract/cancel.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { print_banner } from '@scrow/test'
import { client } from '@scrow/demo/01_create_client.js'
import { moderator } from '@scrow/demo/03_build_proposal.js'
import { new_contract } from '@scrow/demo/05_create_contract.js'
import { print_banner } from '@scrow/test'
import { client } from '@scrow/demo/01_create_client.js'
import { moderator as signer } from '@scrow/demo/03_build_proposal.js'
import { new_contract } from '@scrow/demo/05_create_contract.js'

// Define the contract id we will cancel.
const cid = new_contract.cid
// Generate an auth token from the moderator's signer.
const cancel_tkn = moderator.request.contract_cancel(cid)
const req = signer.request.contract_cancel(cid)
// Send the cancel request, along with the auth token.
const cancel_res = await client.contract.cancel(cid, cancel_tkn)
const res = await client.contract.cancel(cid, req)
// If the request fails, throw an error.
if (!cancel_res.ok) throw new Error(cancel_res.error)
if (!res.ok) throw new Error(res.error)
// Unwrap our response payload.
export const canceled_contract = cancel_res.data.contract
export const canceled_contract = res.data.contract

print_banner('canceled contract')
console.dir(canceled_contract)
Expand Down
6 changes: 3 additions & 3 deletions demo/api/contract/create.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { print_banner } from '@scrow/test'
import { client } from '../../01_create_client.js'
import { session } from '../../04_roles_and_endorse.js'
import { client } from '@scrow/demo/01_create_client.js'
import { draft } from '@scrow/demo/04_finish_draft.js'

// Deliver proposal and endorsements to server.
const res = await client.contract.create(session)
const res = await client.contract.create(draft)
// Check if response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack our published contract.
Expand Down
4 changes: 2 additions & 2 deletions demo/api/contract/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { signers } from '@scrow/demo/02_create_signer.js'
// Select a signer to use.
const signer = signers[0]
// Generate a request token.
const req_token = signer.request.contract_list()
const req = signer.request.contract_list()
// Deliver the request and token.
const res = await client.contract.list(signer.pubkey, req_token)
const res = await client.contract.list(signer.pubkey, req)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack our data payload.
Expand Down
16 changes: 16 additions & 0 deletions demo/api/contract/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { print_banner } from '@scrow/test'
import { client } from '@scrow/demo/01_create_client.js'
import { new_contract } from '@scrow/demo/05_create_contract.js'

// Define the contract id we will use.
const cid = new_contract.cid
// Fetch a contract from the server by cid.
const res = await client.contract.status(cid)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack the data object.
const status = res.data.contract

print_banner('contract status')
console.dir(status, { depth : null })
console.log('\n')
16 changes: 16 additions & 0 deletions demo/draft/alice/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DraftSession } from '@scrow/core'

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

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

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

const drafts = await session.list('wss://relay.damus.io')

console.dir(drafts, { depth : null })
8 changes: 6 additions & 2 deletions demo/draft/alice/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import {
import { client } from '@scrow/demo/01_create_client.js'
import { config } from '@scrow/demo/00_demo_config.js'
import { print_banner } from '@scrow/test'
import { fund_address, sleep } from '@scrow/demo/util.js'
import { agent_draft, secret_id } from '../terms.js'

import {
fund_regtest_address,
sleep
} from '@scrow/demo/util.js'

import { alias, fund_amt, role, signer, wit_tmpl } from './config.js'

/** ========== [ Draft Session ] ========== **/
Expand Down Expand Up @@ -95,7 +99,7 @@ function fund_contract (contract : ContractData) {
} else {
// Use the automated payment for regtest testing.
print_banner('sending deposit')
await fund_address(account.data.address, fund_amt)
await fund_regtest_address(account.data.address, fund_amt)
await sleep(2000)
}

Expand Down
5 changes: 3 additions & 2 deletions demo/draft/bob/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
import { client } from '@scrow/demo/01_create_client.js'
import { config } from '@scrow/demo/00_demo_config.js'
import { print_banner } from '@scrow/test'
import { fund_address, sleep } from '@scrow/demo/util.js'
import { secret_id } from '../terms.js'

import { fund_regtest_address, sleep } from '@scrow/demo/util.js'

import { alias, fund_amt, role, signer, wit_tmpl } from './config.js'

/** ========== [ Draft Session ] ========== **/
Expand Down Expand Up @@ -83,7 +84,7 @@ function fund_contract (contract : ContractData) {
} else {
// Use the automated payment for regtest testing.
print_banner('sending deposit')
await fund_address(account.data.address, fund_amt)
await fund_regtest_address(account.data.address, fund_amt)
await sleep(2000)
}

Expand Down
8 changes: 8 additions & 0 deletions docs/api/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "API Interfaces",
"position": 1,
"link": {
"type": "generated-index",
"description": "Reference list for BitEscrow API interfaces."
}
}
Loading

0 comments on commit f878780

Please sign in to comment.