https://github.com/MetaMask/provider-engine

在学习这个之前应该先看一下什么是zero-client,MetaMask/zero-client

Web3 ProviderEngine

Web3 ProviderEngine is a tool for composing your own web3 providers.

这个模块就是用来教你怎么去构建自己的web3 providers的,从之前的其他学习,如mascara和zero-client等中我们都能够看到需要一个自定义的http://localhost:9001 provider,这里就是怎么实现的模块

Composable

Built to be modular - works via a stack of 'sub-providers' which are like normal web3 providers but only handle a subset of rpc methods.

The subproviders can emit new rpc requests in order to handle their own; e.g. eth_call may trigger eth_getAccountBalanceeth_getCode, and others. The provider engine also handles caching of rpc request results.

const ProviderEngine = require('web3-provider-engine')
const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js')
const FixtureSubprovider = require('web3-provider-engine/subproviders/fixture.js')
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js')
const VmSubprovider = require('web3-provider-engine/subproviders/vm.js')
const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js')
const NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker.js')
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js') var engine = new ProviderEngine()
var web3 = new Web3(engine) // static results
engine.addProvider(new FixtureSubprovider({
web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
net_listening: true,
eth_hashrate: '0x00',
eth_mining: false,
eth_syncing: true,
})) // cache layer
engine.addProvider(new CacheSubprovider()) // filters
engine.addProvider(new FilterSubprovider()) // pending nonce
engine.addProvider(new NonceSubprovider()) // vm
engine.addProvider(new VmSubprovider()) // id mgmt
engine.addProvider(new HookedWalletSubprovider({
getAccounts: function(cb){ ... },
approveTransaction: function(cb){ ... },
signTransaction: function(cb){ ... },
})) // data source
engine.addProvider(new RpcSubprovider({
rpcUrl: 'https://testrpc.metamask.io/',
})) // log new blocks
engine.on('block', function(block){
console.log('================================')
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
console.log('================================')
}) // network connectivity error
engine.on('error', function(err){
// report connectivity errors
console.error(err.stack)
}) // start polling for blocks
engine.start()
 

When importing in webpack:

import * as Web3ProviderEngine  from 'web3-provider-engine';
import * as RpcSource from 'web3-provider-engine/subproviders/rpc';
import * as HookedWalletSubprovider from 'web3-provider-engine/subproviders/hooked-wallet';
 

Built For Zero-Clients

The Ethereum JSON RPC was not designed to have one node service many clients. However a smaller, lighter subset of the JSON RPC can be used to provide the blockchain data that an Ethereum 'zero-client' node would need to function. We handle as many types of requests locally as possible, and just let data lookups fallback to some data source ( hosted rpc, blockchain api, etc ). Categorically, we don’t want / can’t have the following types of RPC calls go to the network:

Ethereum JSON RPC并不是设计成只有一个结点来服务许多用户的。然而更小、更轻的JSON RPC子集可以不需要使用以太坊'zero-client'的结点需要调用的功能就能够提供区块链数据。我们处理尽可能多的本地类型的请求,并让数据查找回退一些数据源。明确,我们不希望/不可能有以下类型的RPC调用网络

  • id mgmt + tx signing (requires private data)
  • filters (requires a stateful data api)
  • vm (expensive, hard to scale)

MetaMask/provider-engine-1的更多相关文章

  1. MetaMask/metamask-extension-provider

    用来探测你的浏览器中有没有安装metamask插件 https://github.com/MetaMask/metamask-extension-provider MetaMask Extension ...

  2. ethereumjs/ethereumjs-wallet

    Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...

  3. trufflesuite/truffle-hdwallet-provider

    https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/index.js 实现代码 truffle-hdwallet ...

  4. ethereum/EIPs-1102 Opt-in provider access metamask不再默认直接连入网页

    eip title author discussions-to status type category created 1102 Opt-in provider access Paul Boucho ...

  5. ethereum/EIPs-1193 Ethereum Provider JavaScript API 如metamask更新后的接口

    eip title author discussions-to status type category created requires 1193 Ethereum Provider JavaScr ...

  6. MetaMask/metamask-inpage-provider

    https://github.com/MetaMask/metamask-inpage-provider Used to initialize the inpage ethereum provider ...

  7. mascara-2(MetaMask/mascara本地实现)-连接线上钱包

    https://github.com/MetaMask/mascara (beta) Add MetaMask to your dapp even if the user doesn't have t ...

  8. metamask源码学习-metamask-controller.js

    The MetaMask Controller——The central metamask controller. Aggregates other controllers and exports a ...

  9. metamask源码学习-inpage.js

    The most confusing part about porting MetaMask to a new platform is the way we provide the Web3 API ...

随机推荐

  1. [android] WebView自定义浏览器

    在布局文件中添加<EditText/>和<Button/>控件, 在布局文件中添加<WebView/>控件 在Activity中获取WebView对象 调用WebV ...

  2. leetcode实践:通过链表存储两数之和

    题目: 两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字.如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的 ...

  3. Android - Dagger2 使用和原理

    Dagger2从入门到放弃再到恍然大悟 http://www.jianshu.com/p/cd2c1c9f68d4 http://www.jianshu.com/p/39d1df6c877d http ...

  4. 【学习笔记】--- 老男孩学Python,day6 字典

    详细方法:http://www.runoob.com/python/python-dictionary.html 1. dict 用大括号{} 括起来. 内部使用key:value的形式来保存数据 { ...

  5. 2016计蒜之道复赛 百度地图的实时路况(Floyd 分治)

    题意 题目链接 Sol 首先一个结论:floyd算法的正确性与最外层\(k\)的顺序无关(只要保证是排列即可) 我大概想到一种证明方式就是把最短路树上的链拿出来,不论怎样枚举都会合并其中的两段,所以正 ...

  6. linux下将本地文件上传到github中?

    今天编写一份Python基础代码,经过Linux上传到github上,遇到点问题,已经解决 1.首先sudo su 进入root 用户 2.ls 检查出当前文件下有什么文件 3. cd 进入你将要上传 ...

  7. onkeyup小练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 关于Dynamics CRM 安装用户权限的说明

    做了这么多年的CRM项目,但发现部分客户的IT安全监管很严格,在CRM系统安装时,要求给出系统安排账号的权限. 这时小伙伴们 坚持不住了~~ 天天都是用域控的admin操作,这个时候问我要什么权限,于 ...

  9. Android--监听View的两个指头是放大和缩小

    private double nLenStart = 0;//监听 WebView所用手势 @Override public boolean onTouch(View v, MotionEvent e ...

  10. 第二篇 windows container 微软的原生容器

    先上图,显示windows container的体积: 以下是我使用docker pull 命令下载后,又用命令保存到本地的,相对于linux container体积依然巨大无比:据官方新闻,微软原生 ...