Skip to content
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

confirming transactions on regtest #326

Closed
yayitswei opened this issue Sep 29, 2017 · 10 comments
Closed

confirming transactions on regtest #326

yayitswei opened this issue Sep 29, 2017 · 10 comments

Comments

@yayitswei
Copy link

yayitswei commented Sep 29, 2017

Could you point me to an example that mines on regtest and confirms transactions? This is a great start but I'm using miner.createJob and job.mineAsync() and finally chain.add(block) as suggested and it's not adding any transactions I've sent previously into the new block. When I look up the transaction it has 0 confirmations.

Thanks for your help!

@jonajosejg
Copy link

'use strict';

process.title = 'bcoin';

const assert = require('assert');
const MTX = require('bcoin/lib/primitives/mtx');
const FullNode = require('bcoin/lib/node/fullnode');
const consensus = require('bcoin/lib/protocol/consensus');
const co = require('bcoin/lib/utils/co');
const coin = require('bcoin/lib/coins/coins');

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')]
});

process.on('unhandledRejection', (err, promise) => {
throw err;
});

(async function connection() {
await node.open();
await node.connect();
await node.pool.connect();
node.pool.startSync();
consensus.COINBASE_MATURITY = 0;
})().then(async function miner() {
const tip = node.chain.tip;
const job = await node.miner.createJob(tip);
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.tx);
});

@jonajosejg
Copy link

I'll include a better example with a variety consecutive blocks / wallet confirms. But running this should add a block / tx to the chain.

@yayitswei
Copy link
Author

Thanks @Rojii! That code is very helpful and I can see the transactions in my newly mined blocks now. But like you said, the wallet transactions aren't hooked up yet, so I'm looking forward to your second example.

@jonajosejg
Copy link

try this one out ,
https://gist.github.com/rojii/0895b45bd126c460e7e586cdc383aa68

@bucko13
Copy link
Contributor

bucko13 commented Oct 21, 2017

I'm going to close this for now @yayitswei. We'll hopefully try and get a guide and script up as well in the near future up on bcoin.io.

@bucko13 bucko13 closed this as completed Oct 21, 2017
@yayitswei
Copy link
Author

I forgot to reply, but your new code was helpful too- thanks!

@jonajosejg
Copy link

No Problem, I'll include a new guide in the next week with a much more functions.

@gnorbsl
Copy link

gnorbsl commented Mar 9, 2018

@Rojii I tried you code, it doesnt seem to solve the problem tho. I looks like the transaction is added to the chain but I dont get any confirmation.

[info] (chain) Block 3a416a3b1a5a4321ca3c3f7665e7763bc7b86955441433996fe85e5aa9dc8248 (1) added to chain (size=196 txs=1 time=13.296796).
[error] (node) tx.hash is not a function
[debug] (miner) Created block template (height=2, weight=4000, fees=0, txs=1, diff=0).
[info] (node) Spawning worker process: 1.
[info] (wallet) Incoming transaction for 1 wallets in WalletDB (05744861c20a3475008beaa67a92f05bda5dab63e025bc4c8114c09d0af9da2c).
[info] (wallet) Marking WalletDB start block at 3a416a3b1a5a4321ca3c3f7665e7763bc7b86955441433996fe85e5aa9dc8248 (1).

I tried to create blocks manually with the client but that doesnt work either.

Any idea what im doing wrong?

@jonajosejg
Copy link

@jonajosejg
Copy link

If you want me to add manual code for adding blocks by height / entry (increment by 1 in height or w.e) let me know. But the code above will add all of the transactions correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants