Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit 71a5277

Browse files
author
cmd
committed
update
1 parent d81ee65 commit 71a5277

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

demo/00_demo_config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,19 @@ const faucets = {
3131
testnet : 'https://bitcoinfaucet.uo1.net'
3232
}
3333

34+
const poll_rates = {
35+
mutiny : [ 10, 6 ],
36+
regtest : [ 10, 6 ],
37+
signet : [ 60, 30 ],
38+
testnet : [ 60, 30 ]
39+
}
40+
3441
export const network = process.argv.slice(2)[0] ?? 'signet'
42+
3543
export const config = configs[network as keyof typeof configs]
3644
export const faucet = faucets[network as keyof typeof faucets]
45+
export const poll = poll_rates[network as keyof typeof faucets]
3746

3847
export const members = [ 'alice', 'bob', 'carol' ]
48+
49+
export const sleep = (ms : number) => new Promise(res => setTimeout(res, ms))

demo/04_roles_and_endorse.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { print_banner } from '@scrow/test'
22

33
import { signers } from './02_create_signer.js'
44
import { roles, template } from './03_build_proposal.js'
5-
import { get_proposal_id } from '@/lib/proposal.js'
65

76
const [ a_signer, b_signer, c_signer ] = signers
87

@@ -16,8 +15,6 @@ print_banner('completed proposal')
1615
console.dir(proposal, { depth : null })
1716

1817
const signatures = signers.map(mbr => {
19-
const prop_id = get_proposal_id(proposal)
20-
console.log(`key ${mbr.pubkey} endorsing id ${prop_id}`)
2118
return mbr.proposal.endorse(proposal)
2219
})
2320

demo/07_deposit_funds.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { print_banner } from '@scrow/test'
22

3-
import { faucet } from './00_demo_config.js'
3+
import { faucet, poll, sleep } from './00_demo_config.js'
4+
45
import { client } from './01_create_client.js'
56
import { signers } from './02_create_signer.js'
67
import { contract } from './05_create_contract.js'
@@ -10,32 +11,30 @@ const { address, agent_id } = account
1011

1112
const vin_fee = contract.feerate * 65
1213
const amt_total = contract.total + vin_fee
14+
const btc_total = amt_total / 100_000_000
1315

1416
print_banner('make a deposit')
1517

1618
console.log('copy this address :', address)
17-
console.log('send this amount :', amt_total, 'sats')
18-
console.log('get funds here :', faucet)
19+
console.log('send this amount :', `${amt_total} sats || ${btc_total} btc`)
20+
console.log('get funds here :', faucet, '\n')
1921

20-
const ival = 30,
21-
retries = 6,
22-
sleep = (ms : number) => new Promise(res => setTimeout(res, ms))
22+
const [ ival, retries ] = poll
2323

2424
let curr = 1,
2525
utxos = await client.oracle.get_address_utxos(address)
2626

27-
console.log('\n')
28-
2927
while (utxos.length === 0 && curr < retries) {
3028
console.log(`[${curr}/${retries}] checking address in ${ival} seconds...`)
3129
await sleep(ival * 1000)
3230
utxos = await client.oracle.get_address_utxos(address)
33-
console.log('utxos:', utxos)
3431
curr += 1
3532
}
3633

3734
if (utxos.length === 0) throw new Error('utxo not found')
3835

36+
console.log('\nutxo:', utxos[0])
37+
3938
// Request the member to sign
4039
const signer = signers[0]
4140
const utxo = utxos[0].txspend

demo/08_check_contract.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { print_banner } from '@scrow/test'
2-
2+
import { poll, sleep } from './00_demo_config.js'
33
import { client } from './01_create_client.js'
44
import { cid } from './07_deposit_funds.js'
55

6-
const ival = 10,
7-
retries = 6,
8-
sleep = (ms : number) => new Promise(res => setTimeout(res, ms))
6+
const [ ival, retries ] = poll
97

108
let curr = 1,
119
res = await client.contract.read(cid)
1210

13-
console.log('\n')
11+
print_banner('awaiting on-chain confirmation of funds')
12+
13+
console.log('depending on the network, this could take a while!\n')
1414

1515
while (res.ok && res.data.contract.activated === null && curr < retries) {
1616
console.log(`[${curr}/${retries}] re-checking contract in ${ival} seconds...`)

demo/09_settle_contract.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { print_banner } from '@scrow/test'
22
import { WitnessData } from '@scrow/core'
33

4+
import { sleep } from './00_demo_config.js'
45
import { client } from './01_create_client.js'
56
import { signers } from './02_create_signer.js'
67
import { active_contract } from './08_check_contract.js'
@@ -30,5 +31,22 @@ const res = await client.contract.submit(contract.cid, witness)
3031
// Check the response is valid.
3132
if (!res.ok) throw new Error(res.error)
3233

34+
const settled_contract = res.data.contract
35+
3336
print_banner('settled contract')
34-
console.dir(res.data.contract, { depth : null })
37+
console.dir(settled_contract, { depth : null })
38+
39+
if (!settled_contract.spent) {
40+
throw new Error('failed to spend contract!')
41+
}
42+
43+
print_banner('final transaction')
44+
45+
console.log('waiting a few seconds for tx to propagate the pool...\n')
46+
await sleep(5000)
47+
48+
const txdata = await client.oracle.get_txdata(settled_contract.spent_txid)
49+
50+
console.dir(txdata, { depth : null })
51+
52+
print_banner('demo complete!')

src/lib/oracle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ export async function get_fee_target (
194194
const feerate = quotes[index]
195195
// If feerate does not exist, throw an error.
196196
if (typeof feerate !== 'number') {
197-
throw new Error('No quote available for target: ' + index)
197+
throw new Error('No quote available for fee target: ' + index)
198198
}
199199
// Else, return feerate from oracle.
200200
return feerate
201201
}
202202

203-
export async function fetcher<T> (
203+
export async function fetcher <T> (
204204
input : URL | RequestInfo,
205205
init ?: RequestInit,
206206
fetcher = fetch

0 commit comments

Comments
 (0)