-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1782 from demergent-labs/psbt
Add a Psbt example
- Loading branch information
Showing
50 changed files
with
4,078 additions
and
79 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; | ||
import { existsSync, rmSync } from 'fs-extra'; | ||
|
||
export async function whileRunningBitcoinDaemon( | ||
callback: () => Promise<boolean> | void | ||
) { | ||
const bitcoinDaemon = await startBitcoinDaemon(); | ||
await callback(); | ||
bitcoinDaemon.kill(); | ||
} | ||
|
||
async function startBitcoinDaemon(): Promise<ChildProcessWithoutNullStreams> { | ||
if (existsSync(`.bitcoin/data/regtest`)) { | ||
rmSync('.bitcoin/data/regtest', { recursive: true, force: true }); | ||
} | ||
const bitcoinDaemon = spawn('.bitcoin/bin/bitcoind', [ | ||
`-conf=${process.cwd()}/.bitcoin.conf`, | ||
`-datadir=${process.cwd()}/.bitcoin/data`, | ||
'--port=18444' | ||
]); | ||
|
||
process.on('uncaughtException', () => { | ||
if (!bitcoinDaemon.killed) { | ||
bitcoinDaemon.kill(); | ||
} | ||
}); | ||
|
||
process.on('exit', () => { | ||
if (!bitcoinDaemon.killed) { | ||
bitcoinDaemon.kill(); | ||
} | ||
}); | ||
|
||
console.info(`starting bitcoind...`); | ||
// This await is necessary to ensure the daemon is running | ||
await new Promise((resolve) => setTimeout(resolve, 5_000)); | ||
return bitcoinDaemon; | ||
} |
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 |
---|---|---|
@@ -1,46 +1,11 @@ | ||
import { getCanisterId } from 'azle/dfx'; | ||
import { runTests } from 'azle/test'; | ||
import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; | ||
import { existsSync, rmSync } from 'fs-extra'; | ||
|
||
import { getTests } from './tests'; | ||
import { whileRunningBitcoinDaemon } from './bitcoin_daemon'; | ||
import { getP2pkhAddress, getTests, P2PKH_ADDRESS_FORM } from './tests'; | ||
|
||
const canisterId = getCanisterId('basic_bitcoin'); | ||
|
||
export async function whileRunningBitcoinDaemon( | ||
callback: () => Promise<boolean> | void | ||
) { | ||
const bitcoinDaemon = await startBitcoinDaemon(); | ||
await callback(); | ||
bitcoinDaemon.kill(); | ||
} | ||
|
||
async function startBitcoinDaemon(): Promise<ChildProcessWithoutNullStreams> { | ||
if (existsSync(`.bitcoin/data/regtest`)) { | ||
rmSync('.bitcoin/data/regtest', { recursive: true, force: true }); | ||
} | ||
const bitcoinDaemon = spawn('.bitcoin/bin/bitcoind', [ | ||
`-conf=${process.cwd()}/.bitcoin.conf`, | ||
`-datadir=${process.cwd()}/.bitcoin/data`, | ||
'--port=18444' | ||
]); | ||
|
||
process.on('uncaughtException', () => { | ||
if (!bitcoinDaemon.killed) { | ||
bitcoinDaemon.kill(); | ||
} | ||
}); | ||
|
||
process.on('exit', () => { | ||
if (!bitcoinDaemon.killed) { | ||
bitcoinDaemon.kill(); | ||
} | ||
}); | ||
|
||
console.info(`starting bitcoind...`); | ||
// This await is necessary to ensure the daemon is running | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
return bitcoinDaemon; | ||
} | ||
|
||
whileRunningBitcoinDaemon(() => runTests(getTests(canisterId))); | ||
whileRunningBitcoinDaemon(() => | ||
runTests(getTests(canisterId, getP2pkhAddress, P2PKH_ADDRESS_FORM)) | ||
); |
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,10 @@ | ||
# Enable regtest mode. This is required to setup a private bitcoin network. | ||
regtest=1 | ||
|
||
# Dummy credentials that are required by `bitcoin-cli`. | ||
rpcuser=ic-btc-integration | ||
rpcpassword=QPQiNaph19FqUsCrBRN0FII7lyM26B51fAMeBQzCb-E= | ||
rpcauth=ic-btc-integration:cdf2741387f3a12438f69092f0fdad8e$62081498c98bee09a0dce2b30671123fa561932992ce377585e8e08bb0c11dfa | ||
|
||
# Enable indexing so we can look up transactions by their ids | ||
txindex=1 |
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,5 @@ | ||
.azle | ||
.bitcoin | ||
.dfx | ||
dfx_generated | ||
node_modules |
Oops, something went wrong.