Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Feb 21, 2024
1 parent fca5251 commit 52350e6
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 194 deletions.
10 changes: 9 additions & 1 deletion demo/00_demo_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const faucets = {
testnet : 'https://bitcoinfaucet.uo1.net'
}

const returns = {
mutiny : 'tb1qd28npep0s8frcm3y7dxqajkcy2m40eysplyr9v',
regtest : 'bcrt1qvjnqnzuyt7je5rhrc0gpjlrm2zagjjq5c9fwkp',
signet : '',
testnet : ''
}

const poll_rates = {
mutiny : [ 10, 6 ],
regtest : [ 10, 6 ],
Expand All @@ -45,5 +52,6 @@ export const config = {
client : configs[network as keyof typeof configs],
faucet : faucets[network as keyof typeof faucets],
members : [ 'alice', 'bob', 'carol' ],
poll : poll_rates[network as keyof typeof poll_rates]
poll : poll_rates[network as keyof typeof poll_rates],
return : returns[network as keyof typeof returns]
}
2 changes: 1 addition & 1 deletion demo/02_create_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function create_signer (alias : string) {
// Simple hash of a string. For testing only.
const seed = Buff.str(alias).digest
// Return an escrow signer.
return EscrowSigner.create(config, seed)
return EscrowSigner.create(config.client, seed)
}

/**
Expand Down
14 changes: 7 additions & 7 deletions demo/03_build_proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export const proposal = create_proposal({
duration : 14400,
moderator : moderator.pubkey,
network : config.network,
paths : [[ 'return', 10000, config.return ]],
schedule : [[ 7200, 'close', '*' ]],
value : 15000,
value : 10000,
})

/**
Expand All @@ -35,8 +36,8 @@ export const role = {
[ 'draw', 5000 ]
],
programs : [
[ 'endorse', 'close', 'heads|tails|draw', 2 ],
[ 'endorse', 'dispute', 'heads|tails', 1 ]
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', 'heads|tails', 1 ]
]
}),
seller : create_policy({
Expand All @@ -46,15 +47,14 @@ export const role = {
[ 'draw', 5000 ]
],
programs : [
[ 'endorse', 'close', 'heads|tails|draw', 2 ],
[ 'endorse', 'dispute', 'heads|tails', 1 ]
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', 'heads|tails', 1 ]
]
}),
agent : create_policy({
title : 'agent',
payment : 5000,
programs : [
[ 'endorse', 'resolve', 'heads|tails|draw', 1 ]
[ 'endorse', 'resolve', '*', 1 ]
]
})
}
30 changes: 20 additions & 10 deletions demo/07_deposit_funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { client } from './01_create_client.js'
import { signers } from './02_create_signer.js'
import { new_contract } from './05_create_contract.js'
import { new_account } from './06_request_account.js'
import { fund_address, sleep } from './util.js'

import {
fund_regtest_address,
fund_mutiny_address,
sleep
} from './util.js'

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

Expand All @@ -28,17 +33,22 @@ const btc_total = amt_total / 100_000_000

/** ========== [ Print Deposit Info ] ========== **/

if (DEMO_MODE || config.network !== 'regtest') {
print_banner('make a deposit')
console.log('copy this address :', address)
console.log('send this amount :', `${amt_total} sats || ${btc_total} btc`)
console.log('get funds here :', config.faucet, '\n')
} else {
print_banner('sending deposit')
await fund_address(address, amt_total)
await sleep(2000)
switch (config.network) {
case 'mutiny':
fund_mutiny_address(address, amt_total)
break
case 'regtest':
fund_regtest_address(address, amt_total)
break
default:
print_banner('make a deposit')
console.log('copy this address :', address)
console.log('send this amount :', `${amt_total} sats || ${btc_total} btc`)
console.log('get funds here :', config.faucet, '\n')
}

await sleep(2000)

/** ========== [ Poll Deposit Status ] ========== **/

const [ ival, retries ] = config.poll
Expand Down
4 changes: 3 additions & 1 deletion demo/09_settle_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const [ a_signer, b_signer ] = signers
const template = {
action : 'close',
method : 'endorse',
path : 'tails'
path : 'return'
}

// Define our contract as the active contract.
Expand Down Expand Up @@ -72,3 +72,5 @@ if (DEMO_MODE) {
console.log('view your transaction here:')
console.log(`\n${client._oracle}/tx/${txid}\n`)
}

await sleep(2000)
4 changes: 2 additions & 2 deletions demo/api/deposit/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { client } from '@scrow/demo/01_create_client.js'
import { depositor } from '@scrow/demo/07_deposit_funds.js'

// Generate a request token.
const req_token = depositor.request.deposit_list()
const req = depositor.request.deposit_list()
// Deliver the request and token.
const res = await client.deposit.list(depositor.pubkey, req_token)
const res = await client.deposit.list(depositor.pubkey, req)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack our response data.
Expand Down
26 changes: 16 additions & 10 deletions demo/api/deposit/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { client } from '@scrow/demo/01_create_client.js'
import { new_account } from '@scrow/demo/06_request_account.js'

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

Expand All @@ -17,17 +18,22 @@ const btc_total = amt_total / 100_000_000

/** ========== [ Print Deposit Info ] ========== **/

if (config.network !== 'regtest') {
print_banner('make a deposit')
console.log('copy this address :', address)
console.log('send this amount :', `${amt_total} sats || ${btc_total} btc`)
console.log('get funds here :', config.faucet, '\n')
} else {
print_banner('sending deposit')
await fund_address(address, amt_total)
await sleep(2000)
switch (config.network) {
case 'mutiny':
fund_mutiny_address(address, amt_total)
break
case 'regtest':
fund_regtest_address(address, amt_total)
break
default:
print_banner('make a deposit')
console.log('copy this address :', address)
console.log('send this amount :', `${amt_total} sats || ${btc_total} btc`)
console.log('get funds here :', config.faucet, '\n')
}

await sleep(2000)

/** ========== [ Poll Deposit Status ] ========== **/

const [ ival, retries ] = config.poll
Expand Down
2 changes: 1 addition & 1 deletion demo/draft/draft.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h4>Console</h2>
</div>

<script type="module">
import { lib, DraftSession, EscrowClient, EscrowSigner } from '../../dist/module.mjs'
import { DraftSession, EscrowClient, EscrowSigner } from '../../dist/module.mjs'

const config = {
hostname : 'https://bitescrow-mutiny.vercel.app',
Expand Down
24 changes: 21 additions & 3 deletions demo/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CoreUtil } from '@scrow/test'

export const sleep = (ms : number) => new Promise(res => setTimeout(res, ms))

export async function fund_address (
export async function fund_regtest_address (
address : string,
amount : number
) {
Expand All @@ -11,10 +11,28 @@ export async function fund_address (
spawn : false,
verbose : false
})
console.log('funding address :', address)
console.log('sending amount :', amount)
return daemon.run(async client => {
console.log('funding address :', address)
console.log('sending amount :', amount)
await CoreUtil.fund_address(client, 'faucet', address, amount, true)
await daemon.shutdown()
})
}

export async function fund_mutiny_address (
address : string,
amount : number
) {
console.log('funding address :', address)
console.log('sending amount :', amount)
const url = 'https://faucet.mutinynet.com/api/onchain'
const opt = {
body : JSON.stringify({ address, sats : amount }),
headers : { 'content-type' : 'application/json' },
method : 'POST'
}
const res = await fetch(url, opt)
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
const { txid } = await res.json()
return txid
}
Loading

0 comments on commit 52350e6

Please sign in to comment.