github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/test/contract_require.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  //_native_require("../../../../../../../../etc/");
    21  //_native_require("assert");
    22  //require("\x00");
    23  //_native_require("lib");
    24  //var FS = require("fs");
    25  var Allowed = function (obj) {
    26      this.allowed = {};
    27      this.parse(obj);
    28  }
    29  
    30  Allowed.prototype = {
    31      toString: function () {
    32          return JSON.stringify(this.allowed);
    33      },
    34  
    35      parse: function (obj) {
    36          if (typeof obj != "undefined") {
    37              var data = JSON.parse(obj);
    38              for (var key in data) {
    39                  this.allowed[key] = new BigNumber(data[key]);
    40              }
    41          }
    42      },
    43  
    44      get: function (key) {
    45          return this.allowed[key];
    46      },
    47  
    48      set: function (key, value) {
    49          this.allowed[key] = new BigNumber(value);
    50      }
    51  }
    52  
    53  var StandardToken = function () {
    54      LocalContractStorage.defineProperties(this, {
    55          _name: null,
    56          _symbol: null,
    57          _decimals: null,
    58          _totalSupply: {
    59              parse: function (value) {
    60                  return new BigNumber(value);
    61              },
    62              stringify: function (o) {
    63                  return o.toString(10);
    64              }
    65          }
    66      });
    67  
    68      LocalContractStorage.defineMapProperties(this, {
    69          "balances": {
    70              parse: function (value) {
    71                  return new BigNumber(value);
    72              },
    73              stringify: function (o) {
    74                  return o.toString(10);
    75              }
    76          },
    77          "allowed": {
    78              parse: function (value) {
    79                  return new Allowed(value);
    80              },
    81              stringify: function (o) {
    82                  return o.toString();
    83              }
    84          }
    85      });
    86  };
    87  
    88  StandardToken.prototype = {
    89      init: function (name, symbol, decimals, totalSupply) {
    90          this._name = name;
    91          this._symbol = symbol;
    92          this._decimals = decimals | 0;
    93          this._totalSupply = new BigNumber(totalSupply).mul(new BigNumber(10).pow(decimals));
    94  
    95          var from = Blockchain.transaction.from;
    96          this.balances.set(from, this._totalSupply);
    97      },
    98  
    99      // Returns the name of the token
   100      name: function () {
   101          return this._name;
   102      },
   103  
   104      // Returns the symbol of the token
   105      symbol: function () {
   106          return this._symbol;
   107      },
   108  
   109      // Returns the number of decimals the token uses
   110      decimals: function () {
   111          return this._decimals;
   112      },
   113  
   114      totalSupply: function () {
   115          return this._totalSupply.toString(10);
   116      },
   117      requireNULL: function (owner) {
   118          require("\x00");
   119      },
   120      requireNotExistPath: function (owner) {
   121          _native_require("../../../../../../../../etc/");
   122      },
   123      requireCurPath: function (owner) {
   124          _native_require("lib");
   125      },
   126      requireNotExistFile: function (owner) {
   127          _native_require("lib.js");
   128      },
   129  };
   130  
   131  module.exports = StandardToken;