From 52350e659e214b5a9d8108d33c3820d7ad8bcce7 Mon Sep 17 00:00:00 2001 From: cmd Date: Tue, 20 Feb 2024 19:45:16 -0600 Subject: [PATCH] update --- demo/00_demo_config.ts | 10 ++- demo/02_create_signer.ts | 2 +- demo/03_build_proposal.ts | 14 +-- demo/07_deposit_funds.ts | 30 ++++--- demo/09_settle_contract.ts | 4 +- demo/api/deposit/list.ts | 4 +- demo/api/deposit/register.ts | 26 +++--- demo/draft/draft.html | 2 +- demo/util.ts | 24 ++++- docs/api/contract.md | 148 +++++++++++++++---------------- docs/api/deposit.md | 113 ++++++++++++++--------- docs/api/server.md | 4 +- docs/api/witness.md | 4 + docs/guides/client.md | 2 +- docs/guides/contract.md | 14 +-- docs/guides/deposit.md | 2 +- docs/guides/proposal.md | 2 +- src/client/api/signer/request.ts | 1 + src/client/class/signer.ts | 6 +- src/lib/index.ts | 1 + test/plat/module.html | 48 +++++----- 21 files changed, 267 insertions(+), 194 deletions(-) diff --git a/demo/00_demo_config.ts b/demo/00_demo_config.ts index ec7e58e0..d058ed69 100644 --- a/demo/00_demo_config.ts +++ b/demo/00_demo_config.ts @@ -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 ], @@ -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] } diff --git a/demo/02_create_signer.ts b/demo/02_create_signer.ts index d0563f1b..2e972582 100644 --- a/demo/02_create_signer.ts +++ b/demo/02_create_signer.ts @@ -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) } /** diff --git a/demo/03_build_proposal.ts b/demo/03_build_proposal.ts index 7435910e..e45840e8 100644 --- a/demo/03_build_proposal.ts +++ b/demo/03_build_proposal.ts @@ -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, }) /** @@ -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({ @@ -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 ] ] }) } diff --git a/demo/07_deposit_funds.ts b/demo/07_deposit_funds.ts index fb7499e3..8b70bc94 100644 --- a/demo/07_deposit_funds.ts +++ b/demo/07_deposit_funds.ts @@ -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' @@ -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 diff --git a/demo/09_settle_contract.ts b/demo/09_settle_contract.ts index 6634555d..5e9a15d0 100644 --- a/demo/09_settle_contract.ts +++ b/demo/09_settle_contract.ts @@ -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. @@ -72,3 +72,5 @@ if (DEMO_MODE) { console.log('view your transaction here:') console.log(`\n${client._oracle}/tx/${txid}\n`) } + +await sleep(2000) diff --git a/demo/api/deposit/list.ts b/demo/api/deposit/list.ts index 30ece997..b999a56d 100644 --- a/demo/api/deposit/list.ts +++ b/demo/api/deposit/list.ts @@ -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. diff --git a/demo/api/deposit/register.ts b/demo/api/deposit/register.ts index 3e21b753..ab2762fe 100644 --- a/demo/api/deposit/register.ts +++ b/demo/api/deposit/register.ts @@ -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' @@ -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 diff --git a/demo/draft/draft.html b/demo/draft/draft.html index 7224c801..bb4626b1 100644 --- a/demo/draft/draft.html +++ b/demo/draft/draft.html @@ -63,7 +63,7 @@

Console