library - basic test server + partial safari fixes

feature/default_network_editable
kumavis 8 years ago
parent 23a144fb8b
commit b7aab95519
  1. 2
      library/controller.js
  2. 4
      library/example.sh
  3. 2
      library/example/index.html
  4. 9
      library/example/index.js
  5. 4
      library/index.js
  6. 3
      library/lib/setup-iframe.js
  7. 3
      library/lib/setup-provider.js
  8. 88
      library/server.js
  9. 2
      library/server/index.html
  10. 5
      package.json

@ -53,6 +53,8 @@ function initializeZeroClient() {
if (err) throw err if (err) throw err
}) })
multiStream.on('data', function(chunk){ console.log(chunk) })
var providerStream = multiStream.createStream('provider') var providerStream = multiStream.createStream('provider')
handleRequestsFromStream(providerStream, provider, logger) handleRequestsFromStream(providerStream, provider, logger)

@ -1,4 +1,4 @@
# run 2 servers and make sure they close together # run 2 servers and make sure they close together
beefy frame.js:bundle.js 9001 --live & beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ] &
beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ]

@ -12,6 +12,6 @@
<button class="action-button-1">SYNC TX</button> <button class="action-button-1">SYNC TX</button>
<button class="action-button-2">ASYNC TX</button> <button class="action-button-2">ASYNC TX</button>
<script src="./zero.js"></script> <script src="./zero.js"></script>
<script src="./bundle.js"></script> <script src="./app.js"></script>
</body> </body>
</html> </html>

