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

Commit 0a80743

Browse files
author
cmd
committed
update
1 parent e8463ea commit 0a80743

File tree

8 files changed

+84
-73
lines changed

8 files changed

+84
-73
lines changed

src/client/class/contract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export class EscrowContract extends EventEmitter {
3131
}
3232

3333
get tab () {
34-
const { agent_fee, balance, pending, terms, subtotal, txfee, total } = this.data
34+
const { agent_fee, balance, pending, terms, subtotal, est_txfee, total } = this.data
3535
return {
3636
balance,
3737
agent_fee : agent_fee[0],
3838
payments : terms.payments.reduce((a, b) => a + b[0], 0),
3939
pending,
4040
subtotal,
41-
txfee,
41+
txfee : est_txfee,
4242
total
4343
}
4444
}

src/lib/contract.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function create_contract (
3030
const published = config.published ?? now()
3131
const signatures = config.signatures ?? []
3232
const subtotal = terms.value + agent_fee[0]
33-
const txout_size = outputs[0][1].length / 2
34-
const txfee = txout_size * feerate
33+
const vout_size = outputs[0][1].length / 2
34+
const txfee = vout_size * feerate
3535

3636
return sort_record({
3737
...config.agent,
@@ -40,6 +40,8 @@ export function create_contract (
4040
balance : 0,
4141
cid : config.cid,
4242
deadline : get_deadline(terms, published),
43+
est_txfee : txfee,
44+
est_txsize : vout_size,
4345
expires_at : null,
4446
feerate : feerate,
4547
moderator : config.moderator ?? null,
@@ -58,11 +60,9 @@ export function create_contract (
5860
subtotal : subtotal,
5961
terms : terms,
6062
total : subtotal + txfee,
61-
txfee : txfee,
62-
txvin_size : 0,
63-
txout_size : txout_size,
6463
updated_at : published,
65-
vm_state : null
64+
vm_state : null,
65+
vout_size : vout_size
6666
})
6767
}
6868

src/lib/return.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929

3030
import * as assert from '../assert.js'
3131

32-
const MIN_RECOVER_FEE = 10000
32+
const MIN_RECOVER_FEE = 1000
3333

3434
/**
3535
* Computes and returns a context

src/schema/contract.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const data = z.object({
2828
balance : num,
2929
cid : hash,
3030
deadline : stamp,
31+
est_txfee : num,
32+
est_txsize : num,
3133
expires_at : stamp.nullable(),
3234
feerate : num,
3335
outputs : output.array(),
@@ -41,11 +43,9 @@ const data = z.object({
4143
subtotal : num,
4244
terms,
4345
total : num,
44-
txfee : num,
45-
txvin_size : num,
46-
txout_size : num,
4746
updated_at : stamp,
4847
vm_state : vm.data.nullable(),
48+
vout_size : num
4949
}).and(agent).and(spend_state).and(close_state)
5050

5151
export default { agent, data, output, request, status }

src/types/contract.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface ContractBase {
3838
balance : number
3939
cid : string
4040
deadline : number
41+
est_txfee : number
42+
est_txsize : number
4143
expires_at : null | number
4244
feerate : number
4345
moderator : string | null
@@ -51,11 +53,9 @@ export interface ContractBase {
5153
subtotal : number
5254
terms : ProposalData
5355
total : number
54-
txfee : number
55-
txvin_size : number
56-
txout_size : number
5756
updated_at : number
5857
vm_state : null | StateData
58+
vout_size : number
5959
}
6060

6161
export type ContractRequest = {

test/client/proposal/configure_clients.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77

88
const config = {
99
hostname : 'http://localhost:3000',
10-
oracle : 'http://172.21.0.3:3000'
10+
oracle : 'http://172.21.0.3:3300'
1111
}
1212

1313
const aliases = [ 'alice', 'bob', 'carol', 'david' ]

test/client/scripts/full_demo.ts

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const VERBOSE = process.env.VERBOSE === 'true'
2424

2525
// Startup a local process of Bitcoin Core for testing.
2626

27-
const config = CONFIG.mutiny
27+
const config = CONFIG.regtest
2828
const core = CoreUtil.get_daemon(config.core)
2929
const cli = await core.startup()
3030

@@ -120,76 +120,84 @@ if (VERBOSE) {
120120
console.dir(contract, { depth : null })
121121
}
122122

123-
// Request an account for the member to use.
124-
const account_res = await client.deposit.request({
125-
pubkey : a_mbr.pubkey,
126-
locktime : 60 * 60 // 1 hour locktime
127-
})
123+
const is_regtest = config.core.network === 'regtest'
128124

129-
// Check the response is valid.
130-
if (!account_res.ok) throw new Error(account_res.error)
125+
const deposits : [ EscrowSigner, number ][] = [
126+
[ a_mbr, 10_000 ],
127+
[ b_mbr, 6_980 ]
128+
]
131129

132-
// Unpack some of the terms.
133-
const { account } = account_res.data
130+
for (const [ mbr, amt ] of deposits) {
134131

135-
if (VERBOSE) {
136-
print_banner('NEW ACCOUNT')
137-
console.dir(account, { depth : null })
138-
}
132+
// Request an account for the member to use.
133+
const account_res = await client.deposit.request({
134+
pubkey : a_mbr.pubkey,
135+
locktime : 60 * 60 // 1 hour locktime
136+
})
139137

140-
const { address, agent_id } = account
138+
// Check the response is valid.
139+
if (!account_res.ok) throw new Error(account_res.error)
141140

142-
// Use our utility methods to fund the address and get the utxo.
143-
const is_regtest = config.core.network === 'regtest'
144-
const txid = await CoreUtil.fund_address(cli, 'faucet', address, 20_000, is_regtest)
141+
// Unpack some of the terms.
142+
const { account } = account_res.data
145143

146-
if (VERBOSE) {
147-
print_banner('DEPOSIT TXID')
148-
console.log(txid)
149-
console.log('\nsleeping for 2s while tx propagates...')
150-
}
144+
if (VERBOSE) {
145+
print_banner(`NEW ACCOUNT`)
146+
console.dir(account, { depth : null })
147+
}
151148

152-
await sleep(2000)
153-
154-
const limit = 10
155-
let fails = 0,
156-
utxo = await client.oracle.get_utxo({ txid, address })
157-
158-
while (!is_regtest && utxo === null && fails < limit) {
159-
try {
160-
console.log('sleeping for 5s...')
161-
await sleep(5000)
162-
console.log('fetching utxo...')
163-
utxo = await client.oracle.get_utxo({ txid, address })
164-
if (utxo === null) throw 'utxo not found'
165-
} catch (err) {
166-
console.log(err)
167-
fails += 1
168-
continue
149+
const { address, agent_id } = account
150+
151+
const txid = await CoreUtil.fund_address(cli, 'faucet', address, amt, is_regtest)
152+
153+
if (VERBOSE) {
154+
print_banner('DEPOSIT TXID')
155+
console.log(txid)
156+
console.log('\nsleeping for 2s while tx propagates...')
169157
}
170-
}
171158

172-
if (utxo === null) throw new Error('utxo not found')
159+
await sleep(2000)
160+
161+
const limit = 10
162+
let fails = 0,
163+
utxo = await client.oracle.get_utxo({ txid, address })
164+
165+
while (!is_regtest && utxo === null && fails < limit) {
166+
try {
167+
console.log('sleeping for 5s...')
168+
await sleep(5000)
169+
console.log('fetching utxo...')
170+
utxo = await client.oracle.get_utxo({ txid, address })
171+
if (utxo === null) throw 'utxo not found'
172+
} catch (err) {
173+
console.log(err)
174+
fails += 1
175+
continue
176+
}
177+
}
173178

174-
// Request the member to sign
175-
const return_tx = await a_mbr.deposit.register_utxo(account, utxo.txspend)
176-
const covenant = await a_mbr.deposit.commit_utxo(account, contract, utxo.txspend)
179+
if (utxo === null) throw new Error('utxo not found')
177180

178-
// Fund the contract directly with the API.
179-
const deposit_res = await client.deposit.fund(agent_id, return_tx, covenant)
181+
// Request the member to sign
182+
const return_tx = await a_mbr.deposit.register_utxo(account, utxo.txspend)
183+
const covenant = await a_mbr.deposit.commit_utxo(account, contract, utxo.txspend)
180184

181-
// Check the response is valid.
182-
if (!deposit_res.ok) throw new Error(deposit_res.error)
185+
// Fund the contract directly with the API.
186+
const deposit_res = await client.deposit.fund(agent_id, return_tx, covenant)
183187

184-
let deposit = deposit_res.data.deposit
188+
// Check the response is valid.
189+
if (!deposit_res.ok) throw new Error(deposit_res.error)
185190

186-
contract = deposit_res.data.contract
191+
const deposit = deposit_res.data.deposit
187192

188-
if (VERBOSE) {
189-
print_banner('NEW DEPOSIT')
190-
console.dir(deposit, { depth : null })
191-
print_banner('UPDATED CONTRACT')
192-
console.dir(contract, { depth : null })
193+
contract = deposit_res.data.contract
194+
195+
if (VERBOSE) {
196+
print_banner(`NEW DEPOSIT FROM ${mbr.pubkey}`)
197+
console.dir(deposit, { depth : null })
198+
print_banner('UPDATED CONTRACT')
199+
console.dir(contract, { depth : null })
200+
}
193201
}
194202

195203
if (contract.status !== 'active') {

test/demo/07_fund_contract.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { account } from './06_request_deposit.js'
66

77
const { address, agent_id } = account
88

9+
const vin_fee = contract.feerate * 65
10+
const amt_total = contract.total + vin_fee
11+
912
print_banner('make a deposit')
1013

1114
console.log('copy this address :', address)
12-
console.log('send this amount :', contract.total, 'sats')
15+
console.log('send this amount :', amt_total, 'sats')
1316
if (contract.terms.network === 'signet') {
1417
console.log('get funds here : https://faucet.mutinynet.com')
1518
} else if (contract.terms.network === 'testnet') {

0 commit comments

Comments
 (0)