https://github.com/ethereumjs/ethereumjs-vm

其实这就是怎么自己使用该模块来生成一个类似geth客户端的以太坊虚拟机,然后进行各类区块链操作

SYNOPSIS概要

Implements Ethereum's VM in Javascript.用Javascript实现以太坊虚拟机

Fork Support分支支持

Starting with the v2.5.0 release we now support both Byzantium and Constantinople fork rules - with Byzantium currently being the default (this will change in the future). See release notes for further details and have a look at the API docs on instructions how to instantiate the VM with the respective fork rules.

v2.5.0版本发布开始,我们现在支持ByzantiumConstantinople两种分支规则-目前Byzantium是默认值(未来会改变)。看 release notes 了解更多版本细节并在说明中查看 API docs文档,了解要如何根据相应的版本初始化虚拟机

If you are still looking for a Spurious Dragon compatible version of this library install the latest of the 2.2.x series (see Changelog).

如果你仍在寻找这个库的Spurious Dragon兼容版本,可以安装最新的2.2.x系列

INSTALL

npm install ethereumjs-vm

 

USAGE

var VM = require('ethereumjs-vm')

//create a new VM instance
var vm = new VM()
var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3' vm.runCode({
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
gasLimit: Buffer.from('ffffffff', 'hex')
}, function(err, results){
console.log('returned: ' + results.return.toString('hex'));
})

Also more examples can be found here更多的例子可以在下面找到

BROWSER

To build for standalone use in the browser, install browserify and check run-transactions-simple example. This will give you a global variable EthVM to use. The generated file will be at ./examples/run-transactions-simple/build.js.

为了创建能够在浏览器中单独使用的情况,需要安装browserify模块,然后查看 run-transactions-simple example例子(可看本博客ethereumjs-vm/examples/run-transactions-simple)。这将提供全局变量EthVM 给你使用。生成的文件将在./examples/run-transactions-simple/build.js

API

VM

For documentation on VM instantiation, exposed API and emitted events see generated API docs.

有关VM实例化、公开API和发出事件的文档,可见生成的API docs  (可看本博客ethereumjs/ethereumjs-vm-2-API文档)

StateManger状态管理

