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

相關文章
相關標籤/搜索