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. Java多线程--并行模式与算法

    Java多线程--并行模式与算法 单例模式 虽然单例模式和并行没有直接关系,但是我们经常会在多线程中使用到单例.单例的好处有: 对于频繁使用的对象可以省去new操作花费的时间: new操作的减少,随之 ...

  2. Cuckoo for Hashing(hash)hunnuoj

    Problem B:Cuckoo for HashingAn integer hash table is a data structure that supports insert, delete a ...

  3. .Net 多线程 异步编程 Await、Async和Task

    await和async简介   await和async是在C#5中引入,并且在.NetFramewor4.5以及.NetCore中进行了支持.主要是解决性能瓶颈,并且增强系统的响应能力. msdn关于 ...

  4. android 点击数字跳转到电话界面

    实现方式两种: 1,在xml文件下很简单的实现 只需要在textview属性中加入android:autoLink="phone".  <TextView           ...

  5. Silverlight提示“Load 操作失败。远程服务器返回了错误: NotFound”

    调试时出现“Load 操作失败.远程服务器返回了错误: NotFound”: 一定要注意此错误之前的错误是什么?基本就是用户Cookie的问题,用户没有登录. 有时需要设置成Any CPU 有时重新编 ...

  6. 微信小程序开发--背景图显示

    这两天开发微信小程序,在设置背景图片时,发现在wxss里面设置 background-image:(url) 属性,不管是开发工具还是线上都无法显示.经过查资料发现,background-image ...

  7. [Android] 设置AlertDialog打开后不消失

    最近项目收尾,一堆bug要改,还要对用户操作体验做一些优化,也是忙的不行.周末难得清闲,出去逛逛,看看风景,还好因为习大大要来,南京最近的天气还不错,只是苦了当地的不少农民工,无活可干,无钱可拿.想想 ...

  8. json_encode无返回结果

    今天写php curl模拟客户端访问测试一个抽奖post数据,拿回来的数据是json,使用json_decode函数就是没结果,百度谷歌好久.终于发现是BOM的文件头造成的, 微软为utf-8文件添加 ...

  9. 如何用 Python 实现 Web 抓取?

    [编者按]本文作者为 Blog Bowl 联合创始人 Shaumik Daityari,主要介绍 Web 抓取技术的基本实现原理和方法.文章系国内 ITOM 管理平台 OneAPM 编译呈现,以下为正 ...

  10. WOE和IV

    woe全称是"Weight of Evidence",即证据权重,是对原始自变量的一种编码形式. 进行WOE编码前,需要先把这个变量进行分组处理(离散化) 其中,pyi是这个组中响 ...