github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/1.0.0/blockchain.js (about)

     1  // Copyright (C) 2017 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  'use strict';
    20  
    21  var Blockchain = function () {
    22      Object.defineProperty(this, "nativeBlockchain", {
    23          configurable: false,
    24          enumerable: false,
    25          get: function(){
    26              return _native_blockchain;
    27          }
    28      });
    29  };
    30  
    31  Blockchain.prototype = {
    32      AccountAddress: 0x57,
    33      ContractAddress: 0x58,
    34  
    35      blockParse: function (str) {
    36          var block = JSON.parse(str);
    37          if (block != null) {
    38              var fb = Object.freeze(block);
    39              Object.defineProperty(this, "block", {
    40                  configurable: false,
    41                  enumerable: false,
    42                  get: function(){
    43                      return fb;
    44                  }
    45              });
    46          }
    47      },
    48      transactionParse: function (str) {
    49          var tx = JSON.parse(str);
    50          if (tx != null) {
    51              var value = tx.value === undefined || tx.value.length === 0 ? "0" : tx.value;
    52              tx.value = new BigNumber(value);
    53              var gasPrice = tx.gasPrice === undefined || tx.gasPrice.length === 0 ? "0" : tx.gasPrice;
    54              tx.gasPrice = new BigNumber(gasPrice);
    55              var gasLimit = tx.gasLimit === undefined || tx.gasLimit.length === 0 ? "0" : tx.gasLimit;
    56              tx.gasLimit = new BigNumber(gasLimit);
    57              
    58              var ft = Object.freeze(tx);
    59              Object.defineProperty(this, "transaction", {
    60                  configurable: false,
    61                  enumerable: false,
    62                  get: function(){
    63                      return ft;
    64                  }
    65              });
    66          }
    67      },
    68      transfer: function (address, value) {
    69          if (!(value instanceof BigNumber)) {
    70              value = new BigNumber(value);
    71          }
    72          var ret = this.nativeBlockchain.transfer(address, value.toString(10));
    73          return ret == 0;
    74      },
    75  
    76      verifyAddress: function (address) {
    77          return this.nativeBlockchain.verifyAddress(address);
    78      }
    79  };
    80  module.exports = new Blockchain();