Bitcoin Forum
April 27, 2024, 06:32:11 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Bitcoin Technical Support / Parse recent transactions with bitcoin core in pruned mode on: September 03, 2019, 03:01:27 AM
I would like to implement the checker of balance with bitcoin core.  For example I have a million of pregenerated addresses and I want to check if balance on any of them had beed changed.  So I got a bitcoin core node running in a pruned mode (there is no point for me to hold the whole blockchain).  I wrote a following POC explorer on bash:

Code:
#!/usr/bin/env bash
set -e
set -o errexit

function process_block() {
  date --rfc-3339=ns
  bhash=${1:-$(bitcoin-cli getbestblockhash)}
  block=$(bitcoin-cli getblock $bhash)
  pbhash=$(echo "$block" | jq -r .previousblockhash)
  height=$(echo "$block" | jq -r .height)
  echo "height: $height"
  nTx=$(echo "$block" | jq -r .nTx)
  echo "$nTx transactions"
  Tx=$(echo "$block" | jq -r .tx[])
  IFS=$'\n'
  for txhash in $Tx; do
    txjson=$(bitcoin-cli getrawtransaction $txhash 1 $bhash)
    addresses=$(echo "$txjson" | jq -r '.vout[].scriptPubKey | select(.type == "pubkeyhash") | .addresses | .[]')
    for a in $addresses; do
      if [[ $a == ${2} ]]; then
        echo "$txjson"
      fi
    done
  done
  process_block $pbhash ${2}
}

process_block "" ${1}

This way I have an access to the destination address and the amount transferred.

The only problem is that it just just too slow.  I have SSD, 2GB RAM and 2x2.8Ghz VPS and I am only able to process about 10 transactions per second.

I haven't run the profiler yet, but I bet it's because of the absence of txindex.

Any idea how my problem can be solved?
2  Bitcoin / Development & Technical Discussion / Generation of addresses with unique 2-char postfixes (from a seed). 1225 limit? on: March 30, 2019, 07:41:23 AM
I wrote a little tool on JS which generate addresses with unique postfixes.
It derives addresses from bip39 mnemonic and uses increments of bip44 derivation path.
What surprised me is that the total number of these addresses is somehow limited to 1225 (I ran increments into 1M, but the unique addresses dwindle out at about 20k), instead of expected 3364 (58^2).
Can anyone expain why this is the case?

Code:
const bitcoin = require('bitcoinjs-lib');
const bip32 = require('bip32');
const bip39 = require('bip39');
const EventEmitter = require('events');
var eventEmitter = new EventEmitter()

function db() {
        var knex = require('knex')({
                client: 'mysql',
                connection: {
                        host : '127.0.0.1',
                        user : 'root',
                        password : 'pw',
                        database : 'btckeygen'
                }
        });
        return knex;
}

function getAddress (node, network) {
  return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address
}

var knex = db();
const dpath = "m/44'/0'/0'";

eventEmitter.on('eIteration', function(i){
        if ( i % 1000 == 0 )
                console.log(i);
        if ( i < 1000000 )
                syncLoop(i + 1);
        else
                process.exit(0);
});

const mnemonic = 'gesture large void donate enroll demise about fade arrest romance knock breeze melody card another';
const seed = bip39.mnemonicToSeed(mnemonic)
const root = bip32.fromSeed(seed)
const string = root.toBase58()
console.log('BIP32 Root: ' + string);
const bip44xprv = root.derivePath(dpath)
const bip44xpub = bip44xprv.neutered().toBase58();
console.log('Account xprv: ' + bip44xprv.toBase58());
console.log('Account xpub: ' + bip44xpub);
const bip32xprv = root.derivePath(dpath + "/0")
const bip32xpub = bip32xprv.neutered().toBase58();
console.log('BIP32 xprv: ' + bip32xprv.toBase58());
console.log('BIP32 xpub: ' + bip32xpub);

function syncLoop(i) {
        const dpathi = dpath + "/0/" + i ;
        const child = root.derivePath(dpathi)
        const addr = getAddress(child, bitcoin.networks.mainnet);
        //console.log('Child' + i + ' Address: ' + addr);
        const prv = child.privateKey.toString('hex');
        const pub = child.publicKey.toString('hex');

        var search = addr.substr(-2);
        knex
  .select('address')
        .from('keystore')
  .where(knex.raw('RIGHT(??, 2) = ?', ['address', `${search}`]))
        .then(function (result) {
                if ( !result || result.length == 0 ) {
                        //console.log(result);
                        //console.log(this.path);
                        knex.insert({derivation_path: this.path, address: this.address, pub: this.pub, prv: this.prv})
                        .returning('id')
                        .into('keystore')
                        .then(function (id) {
                                console.log(id);
                        })
                        .catch(function(e) {
                                console.error(e);
                        });
                }
                eventEmitter.emit('eIteration', this.i)
         }.bind({path:dpathi, address:addr, pub:pub, prv:prv, i:i})
        )
        .catch(function(e) {
                console.error(e);
        });
}

syncLoop(0);
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!