ethereumjs/ethereumjs-vm-5-vm对象

1.运行文件node

var Buffer = require('safe-buffer').Buffer // use for Node.js <4.5.0
var VM = require('./index.js')

// create a new VM instance
var vm = new VM({chain : 'rinkeby'})//设置链接的为Rinkeby链
console.log(vm);

 

2.分析返回的vm对象:json

VM {
  opts: { chain: 'rinkeby' },
  _common:
   Common {
     _chainParams:
      { name: 'rinkeby',
        chainId: 4,
        networkId: 4,
        comment: 'PoA test network',
        url: 'https://www.rinkeby.io',
        genesis:
         { hash:
            '0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177',
           timestamp: '0x58ee40ba',
           gasLimit: 4700000,
           difficulty: 1,
           nonce: '0x0000000000000000',
           extraData:
            '0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
           stateRoot:
            '0x53580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2d' },
        hardforks:
         [ { name: 'chainstart', block: 0, consensus: 'poa', finality: null },
           { name: 'homestead', block: 1, consensus: 'poa', finality: null },
           { name: 'dao', block: null, consensus: 'poa', finality: null },
           { name: 'tangerineWhistle',
             block: 2,
             consensus: 'poa',
             finality: null },
           { name: 'spuriousDragon',
             block: 3,
             consensus: 'poa',
             finality: null },
           { name: 'byzantium',
             block: 1035301,
             consensus: 'poa',
             finality: null },
           { name: 'constantinople',
             block: null,
             consensus: 'poa',
             finality: null },
           { name: 'hybridCasper',
             block: null,
             consensus: 'poa',
             finality: 'pos' } ],
        bootstrapNodes:
         [ { ip: '52.169.42.101',
             port: 30303,
             id:
              'a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf',
             location: 'IE',
             comment: '' },
           { ip: '52.3.158.184',
             port: 30303,
             id:
              '343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8',
             location: '',
             comment: 'INFURA' } ] },
     _hardfork: 'byzantium',
     _supportedHardforks: [ 'byzantium', 'constantinople' ] },
  stateManager:
   StateManager {
     _common:
      Common {
        _chainParams:
         { name: 'rinkeby',
           chainId: 4,
           networkId: 4,
           comment: 'PoA test network',
           url: 'https://www.rinkeby.io',
           genesis:
            { hash:
               '0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177',
              timestamp: '0x58ee40ba',
              gasLimit: 4700000,
              difficulty: 1,
              nonce: '0x0000000000000000',
              extraData:
               '0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
              stateRoot:
               '0x53580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2d' },
           hardforks://从这里能够看出到哪一个区块使用的是哪一个硬分叉的类型
            [ { name: 'chainstart', block: 0, consensus: 'poa', finality: null },//第0个,即初始区块使用的是chainstart 
              { name: 'homestead', block: 1, consensus: 'poa', finality: null },//第一个区块使用的是homestead
              { name: 'dao', block: null, consensus: 'poa', finality: null },//没有使用这种硬分叉类型
              { name: 'tangerineWhistle',//第二个区块使用的是tangerineWhistle
                block: 2,
                consensus: 'poa',
                finality: null },
              { name: 'spuriousDragon',//从三个区块到第1035300使用的是spuriousDragon
                block: 3,
                consensus: 'poa',
                finality: null },
              { name: 'byzantium',//从第1035301个区块到后面使用的都是该硬分叉,如今同步到的区块应该都是第1035301个区块以后的区块了,因此应该知足的都是byzantium硬分叉
                block: 1035301,
                consensus: 'poa',
                finality: null },
              { name: 'constantinople',//没有使用这种硬分叉类型
                block: null,
                consensus: 'poa',
                finality: null },
              { name: 'hybridCasper',//没有使用这种硬分叉类型
                block: null,
                consensus: 'poa',
                finality: 'pos' } ],
           bootstrapNodes://该区块链是经过链接该bootstrapNodes节点对应的区块链获得的,它会同步该节点上至今的全部区块,而后就可以在该Rinkeby区块链上进行操做了
            [ { ip: '52.169.42.101',
                port: 30303,
                id:
                 'a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf',
                location: 'IE',
                comment: '' },
              { ip: '52.3.158.184',
                port: 30303,
                id:
                 '343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8',
                location: '',
                comment: 'INFURA' } ] },
        _hardfork: 'byzantium',
        _supportedHardforks: [ 'byzantium', 'constantinople' ] },//设置的只支持的硬分叉
     _trie:
      SecureTrie {
        EMPTY_TRIE_ROOT:
         <Buffer 56 e8 1f 17 1b cc 55 a6 ff 83 45 e6 92 c0 f8 6e 5b 48 e0 1b 99 6c ad c0 01 62 2f b5 e3 63 b4 21>,
        sem:
         { capacity: 1,
           current: 0,
              .............................


                         buffer: true,
                         type: 'ucs-2' },
                      utf16le:
                       { encode: [Function: encode],
                         decode: [Function: decode],
                         buffer: true,
                         type: 'utf16le' },
                      'utf-16le':
                       { encode: [Function: encode],
                         decode: [Function: decode],
                         buffer: true,
                         type: 'utf-16le' } } },
                _status: 'opening',
                location: '',
                db:
                 DeferredLevelDOWN {
                   location: '',
                   status: 'new',
                   _db: undefined,
                   _operations: [],
                   _iterators: [] } } ],
           _root:
            <Buffer 56 e8 1f 17 1b cc 55 a6 ff 83 45 e6 92 c0 f8 6e 5b 48 e0 1b 99 6c ad c0 01 62 2f b5 e3 63 b4 21>,
           _scratch: null,
           _checkpoints: [],
           checkpoint: [Function: checkpoint],
           commit: [Function: commit],
           revert: [Function: revert],
           _enterCpMode: [Function: _enterCpMode],
           _exitCpMode: [Function: _exitCpMode],
           createScratchReadStream: [Function: createScratchReadStream],
           copy: [Function: bound copy],
           get: [Function: bound get],
           put: [Function: bound put],
           del: [Function: bound del] } },
     _touched: Set {},
     _touchedStack: [],
     _checkpointCount: 0 },
  blockchain:
   { fake: true,
     getBlock: [Function: getBlock],
     delBlock: [Function: delBlock],
     iterator: [Function: iterator] },
  allowUnlimitedContractSize: false,
  emitFreeLogs: false,
  _precompiled:
   { '0000000000000000000000000000000000000001': [Function],
     '0000000000000000000000000000000000000002': [Function],
     '0000000000000000000000000000000000000003': [Function],
     '0000000000000000000000000000000000000004': [Function],
     '0000000000000000000000000000000000000005': [Function],
     '0000000000000000000000000000000000000006': [Function],
     '0000000000000000000000000000000000000007': [Function],
     '0000000000000000000000000000000000000008': [Function] },
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }

