Coder Social home page Coder Social logo

cb-wallet's People

Contributors

weilu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cb-wallet's Issues

Overall design

As discussed in bitcoinjs/bitcoinjs-lib#260 (comment), I feel like the 'all-in-one' design of the Wallet right now is too overwhelming, and leads to bad separation of concerns.

In essence the design needs to cater for three things:

  • Provide a simplified key management API,
    • With the ability to generate/iterate addresses using BIP32,
    • and the ability to sign transactions with addresses
  • Provide unspent Transaction outputs aggregation,
    • With functionality to provide candidates for a particular output value, and
    • Capability to check balance based on blockHeight/confirmations
  • Unspent Transaction output utility functions, such as
    • Create Transaction from inputs, outputs and optional change address, fee

As an example of what this API might look like, here is an example for spending:

var satoshis = 1e5
var inputs = unspents.candidates(satoshis)
var addresses = inputs.filter(function(inputs) { return u.address })

var tx = utils.createTransaction(inputs, outputs, { change: '18eRuS...' , fee: 0 })

wallet.sign(tx).with(addresses)
blockchain.propagate(tx, function(err) {
   ...
})

Then perhaps even a check to see if your address is used might just be:

if (unspents.contains(address)) {
  wallet.next()
}

Thoughts?

Using BIP32-utils discovery might be:

bip32utils.discovery(wallet.getExternalAccount(), 20, function(addresses, callback) {
  blockchain.addresses.summary(addresses, function(err, results) {
    if (err) return callback(err)

    var areSpent = results.map(function(result) {
      return result.totalReceived > 0
    })

    callback(undefined, areSpent)
  })
}, function(err, k) {
  if (err) return done(err)

  console.warn('Discovered ' + k + ' addresses')
  wallet.generate(0, k)

  done()
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.