-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cmd
committed
Feb 23, 2024
1 parent
885cfe7
commit e02d76b
Showing
24 changed files
with
1,321 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Deposit API Demo for endpoint: | ||
* /api/deposit/:dpid/commit | ||
* | ||
* You can run this demo using the shell command: | ||
* yarn load demo/api/deposit/commit | ||
*/ | ||
|
||
import { print_banner } from '@scrow/test' | ||
import { config } from '@scrow/demo/00_demo_config.js' | ||
import { client } from '@scrow/demo/01_create_client.js' | ||
import { signers } from '@scrow/demo/02_create_signer.js' | ||
import { new_contract } from '@scrow/demo/05_create_contract.js' | ||
import { new_account } from '@scrow/demo/06_request_account.js' | ||
|
||
import { | ||
fund_mutiny_address, | ||
fund_regtest_address, | ||
sleep | ||
} from '@scrow/demo/util.js' | ||
|
||
// Unpack account details. | ||
const { address } = new_account | ||
// Define how much sats we want to deposit | ||
const amt_total = 20_000 | ||
// Also compute a total amount in bitcoin. | ||
const btc_total = amt_total / 100_000_000 | ||
|
||
/** ========== [ Print Deposit Info ] ========== **/ | ||
|
||
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 ] ========== **/ | ||
|
||
// Define our polling interval and retries. | ||
const [ ival, retries ] = config.poll | ||
// Poll for utxos from the account address. | ||
const utxos = await client.oracle.poll_address(address, ival, retries, true) | ||
|
||
print_banner('address utxos') | ||
console.log('utxos:', utxos) | ||
|
||
// Get the output data from the utxo. | ||
const utxo = utxos[0].txspend | ||
// Define our funder for the deposit. | ||
const depositor = signers[0] | ||
// Generate a commit request from the depositor. | ||
const req = depositor.account.commit(new_account, new_contract, utxo) | ||
// Deliver our commit request to the server. | ||
const res = await client.deposit.commit(req) | ||
// Check the response is valid. | ||
if (!res.ok) throw new Error(res.error) | ||
// Unpack our data object. | ||
const locked_deposit = res.data.deposit | ||
|
||
print_banner('open deposit') | ||
console.dir(locked_deposit, { depth: null }) | ||
console.log('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Deposit API Demo for endpoint: | ||
* /api/deposit/:dpid/status | ||
* | ||
* You can run this demo using the shell command: | ||
* yarn load demo/api/deposit/status | ||
*/ | ||
|
||
import { print_banner } from '@scrow/test' | ||
import { client } from '@scrow/demo/01_create_client.js' | ||
import { locked_deposit } from '@scrow/demo/07_deposit_funds.js' | ||
|
||
// Define the deposit id we will use. | ||
const dpid = locked_deposit.dpid | ||
// Request to read a deposit via dpid. | ||
const res = await client.deposit.status(dpid) | ||
// Check the response is valid. | ||
if (!res.ok) throw new Error(res.error) | ||
// Unpack the data response | ||
const deposit = res.data.deposit | ||
|
||
print_banner('deposit status') | ||
console.dir(deposit, { depth : null }) | ||
console.log('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.