-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary Regtest Guide #51
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Create a Local Regtest Blockchain | ||
|
||
```post-author | ||
Jonathan Gonzalez | ||
``` | ||
```post-description | ||
This example creates a local Regtest Chain. | ||
``` | ||
|
||
## Regtest Chain Example | ||
The Regtest Network is a local Blockchain in which individuals can almost | ||
instantaneously generate blocks on demand. Including the option to generate private satoshis | ||
with no real-world value. This is ideal for testing Bitcoin Applications. | ||
|
||
This example generates two consecutive blocks, with transaction confirmations | ||
in the Users WalletDB: | ||
|
||
|
||
```javascript | ||
const FullNode = require('bcoin/lib/node/fullnode'); | ||
const consensus = require('bcoin/lib/protocol/consensus'); | ||
|
||
const node = new FullNode({ | ||
network: 'regtest', | ||
db: 'memory', | ||
prefix: '/home/.bcoin/regtest', | ||
apiKey: 'bikeshed', | ||
nodes: '127.0.0.1', | ||
port: 48444, | ||
env: true, | ||
logFile: true, | ||
logConsole: true, | ||
logLevel: 'debug', | ||
persistent: true, | ||
workers: true, | ||
listen: true, | ||
plugins: [require('bcoin/lib/wallet/plugin')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you pull the wallet plugin import into the same section as the others and assign it a variable. |
||
}); | ||
|
||
process.on('unhandledRejection', (err, promise) => { | ||
throw err; | ||
}); | ||
|
||
(async function connection() { | ||
await node.open(); | ||
await node.connect(); | ||
await node.pool.connect(); | ||
await node.pool.startSync(); | ||
consensus.COINBASE_MATURITY = 0; | ||
})().then(async function miner() { | ||
const wdb = node.require('walletdb'); | ||
await node.miner.addAddress(wdb.primary.getReceive()); | ||
|
||
const tip = node.chain.tip; | ||
const job = await node.miner.createJob(tip); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the |
||
const entry = await node.chain.getEntry(node.chain.tip.hash); | ||
const block = await node.miner.mineBlock(entry); | ||
|
||
await node.chain.add(block); | ||
await node.relay(node.chain.db.state); | ||
|
||
const block2 = await node.miner.mineBlock(); | ||
const tx2 = block2.txs[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
await block2.refresh(true); | ||
await node.chain.add(block2); | ||
|
||
const nextEntry = await node.chain.getEntryByHeight(node.chain.height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I ran the script I got an error here because chain doesn't have a Also, it doesn't look like |
||
|
||
const balance = wdb.primary.getBalance(); | ||
await balance; | ||
}); | ||
|
||
|
||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make the imports a little more generalized for different setups. In most of the guides we usually forst do
const bcoin = require('bcoin')
and then pull the modules from there (e.g.const FullNode = bcoin.fullnode;
etc.) that way, people just need to change one line depending on where their version of bcoin is installed.