1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Merge pull request #78 from MetaMask/AutoFaucet

Add auto-fauceting
This commit is contained in:
Dan Finlay 2016-03-29 12:51:32 -07:00
commit 18b75e679f
3 changed files with 30 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "__MSG_appName__", "name": "__MSG_appName__",
"version": "1.1.2", "version": "1.2.0",
"manifest_version": 2, "manifest_version": 2,
"description": "__MSG_appDescription__", "description": "__MSG_appDescription__",
"icons": { "icons": {

View File

@ -0,0 +1,11 @@
var uri = 'https://faucet.metamask.io/'
module.exports = function(address) {
var http = new XMLHttpRequest()
var data = address
http.open('POST', uri, true)
http.setRequestHeader('Content-type', 'application/rawdata')
http.send(data)
}

View File

@ -7,6 +7,7 @@ const async = require('async')
const clone = require('clone') const clone = require('clone')
const extend = require('xtend') const extend = require('xtend')
const createId = require('web3-provider-engine/util/random-id') const createId = require('web3-provider-engine/util/random-id')
const autoFaucet = require('./auto-faucet')
module.exports = IdentityStore module.exports = IdentityStore
@ -47,6 +48,7 @@ IdentityStore.prototype.createNewVault = function(password, entropy, cb){
this._cacheSeedWordsUntilConfirmed(seedWords) this._cacheSeedWordsUntilConfirmed(seedWords)
this._loadIdentities() this._loadIdentities()
this._didUpdate() this._didUpdate()
this._autoFaucet()
cb(null, seedWords) cb(null, seedWords)
}) })
} }
@ -186,14 +188,14 @@ IdentityStore.prototype._cacheSeedWordsUntilConfirmed = function(seedWords) {
// load identities from keyStoreet // load identities from keyStoreet
IdentityStore.prototype._loadIdentities = function(){ IdentityStore.prototype._loadIdentities = function(){
if (!this._isUnlocked()) throw new Error('not unlocked') if (!this._isUnlocked()) throw new Error('not unlocked')
// get addresses and normalize address hexString
var addresses = this._keyStore.getAddresses(this.hdPathString).map((address) => { return '0x'+address }) var addresses = this._getAddresses()
addresses.forEach((address) => { addresses.forEach((address, i) => {
// // add to ethStore // // add to ethStore
this._ethStore.addAccount(address) this._ethStore.addAccount(address)
// add to identities // add to identities
var identity = { var identity = {
name: 'Wally', name: 'Wallet ' + (i+1),
img: 'QmW6hcwYzXrNkuHrpvo58YeZvbZxUddv69ATSHY3BHpPdd', img: 'QmW6hcwYzXrNkuHrpvo58YeZvbZxUddv69ATSHY3BHpPdd',
address: address, address: address,
} }
@ -268,12 +270,22 @@ IdentityStore.prototype._createFirstWallet = function(entropy, derivedKey) {
return keyStore return keyStore
} }
// get addresses and normalize address hexString
IdentityStore.prototype._getAddresses = function() {
return this._keyStore.getAddresses(this.hdPathString).map((address) => { return '0x'+address })
}
IdentityStore.prototype._autoFaucet = function() {
var addresses = this._getAddresses()
autoFaucet(addresses[0])
}
function IdManagement(opts) { function IdManagement(opts) {
if (!opts) opts = {} if (!opts) opts = {}
this.keyStore = opts.keyStore this.keyStore = opts.keyStore
this.derivedKey = opts.derivedKey this.derivedKey = opts.derivedKey
this.hdPathString = opts.hdPathString this.hdPathString = "m/44'/60'/0'/0"
this.getAddresses = function(){ this.getAddresses = function(){
return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address }) return keyStore.getAddresses(this.hdPathString).map(function(address){ return '0x'+address })
@ -289,7 +301,7 @@ function IdManagement(opts) {
txParams.nonce = ethUtil.addHexPrefix(txParams.nonce) txParams.nonce = ethUtil.addHexPrefix(txParams.nonce)
var tx = new Transaction(txParams) var tx = new Transaction(txParams)
var rawTx = '0x'+tx.serialize().toString('hex') var rawTx = '0x'+tx.serialize().toString('hex')
return '0x'+LightwalletSigner.signTx(this.keyStore, this.derivedKey, rawTx, txParams.from) return '0x'+LightwalletSigner.signTx(this.keyStore, this.derivedKey, rawTx, txParams.from, this.hdPathString)
} }
this.getSeed = function(){ this.getSeed = function(){