@ -4,8 +4,10 @@ window.addEventListener('load', web3Detect)
function web3Detect() { function web3Detect() {
if (global.web3) { if (global.web3) {
document.body.innerHTML += 'web3 detected!' document.body.innerHTML += 'web3 detected!'
console.log('web3 detected!')
} else { } else {
document.body.innerHTML += 'no web3 detected!' document.body.innerHTML += 'no web3 detected!'
console.log('no web3 detected!')
} }
startApp() startApp()
} }
@ -13,12 +15,17 @@ function web3Detect() {
var primaryAccount = null var primaryAccount = null
web3.eth.getAccounts(function(err, addresses){ web3.eth.getAccounts(function(err, addresses){
if (err) throw err if (err) throw err
console.log('set address')
primaryAccount = addresses[0] primaryAccount = addresses[0]
}) })
function startApp(){ function startApp(){
console.log('app started')
document.querySelector('.action-button-1').addEventListener('click', function(){ document.querySelector('.action-button-1').addEventListener('click', function(){
console.log('saw click')
console.log('sending tx')
web3.eth.sendTransaction({ web3.eth.sendTransaction({
from: primaryAccount, from: primaryAccount,
value: 0, value: 0,
@ -28,7 +35,9 @@ function startApp(){
}) })
}) })
document.querySelector('.action-button-2').addEventListener('click', function(){ document.querySelector('.action-button-2').addEventListener('click', function(){
console.log('saw click')
setTimeout(function(){ setTimeout(function(){
console.log('sending tx')
web3.eth.sendTransaction({ web3.eth.sendTransaction({
from: primaryAccount, from: primaryAccount,
value: 0, value: 0,

@ -6,11 +6,14 @@ const setupProvider = require('./lib/setup-provider.js')
// //
var provider = setupProvider() var provider = setupProvider()
console.log('debugger point A')
hijackProvider(provider) hijackProvider(provider)
console.log('debugger point B')
var web3 = new Web3(provider) var web3 = new Web3(provider)
web3.setProvider = function(){ web3.setProvider = function(){
console.log('MetaMask - overrode web3.setProvider') console.log('MetaMask - overrode web3.setProvider')
} }
console.log('metamask lib hijacked provider')
// //
// export web3 // export web3
@ -35,6 +38,7 @@ function hijackProvider(provider){
var _super = provider.sendAsync.bind(provider) var _super = provider.sendAsync.bind(provider)
provider.sendAsync = function(payload, cb){ provider.sendAsync = function(payload, cb){
if (payload.method === 'eth_sendTransaction') { if (payload.method === 'eth_sendTransaction') {
console.log('saw send')
shouldPop = true shouldPop = true
} }
_super(payload, cb) _super(payload, cb)

@ -8,10 +8,11 @@ function setupIframe(opts) {
opts = opts || {} opts = opts || {}
var frame = Iframe({ var frame = Iframe({
src: opts.zeroClientProvider || 'https://zero.metamask.io/', src: opts.zeroClientProvider || 'https://zero.metamask.io/',
container: document.head, container: opts.container || document.head,
sandboxAttributes: opts.sandboxAttributes || ['allow-scripts', 'allow-popups'], sandboxAttributes: opts.sandboxAttributes || ['allow-scripts', 'allow-popups'],
}) })
var iframe = frame.iframe var iframe = frame.iframe
iframe.style.setProperty('display', 'none')
var iframeStream = new IframeStream(iframe) var iframeStream = new IframeStream(iframe)
return iframeStream return iframeStream

@ -13,8 +13,9 @@ function getProvider(){
console.log('MetaMask ZeroClient - injecting zero-client iframe!') console.log('MetaMask ZeroClient - injecting zero-client iframe!')
var iframeStream = setupIframe({ var iframeStream = setupIframe({
zeroClientProvider: 'http://localhost:9001', zeroClientProvider: 'http://127.0.0.1:9001',
sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'],
container: document.body,
}) })
var inpageProvider = new MetamaskInpageProvider(iframeStream) var inpageProvider = new MetamaskInpageProvider(iframeStream)

@ -0,0 +1,88 @@
const express = require('express')
const browserify = require('browserify')
const watchify = require('watchify')
const babelify = require('babelify')
const path = require('path')
const zeroBundle = createBundle('./index.js')
const controllerBundle = createBundle('./controller.js')
const appBundle = createBundle('./example/index.js')
//
// Iframe Server
//
// beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ]
const iframeServer = express()
// serve controller bundle
iframeServer.get('/controller.js', function(req, res){
res.send(controllerBundle.latest)
})
// serve static
iframeServer.use(express.static('./server'))
iframeServer.listen('9001')
//
// Dapp Server
//
// beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ]
const dappServer = express()
// serve metamask-lib bundle
dappServer.get('/zero.js', function(req, res){
res.send(zeroBundle.latest)
})
// serve dapp bundle
dappServer.get('/app.js', function(req, res){
res.send(appBundle.latest)
})
// serve static
dappServer.use(express.static('./example'))
dappServer.listen('9002')
function createBundle(entryPoint){
var bundleContainer = {}
var bundler = browserify({
entries: [entryPoint],
cache: {},
packageCache: {},
plugin: [watchify],
})
var bablePreset = path.resolve(__dirname, '../node_modules/babel-preset-es2015')
bundler.transform(babelify, {
global: true,
presets: [bablePreset],
})
bundler.on('update', bundle)
bundle()
return bundleContainer
function bundle() {
bundler.bundle(function(err, result){
if (err) throw err
console.log(`Bundle updated! (${entryPoint})`)
bundleContainer.latest = result.toString()
})
}
}

@ -15,6 +15,6 @@
<body> <body>
Hello! I am the MetaMask iframe. Hello! I am the MetaMask iframe.
<script src="/bundle.js"></script> <script src="/controller.js"></script>
</body> </body>
</html> </html>

@ -8,7 +8,7 @@
"lint": "gulp lint", "lint": "gulp lint",
"dev": "gulp dev", "dev": "gulp dev",
"dist": "gulp dist", "dist": "gulp dist",
"test": "npm run fastTest && npm run ci", "test": "npm run fastTest && npm run ci && npm run lint",
"fastTest": "mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "fastTest": "mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"",
"watch": "mocha watch --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "watch": "mocha watch --compilers js:babel-register --recursive \"test/unit/**/*.js\"",
"ui": "node development/genStates.js && beefy ui-dev.js:bundle.js --live --open --index=./development/index.html --cwd ./", "ui": "node development/genStates.js && beefy ui-dev.js:bundle.js --live --open --index=./development/index.html --cwd ./",
@ -45,6 +45,7 @@
"eth-store": "^1.1.0", "eth-store": "^1.1.0",
"ethereumjs-tx": "^1.0.0", "ethereumjs-tx": "^1.0.0",
"ethereumjs-util": "^4.4.0", "ethereumjs-util": "^4.4.0",
"express": "^4.14.0",
"gulp-eslint": "^2.0.0", "gulp-eslint": "^2.0.0",
"hat": "0.0.3", "hat": "0.0.3",
"identicon.js": "^1.2.1", "identicon.js": "^1.2.1",
@ -78,7 +79,7 @@
"three.js": "^0.73.2", "three.js": "^0.73.2",
"through2": "^2.0.1", "through2": "^2.0.1",
"vreme": "^3.0.2", "vreme": "^3.0.2",
"web3": "^0.17.0-alpha", "web3": "ethereum/web3.js#260ac6e78a8ce4b2e13f5bb0fdb65f4088585876",
"web3-provider-engine": "^8.0.2", "web3-provider-engine": "^8.0.2",
"web3-stream-provider": "^2.0.6", "web3-stream-provider": "^2.0.6",
"xtend": "^4.0.1" "xtend": "^4.0.1"

Loading…
Cancel
Save