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. 虚拟机中安装完 CentOS7minimal 版本后无法联网的问题

    问题描述 安装完系统后无法上网,然后进入到目录 /etc/sysconfig/network-script 查看.发现只有一个 ifcfg-lo. 解决办法 这种情况是没有识别到网卡. 在 VMwar ...

  2. Spring Security(一)

    Spring Security(一) 基本原理 前言 Spring Security核心功能 认证(你是谁) 授权(你能干什么) 攻击防护(防止伪造身份) Srping Security基本原理 项目 ...

  3. 一卡通大冒险(hdu2512)

    一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. (转发)一个通用的C++ 消息总线框架

    注:转自https://www.cnblogs.com/qicosmos/archive/2013/04/28/3048919.html 应用开发过程中经常会处理对象间通信的问题,一般都是对象或接口的 ...

  5. 设计模式(16)--Iterator(迭代器模式)--行为型

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.模式定义: 迭代模式又叫游标(Cursor)模式,是对象的行为模式.迭代模式可以顺序地访问一个聚集中的元素而不 ...

  6. cf250D. The Child and Sequence(线段树 均摊复杂度)

    题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. ...

  7. 【代码笔记】iOS-plist获得城市列表

    一,工程图. 二,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the ...

  8. JSTL 标签大全详解

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/53311722  冷血之心的博客) 一.JSTL标签介绍 1.什么是 ...

  9. .net中反射与IOC容器实现

    反射还是很有用的,比如IOC容器基本上都是通过反射实现的. IOC是什么 IOC:Inversion of Control 控制反转是一种是面向对象编程中的一种设计原则,用来减低计算机代码之间的耦合度 ...

  10. View的measure机制

    Android中View框架的工作机制中,主要有三个过程: 1.View树的测量(measure)Android View框架的measure机制     2.View树的布局(layout) And ...