wietsewind's notebooks

  • Ripple account_info (specific Ledger) - /wietsewind/ripple-account-info-specific-ledger
    Last edited 5 years ago
    const websocket = require('websocket') const RippleClient = require('rippled-ws-client') new RippleClient('wss://s2.ripple.com').then(connection => { connection.send({ command: 'account_info', account: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', ledger_index: 35664185 }).then(response => { console.log('XRP Balance', parseInt(response.account_data.Balance) / 1000000) // Convert drops to XRP connection.close() }) }).catch(console.log)
  • Recover Ripple Minimalist Rekeyed account - /wietsewind/recover-ripple-minimalist-rekeyed-account
    Last edited 5 years ago
    const ripple = require('ripplelib') const minimalistRekeyed = '3QBGZnmsg5UY2EoPFZXwo9238Yp6C9N9ztaRbURcYa49PhvCAtF' let b = ripple.Base.decode_check(ripple.Base.VER_REKEYED, minimalistRekeyed) let y = ripple.sjcl.codec.bytes.fromBits(b.toBits()) let rks = ripple.Base.encode_check(ripple.Base.VER_FAMILY_SEED, y.slice(0,16)) let familySeed = ripple.Base.encode_check(ripple.Base.VER_FAMILY_SEED, y.slice(16)) let seed = ripple.Seed.from_json(familySeed) console.log('Address', seed.get_key().get_address().to_json()) console.log('Secret', familySeed)
  • Sample filter / map / reduce (XRP Transaction Sum) - /wietsewind/sample-filter-map-reduce-xrp-transaction-sum
    Last edited 5 years ago
    /* Filter / Map / Reduce on arrays: Imagine a funnel `filter`, `map`, `reduce`: They take an array as input and at the other send the input is returned processed. filter = decide what should be in the output array map = modify the content of each object that will be in the output array reduce = aggregate the input to some output */ const RippleAPI = require('ripple-lib').RippleAPI const api = new RippleAPI({ server: 'wss://rippled.xrptipbot.com' }) api.connect().then(() => { return api.getTransactions('rPdvC6ccq8hCdPKSPJkPmyZ4Mi1oG2FFkT', { minLedgerVersion: 36542093 }).then(transactions => { // `transactions` is an array with transaction objects. let sum = transactions .filter(tx => { // The .filter runs for each tx in transactions, we call each // transaction (each array member) 'tx'. Only return true // (so: array object to next part of the chain) if this is valid return tx.type === 'payment' && tx.outcome.result === 'tesSUCCESS' && tx.outcome.deliveredAmount.currency === 'XRP' }) .map(tx => { // Convert to drops, prevent rounding errors let value = parseFloat(tx.outcome.deliveredAmount.value) * 1000000 return Math.round(value) }) .reduce((existingTotal, thisValue) => { return existingTotal + thisValue }, 0) // 0 = 2nd argument = startValue console.log('Sum in XRP:', sum / 1000000) }) }).then(() => { }).catch(console.error)
  • google-libphonenumber - /wietsewind/google-libphonenumber
    Last edited 5 years ago - from: https://npm.runkit.com/google-libphonenumber
    let nr = '06 - 83164677' let country = 'NL' const phoneno = '+' + nr.replace(/[^0-9\-\(\)+]+/g, '').trim().replace(/^[0+]+/, '') console.log(phoneno) const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance() const number = phoneUtil.parseAndKeepRawInput(phoneno) console.log(number.getCountryCode()) if (phoneUtil.isValidNumber(number)) { console.log("valid") console.log(phoneUtil.format(number, require('google-libphonenumber').PhoneNumberFormat.E164)) } else { console.log("invalid, try with country", country) const numbercc = phoneUtil.parseAndKeepRawInput(nr, country) console.log(phoneUtil.format(numbercc, require('google-libphonenumber').PhoneNumberFormat.E164)) } //