从上面得知url: 'https://www.rinkeby.io',到该网站一查看:bootstrap

 

1)其提供的链接该Rinkeby链的方法为:网络

https://www.rinkeby.io/#geth区块链

geth --datadir=$HOME/.rinkeby init rinkeby.json

geth --networkid=4 --datadir=$HOME/.rinkeby --cache=1024 --syncmode=full --ethstats='yournode:Respect my authoritah!@stats.rinkeby.io' --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303

和vm返回对象中的bootstrapNodes值是相同的测试

 

2)从其提供的rinkeby.json-构造初始区块的文件获得:网站

{"config":{"chainId":4,"homesteadBlock":1,"eip150Block":2,"eip150Hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block":3,"eip158Block":3,"byzantiumBlock":1035301,"clique":{"period":15,"epoch":30000}},"nonce":"0x0","timestamp":"0x58ee40ba","extraData":"0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","gasLimit":"0x47b760","difficulty":"0x1","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000",.....

其的各个部署信息extraData、timestamp、gasLimit、difficulty等值都是相同的,说明vm上的区块链的初始区块和这个Rinkeby链的初始区块相同ui

从其byzantiumBlockhomesteadBlock值中设置的硬分叉位置也与vm上的区块链的硬分叉配置相同url

 

综上所述,说明设置的区块链链接的就是这个Rinkeby链,因此在该vm上交易或构建合约实际上就是运行在这个Rinkeby测试网络上spa

相关文章
相关标签/搜索