The API for the StateManager is currently in Beta, separate documentation can be found here.StateManager的API目前还是Beta版本,其单独的文档可见 here (可看本博客ethereumjs/ethereumjs-vm-3-StateManager

The StateManager API has been largely reworked recently and the StateManager will be removed from the VM and provided as a separate package in a future v3.0.0 release, see release notes for the v2.5.0 VM release for further details.StateManager的API最近已经重新复用,并且StateManager将从VM中移除,在未来的v3.0.0版本中将作为单独的包来提供,更过未来的细节可见v2.5.0版本的VM发行release notes

Internal Structure内部结构

The VM processes state changes at many levels.

VM在许多级别上流程状态会变化

  • runBlockchain

    • for every block, runBlock 就是对链上的没有区块都运行runBlock方法
  • runBlock
    • for every tx, runTx  就是对区块中的所有交易都运行runTx方法
    • pay miner and uncles  然后付款给矿工和叔块
  • runTx
    • check sender balance 先查看发送者的余额
    • check sender nonce 再检查发送者的nonce值
    • runCall  运行runCall方法
    • transfer gas charges  转移收取的gas费用
  • runCall
    • checkpoint state  保存检查点状态
    • transfer value  转移值
    • load code  下载代码
    • runCode  运行runCode方法
    • materialize created contracts  实现创建的合约
    • revert or commit checkpoint  恢复或提交检查点状态
  • runCode
    • iterate over code 遍历代码
    • run op codes 运行操作码
    • track gas usage 追踪gas的使用
  • OpFns
    • run individual op code 独自运行操作码
    • modify stack 修改堆栈
    • modify memory 修改内存
    • calculate fee 计算开销

The opFns for CREATECALL, and CALLCODE call back up to runCall.

用于CREATECALL和CALLCODE调用的opFns将会回调到 runCall

DEVELOPMENT开发

Developer documentation - currently mainly with information on testing and debugging - can be found here.

开发者文档-目前主要是测试和调试信息-可在here找到

Spurious Dragon

ethereumjs/ethereumjs-vm-1-简介的更多相关文章

  1. VM参数简介

    http://www.cnblogs.com/yuzhaoxin/p/4083612.html block_dump Linux 内核里提供了一个 block_dump 参数用来把 block 读写( ...

  2. java visual VM使用简介

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/44999175 作者:小马 VisualVM 是一款免费的性能分析工具.它通过 jv ...

  3. VMP虚拟机加壳的原理学习

    好久没有到博客写文章了,9月份开学有点忙,参加了一个上海的一个CHINA SIG信息比赛,前几天又无锡南京来回跑了几趟,签了阿里巴巴的安全工程师,准备11月以后过去实习,这之前就好好待在学校学习了. ...

  4. 由异常掉电问题---谈xfs文件系统

    由异常掉电问题---谈xfs文件系统 本文皆是作者自己的学习总结或感悟(linux环境),如有不对,欢迎提出一起探讨!! 目录结构 一.相关知识 二.问题提出 三.处理方法 四.最终结果 一.相关知识 ...

  5. 16. Vue2.4+新增属性$attrs

    vm.$attrs简介 首先我们来看下vue官方对vm.$attrs的介绍: 包含了父作用域中不作为 prop 被识别 (且获取) 的特性绑定 (class 和 style 除外).当一个组件没有声明 ...

  6. ethereumjs/ethereumjs-util

    ethereumjs/ethereumjs-util Most of the string manipulation methods are provided by ethjs-util 更多的字符串 ...

  7. ethereumjs/ethereumjs-common-1-简介

    为了了解ethereumjs/ethereumjs-block-3-代码的使用需要了解的一个模块 https://github.com/ethereumjs/ethereumjs-common Com ...

  8. ethereumjs/ethereumjs-common-2-API文档

    https://github.com/ethereumjs/ethereumjs-common/blob/master/docs/index.md 该API的调用的详细例子可见ethereumjs/e ...

  9. ethereumjs/browser-builds

    https://github.com/ethereumjs/browser-builds ethereumjs - Browser Builds This repository contains br ...

  10. ethereumjs/ethereumjs-vm-2-API文档

    https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/index.md vm.runBlockchain Processes blo ...

随机推荐

  1. 用Lua控制Nginx静态文件的url访问权限

    需求背景:比如我们有一个存储文件的web服务器,一般通过url可直接访问到:http://127.0.0.1/uploads/test.rar,如果我们需要限制别人的访问,可以通过添加lua脚本来控制 ...

  2. java 通用对象排序

    一个排序类,一个排序util? no.no.no…… 使用反射机制,写了一个通用的对象排序util,欢迎指正. 实体类: package entity; public class BaseTypeEn ...

  3. 微软2016校园招聘在线笔试-Professor Q's Software

    题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...

  4. WC2017 游记

    你若安好,便是晴天. 其实本来是有一个写的比较详细的游记的……然而后来给断了,懒得补上了,简单一点好了. Day 0 早早爬起来去赶高铁…… 路上没太多可以写的……坐高铁的时候想起来了一些不开心的事情 ...

  5. com.alibaba.fastjson.JSONObject循环给同一对象赋值会出现"$ref":"$[0]"现象问题

    1.今天定义了一个JSONObject对象,引用的com.alibaba.fastjson.JSONObject,循环给这个对象赋值出现"$ref":"$[0]" ...

  6. CSS 伪类(下)结构性伪类\UI伪类\动态伪类和其他伪类 valid check enable child required link visit

      伪类选择器汇总伪类选择器有4种, 结构性伪类\UI伪类\动态伪类和其他伪类. 具体如下 结构性伪类选择器结构性伪类选择器它能够根据元素在文档中的位置选择元素, 这类元素都有个前缀":&q ...

  7. .net C# Sql数据库SQLHelper类

    using System;using System.Collections.Generic;using System.Text;using System.Collections;using Syste ...

  8. Android架构设计之插件化、组件化

    如今移动app市场已经是百花齐放,其中有不乏有很多大型公司.巨型公司都是通过app创业发展起来的:app类型更加丰富,有电子商务.有视频.有社交.有工具等等,基本上涵盖了各行各业每个角落,为了更加具有 ...

  9. Spring事务管理入门与进阶

    事务管理 一个数据库事务是一个单一的工作单元操作序列.这些操作应该要么完整地执行,要么完全不执行.事务管理是一个重要组成部分,事务管理可以确保数据完整性和一致性.事务具有以下四个关键特性分别是 ACI ...

  10. java indexOf 和 split的用法

    1.java 的 indexOf 方法 ,如果存在 则 指定的字符串的开始位置,如果不存在 则返回-1: 2.java 的 split的方法:将一个字符串分割为子字符串,然后将结果作为字符串数组返回. ...