Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Oct 16, 2023
1 parent 400f9fe commit 7ce3203
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 37 deletions.
12 changes: 1 addition & 11 deletions src/lib/contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { DEFAULT_DEADLINE } from '../config.js'
import { Signer } from '../signer.js'
import { create_settlment } from './spend.js'
import { now } from './util.js'
import { init_vm } from '../vm/main.js'

Expand Down Expand Up @@ -59,7 +57,7 @@ export function get_deadline (
if (effective !== undefined) {
return effective - created
} else {
return deadline ?? DEFAULT_DEADLINE
return created + (deadline ?? DEFAULT_DEADLINE)
}
}

Expand All @@ -77,14 +75,6 @@ export function activate_contract (
}
}

export function close_contract (
agent : Signer,
contract : ContractData,
pathname : string
) {
return create_settlment(agent, contract, pathname)
}

export function get_spend_outputs (
prop : ProposalData,
fees : Payment[]
Expand Down
4 changes: 2 additions & 2 deletions src/lib/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from './recovery.js'

import {
Deposit,
DepositData,
DepositContext,
DepositTemplate,
RecoveryConfig
Expand Down Expand Up @@ -53,7 +53,7 @@ export function parse_deposit (

export function init_deposit (
tmpl : DepositTemplate
) : Deposit {
) : DepositData {
return {
...tmpl,
confirmed : false,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ContractData,
CovenantData,
DepositContext,
Deposit,
DepositData,
MutexContext,
MutexEntry
} from '../types/index.js'
Expand All @@ -49,7 +49,7 @@ export function create_session (

export function create_covenant (
contract : ContractData,
deposit : Deposit,
deposit : DepositData,
signer : Signer
) : CovenantData {
const { session } = contract
Expand All @@ -69,7 +69,7 @@ export function parse_covenant (

export function get_mutex_entries (
contract : ContractData,
deposit : Deposit,
deposit : DepositData,
pnonces : Bytes[]
) : MutexEntry[] {
const { outputs, session } = contract
Expand Down
9 changes: 5 additions & 4 deletions src/lib/spend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import {
AgentSession,
ContractData,
Deposit,
DepositData,
SpendOutput
} from '../types/index.js'

Expand All @@ -27,14 +27,15 @@ import * as assert from '../assert.js'
export function create_settlment (
agent : Signer,
contract : ContractData,
deposits : DepositData[],
pathname : string
) : TxData {
const { funds, outputs, session } = contract
const { outputs, session } = contract
const output = outputs.find(e => e[0] === pathname)
assert.exists(output)
const vin : TxPrevout[] = []
const vout = output[1]
for (const fund of funds) {
for (const fund of deposits) {
const txin = fund.txinput
const sig = sign_txinput(agent, fund, output, session)
vin.push({ ...txin, witness : [ sig ] })
Expand All @@ -44,7 +45,7 @@ export function create_settlment (

export function sign_txinput (
agent : Signer,
deposit : Deposit,
deposit : DepositData,
output : SpendOutput,
session : AgentSession
) : string {
Expand Down
2 changes: 1 addition & 1 deletion src/types/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TxPrevout,
} from '@scrow/tapscript'

export type Deposit = DepositTemplate & DepositMeta
export type DepositData = DepositTemplate & DepositMeta

export interface DepositContext {
deposit_key : Bytes
Expand Down
6 changes: 3 additions & 3 deletions src/validators/covenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import {
ContractData,
CovenantData,
Deposit,
DepositData,
MutexEntry
} from '../types/index.js'

Expand All @@ -25,7 +25,7 @@ export function validate_covenant (

export function verify_covenant (
contract : ContractData,
deposit : Deposit,
deposit : DepositData,
dep_agent : Signer,
ses_agent : Signer,
) {
Expand All @@ -47,7 +47,7 @@ export function verify_covenant (

function check_deposit_agent (
agent : Signer,
deposit : Deposit
deposit : DepositData
) {
const { agent_id, deposit_key } = deposit
assert.ok(agent_id === agent.id, 'Agent ID does not match deposit.')
Expand Down
4 changes: 2 additions & 2 deletions test/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function get_core () : CoreDaemon {
datapath : 'test/data',
network : 'regtest',
isolated : true,
debug : true,
verbose : true
debug : false,
verbose : false
})
}
return daemon
Expand Down
16 changes: 8 additions & 8 deletions test/scratch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { init_deposit } from '@scrow/core/deposit'
import { parse_vm } from '@scrow/core/parse'
import { now } from '@scrow/core/util'
import { get_core } from './core.js'
import { Buff } from '@cmdcode/buff'
import { init_deposit } from '@scrow/core/deposit'
import { parse_vm } from '@scrow/core/parse'
import { create_session } from '@scrow/core/session'
import { create_settlment } from '@scrow/core/spend'
import { now } from '@scrow/core/util'
import { get_core } from './core.js'

import {
activate_contract,
create_contract,
close_contract
} from '@scrow/core/contract'

import {
Expand All @@ -26,8 +28,6 @@ import {
} from '@scrow/core/validate'

import vgen from './src/vectorgen.js'
import { create_session } from '@scrow/core/session'
import { Buff } from '@cmdcode/buff'

/* ------------------- [ Init ] ------------------- */

Expand Down Expand Up @@ -110,7 +110,7 @@ console.dir(parse_vm(new_state), { depth : null })
const { result } = new_state

if (result !== null) {
const txdata = close_contract(agent.signer, contract, result)
const txdata = create_settlment(agent.signer, contract, funds, result)

console.log(banner('closing tx'))
console.dir(txdata, { depth : null })
Expand Down
6 changes: 3 additions & 3 deletions test/src/vectorgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {

import {
ContractData,
Deposit,
DepositData,
DepositTemplate,
ProposalData
} from '@scrow/core'
Expand Down Expand Up @@ -121,9 +121,9 @@ export async function gen_deposits (

async function gen_funds (
contract : ContractData,
deposits : Deposit[],
deposits : DepositData[],
members : MemberData[]
) : Promise<Deposit[]> {
) : Promise<DepositData[]> {
return deposits.map(dep => {
for (const mbr of members) {
const sign_key = Buff.bytes(dep.signing_key).hex
Expand Down

0 comments on commit 7ce3203

Please sign in to comment.