Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Jan 28, 2024
1 parent ac10ac9 commit 33220bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
9 changes: 5 additions & 4 deletions demo/06_request_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { print_banner } from '@scrow/test'
import { client } from './01_create_client.js'
import { signers } from './02_create_signer.js'

const pubkey = signers[0].pubkey
const locktime = 60 * 60 // 1 hour locktime
const res = await client.deposit.request({ pubkey, locktime })
const funder = signers[0]
const acct_req = funder.deposit.request_account(locktime)
const acct_res = await client.deposit.request(acct_req)

// Check the response is valid.
if (!res.ok) throw new Error(res.error)
if (!acct_res.ok) throw new Error(acct_res.error)

// Unpack some of the terms.
export const account = res.data.account
export const { account } = acct_res.data

print_banner('deposit account')
console.dir(account, { depth : null })
8 changes: 4 additions & 4 deletions demo/07_deposit_funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { signers } from './02_create_signer.js'
import { contract } from './05_create_contract.js'
import { account } from './06_request_account.js'

const { address, agent_id } = account
const { address } = account

const vin_fee = contract.feerate * 65
const amt_total = contract.total + vin_fee
Expand Down Expand Up @@ -38,11 +38,11 @@ console.log('\nutxo:', utxos[0])
// Request the member to sign
const signer = signers[0]
const utxo = utxos[0].txspend
const return_tx = await signer.deposit.register_utxo(account, utxo)
const covenant = await signer.deposit.commit_utxo(account, contract, utxo)
const covenant = signer.deposit.commit_utxo(account, contract, utxo)
const reg_req = { ...account, covenant, utxo }

// Fund the contract
const res = await client.deposit.fund(agent_id, return_tx, covenant)
const res = await client.deposit.fund(reg_req)

// Check the response is valid.
if (!res.ok) throw new Error('failed')
Expand Down
3 changes: 2 additions & 1 deletion src/client/api/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { EscrowClient } from '../class/client.js'
import { validate_register_req } from '@/validators/index.js'
import { validate_account_req, validate_register_req } from '@/validators/index.js'

import {
CovenantData,
Expand All @@ -23,6 +23,7 @@ function request_account_api (client : EscrowClient) {
return async (
request : AccountRequest
) : Promise<ApiResponse<AccountDataResponse>> => {
validate_account_req(request)
// Formulate the request.
const url = `${client.host}/api/deposit/request`
// Formulate the request.
Expand Down
22 changes: 10 additions & 12 deletions src/client/api/depositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
} from '@/lib/session.js'

import {
AccountDataResponse,
ApiResponse,
AccountRequest,
ContractData,
CovenantData,
DepositAccount,
Expand All @@ -20,14 +19,13 @@ import {
} from '@/types/index.js'

export function request_account_api (signer : EscrowSigner) {
return async (
return (
locktime : number,
index ?: number
) : Promise<ApiResponse<AccountDataResponse>> => {
) : AccountRequest => {
const deposit_pk = signer.pubkey
const spend_xpub = signer.get_account(index).xpub
const req = { deposit_pk, locktime, spend_xpub }
return signer.client.deposit.request(req)
return { deposit_pk, locktime, spend_xpub }
}
}

Expand All @@ -38,11 +36,11 @@ export function verify_account_api (signer : EscrowSigner) {
}

export function commit_utxo_api (signer : EscrowSigner) {
return async (
return (
account : DepositAccount,
contract : ContractData,
utxo : TxOutput
) : Promise<CovenantData> => {
) : CovenantData => {
// Unpack the deposit object.
const { agent_pk, sequence, spend_xpub } = account
// Check if account xpub is valid.
Expand All @@ -61,10 +59,10 @@ export function commit_utxo_api (signer : EscrowSigner) {
}

export function commit_deposit_api (signer : EscrowSigner) {
return async (
return (
contract : ContractData,
deposit : DepositData
) : Promise<CovenantData> => {
) : CovenantData => {
// Unpack the deposit object.
const {
agent_pk, sequence, txid, vout,
Expand All @@ -88,11 +86,11 @@ export function commit_deposit_api (signer : EscrowSigner) {
}

export function close_deposit_api (signer : EscrowSigner) {
return async (
return (
deposit : DepositData,
txfee : number,
address ?: string
) : Promise<string> => {
) : string => {
// Unpack signer object.
const { txid } = deposit
if (address === undefined) {
Expand Down

0 comments on commit 33220bb

Please sign in to comment.